forked from dfuse-io/client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream-action-traces.ts
84 lines (76 loc) · 2.58 KB
/
stream-action-traces.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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.streamActionTraces(
{
accounts: "eosio.token|thekarmadapp|trustdicewin",
with_inline_traces: true,
with_dbops: true,
with_dtrxops: true,
with_ramops: true,
// Don't confuse with `dbops`, this one streams smart contract's table creation/removal, not changes to rows!
with_tableops: true,
},
(message: InboundMessage<any>) => {
if (message.type === InboundMessageType.LISTENING) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.ACTION_TRACE) {
/**
* JSON examples of various fields possibilities (since they might
* not always appear in the streaming time frame):
*
* ```
* {
* dbops: [
* // An `ActionTraceDbOp` row update operation
* {
* "op": "UPD",
* "action_idx": 8,
* "opayer": "eosbetbank11",
* "npayer": "eosbetbank11",
* "path": "eosio.token/eosbetbank11/accounts/........ehbo5",
* "old": "d11a231c0000000004454f5300000000",
* "new": "cd1a231c0000000004454f5300000000"
* },
*
* // An `ActionTraceDbOp` row insertion operation
* {
* "op": "INS",
* "action_idx": 0,
* "npayer": "hj1111111534",
* "path": "eosio.token/hj1111111125/accounts/........ehbo5",
* "new": "c02709000000000004454f5300000000"
* }
*
* // An `ActionTraceDbOp` row removal operation
* {
* "op": "REM",
* "action_idx": 2,
* "opayer": "trustdicewin",
* "path": "trustdicewin/trustdicewin/hash/......1iwm13h",
* "old": "90bd994111e45fc947f7f7d4823081cdf13d05c12f31bf2049aec55e170aa0bcbf66c85c00000000"
* },
* ]
* }
* ```
*/
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.ERROR) {
console.log(prettifyJson(message.data))
return
}
}
)
await waitFor(15000)
await stream.close()
client.release()
}
runMain(main)