@sentio/sdk 1.30.3 → 1.31.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/lib/builtin/erc1155/index.d.ts +2 -0
- package/lib/builtin/erc1155/index.js +22 -0
- package/lib/builtin/erc1155/index.js.map +1 -0
- package/lib/builtin/erc1155/test-utils.d.ts +6 -0
- package/lib/builtin/erc1155/test-utils.js +57 -0
- package/lib/builtin/erc1155/test-utils.js.map +1 -0
- package/lib/builtin/erc721/index.d.ts +2 -0
- package/lib/builtin/erc721/index.js +22 -0
- package/lib/builtin/erc721/index.js.map +1 -0
- package/lib/builtin/erc721/test-utils.d.ts +5 -0
- package/lib/builtin/erc721/test-utils.js +46 -0
- package/lib/builtin/erc721/test-utils.js.map +1 -0
- package/lib/builtin/internal/ERC1155.d.ts +199 -0
- package/lib/builtin/internal/ERC1155.js +3 -0
- package/lib/builtin/internal/ERC1155.js.map +1 -0
- package/lib/builtin/internal/ERC721.d.ts +252 -0
- package/lib/builtin/internal/ERC721.js +3 -0
- package/lib/builtin/internal/ERC721.js.map +1 -0
- package/lib/builtin/internal/erc1155_processor.d.ts +134 -0
- package/lib/builtin/internal/erc1155_processor.js +337 -0
- package/lib/builtin/internal/erc1155_processor.js.map +1 -0
- package/lib/builtin/internal/erc721_processor.d.ts +169 -0
- package/lib/builtin/internal/erc721_processor.js +479 -0
- package/lib/builtin/internal/erc721_processor.js.map +1 -0
- package/lib/builtin/internal/factories/ERC1155__factory.d.ts +35 -0
- package/lib/builtin/internal/factories/ERC1155__factory.js +332 -0
- package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -0
- package/lib/builtin/internal/factories/ERC721__factory.d.ts +51 -0
- package/lib/builtin/internal/factories/ERC721__factory.js +364 -0
- package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -0
- package/lib/builtin/internal/factories/index.d.ts +2 -0
- package/lib/builtin/internal/factories/index.js +5 -1
- package/lib/builtin/internal/factories/index.js.map +1 -1
- package/lib/builtin/internal/index.d.ts +4 -0
- package/lib/builtin/internal/index.js +5 -1
- package/lib/builtin/internal/index.js.map +1 -1
- package/lib/core/account-processor.d.ts +58 -0
- package/lib/core/account-processor.js +147 -0
- package/lib/core/account-processor.js.map +1 -0
- package/lib/core/base-processor.d.ts +5 -2
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/bind-options.d.ts +5 -0
- package/lib/core/bind-options.js +7 -1
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +7 -1
- package/lib/core/context.js +30 -18
- package/lib/core/context.js.map +1 -1
- package/lib/core/meter.js +6 -0
- package/lib/core/meter.js.map +1 -1
- package/lib/gen/chainquery/protos/chainquery.d.ts +1 -0
- package/lib/gen/chainquery/protos/chainquery.js +17 -1
- package/lib/gen/chainquery/protos/chainquery.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +11 -0
- package/lib/gen/processor/protos/processor.js +84 -3
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.d.ts +1 -0
- package/lib/service.js +67 -42
- package/lib/service.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +6 -2
- package/lib/testing/test-processor-server.js +66 -5
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +1 -1
- package/src/abis/ERC1155.json +314 -0
- package/src/abis/ERC721.json +346 -0
- package/src/builtin/erc1155/index.ts +6 -0
- package/src/builtin/erc1155/test-utils.ts +89 -0
- package/src/builtin/erc721/index.ts +6 -0
- package/src/builtin/erc721/test-utils.ts +71 -0
- package/src/builtin/internal/ERC1155.ts +529 -0
- package/src/builtin/internal/ERC721.ts +639 -0
- package/src/builtin/internal/erc1155_processor.ts +580 -0
- package/src/builtin/internal/erc721_processor.ts +768 -0
- package/src/builtin/internal/factories/ERC1155__factory.ts +335 -0
- package/src/builtin/internal/factories/ERC721__factory.ts +364 -0
- package/src/builtin/internal/factories/index.ts +2 -0
- package/src/builtin/internal/index.ts +4 -0
- package/src/core/account-processor.ts +217 -0
- package/src/core/base-processor.ts +6 -2
- package/src/core/bind-options.ts +6 -0
- package/src/core/context.ts +42 -27
- package/src/core/meter.ts +8 -2
- package/src/gen/chainquery/protos/chainquery.ts +18 -1
- package/src/gen/processor/protos/processor.ts +88 -1
- package/src/service.ts +71 -44
- package/src/testing/test-processor-server.ts +71 -5
package/src/service.ts
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
AptosProcessorState,
|
|
42
42
|
MoveResourcesWithVersionPayload,
|
|
43
43
|
} from './aptos/aptos-processor'
|
|
44
|
+
import { AccountProcessorState } from './core/account-processor'
|
|
44
45
|
;(BigInt.prototype as any).toJSON = function () {
|
|
45
46
|
return this.toString()
|
|
46
47
|
}
|
|
@@ -131,7 +132,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
131
132
|
})
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
// Part 1, prepare EVM processors
|
|
135
|
+
// Part 1.a, prepare EVM processors
|
|
135
136
|
for (const processor of global.PROCESSOR_STATE.processors) {
|
|
136
137
|
// If server favor incremental update this need to change
|
|
137
138
|
// Start basic config for contract
|
|
@@ -195,6 +196,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
195
196
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
|
|
196
197
|
}
|
|
197
198
|
const logFilter: LogFilter = {
|
|
199
|
+
addressType: undefined,
|
|
200
|
+
address: contractConfig.contract?.address,
|
|
198
201
|
topics: [],
|
|
199
202
|
}
|
|
200
203
|
|
|
@@ -216,6 +219,52 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
216
219
|
this.contractConfigs.push(contractConfig)
|
|
217
220
|
}
|
|
218
221
|
|
|
222
|
+
// part 1.b prepare EVM account processors
|
|
223
|
+
for (const processor of AccountProcessorState.INSTANCE.getValues()) {
|
|
224
|
+
const accountConfig: AccountConfig = {
|
|
225
|
+
address: processor.config.address,
|
|
226
|
+
chainId: processor.getChainId().toString(),
|
|
227
|
+
startBlock: processor.config.startBlock ? Long.fromValue(processor.config.startBlock) : Long.ZERO,
|
|
228
|
+
aptosIntervalConfigs: [],
|
|
229
|
+
intervalConfigs: [],
|
|
230
|
+
logConfigs: [],
|
|
231
|
+
}
|
|
232
|
+
// TODO add interval
|
|
233
|
+
for (const eventsHandler of processor.eventHandlers) {
|
|
234
|
+
// associate id with filter
|
|
235
|
+
const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1
|
|
236
|
+
const logConfig: LogHandlerConfig = {
|
|
237
|
+
handlerId: handlerId,
|
|
238
|
+
filters: [],
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (const filter of eventsHandler.filters) {
|
|
242
|
+
if (!filter.topics) {
|
|
243
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
|
|
244
|
+
}
|
|
245
|
+
const logFilter: LogFilter = {
|
|
246
|
+
addressType: filter.addressType,
|
|
247
|
+
address: filter.address,
|
|
248
|
+
topics: [],
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
for (const ts of filter.topics) {
|
|
252
|
+
let hashes: string[] = []
|
|
253
|
+
if (Array.isArray(ts)) {
|
|
254
|
+
hashes = hashes.concat(ts)
|
|
255
|
+
} else if (ts) {
|
|
256
|
+
hashes.push(ts)
|
|
257
|
+
}
|
|
258
|
+
logFilter.topics.push({ hashes: hashes })
|
|
259
|
+
}
|
|
260
|
+
logConfig.filters.push(logFilter)
|
|
261
|
+
}
|
|
262
|
+
accountConfig.logConfigs.push(logConfig)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
this.accountConfigs.push(accountConfig)
|
|
266
|
+
}
|
|
267
|
+
|
|
219
268
|
// Part 2, prepare solana constractors
|
|
220
269
|
for (const solanaProcessor of global.PROCESSOR_STATE.solanaProcessors) {
|
|
221
270
|
const contractConfig: ContractConfig = {
|
|
@@ -327,6 +376,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
327
376
|
startBlock: Long.fromValue(aptosProcessor.config.startVersion.toString()),
|
|
328
377
|
aptosIntervalConfigs: [],
|
|
329
378
|
intervalConfigs: [],
|
|
379
|
+
logConfigs: [],
|
|
330
380
|
}
|
|
331
381
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
|
332
382
|
const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1
|
|
@@ -418,6 +468,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
418
468
|
return this.processAptosEvent(request)
|
|
419
469
|
case HandlerType.APT_RESOURCE:
|
|
420
470
|
return this.processAptosResource(request)
|
|
471
|
+
case HandlerType.ETH_LOG:
|
|
472
|
+
return this.processLog(request)
|
|
421
473
|
default:
|
|
422
474
|
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
423
475
|
}
|
|
@@ -430,24 +482,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
430
482
|
|
|
431
483
|
const promises: Promise<ProcessResult>[] = []
|
|
432
484
|
for (const l of request.bindings) {
|
|
433
|
-
|
|
434
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
435
|
-
}
|
|
436
|
-
// const jsonString = Buffer.from(l.log.raw.buffer).toString("utf-8")
|
|
437
|
-
// const jsonString = String.fromCharCode.apply(null, l.log.raw)
|
|
438
|
-
|
|
439
|
-
try {
|
|
440
|
-
const jsonString = Utf8ArrayToStr(l.data.raw)
|
|
441
|
-
const log: Log = JSON.parse(jsonString)
|
|
442
|
-
const handler = this.eventHandlers[l.handlerId]
|
|
443
|
-
const promise = handler(log).catch((e) => {
|
|
444
|
-
throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + errorString(e))
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
promises.push(promise)
|
|
448
|
-
} catch (e) {
|
|
449
|
-
throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)
|
|
450
|
-
}
|
|
485
|
+
promises.push(this.processLog(l))
|
|
451
486
|
}
|
|
452
487
|
|
|
453
488
|
const result = mergeProcessResults(await Promise.all(promises))
|
|
@@ -468,6 +503,23 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
468
503
|
}
|
|
469
504
|
}
|
|
470
505
|
|
|
506
|
+
async processLog(l: DataBinding): Promise<ProcessResult> {
|
|
507
|
+
if (!l.data) {
|
|
508
|
+
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
try {
|
|
512
|
+
const jsonString = Utf8ArrayToStr(l.data.raw)
|
|
513
|
+
const log: Log = JSON.parse(jsonString)
|
|
514
|
+
const handler = this.eventHandlers[l.handlerId]
|
|
515
|
+
return handler(log).catch((e) => {
|
|
516
|
+
throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + errorString(e))
|
|
517
|
+
})
|
|
518
|
+
} catch (e) {
|
|
519
|
+
throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
471
523
|
async processTransactions(
|
|
472
524
|
request: ProcessTransactionsRequest,
|
|
473
525
|
context: CallContext
|
|
@@ -501,31 +553,6 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
501
553
|
await Promise.all(processorPromises)
|
|
502
554
|
}
|
|
503
555
|
|
|
504
|
-
// if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
|
|
505
|
-
// const processorPromises: Promise<void>[] = []
|
|
506
|
-
// for (const txn of request.transactions) {
|
|
507
|
-
// processorPromises.push(
|
|
508
|
-
// new Promise((resolve, _) => {
|
|
509
|
-
// for (const processor of global.PROCESSOR_STATE.aptosProcessors) {
|
|
510
|
-
// if (processor.address === txn.programAccountId!) {
|
|
511
|
-
// const res = processor.handleTransaction(
|
|
512
|
-
// JSON.parse(new TextDecoder().decode(txn.raw)),
|
|
513
|
-
// txn.slot ?? Long.fromNumber(0)
|
|
514
|
-
// )
|
|
515
|
-
// if (res) {
|
|
516
|
-
// res.gauges.forEach((g) => result.gauges.push(g))
|
|
517
|
-
// res.counters.forEach((c) => result.counters.push(c))
|
|
518
|
-
// res.logs.forEach((l) => result.logs.push(l))
|
|
519
|
-
// }
|
|
520
|
-
// }
|
|
521
|
-
// }
|
|
522
|
-
// resolve()
|
|
523
|
-
// })
|
|
524
|
-
// )
|
|
525
|
-
// }
|
|
526
|
-
// await Promise.all(processorPromises)
|
|
527
|
-
// }
|
|
528
|
-
|
|
529
556
|
recordRuntimeInfo(result, HandlerType.TRANSACTION)
|
|
530
557
|
return {
|
|
531
558
|
result,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AccountConfig,
|
|
2
3
|
BlockBinding,
|
|
3
4
|
ContractConfig,
|
|
4
5
|
DataBinding,
|
|
@@ -25,6 +26,7 @@ import { ProcessorState } from '../state/processor-state'
|
|
|
25
26
|
import { ProcessorServiceImpl } from '../service'
|
|
26
27
|
import { Trace } from '../core/trace'
|
|
27
28
|
import { setProvider } from '../provider'
|
|
29
|
+
import { account } from '../builtin/aptos/0x1'
|
|
28
30
|
|
|
29
31
|
export const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
30
32
|
|
|
@@ -37,7 +39,8 @@ export function cleanTest() {
|
|
|
37
39
|
|
|
38
40
|
export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
39
41
|
service: ProcessorServiceImpl
|
|
40
|
-
|
|
42
|
+
contractConfigs: ContractConfig[]
|
|
43
|
+
accountConfigs: AccountConfig[]
|
|
41
44
|
|
|
42
45
|
constructor(loader: () => void, httpEndpoints: Record<string, string> = {}) {
|
|
43
46
|
cleanTest()
|
|
@@ -58,7 +61,9 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
58
61
|
|
|
59
62
|
async start(request: StartRequest = { templateInstances: [] }, context = TEST_CONTEXT): Promise<Empty> {
|
|
60
63
|
const res = await this.service.start(request, context)
|
|
61
|
-
|
|
64
|
+
const config = await this.getConfig({})
|
|
65
|
+
this.contractConfigs = config.contractConfigs
|
|
66
|
+
this.accountConfigs = config.accountConfigs
|
|
62
67
|
return res
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -114,7 +119,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
114
119
|
}
|
|
115
120
|
const signature = trace.action.input.slice(0, 10)
|
|
116
121
|
|
|
117
|
-
for (const contract of this.
|
|
122
|
+
for (const contract of this.contractConfigs) {
|
|
118
123
|
if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {
|
|
119
124
|
continue
|
|
120
125
|
}
|
|
@@ -155,7 +160,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
buildLogBinding(log: Log, network: Networkish = 1): DataBinding | undefined {
|
|
158
|
-
for (const contract of this.
|
|
163
|
+
for (const contract of this.contractConfigs) {
|
|
159
164
|
if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {
|
|
160
165
|
continue
|
|
161
166
|
}
|
|
@@ -197,6 +202,67 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
197
202
|
}
|
|
198
203
|
return undefined
|
|
199
204
|
}
|
|
205
|
+
testAccountLog(address: string, log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
206
|
+
return this.testAccountLogs(address, [log], network)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
testAccountLogs(address: string, logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
210
|
+
const bindings = []
|
|
211
|
+
for (const log of logs) {
|
|
212
|
+
const binding = this.buildAccountLogBinding(address, log, network)
|
|
213
|
+
if (!binding) {
|
|
214
|
+
throw Error('Invalid test log: ' + JSON.stringify(log))
|
|
215
|
+
}
|
|
216
|
+
bindings.push(binding)
|
|
217
|
+
}
|
|
218
|
+
return this.processLogs({
|
|
219
|
+
bindings: bindings,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
buildAccountLogBinding(address: string, log: Log, network: Networkish = 1): DataBinding | undefined {
|
|
224
|
+
for (const account of this.accountConfigs) {
|
|
225
|
+
if (account.chainId !== getNetwork(network).chainId.toString()) {
|
|
226
|
+
continue
|
|
227
|
+
}
|
|
228
|
+
if (address.toLowerCase() !== account.address.toLowerCase()) {
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
for (const config of account.logConfigs) {
|
|
232
|
+
for (const filter of config.filters) {
|
|
233
|
+
// if (filter.topics.length != log.topics.length) {
|
|
234
|
+
// continue
|
|
235
|
+
// }
|
|
236
|
+
|
|
237
|
+
let match = true
|
|
238
|
+
for (const topicIdx in filter.topics) {
|
|
239
|
+
const logTopic = log.topics[topicIdx]
|
|
240
|
+
const possibleTopic = filter.topics[topicIdx].hashes
|
|
241
|
+
if (possibleTopic.length === 0) {
|
|
242
|
+
// match all
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {
|
|
246
|
+
// find one
|
|
247
|
+
continue
|
|
248
|
+
}
|
|
249
|
+
match = false
|
|
250
|
+
break
|
|
251
|
+
}
|
|
252
|
+
if (match) {
|
|
253
|
+
return {
|
|
254
|
+
data: {
|
|
255
|
+
raw: toBytes(log),
|
|
256
|
+
},
|
|
257
|
+
handlerId: config.handlerId,
|
|
258
|
+
handlerType: HandlerType.ETH_LOG,
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return undefined
|
|
265
|
+
}
|
|
200
266
|
|
|
201
267
|
testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
202
268
|
return this.testBlocks([block], network)
|
|
@@ -223,7 +289,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
223
289
|
},
|
|
224
290
|
handlerIds: [],
|
|
225
291
|
}
|
|
226
|
-
for (const contract of this.
|
|
292
|
+
for (const contract of this.contractConfigs) {
|
|
227
293
|
if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {
|
|
228
294
|
continue
|
|
229
295
|
}
|