@sentio/sdk 1.14.3 → 1.15.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/cli/upload.js +78 -42
- package/lib/cli/upload.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +3 -2
- package/lib/gen/processor/protos/processor.js +34 -17
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.js +24 -11
- package/lib/service.js.map +1 -1
- package/lib/test/erc20.js +5 -0
- package/lib/test/erc20.js.map +1 -1
- package/lib/test/erc20.test.js +13 -0
- package/lib/test/erc20.test.js.map +1 -1
- package/lib/test/sui.test.js +2 -1
- package/lib/test/sui.test.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/upload.ts +76 -38
- package/src/gen/processor/protos/processor.ts +37 -19
- package/src/service.ts +23 -11
- package/src/test/erc20.test.ts +15 -1
- package/src/test/erc20.ts +5 -1
- package/src/test/sui.test.ts +2 -1
|
@@ -194,6 +194,7 @@ export interface ProcessTracesResponse {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
export interface ProcessTransactionsRequest {
|
|
197
|
+
chainId: string;
|
|
197
198
|
transactions: RawTransaction[];
|
|
198
199
|
}
|
|
199
200
|
|
|
@@ -236,9 +237,9 @@ export interface RawTrace {
|
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
export interface RawTransaction {
|
|
239
|
-
txHash: string;
|
|
240
240
|
raw: Uint8Array;
|
|
241
|
-
programAccountId
|
|
241
|
+
programAccountId?: string | undefined;
|
|
242
|
+
slot?: Long | undefined;
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
export interface Instruction {
|
|
@@ -1627,7 +1628,7 @@ export const ProcessTracesResponse = {
|
|
|
1627
1628
|
};
|
|
1628
1629
|
|
|
1629
1630
|
function createBaseProcessTransactionsRequest(): ProcessTransactionsRequest {
|
|
1630
|
-
return { transactions: [] };
|
|
1631
|
+
return { chainId: "", transactions: [] };
|
|
1631
1632
|
}
|
|
1632
1633
|
|
|
1633
1634
|
export const ProcessTransactionsRequest = {
|
|
@@ -1635,8 +1636,11 @@ export const ProcessTransactionsRequest = {
|
|
|
1635
1636
|
message: ProcessTransactionsRequest,
|
|
1636
1637
|
writer: _m0.Writer = _m0.Writer.create()
|
|
1637
1638
|
): _m0.Writer {
|
|
1639
|
+
if (message.chainId !== "") {
|
|
1640
|
+
writer.uint32(10).string(message.chainId);
|
|
1641
|
+
}
|
|
1638
1642
|
for (const v of message.transactions) {
|
|
1639
|
-
RawTransaction.encode(v!, writer.uint32(
|
|
1643
|
+
RawTransaction.encode(v!, writer.uint32(18).fork()).ldelim();
|
|
1640
1644
|
}
|
|
1641
1645
|
return writer;
|
|
1642
1646
|
},
|
|
@@ -1652,6 +1656,9 @@ export const ProcessTransactionsRequest = {
|
|
|
1652
1656
|
const tag = reader.uint32();
|
|
1653
1657
|
switch (tag >>> 3) {
|
|
1654
1658
|
case 1:
|
|
1659
|
+
message.chainId = reader.string();
|
|
1660
|
+
break;
|
|
1661
|
+
case 2:
|
|
1655
1662
|
message.transactions.push(
|
|
1656
1663
|
RawTransaction.decode(reader, reader.uint32())
|
|
1657
1664
|
);
|
|
@@ -1666,6 +1673,7 @@ export const ProcessTransactionsRequest = {
|
|
|
1666
1673
|
|
|
1667
1674
|
fromJSON(object: any): ProcessTransactionsRequest {
|
|
1668
1675
|
return {
|
|
1676
|
+
chainId: isSet(object.chainId) ? String(object.chainId) : "",
|
|
1669
1677
|
transactions: Array.isArray(object?.transactions)
|
|
1670
1678
|
? object.transactions.map((e: any) => RawTransaction.fromJSON(e))
|
|
1671
1679
|
: [],
|
|
@@ -1674,6 +1682,7 @@ export const ProcessTransactionsRequest = {
|
|
|
1674
1682
|
|
|
1675
1683
|
toJSON(message: ProcessTransactionsRequest): unknown {
|
|
1676
1684
|
const obj: any = {};
|
|
1685
|
+
message.chainId !== undefined && (obj.chainId = message.chainId);
|
|
1677
1686
|
if (message.transactions) {
|
|
1678
1687
|
obj.transactions = message.transactions.map((e) =>
|
|
1679
1688
|
e ? RawTransaction.toJSON(e) : undefined
|
|
@@ -1688,6 +1697,7 @@ export const ProcessTransactionsRequest = {
|
|
|
1688
1697
|
object: DeepPartial<ProcessTransactionsRequest>
|
|
1689
1698
|
): ProcessTransactionsRequest {
|
|
1690
1699
|
const message = createBaseProcessTransactionsRequest();
|
|
1700
|
+
message.chainId = object.chainId ?? "";
|
|
1691
1701
|
message.transactions =
|
|
1692
1702
|
object.transactions?.map((e) => RawTransaction.fromPartial(e)) || [];
|
|
1693
1703
|
return message;
|
|
@@ -2266,7 +2276,11 @@ export const RawTrace = {
|
|
|
2266
2276
|
};
|
|
2267
2277
|
|
|
2268
2278
|
function createBaseRawTransaction(): RawTransaction {
|
|
2269
|
-
return {
|
|
2279
|
+
return {
|
|
2280
|
+
raw: new Uint8Array(),
|
|
2281
|
+
programAccountId: undefined,
|
|
2282
|
+
slot: undefined,
|
|
2283
|
+
};
|
|
2270
2284
|
}
|
|
2271
2285
|
|
|
2272
2286
|
export const RawTransaction = {
|
|
@@ -2274,14 +2288,14 @@ export const RawTransaction = {
|
|
|
2274
2288
|
message: RawTransaction,
|
|
2275
2289
|
writer: _m0.Writer = _m0.Writer.create()
|
|
2276
2290
|
): _m0.Writer {
|
|
2277
|
-
if (message.txHash !== "") {
|
|
2278
|
-
writer.uint32(10).string(message.txHash);
|
|
2279
|
-
}
|
|
2280
2291
|
if (message.raw.length !== 0) {
|
|
2281
|
-
writer.uint32(
|
|
2292
|
+
writer.uint32(10).bytes(message.raw);
|
|
2282
2293
|
}
|
|
2283
|
-
if (message.programAccountId !==
|
|
2284
|
-
writer.uint32(
|
|
2294
|
+
if (message.programAccountId !== undefined) {
|
|
2295
|
+
writer.uint32(18).string(message.programAccountId);
|
|
2296
|
+
}
|
|
2297
|
+
if (message.slot !== undefined) {
|
|
2298
|
+
writer.uint32(24).uint64(message.slot);
|
|
2285
2299
|
}
|
|
2286
2300
|
return writer;
|
|
2287
2301
|
},
|
|
@@ -2294,13 +2308,13 @@ export const RawTransaction = {
|
|
|
2294
2308
|
const tag = reader.uint32();
|
|
2295
2309
|
switch (tag >>> 3) {
|
|
2296
2310
|
case 1:
|
|
2297
|
-
message.
|
|
2311
|
+
message.raw = reader.bytes();
|
|
2298
2312
|
break;
|
|
2299
2313
|
case 2:
|
|
2300
|
-
message.
|
|
2314
|
+
message.programAccountId = reader.string();
|
|
2301
2315
|
break;
|
|
2302
2316
|
case 3:
|
|
2303
|
-
message.
|
|
2317
|
+
message.slot = reader.uint64() as Long;
|
|
2304
2318
|
break;
|
|
2305
2319
|
default:
|
|
2306
2320
|
reader.skipType(tag & 7);
|
|
@@ -2312,31 +2326,35 @@ export const RawTransaction = {
|
|
|
2312
2326
|
|
|
2313
2327
|
fromJSON(object: any): RawTransaction {
|
|
2314
2328
|
return {
|
|
2315
|
-
txHash: isSet(object.txHash) ? String(object.txHash) : "",
|
|
2316
2329
|
raw: isSet(object.raw) ? bytesFromBase64(object.raw) : new Uint8Array(),
|
|
2317
2330
|
programAccountId: isSet(object.programAccountId)
|
|
2318
2331
|
? String(object.programAccountId)
|
|
2319
|
-
:
|
|
2332
|
+
: undefined,
|
|
2333
|
+
slot: isSet(object.slot) ? Long.fromValue(object.slot) : undefined,
|
|
2320
2334
|
};
|
|
2321
2335
|
},
|
|
2322
2336
|
|
|
2323
2337
|
toJSON(message: RawTransaction): unknown {
|
|
2324
2338
|
const obj: any = {};
|
|
2325
|
-
message.txHash !== undefined && (obj.txHash = message.txHash);
|
|
2326
2339
|
message.raw !== undefined &&
|
|
2327
2340
|
(obj.raw = base64FromBytes(
|
|
2328
2341
|
message.raw !== undefined ? message.raw : new Uint8Array()
|
|
2329
2342
|
));
|
|
2330
2343
|
message.programAccountId !== undefined &&
|
|
2331
2344
|
(obj.programAccountId = message.programAccountId);
|
|
2345
|
+
message.slot !== undefined &&
|
|
2346
|
+
(obj.slot = (message.slot || undefined).toString());
|
|
2332
2347
|
return obj;
|
|
2333
2348
|
},
|
|
2334
2349
|
|
|
2335
2350
|
fromPartial(object: DeepPartial<RawTransaction>): RawTransaction {
|
|
2336
2351
|
const message = createBaseRawTransaction();
|
|
2337
|
-
message.txHash = object.txHash ?? "";
|
|
2338
2352
|
message.raw = object.raw ?? new Uint8Array();
|
|
2339
|
-
message.programAccountId = object.programAccountId ??
|
|
2353
|
+
message.programAccountId = object.programAccountId ?? undefined;
|
|
2354
|
+
message.slot =
|
|
2355
|
+
object.slot !== undefined && object.slot !== null
|
|
2356
|
+
? Long.fromValue(object.slot)
|
|
2357
|
+
: undefined;
|
|
2340
2358
|
return message;
|
|
2341
2359
|
},
|
|
2342
2360
|
};
|
package/src/service.ts
CHANGED
|
@@ -202,7 +202,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
202
202
|
return {}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
try {
|
|
206
|
+
this.loader()
|
|
207
|
+
} catch (e) {
|
|
208
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))
|
|
209
|
+
}
|
|
206
210
|
|
|
207
211
|
for (const instance of request.templateInstances) {
|
|
208
212
|
const template = global.PROCESSOR_STATE.templates[instance.templateId]
|
|
@@ -220,7 +224,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
220
224
|
endBlock: instance.endBlock,
|
|
221
225
|
})
|
|
222
226
|
}
|
|
223
|
-
|
|
227
|
+
try {
|
|
228
|
+
await this.configure()
|
|
229
|
+
} catch (e) {
|
|
230
|
+
throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))
|
|
231
|
+
}
|
|
224
232
|
this.started = true
|
|
225
233
|
return {}
|
|
226
234
|
}
|
|
@@ -257,7 +265,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
257
265
|
const log: Log = JSON.parse(jsonString)
|
|
258
266
|
const handler = this.eventHandlers[l.handlerId]
|
|
259
267
|
const promise = handler(log).catch((e) => {
|
|
260
|
-
throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + e
|
|
268
|
+
throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + errorString(e))
|
|
261
269
|
})
|
|
262
270
|
|
|
263
271
|
promises.push(promise)
|
|
@@ -302,7 +310,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
302
310
|
logs: [],
|
|
303
311
|
}
|
|
304
312
|
|
|
305
|
-
if (global.PROCESSOR_STATE.suiProcessors) {
|
|
313
|
+
if (request.chainId.toLowerCase().startsWith('sui') && global.PROCESSOR_STATE.suiProcessors) {
|
|
306
314
|
const processorPromises: Promise<void>[] = []
|
|
307
315
|
for (const txn of request.transactions) {
|
|
308
316
|
processorPromises.push(
|
|
@@ -311,14 +319,14 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
311
319
|
const res = processor.handleTransaction(JSON.parse(new TextDecoder().decode(txn.raw)))
|
|
312
320
|
if (res) {
|
|
313
321
|
res.gauges.forEach((g) => {
|
|
314
|
-
if (g.metadata) {
|
|
315
|
-
g.metadata.blockNumber =
|
|
322
|
+
if (g.metadata && txn.slot) {
|
|
323
|
+
g.metadata.blockNumber = txn.slot
|
|
316
324
|
}
|
|
317
325
|
result.gauges.push(g)
|
|
318
326
|
})
|
|
319
327
|
res.counters.forEach((c) => {
|
|
320
|
-
if (c.metadata) {
|
|
321
|
-
c.metadata.blockNumber =
|
|
328
|
+
if (c.metadata && txn.slot) {
|
|
329
|
+
c.metadata.blockNumber = txn.slot
|
|
322
330
|
}
|
|
323
331
|
result.counters.push(c)
|
|
324
332
|
})
|
|
@@ -386,7 +394,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
386
394
|
result.counters.push(c)
|
|
387
395
|
})
|
|
388
396
|
} catch (e) {
|
|
389
|
-
console.error('error processing instruction ' + e
|
|
397
|
+
console.error('error processing instruction ' + errorString(e))
|
|
390
398
|
}
|
|
391
399
|
} else {
|
|
392
400
|
console.warn(
|
|
@@ -447,7 +455,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
447
455
|
const promises: Promise<ProcessResult>[] = []
|
|
448
456
|
for (const handlerId of binding.handlerIds) {
|
|
449
457
|
const promise = this.blockHandlers[handlerId](block).catch((e) => {
|
|
450
|
-
throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\n' + e
|
|
458
|
+
throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\n' + errorString(e))
|
|
451
459
|
})
|
|
452
460
|
promises.push(promise)
|
|
453
461
|
}
|
|
@@ -488,7 +496,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
488
496
|
const trace: Trace = JSON.parse(jsonString)
|
|
489
497
|
|
|
490
498
|
return this.traceHandlers[binding.handlerId](trace).catch((e) => {
|
|
491
|
-
throw new ServerError(Status.INTERNAL, 'error processing trace: ' + jsonString + '\n' + e
|
|
499
|
+
throw new ServerError(Status.INTERNAL, 'error processing trace: ' + jsonString + '\n' + errorString(e))
|
|
492
500
|
})
|
|
493
501
|
}
|
|
494
502
|
}
|
|
@@ -547,3 +555,7 @@ function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
|
|
|
547
555
|
}
|
|
548
556
|
})
|
|
549
557
|
}
|
|
558
|
+
|
|
559
|
+
function errorString(e: Error): string {
|
|
560
|
+
return e.stack || e.message
|
|
561
|
+
}
|
package/src/test/erc20.test.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { HandlerType } from '..'
|
|
|
7
7
|
import { TestProcessorServer } from './test-processor-server'
|
|
8
8
|
import { firstCounterValue, firstGaugeValue } from './metric-utils'
|
|
9
9
|
import { BigNumber } from 'ethers'
|
|
10
|
-
import { mockTransferLog } from '../builtin/erc20/test-utils'
|
|
10
|
+
import { mockApprovalLog, mockTransferLog } from '../builtin/erc20/test-utils'
|
|
11
11
|
import { Trace } from '../trace'
|
|
12
12
|
|
|
13
13
|
describe('Test Basic Examples', () => {
|
|
@@ -80,6 +80,20 @@ describe('Test Basic Examples', () => {
|
|
|
80
80
|
expect(config).deep.equals(config2)
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
+
test('Check log exception', async () => {
|
|
84
|
+
const logData = mockApprovalLog('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', {
|
|
85
|
+
owner: '0x0000000000000000000000000000000000000000',
|
|
86
|
+
spender: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1',
|
|
87
|
+
value: BigNumber.from('1111'),
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
await service.testLog(logData, 56)
|
|
92
|
+
} catch (e) {
|
|
93
|
+
expect(e.message.indexOf('sdk/src/test/erc20.ts') != -1).eq(true)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
83
97
|
const blockData = {
|
|
84
98
|
hash: '0x2b9b7cce1f17f3b7e1f3c2472cc806a07bee3f0baca07d021350950d81d73a42',
|
|
85
99
|
number: 14373295,
|
package/src/test/erc20.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ERC20Processor, ERC20ProcessorTemplate } from '../builtin/erc20'
|
|
2
|
+
import { BigNumber } from '@ethersproject/bignumber'
|
|
2
3
|
|
|
3
4
|
export const filter = ERC20Processor.filters.Transfer(
|
|
4
5
|
'0x0000000000000000000000000000000000000000',
|
|
@@ -34,7 +35,10 @@ ERC20Processor.bind({ address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', net
|
|
|
34
35
|
.onBlock(async function (block, ctx) {
|
|
35
36
|
ctx.meter.Gauge('g2').record(20, { k: 'v' })
|
|
36
37
|
})
|
|
37
|
-
|
|
38
|
+
.onEventApproval(async function (event, ctx) {
|
|
39
|
+
BigNumber.from(10 ** 18)
|
|
40
|
+
// console.log(n)
|
|
41
|
+
})
|
|
38
42
|
ERC20Processor.bind({ address: 'xxxx', network: 56 })
|
|
39
43
|
|
|
40
44
|
ERC20Processor.bind({ address: 'yyyy', network: 1 })
|
package/src/test/sui.test.ts
CHANGED
|
@@ -20,9 +20,10 @@ describe('Test Sui Example', () => {
|
|
|
20
20
|
|
|
21
21
|
test('Check tictactoe transaction dispatch', async () => {
|
|
22
22
|
const request: ProcessTransactionsRequest = {
|
|
23
|
+
chainId: 'SUI_devnet',
|
|
23
24
|
transactions: [
|
|
24
25
|
{
|
|
25
|
-
txHash: 'z3HjnnFFKAaszOi0pMSImtGMpRd2r7ljLjAjUoqs3Kw=',
|
|
26
|
+
// txHash: 'z3HjnnFFKAaszOi0pMSImtGMpRd2r7ljLjAjUoqs3Kw=',
|
|
26
27
|
raw: new TextEncoder().encode(JSON.stringify(testData)),
|
|
27
28
|
programAccountId: '0xb8252513f0b9efaa3e260842c4b84d8ff933522d',
|
|
28
29
|
},
|