envio 3.8.0 → 3.9.0
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 +2 -2
- package/index.d.ts +158 -104
- package/package.json +6 -6
- package/src/AddressRows.res +121 -0
- package/src/AddressRows.res.mjs +143 -0
- package/src/Batch.res +2 -0
- package/src/Batch.res.mjs +2 -1
- package/src/ChainState.res +76 -70
- package/src/ChainState.res.mjs +76 -65
- package/src/ChainState.resi +14 -9
- package/src/Config.res +23 -82
- package/src/Config.res.mjs +19 -63
- package/src/ContractMapping.res +66 -0
- package/src/ContractMapping.res.mjs +73 -0
- package/src/Core.res +20 -0
- package/src/Core.res.mjs +4 -0
- package/src/EventConfigBuilder.res +0 -2
- package/src/EventConfigBuilder.res.mjs +0 -2
- package/src/FetchState.res +59 -67
- package/src/FetchState.res.mjs +34 -44
- package/src/InMemoryStore.res +17 -30
- package/src/InMemoryStore.res.mjs +11 -23
- package/src/IndexerState.res +21 -1
- package/src/IndexerState.res.mjs +9 -3
- package/src/IndexerState.resi +1 -0
- package/src/Main.res +25 -15
- package/src/Main.res.mjs +19 -14
- package/src/MemoryStorage.res +39 -66
- package/src/MemoryStorage.res.mjs +28 -65
- package/src/Metrics.res +15 -1
- package/src/Metrics.res.mjs +5 -1
- package/src/Persistence.res +30 -16
- package/src/Persistence.res.mjs +8 -5
- package/src/PgStorage.res +183 -65
- package/src/PgStorage.res.mjs +92 -58
- package/src/Rollback.res +14 -10
- package/src/Rollback.res.mjs +4 -2
- package/src/SimulateItems.res +5 -12
- package/src/SimulateItems.res.mjs +6 -10
- package/src/TestIndexer.res +93 -111
- package/src/TestIndexer.res.mjs +61 -88
- package/src/Utils.res +7 -0
- package/src/Utils.res.mjs +9 -2
- package/src/Writing.res +2 -0
- package/src/Writing.res.mjs +2 -1
- package/src/bindings/ClickHouse.res +6 -0
- package/src/bindings/ClickHouse.res.mjs +4 -0
- package/src/bindings/NodeJs.res +9 -0
- package/src/bindings/NodeJs.res.mjs +8 -1
- package/src/bindings/Postgres.res +9 -0
- package/src/bindings/Postgres.res.mjs +3 -0
- package/src/db/EntityHistory.res +12 -18
- package/src/db/EntityHistory.res.mjs +3 -14
- package/src/db/InternalTable.res +171 -65
- package/src/db/InternalTable.res.mjs +176 -73
- package/src/db/Table.res +24 -0
- package/src/db/Table.res.mjs +20 -1
- package/src/sources/AddressSet.res +0 -22
- package/src/sources/AddressStore.res +48 -88
- package/src/sources/AddressStore.res.mjs +11 -22
- package/src/sources/SvmHyperSyncClient.res +17 -21
- package/src/sources/SvmHyperSyncSource.res +4 -9
- package/src/sources/SvmHyperSyncSource.res.mjs +5 -13
- package/svm.schema.json +10 -4
|
@@ -1,62 +1,44 @@
|
|
|
1
|
-
// Binding to the Rust `AddressStore` napi class: the chain-wide index of every
|
|
2
|
-
// address being indexed, config-declared or dynamically registered. It owns
|
|
3
|
-
// registration bookkeeping (conflict detection, `effectiveStartBlock`
|
|
4
|
-
// derivation, reorg rollback) and hands out `AddressSet` snapshots for the
|
|
5
|
-
// fetch state's partitions. One store lives per chain on `ChainState`, shared
|
|
6
|
-
// with that chain's source clients — which read it to drop items whose emitter
|
|
7
|
-
// (or address-valued param) isn't registered at the item's block.
|
|
8
1
|
type t
|
|
9
2
|
|
|
10
|
-
// A contract an address may be registered for. Every config contract of every
|
|
11
|
-
// chain, since `context.chain.<Contract>.add` validates against that whole set
|
|
12
|
-
// — a name outside it makes the store throw. `dependsOnAddresses` is whether
|
|
13
|
-
// this chain fetches for the contract by address, which is what makes the store
|
|
14
|
-
// able to answer `fetchable` on a verdict.
|
|
15
3
|
type contract = {name: string, startBlock: option<int>, dependsOnAddresses: bool}
|
|
16
4
|
|
|
17
5
|
type registration = {
|
|
18
6
|
address: Address.t,
|
|
19
7
|
contractName: string,
|
|
20
|
-
// -1 for a config address
|
|
8
|
+
// -1 for a config address.
|
|
21
9
|
registrationBlock: int,
|
|
22
10
|
}
|
|
23
11
|
|
|
24
12
|
type verdict =
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// adds events picks it up on restart, but no partition is built from it.
|
|
13
|
+
// False when nothing on this chain is fetched by address for the contract.
|
|
14
|
+
// The address is still stored and persisted.
|
|
28
15
|
| Added({effectiveStartBlock: int, fetchable: bool})
|
|
29
|
-
// Already registered for the same contract.
|
|
30
16
|
| Duplicate({effectiveStartBlock: int, existingEffectiveStartBlock: int})
|
|
31
|
-
// Already registered for a different contract.
|
|
32
|
-
| Conflict({existingContractName: string})
|
|
33
|
-
// Not a well-formed address for the ecosystem.
|
|
34
17
|
| Invalid
|
|
35
18
|
|
|
36
19
|
type rawVerdict = {
|
|
37
20
|
kind: string,
|
|
38
21
|
fetchable: bool,
|
|
39
22
|
effectiveStartBlock: int,
|
|
40
|
-
existingContractName: Null.t<string>,
|
|
41
23
|
existingEffectiveStartBlock: Null.t<int>,
|
|
42
24
|
}
|
|
43
25
|
|
|
44
|
-
|
|
45
|
-
// checkpoint that owns its row. `checkpointIdx` indexes the block numbers
|
|
46
|
-
// passed to `drainForWrite` — the ids stay on the JS side.
|
|
47
|
-
type drainedAddress = {
|
|
26
|
+
type rejectedRow = {
|
|
48
27
|
address: Address.t,
|
|
49
28
|
contractName: string,
|
|
29
|
+
effectiveStartBlock: int,
|
|
30
|
+
existingEffectiveStartBlock: int,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type drainedAddress = {
|
|
34
|
+
address: NodeJs.Buffer.t,
|
|
35
|
+
contractId: int,
|
|
50
36
|
registrationBlock: int,
|
|
51
37
|
checkpointIdx: int,
|
|
52
38
|
}
|
|
53
39
|
|
|
54
40
|
type makeSetOptions = {
|
|
55
|
-
// Only addresses whose id is at or above this. Ids are handed out in
|
|
56
|
-
// registration order, so a cursor read before a batch (`nextId`) selects
|
|
57
|
-
// exactly what that batch added.
|
|
58
41
|
minId?: int,
|
|
59
|
-
// Inclusive effectiveStartBlock bounds.
|
|
60
42
|
fromStartBlock?: int,
|
|
61
43
|
toStartBlock?: int,
|
|
62
44
|
offset?: int,
|
|
@@ -68,9 +50,6 @@ external newEvm: (Core.addressStoreCtor, bool, array<contract>) => t = "newEvm"
|
|
|
68
50
|
@send external newSvm: (Core.addressStoreCtor, array<contract>) => t = "newSvm"
|
|
69
51
|
@send external newFuel: (Core.addressStoreCtor, array<contract>) => t = "newFuel"
|
|
70
52
|
|
|
71
|
-
// The store's ecosystem is fixed here, from the chain's config, and decides how
|
|
72
|
-
// address strings are parsed and rendered back. EVM carries the chain's
|
|
73
|
-
// address-checksumming setting so entries render exactly as the sources do.
|
|
74
53
|
let make = (~ecosystem: Ecosystem.name, ~shouldChecksum: bool, ~contracts: array<contract>): t => {
|
|
75
54
|
let ctor = Core.getAddon().addressStore
|
|
76
55
|
switch ecosystem {
|
|
@@ -80,34 +59,20 @@ let make = (~ecosystem: Ecosystem.name, ~shouldChecksum: bool, ~contracts: array
|
|
|
80
59
|
}
|
|
81
60
|
}
|
|
82
61
|
|
|
83
|
-
// Every contract an address may be registered for, with the earliest block any
|
|
84
|
-
// of this chain's events for it may fire at. `None` means unrestricted, so it
|
|
85
|
-
// wins over any `Some`: one registration without a start block makes the whole
|
|
86
|
-
// contract's address gate open from the chain's start, and the per-registration
|
|
87
|
-
// start block still holds back the registrations that declared one.
|
|
88
|
-
//
|
|
89
|
-
// A contract whose events are all wildcard is fetched without consulting
|
|
90
|
-
// addresses, so registering one changes nothing about what's queried — it
|
|
91
|
-
// carries `dependsOnAddresses: false` just like a contract named only by
|
|
92
|
-
// `configContractNames`. Either way the addresses are stored and persisted,
|
|
93
|
-
// never fetched.
|
|
94
62
|
let contractsOf = (
|
|
95
63
|
~onEventRegistrations: array<Internal.onEventRegistration>,
|
|
96
|
-
~
|
|
64
|
+
~contractMapping: ContractMapping.t,
|
|
97
65
|
): array<contract> => {
|
|
98
|
-
// Only ever holds a declared start block, so a missing key is unambiguous
|
|
99
|
-
//
|
|
66
|
+
// Only ever holds a declared start block, so a missing key is unambiguous.
|
|
67
|
+
// Storing None in a dict would be indistinguishable from "not seen yet".
|
|
100
68
|
let startBlocks: dict<int> = Dict.make()
|
|
101
69
|
let unrestricted = Utils.Set.make()
|
|
102
70
|
let addressDependent = Utils.Set.make()
|
|
103
|
-
let names = []
|
|
104
|
-
let addName = name =>
|
|
105
|
-
if !(names->Array.includes(name)) {
|
|
106
|
-
names->Array.push(name)->ignore
|
|
107
|
-
}
|
|
108
71
|
onEventRegistrations->Array.forEach(reg => {
|
|
109
72
|
let name = reg.eventConfig.contractName
|
|
110
|
-
|
|
73
|
+
contractMapping
|
|
74
|
+
->ContractMapping.idOfOrThrow(name, ~context=" has event registrations but")
|
|
75
|
+
->ignore
|
|
111
76
|
if reg.dependsOnAddresses {
|
|
112
77
|
addressDependent->Utils.Set.add(name)->ignore
|
|
113
78
|
}
|
|
@@ -123,8 +88,9 @@ let contractsOf = (
|
|
|
123
88
|
)
|
|
124
89
|
}
|
|
125
90
|
})
|
|
126
|
-
|
|
127
|
-
|
|
91
|
+
contractMapping
|
|
92
|
+
->ContractMapping.names
|
|
93
|
+
->Array.map(name => {
|
|
128
94
|
name,
|
|
129
95
|
startBlock: unrestricted->Utils.Set.has(name)
|
|
130
96
|
? None
|
|
@@ -135,45 +101,53 @@ let contractsOf = (
|
|
|
135
101
|
|
|
136
102
|
@send external nextId: t => int = "nextId"
|
|
137
103
|
|
|
138
|
-
// A set holding nothing — what an address-free (wildcard) partition carries, so
|
|
139
|
-
// every partition is queried through the same handle.
|
|
140
104
|
@send external emptySet: t => AddressSet.t = "emptySet"
|
|
141
105
|
|
|
142
|
-
// A set over exactly these addresses, in set order. Every set of a chain must
|
|
143
|
-
// come from that chain's one store — ids are store-scoped, so sets from
|
|
144
|
-
// different stores can't be merged.
|
|
145
|
-
@send external makeSetOf: (t, array<Address.t>) => AddressSet.t = "makeSetOf"
|
|
146
106
|
@send
|
|
147
107
|
external registerBatchRaw: (t, array<registration>) => array<rawVerdict> = "registerBatch"
|
|
148
108
|
@send external seedBatchRaw: (t, array<registration>) => array<rawVerdict> = "seedBatch"
|
|
149
109
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
110
|
+
@send
|
|
111
|
+
external seedRowsRaw: (
|
|
112
|
+
t,
|
|
113
|
+
NodeJs.Buffer.t,
|
|
114
|
+
array<int>,
|
|
115
|
+
array<int>,
|
|
116
|
+
array<int>,
|
|
117
|
+
) => array<rejectedRow> = "seedRows"
|
|
118
|
+
|
|
119
|
+
let seedRows = (store: t, rows: AddressRows.seedRows) => {
|
|
120
|
+
let (bytes, lengths) = AddressRows.packBuffers(rows.addresses)
|
|
121
|
+
store->seedRowsRaw(bytes, lengths, rows.contractIds, rows.registrationBlocks)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Throws with the queue untouched when a drained registration's block has no
|
|
125
|
+
// checkpoint in the batch.
|
|
154
126
|
@send
|
|
155
127
|
external drainForWrite: (t, int, array<int>) => array<drainedAddress> = "drainForWrite"
|
|
156
128
|
|
|
157
|
-
// How many registrations await persistence — lets a caller skip the work of
|
|
158
|
-
// assembling what `drainForWrite` needs.
|
|
159
129
|
@send external pendingCount: t => int = "pendingCount"
|
|
160
130
|
|
|
161
|
-
// The registrations still awaiting persistence. For assertions.
|
|
162
131
|
@send external pendingEntries: t => array<Internal.indexingContract> = "pendingEntries"
|
|
163
132
|
@send external makeSetRaw: (t, string, makeSetOptions) => AddressSet.t = "makeSet"
|
|
164
133
|
@send external contractCount: (t, string) => int = "contractCount"
|
|
134
|
+
|
|
135
|
+
type contractAddressCount = {contractName: string, count: int}
|
|
136
|
+
|
|
137
|
+
@send external contractCounts: t => array<contractAddressCount> = "contractCounts"
|
|
165
138
|
@send external size: t => int = "size"
|
|
166
139
|
|
|
167
|
-
// The chain-wide gate routing applies, exposed for the simulate source — it has
|
|
168
|
-
// no real query boundary to gate at.
|
|
169
140
|
@send external isIndexedAt: (t, Address.t, string, int) => bool = "isIndexedAt"
|
|
170
141
|
|
|
171
|
-
|
|
172
|
-
// were dropped. Ids are tombstoned rather than reused, so sets built before the
|
|
173
|
-
// rollback still point at the right entries.
|
|
174
|
-
@send external rollback: (t, int) => int = "rollback"
|
|
142
|
+
type rolledBackAddress = {address: NodeJs.Buffer.t, contractId: int}
|
|
175
143
|
|
|
176
|
-
|
|
144
|
+
// Ids are tombstoned rather than reused, so sets built before the rollback
|
|
145
|
+
// still point at the right entries.
|
|
146
|
+
@send external rollback: (t, int) => array<rolledBackAddress> = "rollback"
|
|
147
|
+
|
|
148
|
+
@send external getAll: (t, Address.t) => array<Internal.indexingContract> = "getAll"
|
|
149
|
+
|
|
150
|
+
@send external dynamicContractNames: t => array<string> = "dynamicContractNames"
|
|
177
151
|
|
|
178
152
|
@send external contractAddresses: (t, string) => array<Address.t> = "contractAddresses"
|
|
179
153
|
|
|
@@ -185,30 +159,16 @@ let toVerdict = (raw: rawVerdict): verdict =>
|
|
|
185
159
|
effectiveStartBlock: raw.effectiveStartBlock,
|
|
186
160
|
existingEffectiveStartBlock: raw.existingEffectiveStartBlock->Null.getUnsafe,
|
|
187
161
|
})
|
|
188
|
-
| "conflict" => Conflict({existingContractName: raw.existingContractName->Null.getUnsafe})
|
|
189
162
|
| "invalid" => Invalid
|
|
190
163
|
| kind => JsError.throwWithMessage(`Unexpected address registration verdict "${kind}"`)
|
|
191
164
|
}
|
|
192
165
|
|
|
193
|
-
// Registers dynamic registrations, resolving each address against both the
|
|
194
|
-
// store and the batch's own earlier entries — so two contracts claiming one
|
|
195
|
-
// address inside a single batch conflict just as they would across batches.
|
|
196
|
-
// Verdicts come back in the batch's order. What it adds is pending persistence
|
|
197
|
-
// until a batch write drains it.
|
|
198
|
-
//
|
|
199
166
|
// An unknown contract name throws with none of the batch applied.
|
|
200
167
|
let registerBatch = (store: t, registrations: array<registration>): array<verdict> =>
|
|
201
168
|
store->registerBatchRaw(registrations)->Array.map(toVerdict)
|
|
202
169
|
|
|
203
|
-
// `registerBatch` for addresses the database already holds — config addresses
|
|
204
|
-
// and the dynamic ones a resume restores. Nothing is marked pending, so nothing
|
|
205
|
-
// is ever written back.
|
|
206
170
|
let seedBatch = (store: t, registrations: array<registration>): array<verdict> =>
|
|
207
171
|
store->seedBatchRaw(registrations)->Array.map(toVerdict)
|
|
208
172
|
|
|
209
173
|
let makeSet = (store: t, ~contractName, ~options={}: makeSetOptions) =>
|
|
210
174
|
store->makeSetRaw(contractName, options)
|
|
211
|
-
|
|
212
|
-
// The entry an address is registered under, whichever contract holds it —
|
|
213
|
-
// addresses are unique chain-wide. `None` once rolled back.
|
|
214
|
-
let get = (store: t, address) => store->getRaw(address)->Null.toOption
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Core from "../Core.res.mjs";
|
|
4
|
+
import * as AddressRows from "../AddressRows.res.mjs";
|
|
4
5
|
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
5
6
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
6
|
-
import * as
|
|
7
|
+
import * as ContractMapping from "../ContractMapping.res.mjs";
|
|
7
8
|
|
|
8
9
|
function make(ecosystem, shouldChecksum, contracts) {
|
|
9
10
|
let ctor = Core.getAddon().AddressStore;
|
|
@@ -17,20 +18,13 @@ function make(ecosystem, shouldChecksum, contracts) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
function contractsOf(onEventRegistrations,
|
|
21
|
+
function contractsOf(onEventRegistrations, contractMapping) {
|
|
21
22
|
let startBlocks = {};
|
|
22
23
|
let unrestricted = new Set();
|
|
23
24
|
let addressDependent = new Set();
|
|
24
|
-
let names = [];
|
|
25
|
-
let addName = name => {
|
|
26
|
-
if (!names.includes(name)) {
|
|
27
|
-
names.push(name);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
25
|
onEventRegistrations.forEach(reg => {
|
|
32
26
|
let name = reg.eventConfig.contractName;
|
|
33
|
-
|
|
27
|
+
ContractMapping.idOfOrThrow(contractMapping, name, " has event registrations but");
|
|
34
28
|
if (reg.dependsOnAddresses) {
|
|
35
29
|
addressDependent.add(name);
|
|
36
30
|
}
|
|
@@ -42,14 +36,18 @@ function contractsOf(onEventRegistrations, configContractNames) {
|
|
|
42
36
|
}
|
|
43
37
|
unrestricted.add(name);
|
|
44
38
|
});
|
|
45
|
-
|
|
46
|
-
return names.map(name => ({
|
|
39
|
+
return ContractMapping.names(contractMapping).map(name => ({
|
|
47
40
|
name: name,
|
|
48
41
|
startBlock: unrestricted.has(name) ? undefined : startBlocks[name],
|
|
49
42
|
dependsOnAddresses: addressDependent.has(name)
|
|
50
43
|
}));
|
|
51
44
|
}
|
|
52
45
|
|
|
46
|
+
function seedRows(store, rows) {
|
|
47
|
+
let match = AddressRows.packBuffers(rows.addresses);
|
|
48
|
+
return store.seedRows(match[0], match[1], rows.contractIds, rows.registrationBlocks);
|
|
49
|
+
}
|
|
50
|
+
|
|
53
51
|
function toVerdict(raw) {
|
|
54
52
|
let kind = raw.kind;
|
|
55
53
|
switch (kind) {
|
|
@@ -59,11 +57,6 @@ function toVerdict(raw) {
|
|
|
59
57
|
effectiveStartBlock: raw.effectiveStartBlock,
|
|
60
58
|
fetchable: raw.fetchable
|
|
61
59
|
};
|
|
62
|
-
case "conflict" :
|
|
63
|
-
return {
|
|
64
|
-
TAG: "Conflict",
|
|
65
|
-
existingContractName: raw.existingContractName
|
|
66
|
-
};
|
|
67
60
|
case "duplicate" :
|
|
68
61
|
return {
|
|
69
62
|
TAG: "Duplicate",
|
|
@@ -90,17 +83,13 @@ function makeSet(store, contractName, optionsOpt) {
|
|
|
90
83
|
return store.makeSet(contractName, options);
|
|
91
84
|
}
|
|
92
85
|
|
|
93
|
-
function get(store, address) {
|
|
94
|
-
return Primitive_option.fromNull(store.get(address));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
86
|
export {
|
|
98
87
|
make,
|
|
99
88
|
contractsOf,
|
|
89
|
+
seedRows,
|
|
100
90
|
toVerdict,
|
|
101
91
|
registerBatch,
|
|
102
92
|
seedBatch,
|
|
103
93
|
makeSet,
|
|
104
|
-
get,
|
|
105
94
|
}
|
|
106
95
|
/* Core Not a pure module */
|
|
@@ -144,16 +144,7 @@ module ResponseTypes = {
|
|
|
144
144
|
type block = {
|
|
145
145
|
slot: int,
|
|
146
146
|
blockhash: string,
|
|
147
|
-
blockTime
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/// Borsh-decoded view attached by the Rust client. `argsJson`/`accountsJson`
|
|
151
|
-
/// are stringified to side-step napi-rs's lack of native JSON passthrough.
|
|
152
|
-
type decodedInstruction = {
|
|
153
|
-
name: string,
|
|
154
|
-
argsJson: string,
|
|
155
|
-
accountsJson: string,
|
|
156
|
-
extraAccounts: array<string>,
|
|
147
|
+
blockTime: Null.t<int>,
|
|
157
148
|
}
|
|
158
149
|
|
|
159
150
|
type instructionCall = {
|
|
@@ -164,16 +155,16 @@ module ResponseTypes = {
|
|
|
164
155
|
executingAccount: string,
|
|
165
156
|
accountArguments: array<string>,
|
|
166
157
|
data: string,
|
|
167
|
-
d1
|
|
168
|
-
d2
|
|
169
|
-
d4
|
|
170
|
-
d8
|
|
158
|
+
d1: Null.t<string>,
|
|
159
|
+
d2: Null.t<string>,
|
|
160
|
+
d4: Null.t<string>,
|
|
161
|
+
d8: Null.t<string>,
|
|
171
162
|
isInner: bool,
|
|
172
163
|
/** Success of the parent transaction, not of this invocation. */
|
|
173
164
|
txSuccess: bool,
|
|
174
165
|
/** Per-invocation failure reason (e.g. "custom program error: 0x1"). */
|
|
175
|
-
error
|
|
176
|
-
computeUnitsConsumed
|
|
166
|
+
error: Null.t<string>,
|
|
167
|
+
computeUnitsConsumed: Null.t<bigint>,
|
|
177
168
|
}
|
|
178
169
|
|
|
179
170
|
type queryResponseData = {
|
|
@@ -206,9 +197,11 @@ module EventItems = {
|
|
|
206
197
|
clientFilteredContracts: option<array<string>>,
|
|
207
198
|
}
|
|
208
199
|
|
|
200
|
+
// NAPI encodes Rust `None` as `null`, never `undefined`, so an unselected
|
|
201
|
+
// key arrives as an explicit null rather than a missing field.
|
|
209
202
|
type log = {
|
|
210
|
-
kind
|
|
211
|
-
message
|
|
203
|
+
kind: Null.t<string>,
|
|
204
|
+
message: Null.t<string>,
|
|
212
205
|
}
|
|
213
206
|
|
|
214
207
|
// One routed instruction; `block` and `transaction` are materialised from
|
|
@@ -222,9 +215,12 @@ module EventItems = {
|
|
|
222
215
|
accounts: array<string>,
|
|
223
216
|
data: string,
|
|
224
217
|
isInner: bool,
|
|
225
|
-
decoded
|
|
226
|
-
//
|
|
227
|
-
|
|
218
|
+
// Borsh-decoded args as a JSON object literal, `{}` when the routed
|
|
219
|
+
// registration reads no args. An instruction the schema rejects is dropped
|
|
220
|
+
// in Rust, so a selected `args` is always decoded.
|
|
221
|
+
argsJson: string,
|
|
222
|
+
// Non-null only when the routed registration selected `fields.log`.
|
|
223
|
+
logs: Null.t<array<log>>,
|
|
228
224
|
}
|
|
229
225
|
|
|
230
226
|
type response = {
|
|
@@ -10,11 +10,6 @@ type options = {
|
|
|
10
10
|
addressStore: AddressStore.t,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
let parseArgs = (d: SvmHyperSyncClient.ResponseTypes.decodedInstruction): JSON.t =>
|
|
14
|
-
try JSON.parseOrThrow(d.argsJson) catch {
|
|
15
|
-
| _ => JSON.Object(Dict.make())
|
|
16
|
-
}
|
|
17
|
-
|
|
18
13
|
let namedAccounts = (
|
|
19
14
|
~idlNames: array<string>,
|
|
20
15
|
~accountArguments: array<string>,
|
|
@@ -40,13 +35,13 @@ let namedAccounts = (
|
|
|
40
35
|
let selectedLog = (log: SvmHyperSyncClient.EventItems.log, ~logFields: Utils.Set.t<string>): Envio.svmLog => {
|
|
41
36
|
let out = Dict.make()
|
|
42
37
|
if logFields->Utils.Set.has("kind") {
|
|
43
|
-
switch log.kind {
|
|
38
|
+
switch log.kind->Null.toOption {
|
|
44
39
|
| Some(kind) => out->Dict.set("kind", kind)
|
|
45
40
|
| None => ()
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
43
|
if logFields->Utils.Set.has("message") {
|
|
49
|
-
switch log.message {
|
|
44
|
+
switch log.message->Null.toOption {
|
|
50
45
|
| Some(message) => out->Dict.set("message", message)
|
|
51
46
|
| None => ()
|
|
52
47
|
}
|
|
@@ -89,7 +84,7 @@ let toSvmInstruction = (
|
|
|
89
84
|
out->setField("isInner", item.isInner)
|
|
90
85
|
}
|
|
91
86
|
if hasSelection("args") {
|
|
92
|
-
out->setField("args", item.
|
|
87
|
+
out->setField("args", item.argsJson->JSON.parseOrThrow)
|
|
93
88
|
}
|
|
94
89
|
if hasSelection("accounts") {
|
|
95
90
|
out->setField(
|
|
@@ -104,7 +99,7 @@ let toSvmInstruction = (
|
|
|
104
99
|
out->setField(
|
|
105
100
|
"logs",
|
|
106
101
|
item.logs
|
|
107
|
-
->
|
|
102
|
+
->Null.getOr([])
|
|
108
103
|
->Array.map(log => selectedLog(log, ~logFields=fieldSelection.logFields)),
|
|
109
104
|
)
|
|
110
105
|
}
|
|
@@ -3,19 +3,12 @@
|
|
|
3
3
|
import * as Source from "./Source.res.mjs";
|
|
4
4
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
5
5
|
import * as Performance from "../bindings/Performance.res.mjs";
|
|
6
|
+
import * as Stdlib_Null from "@rescript/runtime/lib/es6/Stdlib_Null.js";
|
|
6
7
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
8
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
8
9
|
import * as SvmHyperSyncClient from "./SvmHyperSyncClient.res.mjs";
|
|
9
10
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
10
11
|
|
|
11
|
-
function parseArgs(d) {
|
|
12
|
-
try {
|
|
13
|
-
return JSON.parse(d.argsJson);
|
|
14
|
-
} catch (exn) {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
function namedAccounts(idlNames, accountArguments) {
|
|
20
13
|
let out = {};
|
|
21
14
|
idlNames.forEach((name, i) => {
|
|
@@ -36,13 +29,13 @@ function selectedLog(log, logFields) {
|
|
|
36
29
|
let out = {};
|
|
37
30
|
if (logFields.has("kind")) {
|
|
38
31
|
let kind = log.kind;
|
|
39
|
-
if (kind !==
|
|
32
|
+
if (kind !== null) {
|
|
40
33
|
out["kind"] = kind;
|
|
41
34
|
}
|
|
42
35
|
}
|
|
43
36
|
if (logFields.has("message")) {
|
|
44
37
|
let message = log.message;
|
|
45
|
-
if (message !==
|
|
38
|
+
if (message !== null) {
|
|
46
39
|
out["message"] = message;
|
|
47
40
|
}
|
|
48
41
|
}
|
|
@@ -73,7 +66,7 @@ function toSvmInstruction(item, programName, instructionName, eventConfig, field
|
|
|
73
66
|
setField(out, "isInner", item.isInner);
|
|
74
67
|
}
|
|
75
68
|
if (fieldSelection.instructionFields.has("args")) {
|
|
76
|
-
setField(out, "args",
|
|
69
|
+
setField(out, "args", JSON.parse(item.argsJson));
|
|
77
70
|
}
|
|
78
71
|
if (fieldSelection.instructionFields.has("accounts")) {
|
|
79
72
|
setField(out, "accounts", namedAccounts(eventConfig.accounts, item.accounts));
|
|
@@ -82,7 +75,7 @@ function toSvmInstruction(item, programName, instructionName, eventConfig, field
|
|
|
82
75
|
setField(out, "accountArguments", item.accounts);
|
|
83
76
|
}
|
|
84
77
|
if (fieldSelection.logFields.size > 0) {
|
|
85
|
-
setField(out, "logs",
|
|
78
|
+
setField(out, "logs", Stdlib_Null.getOr(item.logs, []).map(log => selectedLog(log, fieldSelection.logFields)));
|
|
86
79
|
}
|
|
87
80
|
return out;
|
|
88
81
|
}
|
|
@@ -189,7 +182,6 @@ function make(param) {
|
|
|
189
182
|
}
|
|
190
183
|
|
|
191
184
|
export {
|
|
192
|
-
parseArgs,
|
|
193
185
|
namedAccounts,
|
|
194
186
|
selectedLog,
|
|
195
187
|
setField,
|
package/svm.schema.json
CHANGED
|
@@ -297,8 +297,15 @@
|
|
|
297
297
|
"type": "object",
|
|
298
298
|
"properties": {
|
|
299
299
|
"hypersync_config": {
|
|
300
|
-
"description": "HyperSync Config for fetching historical instructions on this chain.",
|
|
301
|
-
"
|
|
300
|
+
"description": "HyperSync Config for fetching historical instructions on this chain. Optional for the `solana` and `solana-devnet` chain ids, which default to their public HyperSync endpoints; required for any other chain id.",
|
|
301
|
+
"anyOf": [
|
|
302
|
+
{
|
|
303
|
+
"$ref": "#/$defs/HypersyncConfig"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
"type": "null"
|
|
307
|
+
}
|
|
308
|
+
]
|
|
302
309
|
},
|
|
303
310
|
"programs": {
|
|
304
311
|
"description": "Solana programs to index on this chain.",
|
|
@@ -310,7 +317,6 @@
|
|
|
310
317
|
},
|
|
311
318
|
"additionalProperties": false,
|
|
312
319
|
"required": [
|
|
313
|
-
"hypersync_config",
|
|
314
320
|
"programs"
|
|
315
321
|
]
|
|
316
322
|
},
|
|
@@ -318,7 +324,7 @@
|
|
|
318
324
|
"type": "object",
|
|
319
325
|
"properties": {
|
|
320
326
|
"url": {
|
|
321
|
-
"description": "URL of the HyperSync endpoint (
|
|
327
|
+
"description": "URL of the HyperSync endpoint (defaults to the public endpoint of the chain id: https://solana.hypersync.xyz for `solana`, https://solana-devnet.hypersync.xyz for `solana-devnet`)",
|
|
322
328
|
"type": "string"
|
|
323
329
|
}
|
|
324
330
|
},
|