@sentio/sdk 3.0.0-rc-next.5 → 3.0.0-rc.10

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 (87) hide show
  1. package/lib/aptos/aptos-plugin.js +22 -22
  2. package/lib/aptos/aptos-plugin.js.map +1 -1
  3. package/lib/aptos/aptos-resource-processor-template.d.ts +2 -1
  4. package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
  5. package/lib/aptos/aptos-resource-processor-template.js +28 -25
  6. package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
  7. package/lib/core/base-context.d.ts +2 -1
  8. package/lib/core/base-context.d.ts.map +1 -1
  9. package/lib/core/base-context.js +6 -0
  10. package/lib/core/base-context.js.map +1 -1
  11. package/lib/core/core-plugin.d.ts.map +1 -1
  12. package/lib/core/core-plugin.js +0 -3
  13. package/lib/core/core-plugin.js.map +1 -1
  14. package/lib/core/normalization.d.ts.map +1 -1
  15. package/lib/core/normalization.js +1 -7
  16. package/lib/core/normalization.js.map +1 -1
  17. package/lib/cosmos/cosmos-plugin.d.ts +0 -1
  18. package/lib/cosmos/cosmos-plugin.d.ts.map +1 -1
  19. package/lib/cosmos/cosmos-plugin.js +0 -4
  20. package/lib/cosmos/cosmos-plugin.js.map +1 -1
  21. package/lib/eth/base-processor-template.d.ts +2 -1
  22. package/lib/eth/base-processor-template.d.ts.map +1 -1
  23. package/lib/eth/base-processor-template.js +26 -24
  24. package/lib/eth/base-processor-template.js.map +1 -1
  25. package/lib/eth/base-processor.d.ts +2 -2
  26. package/lib/eth/base-processor.d.ts.map +1 -1
  27. package/lib/eth/base-processor.js +5 -1
  28. package/lib/eth/base-processor.js.map +1 -1
  29. package/lib/eth/eth-plugin.d.ts +0 -1
  30. package/lib/eth/eth-plugin.d.ts.map +1 -1
  31. package/lib/eth/eth-plugin.js +12 -8
  32. package/lib/eth/eth-plugin.js.map +1 -1
  33. package/lib/eth/eth.d.ts +1 -0
  34. package/lib/eth/eth.d.ts.map +1 -1
  35. package/lib/eth/eth.js.map +1 -1
  36. package/lib/fuel/fuel-plugin.d.ts +0 -1
  37. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  38. package/lib/fuel/fuel-plugin.js +0 -4
  39. package/lib/fuel/fuel-plugin.js.map +1 -1
  40. package/lib/fuel/fuel-processor-template.d.ts +2 -1
  41. package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
  42. package/lib/fuel/fuel-processor-template.js +28 -23
  43. package/lib/fuel/fuel-processor-template.js.map +1 -1
  44. package/lib/iota/iota-object-processor-template.d.ts +2 -1
  45. package/lib/iota/iota-object-processor-template.d.ts.map +1 -1
  46. package/lib/iota/iota-object-processor-template.js +51 -39
  47. package/lib/iota/iota-object-processor-template.js.map +1 -1
  48. package/lib/iota/iota-plugin-part.js +1 -1
  49. package/lib/iota/iota-plugin-part.js.map +1 -1
  50. package/lib/stark/starknet-plugin.d.ts +0 -1
  51. package/lib/stark/starknet-plugin.d.ts.map +1 -1
  52. package/lib/stark/starknet-plugin.js +0 -4
  53. package/lib/stark/starknet-plugin.js.map +1 -1
  54. package/lib/sui/sui-object-processor-template.d.ts +2 -1
  55. package/lib/sui/sui-object-processor-template.d.ts.map +1 -1
  56. package/lib/sui/sui-object-processor-template.js +51 -39
  57. package/lib/sui/sui-object-processor-template.js.map +1 -1
  58. package/lib/sui/sui-plugin-part.js +1 -1
  59. package/lib/sui/sui-plugin-part.js.map +1 -1
  60. package/lib/testing/test-processor-server.d.ts +12 -3
  61. package/lib/testing/test-processor-server.d.ts.map +1 -1
  62. package/lib/testing/test-processor-server.js +47 -7
  63. package/lib/testing/test-processor-server.js.map +1 -1
  64. package/package.json +5 -5
  65. package/src/aptos/aptos-plugin.ts +23 -23
  66. package/src/aptos/aptos-resource-processor-template.ts +36 -30
  67. package/src/core/base-context.ts +8 -1
  68. package/src/core/core-plugin.ts +0 -4
  69. package/src/core/normalization.ts +1 -6
  70. package/src/cosmos/cosmos-plugin.ts +0 -5
  71. package/src/eth/base-processor-template.ts +32 -27
  72. package/src/eth/base-processor.ts +19 -15
  73. package/src/eth/eth-plugin.ts +11 -9
  74. package/src/eth/eth.ts +2 -0
  75. package/src/fuel/fuel-plugin.ts +0 -5
  76. package/src/fuel/fuel-processor-template.ts +34 -26
  77. package/src/iota/iota-object-processor-template.ts +61 -46
  78. package/src/iota/iota-plugin-part.ts +1 -1
  79. package/src/stark/starknet-plugin.ts +0 -5
  80. package/src/sui/sui-object-processor-template.ts +63 -47
  81. package/src/sui/sui-plugin-part.ts +1 -1
  82. package/src/testing/test-processor-server.ts +64 -10
  83. package/lib/core/template.d.ts +0 -2
  84. package/lib/core/template.d.ts.map +0 -1
  85. package/lib/core/template.js +0 -2
  86. package/lib/core/template.js.map +0 -1
  87. package/src/core/template.ts +0 -1
@@ -1,8 +1,7 @@
1
1
  import { FuelContext, FuelContractContext } from './context.js'
2
2
  import { HandleInterval, TemplateInstance } from '@sentio/protos'
3
3
  import { PromiseOrVoid } from '../core/promises.js'
4
- import { ListStateStorage } from '@sentio/runtime'
5
- import { TemplateInstanceState } from '../core/template.js'
4
+ import { ListStateStorage, processMetrics } from '@sentio/runtime'
6
5
  import { Contract } from 'fuels'
7
6
  import { FuelBlock, FuelLog, FuelTransaction } from './types.js'
8
7
  import { DEFAULT_FUEL_FETCH_CONFIG, FuelFetchConfig } from './transaction.js'
@@ -16,7 +15,7 @@ export class FuelProcessorTemplateProcessorState extends ListStateStorage<FuelBa
16
15
 
17
16
  export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
18
17
  id: number
19
- binds = new Set<string>()
18
+ instances = new Set<string>()
20
19
  blockHandlers: {
21
20
  handlerName: string
22
21
  handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid
@@ -52,28 +51,6 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
52
51
  * @param ctx
53
52
  */
54
53
  public bind(options: Omit<Omit<FuelProcessorConfig, 'chainId'>, 'abi'>, ctx: FuelContext): void {
55
- const sig = getOptionsSignature({
56
- address: options.address,
57
- chainId: ctx.chainId
58
- })
59
- if (this.binds.has(sig)) {
60
- console.log(`Same address can be bind to one template only once, ignore duplicate bind: ${sig}`)
61
- return
62
- }
63
- this.binds.add(sig)
64
-
65
- const processor = this.bindInternal({ ...options, chainId: ctx.chainId })
66
-
67
- for (const eh of this.logHandlers) {
68
- processor.onLog(eh.logIdFilter, eh.handler, eh.handlerOptions, eh.handlerName)
69
- }
70
- for (const bh of this.blockHandlers) {
71
- processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.handlerOptions, bh.handlerName)
72
- }
73
- for (const th of this.transactionHandlers) {
74
- processor.onTransaction(th.handler, th.handlerOptions, th.handlerName)
75
- }
76
-
77
54
  const instance: TemplateInstance = {
78
55
  templateId: this.id,
79
56
  contract: {
@@ -87,12 +64,43 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
87
64
  baseLabels: {}
88
65
  // baseLabels: options.baseLabels
89
66
  }
90
- TemplateInstanceState.INSTANCE.addValue(instance)
67
+
68
+ ctx.sendTemplateInstance(instance)
69
+
91
70
  ctx.update({
92
71
  states: {
93
72
  configUpdated: true
94
73
  }
95
74
  })
75
+
76
+ processMetrics.processor_template_instance_count.add(1, {
77
+ chain_id: ctx.chainId,
78
+ template: this.constructor.name
79
+ })
80
+ }
81
+
82
+ public startInstance(options: Omit<Omit<FuelProcessorConfig, 'chainId'>, 'abi'>, ctx: FuelContext): void {
83
+ const sig = getOptionsSignature({
84
+ address: options.address,
85
+ chainId: ctx.chainId
86
+ })
87
+ if (this.instances.has(sig)) {
88
+ console.debug(`Same address can be bind to one template only once, ignore duplicate bind: ${sig}`)
89
+ return
90
+ }
91
+ this.instances.add(sig)
92
+
93
+ const processor = this.bindInternal({ ...options, chainId: ctx.chainId })
94
+
95
+ for (const eh of this.logHandlers) {
96
+ processor.onLog(eh.logIdFilter, eh.handler, eh.handlerOptions, eh.handlerName)
97
+ }
98
+ for (const bh of this.blockHandlers) {
99
+ processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.handlerOptions, bh.handlerName)
100
+ }
101
+ for (const th of this.transactionHandlers) {
102
+ processor.onTransaction(th.handler, th.handlerOptions, th.handlerName)
103
+ }
96
104
  }
97
105
 
98
106
  protected onLog<T>(
@@ -1,5 +1,5 @@
1
- import { HandleInterval, MoveAccountFetchConfig, MoveFetchConfig } from '@sentio/protos'
2
- import { ListStateStorage } from '@sentio/runtime'
1
+ import { HandleInterval, MoveAccountFetchConfig, MoveFetchConfig, TemplateInstance } from '@sentio/protos'
2
+ import { ListStateStorage, processMetrics } from '@sentio/runtime'
3
3
  import { IotaAddressContext, IotaContext, IotaObjectContext } from './context.js'
4
4
  import { IotaMoveObject, IotaTransactionBlockResponse } from '@iota/iota-sdk/client'
5
5
  import { PromiseOrVoid } from '../core/index.js'
@@ -12,7 +12,6 @@ import {
12
12
  IotaObjectProcessor,
13
13
  IotaWrappedObjectProcessor
14
14
  } from './iota-object-processor.js'
15
- import { TemplateInstanceState } from '../core/template.js'
16
15
  import { IotaBindOptions } from './iota-processor.js'
17
16
  import { TransactionFilter, accountAddressString } from '../move/index.js'
18
17
  import { ServerError, Status } from 'nice-grpc'
@@ -40,7 +39,7 @@ export abstract class IotaObjectOrAddressProcessorTemplate<
40
39
  > {
41
40
  id: number
42
41
  objectHandlers: ObjectHandler<HandlerType>[] = []
43
- binds = new Set<string>()
42
+ instances = new Set<string>()
44
43
 
45
44
  constructor() {
46
45
  this.id = IotaAccountProcessorTemplateState.INSTANCE.getValues().length
@@ -60,12 +59,49 @@ export abstract class IotaObjectOrAddressProcessorTemplate<
60
59
  }
61
60
  id = accountAddressString(id)
62
61
 
62
+ const instance: TemplateInstance = {
63
+ templateId: this.id,
64
+ contract: {
65
+ name: '',
66
+ chainId: options.network,
67
+ address: id,
68
+ abi: ''
69
+ },
70
+ startBlock: options.startCheckpoint || 0n,
71
+ endBlock: options.endCheckpoint || 0n,
72
+ baseLabels: options.baseLabels
73
+ }
74
+
75
+ ctx.sendTemplateInstance(instance)
76
+
77
+ ctx.update({
78
+ states: {
79
+ configUpdated: true
80
+ }
81
+ })
82
+
83
+ processMetrics.processor_template_instance_count.add(1, {
84
+ chain_id: options.network,
85
+ template: this.constructor.name
86
+ })
87
+ }
88
+
89
+ startInstance(options: OptionType, ctx: IotaContext): void {
90
+ options.network = options.network || ctx.network
91
+ options.startCheckpoint = options.startCheckpoint || ctx.checkpoint
92
+ let id = (options as IotaObjectBindOptions).objectId || (options as IotaBindOptions).address
93
+
94
+ if (id === '*') {
95
+ throw new ServerError(Status.INVALID_ARGUMENT, "can't bind template instance with *")
96
+ }
97
+ id = accountAddressString(id)
98
+
63
99
  const sig = [options.network, id].join('_')
64
- if (this.binds.has(sig)) {
65
- console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)
100
+ if (this.instances.has(sig)) {
101
+ console.debug(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)
66
102
  return
67
103
  }
68
- this.binds.add(sig)
104
+ this.instances.add(sig)
69
105
 
70
106
  const processor = this.createProcessor(options)
71
107
  for (const h of this.objectHandlers) {
@@ -78,25 +114,6 @@ export abstract class IotaObjectOrAddressProcessorTemplate<
78
114
  h.handlerName
79
115
  )
80
116
  }
81
- const config = processor.config
82
-
83
- ctx.update({
84
- states: {
85
- configUpdated: true
86
- }
87
- })
88
- TemplateInstanceState.INSTANCE.addValue({
89
- templateId: this.id,
90
- contract: {
91
- name: '',
92
- chainId: config.network,
93
- address: config.address,
94
- abi: ''
95
- },
96
- startBlock: config.startCheckpoint,
97
- endBlock: config.endCheckpoint || 0n,
98
- baseLabels: config.baseLabels
99
- })
100
117
  console.log(`successfully bind template ${sig}`)
101
118
  }
102
119
 
@@ -111,31 +128,14 @@ export abstract class IotaObjectOrAddressProcessorTemplate<
111
128
  id = accountAddressString(id)
112
129
 
113
130
  const sig = [options.network, id].join('_')
114
- if (!this.binds.has(sig)) {
131
+ if (!this.instances.has(sig)) {
115
132
  console.log(`the template instance ${sig} not existed or already unbind`)
116
133
  return
117
134
  }
118
- this.binds.delete(sig)
119
-
120
- let deleted = 0
121
- const oldTemplateInstances = TemplateInstanceState.INSTANCE.unregister()
122
- for (const templateInstance of oldTemplateInstances) {
123
- if (templateInstance.contract?.chainId === options.network && templateInstance.contract.address == id) {
124
- deleted++
125
- continue
126
- }
127
- TemplateInstanceState.INSTANCE.addValue(templateInstance)
128
- }
129
-
130
- if (deleted !== 1) {
131
- throw new ServerError(
132
- Status.INVALID_ARGUMENT,
133
- `Failed to delete template instance ${sig}, deleted ${deleted} times`
134
- )
135
- }
135
+ this.instances.delete(sig)
136
136
 
137
137
  const oldProcessors = IotaAccountProcessorState.INSTANCE.unregister()
138
- deleted = 0
138
+ let deleted = 0
139
139
  for (const processor of oldProcessors) {
140
140
  if (processor.templateId === this.id) {
141
141
  if (processor.config.network == options.network && processor.config.address === id) {
@@ -160,6 +160,21 @@ export abstract class IotaObjectOrAddressProcessorTemplate<
160
160
  configUpdated: true
161
161
  }
162
162
  })
163
+ ctx.sendTemplateInstance(
164
+ {
165
+ templateId: this.id,
166
+ contract: {
167
+ name: '',
168
+ chainId: options.network,
169
+ address: id,
170
+ abi: ''
171
+ },
172
+ startBlock: options.startCheckpoint || 0n,
173
+ endBlock: options.endCheckpoint || 0n,
174
+ baseLabels: options.baseLabels
175
+ },
176
+ true
177
+ )
163
178
  }
164
179
 
165
180
  protected onInterval(
@@ -45,7 +45,7 @@ export class IotaPluginPart {
45
45
  const template: IotaObjectOrAddressProcessorTemplate<any, any, any> =
46
46
  IotaAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId]
47
47
 
48
- template.bind(
48
+ template.startInstance(
49
49
  {
50
50
  address: instance.contract?.address || '',
51
51
  objectId: instance.contract?.address || '',
@@ -10,7 +10,6 @@ import {
10
10
  } from '@sentio/protos'
11
11
 
12
12
  import { ServerError, Status } from 'nice-grpc'
13
- import { TemplateInstanceState } from '../core/template.js'
14
13
  import { HandlerRegister } from '../core/handler-register.js'
15
14
  import { StarknetProcessorState } from './starknet-processor.js'
16
15
  import { hash } from 'starknet'
@@ -79,10 +78,6 @@ export class StarknetPlugin extends Plugin {
79
78
 
80
79
  async start(request: StartRequest) {}
81
80
 
82
- stateDiff(config: ProcessConfigResponse): boolean {
83
- return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
84
- }
85
-
86
81
  async processEvent(binding: DataBinding): Promise<ProcessResult> {
87
82
  if (!binding.data?.starknetEvents?.result) {
88
83
  throw new ServerError(Status.INVALID_ARGUMENT, "starknetEvents can't be null")
@@ -1,5 +1,5 @@
1
- import { HandleInterval, MoveAccountFetchConfig, MoveFetchConfig } from '@sentio/protos'
2
- import { ListStateStorage } from '@sentio/runtime'
1
+ import { HandleInterval, MoveAccountFetchConfig, MoveFetchConfig, TemplateInstance } from '@sentio/protos'
2
+ import { ListStateStorage, processMetrics } from '@sentio/runtime'
3
3
  import { SuiAddressContext, SuiContext, SuiObjectContext } from './context.js'
4
4
  import { SuiMoveObject, SuiTransactionBlockResponse } from '@mysten/sui/client'
5
5
  import { PromiseOrVoid } from '../core/index.js'
@@ -12,9 +12,8 @@ import {
12
12
  SuiObjectProcessor,
13
13
  SuiWrappedObjectProcessor
14
14
  } from './sui-object-processor.js'
15
- import { TemplateInstanceState } from '../core/template.js'
16
15
  import { SuiBindOptions } from './sui-processor.js'
17
- import { TransactionFilter, accountAddressString } from '../move/index.js'
16
+ import { accountAddressString, TransactionFilter } from '../move/index.js'
18
17
  import { ServerError, Status } from 'nice-grpc'
19
18
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
20
19
 
@@ -40,7 +39,7 @@ export abstract class SuiObjectOrAddressProcessorTemplate<
40
39
  > {
41
40
  id: number
42
41
  objectHandlers: ObjectHandler<HandlerType>[] = []
43
- binds = new Set<string>()
42
+ instances = new Set<string>()
44
43
 
45
44
  constructor() {
46
45
  this.id = SuiAccountProcessorTemplateState.INSTANCE.getValues().length
@@ -60,12 +59,49 @@ export abstract class SuiObjectOrAddressProcessorTemplate<
60
59
  }
61
60
  id = accountAddressString(id)
62
61
 
62
+ const instance: TemplateInstance = {
63
+ templateId: this.id,
64
+ contract: {
65
+ name: '',
66
+ chainId: options.network,
67
+ address: id,
68
+ abi: ''
69
+ },
70
+ startBlock: options.startCheckpoint || 0n,
71
+ endBlock: options.endCheckpoint || 0n,
72
+ baseLabels: options.baseLabels
73
+ }
74
+
75
+ ctx.sendTemplateInstance(instance)
76
+
77
+ ctx.update({
78
+ states: {
79
+ configUpdated: true
80
+ }
81
+ })
82
+
83
+ processMetrics.processor_template_instance_count.add(1, {
84
+ chain_id: options.network,
85
+ template: this.constructor.name
86
+ })
87
+ }
88
+
89
+ startInstance(options: OptionType, ctx: SuiContext): void {
90
+ options.network = options.network || ctx.network
91
+ options.startCheckpoint = options.startCheckpoint || ctx.checkpoint
92
+ let id = (options as SuiObjectBindOptions).objectId || (options as SuiBindOptions).address
93
+
94
+ if (id === '*') {
95
+ throw new ServerError(Status.INVALID_ARGUMENT, "can't bind template instance with *")
96
+ }
97
+ id = accountAddressString(id)
98
+
63
99
  const sig = [options.network, id].join('_')
64
- if (this.binds.has(sig)) {
65
- console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)
100
+ if (this.instances.has(sig)) {
101
+ console.debug(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)
66
102
  return
67
103
  }
68
- this.binds.add(sig)
104
+ this.instances.add(sig)
69
105
 
70
106
  const processor = this.createProcessor(options)
71
107
  for (const h of this.objectHandlers) {
@@ -78,25 +114,6 @@ export abstract class SuiObjectOrAddressProcessorTemplate<
78
114
  h.handlerName
79
115
  )
80
116
  }
81
- const config = processor.config
82
-
83
- ctx.update({
84
- states: {
85
- configUpdated: true
86
- }
87
- })
88
- TemplateInstanceState.INSTANCE.addValue({
89
- templateId: this.id,
90
- contract: {
91
- name: '',
92
- chainId: config.network,
93
- address: config.address,
94
- abi: ''
95
- },
96
- startBlock: config.startCheckpoint,
97
- endBlock: config.endCheckpoint || 0n,
98
- baseLabels: config.baseLabels
99
- })
100
117
  console.log(`successfully bind template ${sig}`)
101
118
  }
102
119
 
@@ -111,31 +128,14 @@ export abstract class SuiObjectOrAddressProcessorTemplate<
111
128
  id = accountAddressString(id)
112
129
 
113
130
  const sig = [options.network, id].join('_')
114
- if (!this.binds.has(sig)) {
131
+ if (!this.instances.has(sig)) {
115
132
  console.log(`the template instance ${sig} not existed or already unbind`)
116
133
  return
117
134
  }
118
- this.binds.delete(sig)
119
-
120
- let deleted = 0
121
- const oldTemplateInstances = TemplateInstanceState.INSTANCE.unregister()
122
- for (const templateInstance of oldTemplateInstances) {
123
- if (templateInstance.contract?.chainId === options.network && templateInstance.contract.address == id) {
124
- deleted++
125
- continue
126
- }
127
- TemplateInstanceState.INSTANCE.addValue(templateInstance)
128
- }
129
-
130
- if (deleted !== 1) {
131
- throw new ServerError(
132
- Status.INVALID_ARGUMENT,
133
- `Failed to delete template instance ${sig}, deleted ${deleted} times`
134
- )
135
- }
135
+ this.instances.delete(sig)
136
136
 
137
137
  const oldProcessors = SuiAccountProcessorState.INSTANCE.unregister()
138
- deleted = 0
138
+ let deleted = 0
139
139
  for (const processor of oldProcessors) {
140
140
  if (processor.templateId === this.id) {
141
141
  if (processor.config.network == options.network && processor.config.address === id) {
@@ -160,6 +160,22 @@ export abstract class SuiObjectOrAddressProcessorTemplate<
160
160
  configUpdated: true
161
161
  }
162
162
  })
163
+
164
+ ctx.sendTemplateInstance(
165
+ {
166
+ templateId: this.id,
167
+ contract: {
168
+ name: '',
169
+ chainId: options.network,
170
+ address: id,
171
+ abi: ''
172
+ },
173
+ startBlock: options.startCheckpoint || 0n,
174
+ endBlock: options.endCheckpoint || 0n,
175
+ baseLabels: options.baseLabels
176
+ },
177
+ true
178
+ )
163
179
  }
164
180
 
165
181
  protected onInterval(
@@ -45,7 +45,7 @@ export class SuiPluginPart {
45
45
  const template: SuiObjectOrAddressProcessorTemplate<any, any, any> =
46
46
  SuiAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId]
47
47
 
48
- template.bind(
48
+ template.startInstance(
49
49
  {
50
50
  address: instance.contract?.address || '',
51
51
  objectId: instance.contract?.address || '',
@@ -14,10 +14,19 @@ import {
14
14
  ProcessStreamRequest,
15
15
  ProcessStreamResponse,
16
16
  ServerStreamingMethodResult,
17
- StartRequest
17
+ StartRequest,
18
+ TemplateInstance,
19
+ TimeseriesResult
18
20
  } from '@sentio/protos'
19
21
  import { CallContext } from 'nice-grpc-common'
20
- import { Endpoints, PluginManager, ProcessorServiceImpl, State, StoreContext } from '@sentio/runtime'
22
+ import {
23
+ Endpoints,
24
+ IDataBindingContext,
25
+ PluginManager,
26
+ ProcessorServiceImpl,
27
+ State,
28
+ StoreContext
29
+ } from '@sentio/runtime'
21
30
 
22
31
  import { AptosFacet } from './aptos-facet.js'
23
32
  import { SolanaFacet } from './solana-facet.js'
@@ -45,7 +54,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
45
54
  service: ProcessorServiceImpl
46
55
  contractConfigs: ContractConfig[]
47
56
  accountConfigs: AccountConfig[]
48
- storeContext: StoreContext
57
+ storeContext: TestStoreContext
49
58
 
50
59
  aptos: AptosFacet
51
60
  eth: EthFacet
@@ -77,7 +86,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
77
86
 
78
87
  // start a memory database for testing
79
88
  const subject = new Subject<DeepPartial<ProcessStreamResponse>>()
80
- this.storeContext = new StoreContext(subject, 1)
89
+ this.storeContext = new TestStoreContext(subject, 1)
81
90
  this._db = new MemoryDatabase(this.storeContext)
82
91
  }
83
92
 
@@ -87,6 +96,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
87
96
  this.contractConfigs = config.contractConfigs
88
97
  this.accountConfigs = config.accountConfigs
89
98
  this._db.start()
99
+ this.storeContext.templateInstances = request.templateInstances
90
100
  return res
91
101
  }
92
102
 
@@ -94,23 +104,43 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
94
104
  return this.service.stop(request, context)
95
105
  }
96
106
 
97
- getConfig(request: ProcessConfigRequest, context = TEST_CONTEXT): Promise<ProcessConfigResponse> {
98
- return this.service.getConfig(request, context)
107
+ async getConfig(request: ProcessConfigRequest, context = TEST_CONTEXT): Promise<ProcessConfigResponse> {
108
+ const config = await this.service.getConfig(request, context)
109
+ return {
110
+ ...config,
111
+ templateInstances: this.storeContext.templateInstances
112
+ }
99
113
  }
100
114
 
101
115
  processBindings(
102
116
  request: ProcessBindingsRequest,
103
117
  context: CallContext = TEST_CONTEXT
104
118
  ): Promise<ProcessBindingResponse> {
105
- return PluginManager.INSTANCE.dbContextLocalStorage.run(this.storeContext, () => {
106
- return this.service.processBindings(request, context)
119
+ return PluginManager.INSTANCE.dbContextLocalStorage.run(this.storeContext, async () => {
120
+ const ret = await this.service.processBindings(request, context)
121
+ if (ret.result?.states?.configUpdated) {
122
+ // template may changed
123
+ await PluginManager.INSTANCE.updateTemplates({
124
+ chainId: request.bindings[0].chainId,
125
+ templateInstances: this.storeContext.templateInstances
126
+ })
127
+ }
128
+ return ret
107
129
  })
108
130
  }
109
131
 
110
- processBinding(request: DataBinding, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {
111
- return PluginManager.INSTANCE.dbContextLocalStorage.run(this.storeContext, () => {
132
+ async processBinding(request: DataBinding, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {
133
+ const ret = await PluginManager.INSTANCE.dbContextLocalStorage.run(this.storeContext, () => {
112
134
  return this.service.processBindings({ bindings: [request] }, context)
113
135
  })
136
+ if (ret.result?.states?.configUpdated) {
137
+ // template may changed
138
+ await PluginManager.INSTANCE.updateTemplates({
139
+ chainId: request.chainId,
140
+ templateInstances: this.storeContext.templateInstances
141
+ })
142
+ }
143
+ return ret
114
144
  }
115
145
 
116
146
  processBindingsStream(
@@ -138,3 +168,27 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
138
168
  return this._db.store
139
169
  }
140
170
  }
171
+
172
+ class TestStoreContext extends StoreContext implements IDataBindingContext {
173
+ constructor(
174
+ readonly subject: Subject<DeepPartial<ProcessStreamResponse>>,
175
+ processId: number
176
+ ) {
177
+ super(subject, processId)
178
+ }
179
+
180
+ templateInstances: TemplateInstance[] = []
181
+
182
+ sendTemplateRequest(templates: Array<TemplateInstance>, remove: boolean): void {
183
+ if (remove) {
184
+ this.templateInstances = this.templateInstances.filter(
185
+ (i) => !templates.find((t) => t.templateId === i.templateId && t.contract?.address === i.contract?.address)
186
+ )
187
+ } else {
188
+ this.templateInstances.push(...templates)
189
+ }
190
+ }
191
+ sendTimeseriesRequest(timeseries: Array<TimeseriesResult>): void {
192
+ throw new Error('Method not implemented.')
193
+ }
194
+ }
@@ -1,2 +0,0 @@
1
- export { TemplateInstanceState } from '@sentio/runtime';
2
- //# sourceMappingURL=template.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/core/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export { TemplateInstanceState } from '@sentio/runtime';
2
- //# sourceMappingURL=template.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/core/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA"}
@@ -1 +0,0 @@
1
- export { TemplateInstanceState } from '@sentio/runtime'