forked from dfuse-io/client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream-table-rows.ts
42 lines (34 loc) · 1.08 KB
/
stream-table-rows.ts
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
37
38
39
40
41
42
import { DFUSE_API_KEY, runMain, DFUSE_API_NETWORK, prettifyJson } from "../../config"
import { createDfuseClient, InboundMessage, InboundMessageType, waitFor } 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.LISTENING) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.TABLE_SNAPSHOT) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.TABLE_DELTA) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.ERROR) {
console.log(prettifyJson(message.data))
return
}
},
{ fetch: true }
)
await waitFor(15000)
await stream.close()
client.release()
}
runMain(main)