@sentio/sdk 1.19.4 → 1.19.5

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.
Files changed (98) hide show
  1. package/lib/aptos/aptos-processor.d.ts +40 -0
  2. package/lib/aptos/aptos-processor.js +126 -0
  3. package/lib/aptos/aptos-processor.js.map +1 -0
  4. package/lib/aptos/bind-options.d.ts +11 -0
  5. package/lib/aptos/bind-options.js +17 -0
  6. package/lib/aptos/bind-options.js.map +1 -0
  7. package/lib/aptos/context.d.ts +12 -0
  8. package/lib/aptos/context.js +33 -0
  9. package/lib/aptos/context.js.map +1 -0
  10. package/lib/aptos/index.d.ts +5 -0
  11. package/lib/aptos/index.js +11 -0
  12. package/lib/aptos/index.js.map +1 -0
  13. package/lib/core/base-processor-template.js.map +1 -1
  14. package/lib/core/base-processor.d.ts +1 -1
  15. package/lib/core/base-processor.js.map +1 -1
  16. package/lib/core/bind-options.d.ts +0 -2
  17. package/lib/core/bind-options.js +1 -4
  18. package/lib/core/bind-options.js.map +1 -1
  19. package/lib/core/context.d.ts +10 -10
  20. package/lib/core/context.js +65 -11
  21. package/lib/core/context.js.map +1 -1
  22. package/lib/core/index.d.ts +1 -2
  23. package/lib/core/index.js +1 -4
  24. package/lib/core/index.js.map +1 -1
  25. package/lib/core/logger.d.ts +1 -1
  26. package/lib/core/logger.js +5 -5
  27. package/lib/core/logger.js.map +1 -1
  28. package/lib/core/metadata.d.ts +1 -1
  29. package/lib/core/metadata.js +3 -79
  30. package/lib/core/metadata.js.map +1 -1
  31. package/lib/core/meter.d.ts +1 -1
  32. package/lib/core/meter.js +2 -2
  33. package/lib/core/meter.js.map +1 -1
  34. package/lib/core/numberish.d.ts +1 -1
  35. package/lib/core/numberish.js +7 -7
  36. package/lib/core/numberish.js.map +1 -1
  37. package/lib/core/numberish.test.js.map +1 -1
  38. package/lib/core/solana-processor.d.ts +1 -1
  39. package/lib/core/solana-processor.js.map +1 -1
  40. package/lib/core/sui-processor.d.ts +1 -1
  41. package/lib/core/sui-processor.js.map +1 -1
  42. package/lib/gen/index.d.ts +1 -0
  43. package/lib/gen/index.js +18 -0
  44. package/lib/gen/index.js.map +1 -0
  45. package/lib/index.d.ts +2 -1
  46. package/lib/index.js +15 -2
  47. package/lib/index.js.map +1 -1
  48. package/lib/processor-state.d.ts +2 -1
  49. package/lib/processor-state.js.map +1 -1
  50. package/lib/service.d.ts +2 -2
  51. package/lib/service.js +41 -36
  52. package/lib/service.js.map +1 -1
  53. package/lib/testing/metric-utils.d.ts +1 -1
  54. package/lib/testing/metric-utils.js +2 -2
  55. package/lib/testing/metric-utils.js.map +1 -1
  56. package/lib/testing/test-processor-server.d.ts +2 -1
  57. package/lib/testing/test-processor-server.js +11 -11
  58. package/lib/testing/test-processor-server.js.map +1 -1
  59. package/lib/testing/test-provider.js +2 -2
  60. package/lib/testing/test-provider.js.map +1 -1
  61. package/lib/tests/aptos.test.js +44 -12
  62. package/lib/tests/aptos.test.js.map +1 -1
  63. package/lib/tests/souffl3.js +16 -4
  64. package/lib/tests/souffl3.js.map +1 -1
  65. package/lib/utils/chain.d.ts +1 -0
  66. package/lib/utils/chain.js +3 -1
  67. package/lib/utils/chain.js.map +1 -1
  68. package/package.json +3 -5
  69. package/src/aptos/aptos-processor.ts +156 -0
  70. package/src/aptos/bind-options.ts +15 -0
  71. package/src/aptos/context.ts +35 -0
  72. package/src/aptos/index.ts +8 -0
  73. package/src/core/base-processor-template.ts +1 -1
  74. package/src/core/base-processor.ts +1 -1
  75. package/src/core/bind-options.ts +0 -1
  76. package/src/core/context.ts +74 -15
  77. package/src/core/index.ts +2 -2
  78. package/src/core/logger.ts +1 -1
  79. package/src/core/metadata.ts +4 -76
  80. package/src/core/meter.ts +1 -1
  81. package/src/core/numberish.test.ts +1 -1
  82. package/src/core/numberish.ts +1 -1
  83. package/src/core/solana-processor.ts +1 -1
  84. package/src/core/sui-processor.ts +1 -1
  85. package/src/gen/index.ts +1 -0
  86. package/src/index.ts +4 -1
  87. package/src/processor-state.ts +3 -1
  88. package/src/service.ts +29 -29
  89. package/src/testing/metric-utils.ts +2 -2
  90. package/src/testing/test-processor-server.ts +5 -2
  91. package/src/testing/test-provider.ts +1 -1
  92. package/src/tests/aptos.test.ts +47 -11
  93. package/src/tests/souffl3.ts +30 -12
  94. package/src/utils/chain.ts +2 -0
  95. package/lib/core/aptos-processor.d.ts +0 -41
  96. package/lib/core/aptos-processor.js +0 -125
  97. package/lib/core/aptos-processor.js.map +0 -1
  98. package/src/core/aptos-processor.ts +0 -147
package/src/core/index.ts CHANGED
@@ -3,13 +3,13 @@ export { Context, ContractView, BoundContractView, SolanaContext } from './conte
3
3
  export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter'
4
4
  export { type Numberish, toBigInteger, toMetricValue } from './numberish'
5
5
 
6
- export { BindOptions, SolanaBindOptions, SuiBindOptions, AptosBindOptions } from './bind-options'
6
+ export { BindOptions, SolanaBindOptions, SuiBindOptions } from './bind-options'
7
7
 
8
8
  export { BaseProcessor } from './base-processor'
9
9
  export { GenericProcessor } from './generic-processor'
10
10
  export { BaseProcessorTemplate } from './base-processor-template'
11
11
  export { SolanaBaseProcessor } from './solana-processor'
12
12
  export { SuiBaseProcessor } from './sui-processor'
13
- export { AptosBaseProcessor } from './aptos-processor'
13
+ // export * from '../aptos'
14
14
 
15
15
  export type { TypedCallTrace, Trace } from './trace'
@@ -1,6 +1,6 @@
1
1
  import { BaseContext } from './context'
2
2
  import { Labels, GetRecordMetaData } from './metadata'
3
- import { LogLevel } from '@sentio/sdk'
3
+ import { LogLevel } from '../gen'
4
4
 
5
5
  export type Attributes = Record<string, any>
6
6
 
@@ -1,7 +1,6 @@
1
- import { AptosContext, BaseContext, Context, SolanaContext, SuiContext } from './context'
2
- import { MetricDescriptor, RecordMetaData } from '@sentio/sdk'
3
- import { APTOS_TESTNET_ID, SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'
4
- import { Metric, normalizeLabels, normalizeName } from './meter'
1
+ import { BaseContext } from './context'
2
+ import { MetricDescriptor, RecordMetaData } from '../gen'
3
+ import { Metric, normalizeName } from './meter'
5
4
 
6
5
  export type Labels = { [key: string]: string }
7
6
 
@@ -17,76 +16,5 @@ export function GetRecordMetaData(ctx: BaseContext, metric: Metric | undefined,
17
16
  descriptor.name = normalizeName(descriptor.name)
18
17
  }
19
18
 
20
- if (ctx instanceof Context) {
21
- if (ctx.log) {
22
- return {
23
- contractAddress: ctx.contract.rawContract.address,
24
- blockNumber: ctx.blockNumber,
25
- transactionIndex: ctx.log.transactionIndex,
26
- transactionHash: ctx.transactionHash || '',
27
- logIndex: ctx.log.logIndex,
28
- chainId: ctx.chainId.toString(),
29
- descriptor: descriptor,
30
- labels: normalizeLabels(labels),
31
- }
32
- }
33
- if (ctx.block) {
34
- return {
35
- contractAddress: ctx.contract.rawContract.address,
36
- blockNumber: ctx.blockNumber,
37
- transactionIndex: -1,
38
- transactionHash: '',
39
- logIndex: -1,
40
- chainId: ctx.chainId.toString(),
41
- descriptor: descriptor,
42
- labels: normalizeLabels(labels),
43
- }
44
- }
45
- if (ctx.trace) {
46
- return {
47
- contractAddress: ctx.contract.rawContract.address,
48
- blockNumber: ctx.blockNumber,
49
- transactionIndex: ctx.trace.transactionPosition,
50
- transactionHash: ctx.transactionHash || '',
51
- logIndex: -1,
52
- chainId: ctx.chainId.toString(),
53
- descriptor: descriptor,
54
- labels: normalizeLabels(labels),
55
- }
56
- }
57
- } else if (ctx instanceof SolanaContext) {
58
- return {
59
- contractAddress: ctx.address,
60
- blockNumber: ctx.blockNumber,
61
- transactionIndex: 0,
62
- transactionHash: '', // TODO add
63
- logIndex: 0,
64
- chainId: SOL_MAINMET_ID, // TODO set in context
65
- descriptor: descriptor,
66
- labels: normalizeLabels(labels),
67
- }
68
- } else if (ctx instanceof SuiContext) {
69
- return {
70
- contractAddress: ctx.address,
71
- blockNumber: ctx.blockNumber,
72
- transactionIndex: 0,
73
- transactionHash: '', // TODO
74
- logIndex: 0,
75
- chainId: SUI_DEVNET_ID, // TODO set in context
76
- descriptor: descriptor,
77
- labels: normalizeLabels(labels),
78
- }
79
- } else if (ctx instanceof AptosContext) {
80
- return {
81
- contractAddress: ctx.address,
82
- blockNumber: ctx.blockNumber,
83
- transactionIndex: 0,
84
- transactionHash: '', // TODO
85
- logIndex: 0,
86
- chainId: APTOS_TESTNET_ID, // TODO set in context
87
- descriptor: descriptor,
88
- labels: normalizeLabels(labels),
89
- }
90
- }
91
- throw new Error("This can't happen")
19
+ return ctx.getMetaData(descriptor, labels)
92
20
  }
package/src/core/meter.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MetricDescriptor } from '../gen/processor/protos/processor'
1
+ import { MetricDescriptor } from '../gen'
2
2
  import { BaseContext } from './context'
3
3
  import { toMetricValue, Numberish } from './numberish'
4
4
  import { GetRecordMetaData, Labels } from './metadata'
@@ -3,7 +3,7 @@ import { toBigInteger, toMetricValue } from './numberish'
3
3
  import { webcrypto } from 'crypto'
4
4
  import { BigNumber } from 'ethers'
5
5
  import { performance } from 'perf_hooks'
6
- import { BigInteger } from '../gen/processor/protos/processor'
6
+ import { BigInteger } from '../gen'
7
7
  import { BigDecimal } from '.'
8
8
 
9
9
  // TODO add test for type conversion
@@ -1,5 +1,5 @@
1
1
  import { BigNumber } from 'ethers'
2
- import { BigInteger, MetricValue } from '../gen/processor/protos/processor'
2
+ import { BigInteger, MetricValue } from '../gen'
3
3
  import { BigDecimal } from '.'
4
4
  import { BN } from '@project-serum/anchor'
5
5
 
@@ -1,4 +1,4 @@
1
- import { ProcessResult } from '../gen/processor/protos/processor'
1
+ import { ProcessResult } from '../gen'
2
2
  import { SolanaContext } from './context'
3
3
  import Long from 'long'
4
4
  import { Instruction } from '@project-serum/anchor'
@@ -1,6 +1,6 @@
1
1
  import { SuiBindOptions } from './bind-options'
2
2
  import { SuiContext } from './context'
3
- import { ProcessResult } from '..'
3
+ import { ProcessResult } from '../gen'
4
4
  import Long from 'long'
5
5
 
6
6
  type IndexConfigure = {
@@ -0,0 +1 @@
1
+ export * from '../gen/processor/protos/processor'
package/src/index.ts CHANGED
@@ -7,5 +7,8 @@ export { EthersError } from './error'
7
7
 
8
8
  export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'
9
9
 
10
- export * from './gen/processor/protos/processor'
10
+ export * from './gen'
11
+
11
12
  export * from './core'
13
+
14
+ export * as aptos from './aptos'
@@ -5,8 +5,10 @@ import {
5
5
  BaseProcessorTemplate,
6
6
  SolanaBaseProcessor,
7
7
  SuiBaseProcessor,
8
- AptosBaseProcessor,
9
8
  } from './core'
9
+
10
+ import { AptosBaseProcessor } from './aptos'
11
+
10
12
  import { BaseContract } from 'ethers'
11
13
  import { TemplateInstance } from './gen/processor/protos/processor'
12
14
  import { Provider } from '@ethersproject/providers'
package/src/service.ts CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  ProcessTransactionsRequest,
23
23
  StartRequest,
24
24
  TemplateInstance,
25
- } from './gen/processor/protos/processor'
25
+ } from './gen'
26
26
 
27
27
  import { Empty } from './gen/google/protobuf/empty'
28
28
  import Long from 'long'
@@ -213,13 +213,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
213
213
  contract: {
214
214
  name: aptosProcessor.name,
215
215
  chainId: APTOS_TESTNET_ID,
216
- address: aptosProcessor.address,
216
+ address: aptosProcessor.config.address,
217
217
  abi: '',
218
218
  },
219
219
  blockConfigs: [],
220
220
  logConfigs: [],
221
221
  traceConfigs: [],
222
- startBlock: aptosProcessor.config.startSeqNumber,
222
+ startBlock: aptosProcessor.config.startVersion,
223
223
  endBlock: DEFAULT_MAX_BLOCK,
224
224
  instructionConfig: undefined,
225
225
  aptosEventConfigs: [],
@@ -324,7 +324,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
324
324
  async processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult> {
325
325
  switch (request.handlerType) {
326
326
  case HandlerType.APT_CALL:
327
- return this.processAptosCall(request)
327
+ return this.processAptosFunctionCall(request)
328
328
  case HandlerType.APT_EVENT:
329
329
  return this.processAptosEvent(request)
330
330
  default:
@@ -410,30 +410,30 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
410
410
  await Promise.all(processorPromises)
411
411
  }
412
412
 
413
- if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
414
- const processorPromises: Promise<void>[] = []
415
- for (const txn of request.transactions) {
416
- processorPromises.push(
417
- new Promise((resolve, _) => {
418
- for (const processor of global.PROCESSOR_STATE.aptosProcessors) {
419
- if (processor.address === txn.programAccountId!) {
420
- const res = processor.handleTransaction(
421
- JSON.parse(new TextDecoder().decode(txn.raw)),
422
- txn.slot ?? Long.fromNumber(0)
423
- )
424
- if (res) {
425
- res.gauges.forEach((g) => result.gauges.push(g))
426
- res.counters.forEach((c) => result.counters.push(c))
427
- res.logs.forEach((l) => result.logs.push(l))
428
- }
429
- }
430
- }
431
- resolve()
432
- })
433
- )
434
- }
435
- await Promise.all(processorPromises)
436
- }
413
+ // if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
414
+ // const processorPromises: Promise<void>[] = []
415
+ // for (const txn of request.transactions) {
416
+ // processorPromises.push(
417
+ // new Promise((resolve, _) => {
418
+ // for (const processor of global.PROCESSOR_STATE.aptosProcessors) {
419
+ // if (processor.address === txn.programAccountId!) {
420
+ // const res = processor.handleTransaction(
421
+ // JSON.parse(new TextDecoder().decode(txn.raw)),
422
+ // txn.slot ?? Long.fromNumber(0)
423
+ // )
424
+ // if (res) {
425
+ // res.gauges.forEach((g) => result.gauges.push(g))
426
+ // res.counters.forEach((c) => result.counters.push(c))
427
+ // res.logs.forEach((l) => result.logs.push(l))
428
+ // }
429
+ // }
430
+ // }
431
+ // resolve()
432
+ // })
433
+ // )
434
+ // }
435
+ // await Promise.all(processorPromises)
436
+ // }
437
437
 
438
438
  recordRuntimeInfo(result, HandlerType.TRANSACTION)
439
439
  return {
@@ -575,7 +575,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
575
575
  return result
576
576
  }
577
577
 
578
- async processAptosCall(binding: DataBinding): Promise<ProcessResult> {
578
+ async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {
579
579
  if (!binding.data) {
580
580
  throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
581
581
  }
@@ -1,6 +1,6 @@
1
1
  import { DeepPartial } from '../gen/builtin'
2
- import { BigDecimal, MetricValue, ProcessResult } from '@sentio/sdk'
3
- import { Numberish } from '../core'
2
+ import { MetricValue, ProcessResult } from '../gen'
3
+ import { Numberish, BigDecimal } from '../core'
4
4
  import { BigNumber } from 'ethers'
5
5
 
6
6
  export function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined {
@@ -25,7 +25,7 @@ import { Block, Log } from '@ethersproject/abstract-provider'
25
25
  import Long from 'long'
26
26
  import { getNetwork, Networkish } from '@ethersproject/providers'
27
27
 
28
- const TEST_CONTEXT: CallContext = <CallContext>{}
28
+ export const TEST_CONTEXT: CallContext = <CallContext>{}
29
29
 
30
30
  function cleanTest() {
31
31
  global.PROCESSOR_STATE = new ProcessorState()
@@ -238,7 +238,10 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
238
238
  return binding
239
239
  }
240
240
 
241
- processBindings(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse> {
241
+ processBindings(
242
+ request: ProcessBindingsRequest,
243
+ context: CallContext = TEST_CONTEXT
244
+ ): Promise<ProcessBindingResponse> {
242
245
  return this.service.processBindings(request, context)
243
246
  }
244
247
  }
@@ -1,6 +1,6 @@
1
1
  import { ChainConfig } from '../chain-config'
2
2
  import { CHAIN_MAP } from '../utils/chain'
3
- import { setProvider } from '@sentio/sdk'
3
+ import { setProvider } from '../provider'
4
4
 
5
5
  export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): boolean {
6
6
  const dummyConfig: Record<string, ChainConfig> = {}
@@ -1,8 +1,6 @@
1
1
  import { expect } from 'chai'
2
- import Long from 'long'
3
2
  import { TextEncoder } from 'util'
4
- import { ProcessTransactionsRequest } from '..'
5
- import { chain } from '../utils'
3
+ import { HandlerType, ProcessBindingsRequest } from '..'
6
4
 
7
5
  import { TestProcessorServer } from '../testing'
8
6
 
@@ -21,20 +19,57 @@ describe('Test Aptos Example', () => {
21
19
  })
22
20
 
23
21
  test('Check souffl3 transaction dispatch', async () => {
24
- const request: ProcessTransactionsRequest = {
25
- chainId: chain.APTOS_TESTNET_ID,
26
- transactions: [
22
+ const request: ProcessBindingsRequest = {
23
+ bindings: [
27
24
  {
28
- raw: new TextEncoder().encode(JSON.stringify(testData)),
29
- programAccountId: '4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
30
- slot: Long.fromNumber(12345),
25
+ data: {
26
+ raw: new TextEncoder().encode(JSON.stringify(testData)),
27
+ },
28
+ handlerId: 0,
29
+ handlerType: HandlerType.APT_CALL,
30
+ },
31
+ ],
32
+ }
33
+ const res = await service.processBindings(request)
34
+ expect(res.result?.counters).length(1)
35
+ expect(res.result?.gauges).length(0)
36
+ expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
37
+ })
38
+
39
+ test('Check souffl3 function call dispatch', async () => {
40
+ const request: ProcessBindingsRequest = {
41
+ bindings: [
42
+ {
43
+ data: {
44
+ raw: new TextEncoder().encode(JSON.stringify(testData)),
45
+ },
46
+ handlerId: 1,
47
+ handlerType: HandlerType.APT_CALL,
48
+ },
49
+ ],
50
+ }
51
+ const res = await service.processBindings(request)
52
+ expect(res.result?.counters).length(1)
53
+ expect(res.result?.gauges).length(0)
54
+ expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
55
+ })
56
+
57
+ test('Check souffl3 event dispatch', async () => {
58
+ const request: ProcessBindingsRequest = {
59
+ bindings: [
60
+ {
61
+ data: {
62
+ raw: new TextEncoder().encode(JSON.stringify(testData.events[1])),
63
+ },
64
+ handlerId: 0,
65
+ handlerType: HandlerType.APT_EVENT,
31
66
  },
32
67
  ],
33
68
  }
34
- const res = await service.processTransactions(request)
69
+ const res = await service.processBindings(request)
35
70
  expect(res.result?.counters).length(1)
36
71
  expect(res.result?.gauges).length(0)
37
- expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(12345)
72
+ expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
38
73
  })
39
74
  })
40
75
 
@@ -84,6 +119,7 @@ const testData = {
84
119
  },
85
120
  },
86
121
  {
122
+ version: '18483034',
87
123
  guid: {
88
124
  creation_number: '2',
89
125
  account_address: '0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
@@ -1,7 +1,7 @@
1
- import { AptosBindOptions, AptosBaseProcessor } from '@sentio/sdk'
1
+ import { aptos } from '@sentio/sdk'
2
2
 
3
- class Souffl3 extends AptosBaseProcessor {
4
- static bind(options: AptosBindOptions): Souffl3 {
3
+ class Souffl3 extends aptos.AptosBaseProcessor {
4
+ static bind(options: aptos.AptosBindOptions): Souffl3 {
5
5
  if (options && !options.name) {
6
6
  options.name = 'souffl3'
7
7
  }
@@ -10,14 +10,32 @@ class Souffl3 extends AptosBaseProcessor {
10
10
  }
11
11
 
12
12
  Souffl3.bind({
13
- startBlock: 6604913,
14
- address: '4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
15
- }).onTransaction((txn, ctx) => {
16
- if (txn.events) {
17
- for (const event of txn.events) {
18
- if (event && event.type === '0x3::token::DepositEvent') {
19
- ctx.meter.Counter('deposit_token_count').add(Number(event.data.amount))
13
+ startVersion: 6604913,
14
+ address: '0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
15
+ })
16
+ .onTransaction((txn, ctx) => {
17
+ if (txn.events) {
18
+ for (const event of txn.events) {
19
+ if (event && event.type === '0x3::token::DepositEvent') {
20
+ ctx.meter.Counter('deposit_token_count').add(Number(event.data.amount))
21
+ }
20
22
  }
21
23
  }
22
- }
23
- })
24
+ })
25
+ .onFunctionCall(
26
+ (call, ctx) => {
27
+ ctx.meter.Counter('call_num').add(1)
28
+ },
29
+ {
30
+ function: 'SouffleChefCampaign::pull_token_v2',
31
+ typeArguments: undefined,
32
+ }
33
+ )
34
+ .onEvent(
35
+ (event, ctx) => {
36
+ ctx.meter.Counter('evt_num').add(1)
37
+ },
38
+ {
39
+ type: '0x1::coin::DepositEvent',
40
+ }
41
+ )
@@ -91,7 +91,9 @@ export const SUI_DEVNET_ID = 'sui_devnet'
91
91
  CHAIN_MAP[SUI_DEVNET_ID] = 'sui-dev'
92
92
 
93
93
  export const APTOS_TESTNET_ID = 'aptos_testnet'
94
+ export const APTOS_MAINNET_ID = 'aptos_mainnet'
94
95
  CHAIN_MAP[APTOS_TESTNET_ID] = 'aptos-test'
96
+ CHAIN_MAP[APTOS_MAINNET_ID] = 'aptos-mainnet'
95
97
 
96
98
  export function getChainName(chainId: string | number): string {
97
99
  if (typeof chainId === 'number') {
@@ -1,41 +0,0 @@
1
- import { AptosBindOptions } from './bind-options';
2
- import { AptosContext } from './context';
3
- import { ProcessResult } from '..';
4
- import Long from 'long';
5
- declare type IndexConfigure = {
6
- startSeqNumber: Long;
7
- endSeqNumber?: Long;
8
- };
9
- export interface AptosEventFilter {
10
- type: string;
11
- }
12
- export interface AptosCallFilter {
13
- function: string;
14
- typeArguments: string[] | undefined;
15
- }
16
- export declare class AptosEventHandler {
17
- filters: AptosEventFilter[];
18
- handler: (event: any) => Promise<ProcessResult>;
19
- }
20
- export declare class AptosCallHandler {
21
- filters: AptosCallFilter[];
22
- handler: (func: any) => Promise<ProcessResult>;
23
- }
24
- export declare class AptosBaseProcessor {
25
- transactionHanlder: (transaction: any, ctx: AptosContext) => void;
26
- address: string;
27
- name: string;
28
- config: IndexConfigure;
29
- eventHandlers: AptosEventHandler[];
30
- callHandlers: AptosCallHandler[];
31
- constructor(options: AptosBindOptions);
32
- bind(options: AptosBindOptions): void;
33
- onTransaction(handler: (transaction: any, ctx: AptosContext) => void): this;
34
- onEvent(handler: (event: any, ctx: AptosContext) => void, filter: AptosEventFilter | AptosEventFilter[]): void;
35
- onCall(handler: (func: any, ctx: AptosContext) => void, filter: AptosCallFilter | AptosCallFilter[]): void;
36
- handleTransaction(txn: any, slot: Long): ProcessResult | null;
37
- isBind(): boolean;
38
- startSlot(startSlot: Long | number): this;
39
- endBlock(endBlock: Long | number): this;
40
- }
41
- export {};
@@ -1,125 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AptosBaseProcessor = exports.AptosCallHandler = exports.AptosEventHandler = void 0;
7
- const context_1 = require("./context");
8
- const long_1 = __importDefault(require("long"));
9
- class AptosEventHandler {
10
- filters;
11
- handler;
12
- }
13
- exports.AptosEventHandler = AptosEventHandler;
14
- class AptosCallHandler {
15
- filters;
16
- handler;
17
- }
18
- exports.AptosCallHandler = AptosCallHandler;
19
- class AptosBaseProcessor {
20
- transactionHanlder;
21
- address;
22
- name;
23
- config = { startSeqNumber: new long_1.default(0) };
24
- eventHandlers = [];
25
- callHandlers = [];
26
- constructor(options) {
27
- if (options) {
28
- this.bind(options);
29
- }
30
- global.PROCESSOR_STATE.aptosProcessors.push(this);
31
- }
32
- bind(options) {
33
- this.address = options.address;
34
- this.name = options.name || this.address;
35
- if (options.startBlock) {
36
- this.startSlot(options.startBlock);
37
- }
38
- if (options.endBlock) {
39
- this.endBlock(options.endBlock);
40
- }
41
- }
42
- onTransaction(handler) {
43
- if (!this.isBind()) {
44
- throw new Error("Processor doesn't bind to an address");
45
- }
46
- this.transactionHanlder = handler;
47
- return this;
48
- }
49
- onEvent(handler, filter) {
50
- let _filters = [];
51
- if (Array.isArray(filter)) {
52
- _filters = filter;
53
- }
54
- else {
55
- _filters.push(filter);
56
- }
57
- this.eventHandlers.push({
58
- handler: async function (event) {
59
- const ctx = new context_1.AptosContext(this.address, event.slot);
60
- if (event) {
61
- handler(event, ctx);
62
- }
63
- return {
64
- gauges: ctx.gauges,
65
- counters: ctx.counters,
66
- logs: ctx.logs,
67
- };
68
- },
69
- filters: _filters,
70
- });
71
- }
72
- onCall(handler, filter) {
73
- let _filters = [];
74
- if (Array.isArray(filter)) {
75
- _filters = filter;
76
- }
77
- else {
78
- _filters.push(filter);
79
- }
80
- this.callHandlers.push({
81
- handler: async function (call) {
82
- const ctx = new context_1.AptosContext(this.address, call.slot);
83
- if (call) {
84
- handler(call, ctx);
85
- }
86
- return {
87
- gauges: ctx.gauges,
88
- counters: ctx.counters,
89
- logs: ctx.logs,
90
- };
91
- },
92
- filters: _filters,
93
- });
94
- }
95
- handleTransaction(txn, slot) {
96
- const ctx = new context_1.AptosContext(this.address, slot);
97
- if (txn) {
98
- this.transactionHanlder(txn, ctx);
99
- }
100
- return {
101
- gauges: ctx.gauges,
102
- counters: ctx.counters,
103
- logs: ctx.logs,
104
- };
105
- }
106
- isBind() {
107
- return this.address !== null;
108
- }
109
- startSlot(startSlot) {
110
- if (typeof startSlot === 'number') {
111
- startSlot = long_1.default.fromNumber(startSlot);
112
- }
113
- this.config.startSeqNumber = startSlot;
114
- return this;
115
- }
116
- endBlock(endBlock) {
117
- if (typeof endBlock === 'number') {
118
- endBlock = long_1.default.fromNumber(endBlock);
119
- }
120
- this.config.endSeqNumber = endBlock;
121
- return this;
122
- }
123
- }
124
- exports.AptosBaseProcessor = AptosBaseProcessor;
125
- //# sourceMappingURL=aptos-processor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/core/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAwC;AAExC,gDAAuB;AAevB,MAAa,iBAAiB;IAC5B,OAAO,CAAoB;IAC3B,OAAO,CAAwC;CAChD;AAHD,8CAGC;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAmB;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GAAG,IAAI,sBAAY,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAEhD,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,IAAI,EAAE,GAAG,CAAC,IAAI;SACf,CAAA;IACH,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAA;IAC9B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,SAAS,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAtHD,gDAsHC","sourcesContent":["import { AptosBindOptions } from './bind-options'\nimport { AptosContext } from './context'\nimport { ProcessResult } from '..'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport interface AptosEventFilter {\n type: string\n}\nexport interface AptosCallFilter {\n function: string\n typeArguments: string[] | undefined\n}\n\nexport class AptosEventHandler {\n filters: AptosEventFilter[]\n handler: (event: any) => Promise<ProcessResult>\n}\n\nexport class AptosCallHandler {\n filters: AptosCallFilter[]\n handler: (func: any) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: AptosContext) => void\n address: string\n name: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n eventHandlers: AptosEventHandler[] = []\n callHandlers: AptosCallHandler[] = []\n\n constructor(options: AptosBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n bind(options: AptosBindOptions) {\n this.address = options.address\n this.name = options.name || this.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n }\n\n public onTransaction(handler: (transaction: any, ctx: AptosContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.transactionHanlder = handler\n\n return this\n }\n\n public onEvent(handler: (event: any, ctx: AptosContext) => void, filter: AptosEventFilter | AptosEventFilter[]) {\n let _filters: AptosEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n this.eventHandlers.push({\n handler: async function (event) {\n const ctx = new AptosContext(this.address, event.slot)\n if (event) {\n handler(event, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n }\n\n public onCall(handler: (func: any, ctx: AptosContext) => void, filter: AptosCallFilter | AptosCallFilter[]) {\n let _filters: AptosCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n this.callHandlers.push({\n handler: async function (call) {\n const ctx = new AptosContext(this.address, call.slot)\n if (call) {\n handler(call, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new AptosContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}