-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathstream-global-state-ws.ts
More file actions
36 lines (30 loc) · 942 Bytes
/
stream-global-state-ws.ts
File metadata and controls
36 lines (30 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { DFUSE_API_KEY, runMain, DFUSE_API_NETWORK } from "../../config"
import {
createDfuseClient,
InboundMessage,
InboundMessageType,
waitFor,
TableDeltaData,
} from "@dfuse/client"
async function main(): Promise<void> {
const client = createDfuseClient({
apiKey: DFUSE_API_KEY,
network: DFUSE_API_NETWORK,
})
const stream = await client.streamTableRows(
{ code: "eosio", scope: "eosio", table: "global" },
(message: InboundMessage) => {
if (message.type === InboundMessageType.TABLE_DELTA) {
const { dbop, block_num } = message.data as TableDeltaData
const { total_ram_stake, total_unpaid_blocks } = dbop.new?.json
console.log(
`Global state change @ #${block_num} [Total RAM Stake ${total_ram_stake}, Total Unpaid Block Count ${total_unpaid_blocks}]`
)
}
}
)
await waitFor(5000)
await stream.close()
client.release()
}
runMain(main)