@o1-labs/mina-archive-node-graphql 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +321 -0
- package/build/benchmark/setup.js +32 -0
- package/build/benchmark/setup.js.map +1 -0
- package/build/src/blockchain/constants.js +2 -0
- package/build/src/blockchain/constants.js.map +1 -0
- package/build/src/blockchain/types.js +7 -0
- package/build/src/blockchain/types.js.map +1 -0
- package/build/src/blockchain/utils.js +39 -0
- package/build/src/blockchain/utils.js.map +1 -0
- package/build/src/consensus/mina-consensus.js +59 -0
- package/build/src/consensus/mina-consensus.js.map +1 -0
- package/build/src/context.js +10 -0
- package/build/src/context.js.map +1 -0
- package/build/src/db/archive-node-adapter/archive-node-adapter.interface.js +2 -0
- package/build/src/db/archive-node-adapter/archive-node-adapter.interface.js.map +1 -0
- package/build/src/db/archive-node-adapter/archive-node-adapter.js +47 -0
- package/build/src/db/archive-node-adapter/archive-node-adapter.js.map +1 -0
- package/build/src/db/sql/events-actions/queries.js +438 -0
- package/build/src/db/sql/events-actions/queries.js.map +1 -0
- package/build/src/db/sql/events-actions/types.js +2 -0
- package/build/src/db/sql/events-actions/types.js.map +1 -0
- package/build/src/errors/error.js +17 -0
- package/build/src/errors/error.js.map +1 -0
- package/build/src/index.js +27 -0
- package/build/src/index.js.map +1 -0
- package/build/src/resolvers-types.js +8 -0
- package/build/src/resolvers-types.js.map +1 -0
- package/build/src/resolvers.js +67 -0
- package/build/src/resolvers.js.map +1 -0
- package/build/src/server/plugins.js +39 -0
- package/build/src/server/plugins.js.map +1 -0
- package/build/src/server/server.js +25 -0
- package/build/src/server/server.js.map +1 -0
- package/build/src/services/actions-service/actions-service.interface.js +2 -0
- package/build/src/services/actions-service/actions-service.interface.js.map +1 -0
- package/build/src/services/actions-service/actions-service.js +94 -0
- package/build/src/services/actions-service/actions-service.js.map +1 -0
- package/build/src/services/blocks-service/blocks-service.interface.js +2 -0
- package/build/src/services/blocks-service/blocks-service.interface.js.map +1 -0
- package/build/src/services/blocks-service/blocks-service.js +263 -0
- package/build/src/services/blocks-service/blocks-service.js.map +1 -0
- package/build/src/services/data-adapters/database-row-adapters.js +116 -0
- package/build/src/services/data-adapters/database-row-adapters.js.map +1 -0
- package/build/src/services/events-service/events-service.interface.js +2 -0
- package/build/src/services/events-service/events-service.interface.js.map +1 -0
- package/build/src/services/events-service/events-service.js +64 -0
- package/build/src/services/events-service/events-service.js.map +1 -0
- package/build/src/services/network-service/network-service.interface.js +2 -0
- package/build/src/services/network-service/network-service.interface.js.map +1 -0
- package/build/src/services/network-service/network-service.js +31 -0
- package/build/src/services/network-service/network-service.js.map +1 -0
- package/build/src/tracing/jaeger-setup.js +39 -0
- package/build/src/tracing/jaeger-setup.js.map +1 -0
- package/build/src/tracing/jaeger-tracing.js +29 -0
- package/build/src/tracing/jaeger-tracing.js.map +1 -0
- package/build/src/tracing/tracer.js +31 -0
- package/build/src/tracing/tracer.js.map +1 -0
- package/build/tests/__mocks__/generate_mock_data.js +13 -0
- package/build/tests/__mocks__/generate_mock_data.js.map +1 -0
- package/build/tests/consensus/run-compare.js +40 -0
- package/build/tests/consensus/run-compare.js.map +1 -0
- package/build/tests/consensus/select-consensus-precomputed.js +80 -0
- package/build/tests/consensus/select-consensus-precomputed.js.map +1 -0
- package/build/tests/consensus/types.js +15 -0
- package/build/tests/consensus/types.js.map +1 -0
- package/build/tests/devnet-dump/devnet-dump.test.js +311 -0
- package/build/tests/devnet-dump/devnet-dump.test.js.map +1 -0
- package/build/tests/devnet-dump/setup.js +58 -0
- package/build/tests/devnet-dump/setup.js.map +1 -0
- package/build/tests/integration/integration.test.js +226 -0
- package/build/tests/integration/integration.test.js.map +1 -0
- package/build/tests/integration/setup.js +82 -0
- package/build/tests/integration/setup.js.map +1 -0
- package/build/tests/live-api/actions.test.js +4 -0
- package/build/tests/live-api/actions.test.js.map +1 -0
- package/build/tests/live-api/blocks.test.js +116 -0
- package/build/tests/live-api/blocks.test.js.map +1 -0
- package/build/tests/live-api/events.test.js +97 -0
- package/build/tests/live-api/events.test.js.map +1 -0
- package/build/tests/live-api/networkState.test.js +27 -0
- package/build/tests/live-api/networkState.test.js.map +1 -0
- package/build/tests/live-network/live-network.test.js +144 -0
- package/build/tests/live-network/live-network.test.js.map +1 -0
- package/build/tests/live-network/setup.js +206 -0
- package/build/tests/live-network/setup.js.map +1 -0
- package/build/tests/resolvers.test.js +475 -0
- package/build/tests/resolvers.test.js.map +1 -0
- package/build/tests/services/actions-service/actions-service.test.js +124 -0
- package/build/tests/services/actions-service/actions-service.test.js.map +1 -0
- package/build/tests/services/blocks-service/blocks-service.test.js +348 -0
- package/build/tests/services/blocks-service/blocks-service.test.js.map +1 -0
- package/build/tests/services/events-service/events-service.test.js +185 -0
- package/build/tests/services/events-service/events-service.test.js.map +1 -0
- package/build/tests/test-helpers.js +11 -0
- package/build/tests/test-helpers.js.map +1 -0
- package/build/tests/unit/blockchain-utils.test.js +106 -0
- package/build/tests/unit/blockchain-utils.test.js.map +1 -0
- package/build/tests/unit/consensus.test.js +154 -0
- package/build/tests/unit/consensus.test.js.map +1 -0
- package/build/tests/unit/error-handling.test.js +52 -0
- package/build/tests/unit/error-handling.test.js.map +1 -0
- package/build/tests/utils.test.js +313 -0
- package/build/tests/utils.test.js.map +1 -0
- package/build/zkapp/contract.js +144 -0
- package/build/zkapp/contract.js.map +1 -0
- package/build/zkapp/utils.js +174 -0
- package/build/zkapp/utils.js.map +1 -0
- package/package.json +85 -0
- package/schema.graphql +221 -0
- package/src/blockchain/constants.ts +2 -0
- package/src/blockchain/types.ts +121 -0
- package/src/blockchain/utils.ts +54 -0
- package/src/consensus/mina-consensus.ts +137 -0
- package/src/context.ts +18 -0
- package/src/db/archive-node-adapter/archive-node-adapter.interface.ts +23 -0
- package/src/db/archive-node-adapter/archive-node-adapter.ts +101 -0
- package/src/db/sql/events-actions/queries.ts +490 -0
- package/src/db/sql/events-actions/types.ts +208 -0
- package/src/envionment.d.ts +18 -0
- package/src/errors/error.ts +20 -0
- package/src/index.ts +31 -0
- package/src/resolvers-types.ts +754 -0
- package/src/resolvers.ts +102 -0
- package/src/server/plugins.ts +56 -0
- package/src/server/server.ts +30 -0
- package/src/services/actions-service/actions-service.interface.ts +9 -0
- package/src/services/actions-service/actions-service.ts +195 -0
- package/src/services/blocks-service/blocks-service.interface.ts +11 -0
- package/src/services/blocks-service/blocks-service.ts +407 -0
- package/src/services/data-adapters/database-row-adapters.ts +261 -0
- package/src/services/events-service/events-service.interface.ts +6 -0
- package/src/services/events-service/events-service.ts +118 -0
- package/src/services/network-service/network-service.interface.ts +5 -0
- package/src/services/network-service/network-service.ts +53 -0
- package/src/tracing/jaeger-setup.ts +65 -0
- package/src/tracing/jaeger-tracing.ts +44 -0
- package/src/tracing/tracer.ts +52 -0
- package/tsconfig.json +104 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import type postgres from 'postgres';
|
|
2
|
+
import { ArchiveNodeDatabaseRow } from './types.js';
|
|
3
|
+
import { BlockStatusFilter } from '../../../blockchain/types.js';
|
|
4
|
+
import { BLOCK_RANGE_SIZE } from '../../../server/server.js';
|
|
5
|
+
|
|
6
|
+
function fullChainCTE(db_client: postgres.Sql, from?: string, to?: string) {
|
|
7
|
+
let toAsNum = to ? Number(to) : undefined;
|
|
8
|
+
let fromAsNum = from ? Number(from) : undefined;
|
|
9
|
+
if (fromAsNum) {
|
|
10
|
+
const maxRange = fromAsNum + BLOCK_RANGE_SIZE;
|
|
11
|
+
toAsNum = toAsNum ? Math.min(toAsNum, maxRange) : maxRange;
|
|
12
|
+
} else if (toAsNum) {
|
|
13
|
+
fromAsNum = toAsNum - BLOCK_RANGE_SIZE;
|
|
14
|
+
}
|
|
15
|
+
return db_client`
|
|
16
|
+
RECURSIVE pending_chain AS (
|
|
17
|
+
(
|
|
18
|
+
SELECT
|
|
19
|
+
id, state_hash, parent_hash, parent_id, height, global_slot_since_genesis, global_slot_since_hard_fork, timestamp, chain_status, ledger_hash, last_vrf_output
|
|
20
|
+
FROM
|
|
21
|
+
blocks b
|
|
22
|
+
WHERE
|
|
23
|
+
height = (SELECT max(height) FROM blocks)
|
|
24
|
+
)
|
|
25
|
+
UNION ALL
|
|
26
|
+
SELECT
|
|
27
|
+
b.id, b.state_hash, b.parent_hash, b.parent_id, b.height, b.global_slot_since_genesis, b.global_slot_since_hard_fork, b.timestamp, b.chain_status, b.ledger_hash, b.last_vrf_output
|
|
28
|
+
FROM
|
|
29
|
+
blocks b
|
|
30
|
+
INNER JOIN pending_chain ON b.id = pending_chain.parent_id
|
|
31
|
+
AND pending_chain.id <> pending_chain.parent_id
|
|
32
|
+
AND pending_chain.chain_status <> 'canonical'
|
|
33
|
+
),
|
|
34
|
+
full_chain AS (
|
|
35
|
+
SELECT
|
|
36
|
+
DISTINCT id, state_hash, parent_id, parent_hash, height, global_slot_since_genesis, global_slot_since_hard_fork, timestamp, chain_status, ledger_hash, (SELECT max(height) FROM blocks) - height AS distance_from_max_block_height, last_vrf_output
|
|
37
|
+
FROM
|
|
38
|
+
(
|
|
39
|
+
SELECT
|
|
40
|
+
id, state_hash, parent_id, parent_hash, height, global_slot_since_genesis, global_slot_since_hard_fork, timestamp, chain_status, ledger_hash, last_vrf_output
|
|
41
|
+
FROM
|
|
42
|
+
pending_chain
|
|
43
|
+
WHERE 1=1
|
|
44
|
+
${
|
|
45
|
+
// If fromAsNum is not undefined, then we have also set toAsNum and can safely query the range
|
|
46
|
+
// If no params ar provided, then we query the last BLOCK_RANGE_SIZE blocks
|
|
47
|
+
fromAsNum
|
|
48
|
+
? db_client`AND height >= ${fromAsNum} AND height < ${toAsNum!}`
|
|
49
|
+
: db_client`AND height >= (
|
|
50
|
+
SELECT MAX(height)
|
|
51
|
+
FROM pending_chain
|
|
52
|
+
) - ${BLOCK_RANGE_SIZE}`
|
|
53
|
+
}
|
|
54
|
+
UNION ALL
|
|
55
|
+
SELECT
|
|
56
|
+
id, state_hash, parent_id, parent_hash, height, global_slot_since_genesis, global_slot_since_hard_fork, timestamp, chain_status, ledger_hash, last_vrf_output
|
|
57
|
+
FROM
|
|
58
|
+
blocks b
|
|
59
|
+
WHERE
|
|
60
|
+
chain_status = 'canonical'
|
|
61
|
+
${
|
|
62
|
+
// If fromAsNum is not undefined, then we have also set toAsNum and can safely query the range
|
|
63
|
+
// If no params ar provided, then we query the last BLOCK_RANGE_SIZE blocks
|
|
64
|
+
fromAsNum
|
|
65
|
+
? db_client`AND b.height >= ${fromAsNum} AND b.height < ${toAsNum!}`
|
|
66
|
+
: db_client`AND b.height >= (
|
|
67
|
+
SELECT MAX(b2.height)
|
|
68
|
+
FROM blocks b2
|
|
69
|
+
) - ${BLOCK_RANGE_SIZE}`
|
|
70
|
+
}
|
|
71
|
+
) AS full_chain
|
|
72
|
+
)
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function accountIdentifierCTE(
|
|
77
|
+
db_client: postgres.Sql,
|
|
78
|
+
address: string,
|
|
79
|
+
tokenId: string
|
|
80
|
+
) {
|
|
81
|
+
return db_client`
|
|
82
|
+
account_identifier AS (
|
|
83
|
+
SELECT
|
|
84
|
+
id AS requesting_zkapp_account_identifier_id
|
|
85
|
+
FROM
|
|
86
|
+
account_identifiers ai
|
|
87
|
+
WHERE
|
|
88
|
+
ai.public_key_id = (SELECT id FROM public_keys WHERE value = ${address})
|
|
89
|
+
AND
|
|
90
|
+
ai.token_id = (SELECT id FROM tokens WHERE value = ${tokenId})
|
|
91
|
+
)`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function blocksAccessedCTE(db_client: postgres.Sql, status: BlockStatusFilter) {
|
|
95
|
+
return db_client`
|
|
96
|
+
blocks_accessed AS
|
|
97
|
+
(
|
|
98
|
+
SELECT
|
|
99
|
+
requesting_zkapp_account_identifier_id,
|
|
100
|
+
block_id,
|
|
101
|
+
account_identifier_id,
|
|
102
|
+
zkapp_id,
|
|
103
|
+
id AS account_access_id,
|
|
104
|
+
state_hash,
|
|
105
|
+
parent_hash,
|
|
106
|
+
height,
|
|
107
|
+
global_slot_since_genesis,
|
|
108
|
+
global_slot_since_hard_fork,
|
|
109
|
+
timestamp,
|
|
110
|
+
chain_status,
|
|
111
|
+
ledger_hash,
|
|
112
|
+
distance_from_max_block_height,
|
|
113
|
+
last_vrf_output
|
|
114
|
+
FROM
|
|
115
|
+
account_identifier ai
|
|
116
|
+
INNER JOIN accounts_accessed aa ON ai.requesting_zkapp_account_identifier_id = aa.account_identifier_id
|
|
117
|
+
INNER JOIN full_chain b ON aa.block_id = b.id
|
|
118
|
+
WHERE
|
|
119
|
+
1 = 1
|
|
120
|
+
${
|
|
121
|
+
status === BlockStatusFilter.all
|
|
122
|
+
? db_client``
|
|
123
|
+
: db_client`AND chain_status = ${status.toLowerCase()}`
|
|
124
|
+
}
|
|
125
|
+
)`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function emittedZkAppCommandsCTE(db_client: postgres.Sql) {
|
|
129
|
+
return db_client`
|
|
130
|
+
emitted_zkapp_commands AS (
|
|
131
|
+
SELECT
|
|
132
|
+
blocks_accessed.requesting_zkapp_account_identifier_id,
|
|
133
|
+
blocks_accessed.block_id,
|
|
134
|
+
blocks_accessed.account_identifier_id,
|
|
135
|
+
blocks_accessed.zkapp_id,
|
|
136
|
+
blocks_accessed.account_access_id,
|
|
137
|
+
blocks_accessed.state_hash,
|
|
138
|
+
blocks_accessed.parent_hash,
|
|
139
|
+
blocks_accessed.height,
|
|
140
|
+
blocks_accessed.global_slot_since_genesis,
|
|
141
|
+
blocks_accessed.global_slot_since_hard_fork,
|
|
142
|
+
blocks_accessed.timestamp,
|
|
143
|
+
blocks_accessed.chain_status,
|
|
144
|
+
blocks_accessed.ledger_hash,
|
|
145
|
+
blocks_accessed.distance_from_max_block_height,
|
|
146
|
+
blocks_accessed.last_vrf_output,
|
|
147
|
+
zkcu.id AS zkapp_account_update_id,
|
|
148
|
+
bzkc.sequence_no AS sequence_number,
|
|
149
|
+
zkapp_fee_payer_body_id,
|
|
150
|
+
zkapp_account_updates_ids,
|
|
151
|
+
authorization_kind,
|
|
152
|
+
status,
|
|
153
|
+
memo,
|
|
154
|
+
hash,
|
|
155
|
+
body_id,
|
|
156
|
+
events_id,
|
|
157
|
+
actions_id
|
|
158
|
+
FROM
|
|
159
|
+
blocks_accessed
|
|
160
|
+
INNER JOIN blocks_zkapp_commands bzkc ON blocks_accessed.block_id = bzkc.block_id
|
|
161
|
+
INNER JOIN zkapp_commands zkc ON bzkc.zkapp_command_id = zkc.id
|
|
162
|
+
INNER JOIN zkapp_account_update zkcu ON zkcu.id = ANY(zkc.zkapp_account_updates_ids)
|
|
163
|
+
INNER JOIN zkapp_account_update_body zkcu_body ON zkcu_body.id = zkcu.body_id
|
|
164
|
+
AND zkcu_body.account_identifier_id = requesting_zkapp_account_identifier_id
|
|
165
|
+
WHERE
|
|
166
|
+
bzkc.status <> 'failed'
|
|
167
|
+
)`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function emittedEventsCTE(db_client: postgres.Sql) {
|
|
171
|
+
return db_client`
|
|
172
|
+
emitted_events AS (
|
|
173
|
+
SELECT
|
|
174
|
+
emitted_zkapp_commands.requesting_zkapp_account_identifier_id,
|
|
175
|
+
emitted_zkapp_commands.block_id,
|
|
176
|
+
emitted_zkapp_commands.account_identifier_id,
|
|
177
|
+
emitted_zkapp_commands.zkapp_id,
|
|
178
|
+
emitted_zkapp_commands.account_access_id,
|
|
179
|
+
emitted_zkapp_commands.state_hash,
|
|
180
|
+
emitted_zkapp_commands.parent_hash,
|
|
181
|
+
emitted_zkapp_commands.height,
|
|
182
|
+
emitted_zkapp_commands.global_slot_since_genesis,
|
|
183
|
+
emitted_zkapp_commands.global_slot_since_hard_fork,
|
|
184
|
+
emitted_zkapp_commands.timestamp,
|
|
185
|
+
emitted_zkapp_commands.chain_status,
|
|
186
|
+
emitted_zkapp_commands.ledger_hash,
|
|
187
|
+
emitted_zkapp_commands.distance_from_max_block_height,
|
|
188
|
+
emitted_zkapp_commands.last_vrf_output,
|
|
189
|
+
emitted_zkapp_commands.zkapp_account_update_id,
|
|
190
|
+
emitted_zkapp_commands.sequence_number,
|
|
191
|
+
emitted_zkapp_commands.zkapp_fee_payer_body_id,
|
|
192
|
+
emitted_zkapp_commands.zkapp_account_updates_ids,
|
|
193
|
+
emitted_zkapp_commands.authorization_kind,
|
|
194
|
+
emitted_zkapp_commands.status,
|
|
195
|
+
emitted_zkapp_commands.memo,
|
|
196
|
+
emitted_zkapp_commands.hash,
|
|
197
|
+
emitted_zkapp_commands.body_id,
|
|
198
|
+
emitted_zkapp_commands.events_id,
|
|
199
|
+
emitted_zkapp_commands.actions_id,
|
|
200
|
+
zke.id AS account_update_event_id,
|
|
201
|
+
zke.element_ids AS event_element_ids,
|
|
202
|
+
zkfa.element_ids AS event_field_element_ids,
|
|
203
|
+
zkfa.id AS event_field_elements_id,
|
|
204
|
+
zkf.id AS field_id,
|
|
205
|
+
zkf.field AS field_value
|
|
206
|
+
FROM
|
|
207
|
+
emitted_zkapp_commands
|
|
208
|
+
INNER JOIN zkapp_events zke ON zke.id = emitted_zkapp_commands.events_id
|
|
209
|
+
INNER JOIN zkapp_field_array zkfa ON zkfa.id = ANY(zke.element_ids)
|
|
210
|
+
INNER JOIN zkapp_field zkf ON zkf.id = ANY(zkfa.element_ids)
|
|
211
|
+
)
|
|
212
|
+
`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function emittedActionsCTE(db_client: postgres.Sql) {
|
|
216
|
+
return db_client`
|
|
217
|
+
emitted_actions AS (
|
|
218
|
+
SELECT
|
|
219
|
+
emitted_zkapp_commands.block_id,
|
|
220
|
+
emitted_zkapp_commands.zkapp_id,
|
|
221
|
+
emitted_zkapp_commands.state_hash,
|
|
222
|
+
emitted_zkapp_commands.parent_hash,
|
|
223
|
+
emitted_zkapp_commands.height,
|
|
224
|
+
emitted_zkapp_commands.global_slot_since_genesis,
|
|
225
|
+
emitted_zkapp_commands.global_slot_since_hard_fork,
|
|
226
|
+
emitted_zkapp_commands.timestamp,
|
|
227
|
+
emitted_zkapp_commands.chain_status,
|
|
228
|
+
emitted_zkapp_commands.ledger_hash,
|
|
229
|
+
emitted_zkapp_commands.distance_from_max_block_height,
|
|
230
|
+
emitted_zkapp_commands.last_vrf_output,
|
|
231
|
+
emitted_zkapp_commands.zkapp_account_update_id,
|
|
232
|
+
emitted_zkapp_commands.sequence_number,
|
|
233
|
+
emitted_zkapp_commands.zkapp_fee_payer_body_id,
|
|
234
|
+
emitted_zkapp_commands.zkapp_account_updates_ids,
|
|
235
|
+
emitted_zkapp_commands.authorization_kind,
|
|
236
|
+
emitted_zkapp_commands.status,
|
|
237
|
+
emitted_zkapp_commands.memo,
|
|
238
|
+
emitted_zkapp_commands.hash,
|
|
239
|
+
emitted_zkapp_commands.body_id,
|
|
240
|
+
emitted_zkapp_commands.events_id,
|
|
241
|
+
emitted_zkapp_commands.actions_id,
|
|
242
|
+
zke.id AS account_update_event_id,
|
|
243
|
+
zke.element_ids AS event_element_ids,
|
|
244
|
+
zkfa.element_ids AS event_field_element_ids,
|
|
245
|
+
zkfa.id AS event_field_elements_id,
|
|
246
|
+
zkf.id AS field_id,
|
|
247
|
+
zkf.field AS field_value
|
|
248
|
+
FROM
|
|
249
|
+
emitted_zkapp_commands
|
|
250
|
+
INNER JOIN zkapp_events zke ON zke.id = emitted_zkapp_commands.actions_id
|
|
251
|
+
INNER JOIN zkapp_field_array zkfa ON zkfa.id = ANY(zke.element_ids)
|
|
252
|
+
INNER JOIN zkapp_field zkf ON zkf.id = ANY(zkfa.element_ids)
|
|
253
|
+
)
|
|
254
|
+
`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function emittedActionStateCTE(
|
|
258
|
+
db_client: postgres.Sql,
|
|
259
|
+
fromActionState?: string,
|
|
260
|
+
endActionState?: string
|
|
261
|
+
) {
|
|
262
|
+
return db_client`
|
|
263
|
+
emitted_action_state AS (
|
|
264
|
+
SELECT
|
|
265
|
+
zkf0.field AS action_state_value1,
|
|
266
|
+
zkf1.field AS action_state_value2,
|
|
267
|
+
zkf2.field AS action_state_value3,
|
|
268
|
+
zkf3.field AS action_state_value4,
|
|
269
|
+
zkf4.field AS action_state_value5,
|
|
270
|
+
emitted_actions.last_vrf_output,
|
|
271
|
+
emitted_actions.block_id,
|
|
272
|
+
emitted_actions.zkapp_id,
|
|
273
|
+
emitted_actions.state_hash,
|
|
274
|
+
emitted_actions.parent_hash,
|
|
275
|
+
emitted_actions.height,
|
|
276
|
+
emitted_actions.global_slot_since_genesis,
|
|
277
|
+
emitted_actions.global_slot_since_hard_fork,
|
|
278
|
+
emitted_actions.timestamp,
|
|
279
|
+
emitted_actions.chain_status,
|
|
280
|
+
emitted_actions.ledger_hash,
|
|
281
|
+
emitted_actions.distance_from_max_block_height,
|
|
282
|
+
emitted_actions.last_vrf_output,
|
|
283
|
+
emitted_actions.zkapp_account_update_id,
|
|
284
|
+
emitted_actions.sequence_number,
|
|
285
|
+
emitted_actions.zkapp_fee_payer_body_id,
|
|
286
|
+
emitted_actions.zkapp_account_updates_ids,
|
|
287
|
+
emitted_actions.authorization_kind,
|
|
288
|
+
emitted_actions.status,
|
|
289
|
+
emitted_actions.memo,
|
|
290
|
+
emitted_actions.hash,
|
|
291
|
+
emitted_actions.body_id,
|
|
292
|
+
emitted_actions.events_id,
|
|
293
|
+
emitted_actions.actions_id,
|
|
294
|
+
emitted_actions.account_update_event_id,
|
|
295
|
+
emitted_actions.event_element_ids,
|
|
296
|
+
emitted_actions.event_field_element_ids,
|
|
297
|
+
emitted_actions.event_field_elements_id,
|
|
298
|
+
emitted_actions.field_id,
|
|
299
|
+
emitted_actions.field_value
|
|
300
|
+
FROM
|
|
301
|
+
emitted_actions
|
|
302
|
+
INNER JOIN zkapp_accounts zkacc ON zkacc.id = emitted_actions.zkapp_id
|
|
303
|
+
INNER JOIN zkapp_action_states zks ON zks.id = zkacc.action_state_id
|
|
304
|
+
INNER JOIN zkapp_field zkf0 ON zkf0.id = zks.element0
|
|
305
|
+
INNER JOIN zkapp_field zkf1 ON zkf1.id = zks.element1
|
|
306
|
+
INNER JOIN zkapp_field zkf2 ON zkf2.id = zks.element2
|
|
307
|
+
INNER JOIN zkapp_field zkf3 ON zkf3.id = zks.element3
|
|
308
|
+
INNER JOIN zkapp_field zkf4 ON zkf4.id = zks.element4
|
|
309
|
+
WHERE
|
|
310
|
+
1 = 1
|
|
311
|
+
${
|
|
312
|
+
fromActionState
|
|
313
|
+
? db_client`AND zkf0.id >= (SELECT id FROM zkapp_field WHERE field = ${fromActionState})`
|
|
314
|
+
: db_client``
|
|
315
|
+
}
|
|
316
|
+
${
|
|
317
|
+
endActionState
|
|
318
|
+
? db_client`AND zkf0.id <= (SELECT id FROM zkapp_field WHERE field = ${endActionState})`
|
|
319
|
+
: db_client``
|
|
320
|
+
}
|
|
321
|
+
)`;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function getEventsQuery(
|
|
325
|
+
db_client: postgres.Sql,
|
|
326
|
+
address: string,
|
|
327
|
+
tokenId: string,
|
|
328
|
+
status: BlockStatusFilter,
|
|
329
|
+
to?: string,
|
|
330
|
+
from?: string
|
|
331
|
+
) {
|
|
332
|
+
return db_client<ArchiveNodeDatabaseRow[]>`
|
|
333
|
+
WITH
|
|
334
|
+
${fullChainCTE(db_client, from, to)},
|
|
335
|
+
${accountIdentifierCTE(db_client, address, tokenId)},
|
|
336
|
+
${blocksAccessedCTE(db_client, status)},
|
|
337
|
+
${emittedZkAppCommandsCTE(db_client)},
|
|
338
|
+
${emittedEventsCTE(db_client)}
|
|
339
|
+
SELECT
|
|
340
|
+
last_vrf_output,
|
|
341
|
+
block_id,
|
|
342
|
+
zkapp_id,
|
|
343
|
+
state_hash,
|
|
344
|
+
parent_hash,
|
|
345
|
+
height,
|
|
346
|
+
global_slot_since_genesis,
|
|
347
|
+
global_slot_since_hard_fork,
|
|
348
|
+
timestamp,
|
|
349
|
+
chain_status,
|
|
350
|
+
ledger_hash,
|
|
351
|
+
distance_from_max_block_height,
|
|
352
|
+
last_vrf_output,
|
|
353
|
+
zkapp_account_update_id,
|
|
354
|
+
sequence_number,
|
|
355
|
+
zkapp_fee_payer_body_id,
|
|
356
|
+
zkapp_account_updates_ids,
|
|
357
|
+
authorization_kind,
|
|
358
|
+
status,
|
|
359
|
+
memo,
|
|
360
|
+
hash,
|
|
361
|
+
body_id,
|
|
362
|
+
events_id,
|
|
363
|
+
actions_id,
|
|
364
|
+
account_update_event_id,
|
|
365
|
+
event_element_ids,
|
|
366
|
+
event_field_element_ids,
|
|
367
|
+
event_field_elements_id,
|
|
368
|
+
field_id,
|
|
369
|
+
field_value
|
|
370
|
+
FROM emitted_events
|
|
371
|
+
`;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export function getActionsQuery(
|
|
375
|
+
db_client: postgres.Sql,
|
|
376
|
+
address: string,
|
|
377
|
+
tokenId: string,
|
|
378
|
+
status: BlockStatusFilter,
|
|
379
|
+
to?: string,
|
|
380
|
+
from?: string,
|
|
381
|
+
fromActionState?: string,
|
|
382
|
+
endActionState?: string
|
|
383
|
+
) {
|
|
384
|
+
return db_client<ArchiveNodeDatabaseRow[]>`
|
|
385
|
+
WITH
|
|
386
|
+
${fullChainCTE(db_client, from, to)},
|
|
387
|
+
${accountIdentifierCTE(db_client, address, tokenId)},
|
|
388
|
+
${blocksAccessedCTE(db_client, status)},
|
|
389
|
+
${emittedZkAppCommandsCTE(db_client)},
|
|
390
|
+
${emittedActionsCTE(db_client)},
|
|
391
|
+
${emittedActionStateCTE(db_client, fromActionState, endActionState)}
|
|
392
|
+
SELECT *
|
|
393
|
+
FROM emitted_action_state
|
|
394
|
+
`;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export function getNetworkStateQuery(db_client: postgres.Sql) {
|
|
398
|
+
return db_client`
|
|
399
|
+
WITH max_heights AS (
|
|
400
|
+
SELECT
|
|
401
|
+
chain_status,
|
|
402
|
+
MAX(height) AS max_height
|
|
403
|
+
FROM blocks
|
|
404
|
+
WHERE chain_status IN ('canonical', 'pending')
|
|
405
|
+
GROUP BY chain_status
|
|
406
|
+
)
|
|
407
|
+
SELECT b.*
|
|
408
|
+
FROM blocks b
|
|
409
|
+
JOIN max_heights mh
|
|
410
|
+
ON b.chain_status = mh.chain_status
|
|
411
|
+
AND b.height = mh.max_height;
|
|
412
|
+
`;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export function checkActionState(db_client: postgres.Sql, actionState: string) {
|
|
416
|
+
return db_client`
|
|
417
|
+
SELECT field FROM zkapp_field WHERE field = ${actionState}
|
|
418
|
+
`;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function getTables(db_client: postgres.Sql) {
|
|
422
|
+
return db_client`
|
|
423
|
+
SELECT tablename FROM pg_catalog.pg_tables where schemaname='public';
|
|
424
|
+
`;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export const USED_TABLES = [
|
|
428
|
+
'blocks',
|
|
429
|
+
'account_identifiers',
|
|
430
|
+
'accounts_accessed',
|
|
431
|
+
'blocks_zkapp_commands',
|
|
432
|
+
'zkapp_commands',
|
|
433
|
+
'zkapp_account_update',
|
|
434
|
+
'zkapp_account_update_body',
|
|
435
|
+
'zkapp_events',
|
|
436
|
+
'zkapp_field_array',
|
|
437
|
+
'zkapp_field',
|
|
438
|
+
'zkapp_verification_key_hashes',
|
|
439
|
+
'zkapp_verification_keys',
|
|
440
|
+
'zkapp_accounts',
|
|
441
|
+
'zkapp_action_states',
|
|
442
|
+
] as const;
|
|
443
|
+
|
|
444
|
+
export function getZkappsWithPendingEventsQuery(db_client: postgres.Sql) {
|
|
445
|
+
return db_client`
|
|
446
|
+
WITH RECURSIVE pending_chain(id, parent_id, chain_status) AS (
|
|
447
|
+
-- start at the tip
|
|
448
|
+
SELECT id, parent_id, chain_status
|
|
449
|
+
FROM blocks
|
|
450
|
+
WHERE height = (SELECT MAX(height) FROM blocks)
|
|
451
|
+
|
|
452
|
+
UNION ALL
|
|
453
|
+
|
|
454
|
+
-- walk back until we re-join the canonical branch
|
|
455
|
+
SELECT b.id, b.parent_id, b.chain_status
|
|
456
|
+
FROM blocks b
|
|
457
|
+
JOIN pending_chain pc
|
|
458
|
+
ON b.id = pc.parent_id
|
|
459
|
+
WHERE pc.id <> pc.parent_id
|
|
460
|
+
AND pc.chain_status <> 'canonical'
|
|
461
|
+
)
|
|
462
|
+
SELECT DISTINCT
|
|
463
|
+
pk.value AS public_key
|
|
464
|
+
FROM
|
|
465
|
+
pending_chain pc
|
|
466
|
+
|
|
467
|
+
-- only commands in this block that didn’t fail
|
|
468
|
+
JOIN blocks_zkapp_commands bzc
|
|
469
|
+
ON bzc.block_id = pc.id
|
|
470
|
+
AND bzc.status <> 'failed'
|
|
471
|
+
|
|
472
|
+
-- get the command, then unwind its array of account-update IDs
|
|
473
|
+
JOIN zkapp_commands zkc
|
|
474
|
+
ON zkc.id = bzc.zkapp_command_id
|
|
475
|
+
JOIN LATERAL UNNEST(zkc.zkapp_account_updates_ids) AS upd(id) ON TRUE
|
|
476
|
+
|
|
477
|
+
-- pick up the body, but only if it actually emitted events
|
|
478
|
+
JOIN zkapp_account_update au
|
|
479
|
+
ON au.id = upd.id
|
|
480
|
+
JOIN zkapp_account_update_body aub
|
|
481
|
+
ON aub.id = au.body_id
|
|
482
|
+
AND aub.events_id IS NOT NULL
|
|
483
|
+
|
|
484
|
+
-- map back to the account’s public key
|
|
485
|
+
JOIN account_identifiers ai
|
|
486
|
+
ON ai.id = aub.account_identifier_id
|
|
487
|
+
JOIN public_keys pk
|
|
488
|
+
ON pk.id = ai.public_key_id;
|
|
489
|
+
`;
|
|
490
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Namespaces are used here as an alias to the simple number and number[] types in order to model
|
|
2
|
+
// the relationships between the different types of data in the system.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A Field is the smallest unit of raw data in an Event
|
|
6
|
+
*/
|
|
7
|
+
namespace Field {
|
|
8
|
+
/**
|
|
9
|
+
* The id of the Field in the archive node postres DB
|
|
10
|
+
*/
|
|
11
|
+
export type Id = number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The raw value of the Field
|
|
15
|
+
*/
|
|
16
|
+
export type Value = string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An EventFieldArray is an Array of {@link Field.Id} which represents a multi-Field datum within an event
|
|
21
|
+
* For instance, a public key is 2 fields, so it will generate an EventFieldArray with 2 Field.Ids
|
|
22
|
+
*/
|
|
23
|
+
namespace EventFieldArray {
|
|
24
|
+
/**
|
|
25
|
+
* The id of the EventFieldArray in the archive node postres DB
|
|
26
|
+
*/
|
|
27
|
+
export type Id = number;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An array of {@link Field.Id}
|
|
31
|
+
*/
|
|
32
|
+
export type FieldIds = Field.Id[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An Event is a collection of {@link EventFieldArray.Id} which represents a single event in the system
|
|
37
|
+
* Because an event may contain multiple data, it is represented as an array of arrays
|
|
38
|
+
*/
|
|
39
|
+
namespace Event {
|
|
40
|
+
/**
|
|
41
|
+
* The id of the Event in the archive node postres DB
|
|
42
|
+
*/
|
|
43
|
+
export type Id = number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* An array of {@link EventFieldArray.Id}
|
|
47
|
+
*/
|
|
48
|
+
export type EventFieldArrayIds = EventFieldArray.Id[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Represents a complete row from the Archive Node database.
|
|
53
|
+
* This structure gathers information related to blocks, transactions, events, and associated zkApp updates.
|
|
54
|
+
*/
|
|
55
|
+
export type ArchiveNodeDatabaseRow = {
|
|
56
|
+
/**
|
|
57
|
+
* Unique block identifier.
|
|
58
|
+
*/
|
|
59
|
+
block_id: number;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* zkApp identifier.
|
|
63
|
+
*/
|
|
64
|
+
zkapp_id: number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Hash representing the state of the block.
|
|
68
|
+
*/
|
|
69
|
+
state_hash: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Hash representing the parent of the block.
|
|
73
|
+
*/
|
|
74
|
+
parent_hash: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Numeric representation of block's height in the chain.
|
|
78
|
+
*/
|
|
79
|
+
height: string;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Slot count since genesis.
|
|
83
|
+
*/
|
|
84
|
+
global_slot_since_genesis: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Slot count since the last hard fork.
|
|
88
|
+
* @type {string}
|
|
89
|
+
*/
|
|
90
|
+
global_slot_since_hard_fork: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Type of authorization used for the block.
|
|
94
|
+
*/
|
|
95
|
+
authorization_kind: string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Timestamp when the block was created.
|
|
99
|
+
*/
|
|
100
|
+
timestamp: string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Current status of the block within the chain (e.g., canonical, orphaned).
|
|
104
|
+
*/
|
|
105
|
+
chain_status: string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sequence number of the transaction within a block.
|
|
109
|
+
*/
|
|
110
|
+
sequence_number: number;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Hash representing the ledger state.
|
|
114
|
+
*/
|
|
115
|
+
ledger_hash: string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Distance from the block with the maximum height.
|
|
119
|
+
*/
|
|
120
|
+
distance_from_max_block_height: string;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Unique identifier for the zkApp account update.
|
|
124
|
+
*/
|
|
125
|
+
zkapp_account_update_id: number;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* List of Account Update IDs associated with the transaction
|
|
129
|
+
*/
|
|
130
|
+
zkapp_account_updates_ids: number[];
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Status of the transaction.
|
|
134
|
+
*/
|
|
135
|
+
status: string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Optional memo field for additional details.
|
|
139
|
+
*/
|
|
140
|
+
memo: string;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Unique hash identifier for this row's data.
|
|
144
|
+
*/
|
|
145
|
+
hash: string;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* ID of a single event in an account update.
|
|
149
|
+
*/
|
|
150
|
+
account_update_event_id: Event.Id;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* List of IDs of the field arrays used to construct the event array.
|
|
154
|
+
*/
|
|
155
|
+
event_element_ids: Event.EventFieldArrayIds;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* ID referencing an array of field elements associated with an event.
|
|
159
|
+
*/
|
|
160
|
+
event_field_elements_id: EventFieldArray.Id;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* List of `element_ids` that are used to construct the field array.
|
|
164
|
+
* Each entry corresponds to a `Field.Id`, linking to a `Field`.
|
|
165
|
+
*/
|
|
166
|
+
event_field_element_ids: EventFieldArray.FieldIds;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Unique ID for a `field`.
|
|
170
|
+
* Each `field_id` corresponds to one `Field`.
|
|
171
|
+
*/
|
|
172
|
+
field_id: Field.Id;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Value of the field corresponding to `field_id`.
|
|
176
|
+
*/
|
|
177
|
+
field_value: Field.Value;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Output of the last VRF (Verifiable Random Function).
|
|
181
|
+
*/
|
|
182
|
+
last_vrf_output: string;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* (Optional) Action state value 1.
|
|
186
|
+
*/
|
|
187
|
+
action_state_value1?: string;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* (Optional) Action state value 2.
|
|
191
|
+
*/
|
|
192
|
+
action_state_value2?: string;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* (Optional) Action state value 3.
|
|
196
|
+
*/
|
|
197
|
+
action_state_value3?: string;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* (Optional) Action state value 4.
|
|
201
|
+
*/
|
|
202
|
+
action_state_value4?: string;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* (Optional) Action state value 5.
|
|
206
|
+
*/
|
|
207
|
+
action_state_value5?: string;
|
|
208
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace NodeJS {
|
|
3
|
+
interface ProcessEnv {
|
|
4
|
+
LOG_LEVEL: string;
|
|
5
|
+
PORT?: string;
|
|
6
|
+
PG_CONN: string;
|
|
7
|
+
CORS_ORIGIN?: string;
|
|
8
|
+
ENABLE_LOGGING?: bool;
|
|
9
|
+
ENABLE_INTROSPECTION?: bool;
|
|
10
|
+
ENABLE_GRAPHIQL?: bool;
|
|
11
|
+
ENABLE_JAEGER?: bool;
|
|
12
|
+
JAEGER_ENDPOINT?: string;
|
|
13
|
+
JAEGER_SERVICE_NAME?: string;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {};
|