forked from discord/discord-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfuse.js
33 lines (28 loc) · 1.09 KB
/
dfuse.js
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
import 'dotenv/config';
export default async function dfuseClient(client) {
const streamTransfer = `subscription($cursor: String!) {
searchTransactionsForward(query: "receiver:eosio.token action:transfer -data.quantity:'0.0001 EOS'", cursor: $cursor) {
undo cursor
trace {
matchingActions { json }
}
}
}`
await client.graphql(streamTransfer, (message, stream) => {
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 }) => {
const { from, to, quantity, memo } = json
console.log(`Transfer [${from} -> ${to}, ${quantity}] (${memo})`)
})
stream.mark({ cursor: data.cursor })
}
if (message.type === "complete") {
console.log("Stream completed")
}
})
}