@sentio/sdk 1.14.4 → 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.
@@ -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: string;
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(10).fork()).ldelim();
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 { txHash: "", raw: new Uint8Array(), programAccountId: "" };
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(18).bytes(message.raw);
2292
+ writer.uint32(10).bytes(message.raw);
2282
2293
  }
2283
- if (message.programAccountId !== "") {
2284
- writer.uint32(26).string(message.programAccountId);
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.txHash = reader.string();
2311
+ message.raw = reader.bytes();
2298
2312
  break;
2299
2313
  case 2:
2300
- message.raw = reader.bytes();
2314
+ message.programAccountId = reader.string();
2301
2315
  break;
2302
2316
  case 3:
2303
- message.programAccountId = reader.string();
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
@@ -205,7 +205,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
205
205
  try {
206
206
  this.loader()
207
207
  } catch (e) {
208
- throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor : ' + e.toString())
208
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))
209
209
  }
210
210
 
211
211
  for (const instance of request.templateInstances) {
@@ -227,7 +227,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
227
227
  try {
228
228
  await this.configure()
229
229
  } catch (e) {
230
- throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + e.toString())
230
+ throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))
231
231
  }
232
232
  this.started = true
233
233
  return {}
@@ -265,7 +265,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
265
265
  const log: Log = JSON.parse(jsonString)
266
266
  const handler = this.eventHandlers[l.handlerId]
267
267
  const promise = handler(log).catch((e) => {
268
- throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + e.toString())
268
+ throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\n' + errorString(e))
269
269
  })
270
270
 
271
271
  promises.push(promise)
@@ -310,7 +310,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
310
310
  logs: [],
311
311
  }
312
312
 
313
- if (global.PROCESSOR_STATE.suiProcessors) {
313
+ if (request.chainId.toLowerCase().startsWith('sui') && global.PROCESSOR_STATE.suiProcessors) {
314
314
  const processorPromises: Promise<void>[] = []
315
315
  for (const txn of request.transactions) {
316
316
  processorPromises.push(
@@ -319,14 +319,14 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
319
319
  const res = processor.handleTransaction(JSON.parse(new TextDecoder().decode(txn.raw)))
320
320
  if (res) {
321
321
  res.gauges.forEach((g) => {
322
- if (g.metadata) {
323
- g.metadata.blockNumber = Long.fromString(txn.programAccountId)
322
+ if (g.metadata && txn.slot) {
323
+ g.metadata.blockNumber = txn.slot
324
324
  }
325
325
  result.gauges.push(g)
326
326
  })
327
327
  res.counters.forEach((c) => {
328
- if (c.metadata) {
329
- c.metadata.blockNumber = Long.fromString(txn.programAccountId)
328
+ if (c.metadata && txn.slot) {
329
+ c.metadata.blockNumber = txn.slot
330
330
  }
331
331
  result.counters.push(c)
332
332
  })
@@ -394,7 +394,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
394
394
  result.counters.push(c)
395
395
  })
396
396
  } catch (e) {
397
- console.error('error processing instruction ' + e.toString())
397
+ console.error('error processing instruction ' + errorString(e))
398
398
  }
399
399
  } else {
400
400
  console.warn(
@@ -455,7 +455,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
455
455
  const promises: Promise<ProcessResult>[] = []
456
456
  for (const handlerId of binding.handlerIds) {
457
457
  const promise = this.blockHandlers[handlerId](block).catch((e) => {
458
- throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\n' + e.toString())
458
+ throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\n' + errorString(e))
459
459
  })
460
460
  promises.push(promise)
461
461
  }
@@ -496,7 +496,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
496
496
  const trace: Trace = JSON.parse(jsonString)
497
497
 
498
498
  return this.traceHandlers[binding.handlerId](trace).catch((e) => {
499
- throw new ServerError(Status.INTERNAL, 'error processing trace: ' + jsonString + '\n' + e.toString())
499
+ throw new ServerError(Status.INTERNAL, 'error processing trace: ' + jsonString + '\n' + errorString(e))
500
500
  })
501
501
  }
502
502
  }
@@ -555,3 +555,7 @@ function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
555
555
  }
556
556
  })
557
557
  }
558
+
559
+ function errorString(e: Error): string {
560
+ return e.stack || e.message
561
+ }
@@ -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 })
@@ -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
  },