forked from dfuse-io/client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfuse-for-eosio.ts
59 lines (49 loc) · 1.54 KB
/
dfuse-for-eosio.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { runMain } from "../../config"
import { createDfuseClient, waitFor } from "@dfuse/client"
/**
* This shows how to configure the `client-js` instance when working with
* a locally dfuse instance running through `dfuseeos` binary using the
* standard configuration.
*
* This example assumes you have dfuse for EOSIO running
* (https://github.com/dfuse-io/dfuse-eosio#getting-started) using the standard
* configuration.
*/
async function main(): Promise<void> {
const client = createDfuseClient({
network: "localhost:8080",
authentication: false,
secure: false,
})
const streamTransfer = `subscription($cursor: String!) {
searchTransactionsForward(query: "receiver:eosio action:onblock", cursor: $cursor) {
undo cursor
trace {
matchingActions { json }
}
}
}`
const stream = await client.graphql(streamTransfer, (message) => {
if (message.type === "error") {
console.log("An error occurred", message.errors, message.terminal)
}
if (message.type === "data") {
const data = message.data.searchTransactionsForward
const actions = data.trace.matchingActions
actions.forEach(({ json }: any) => {
const {
header: { timestamp: timeSlot, producer },
} = json
console.log(`Action [${producer} @ ${timeSlot}]`)
})
stream.mark({ cursor: data.cursor })
}
if (message.type === "complete") {
console.log("Stream completed")
}
})
await waitFor(5000)
await stream.close()
client.release()
}
runMain(main)