@sentio/sdk 2.35.1-rc.1 → 2.36.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 (54) hide show
  1. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  2. package/lib/aptos/aptos-plugin.js +30 -20
  3. package/lib/aptos/aptos-plugin.js.map +1 -1
  4. package/lib/fuel/asset-processor.d.ts +36 -0
  5. package/lib/fuel/asset-processor.d.ts.map +1 -0
  6. package/lib/fuel/asset-processor.js +87 -0
  7. package/lib/fuel/asset-processor.js.map +1 -0
  8. package/lib/fuel/base-processor.d.ts +8 -6
  9. package/lib/fuel/base-processor.d.ts.map +1 -1
  10. package/lib/fuel/base-processor.js +14 -11
  11. package/lib/fuel/base-processor.js.map +1 -1
  12. package/lib/fuel/codegen/codegen.js +62 -15
  13. package/lib/fuel/codegen/codegen.js.map +1 -1
  14. package/lib/fuel/context.d.ts +12 -4
  15. package/lib/fuel/context.d.ts.map +1 -1
  16. package/lib/fuel/context.js +21 -7
  17. package/lib/fuel/context.js.map +1 -1
  18. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  19. package/lib/fuel/fuel-plugin.js +18 -30
  20. package/lib/fuel/fuel-plugin.js.map +1 -1
  21. package/lib/fuel/fuel-processor.d.ts +4 -11
  22. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  23. package/lib/fuel/fuel-processor.js +12 -12
  24. package/lib/fuel/fuel-processor.js.map +1 -1
  25. package/lib/fuel/index.d.ts +2 -0
  26. package/lib/fuel/index.d.ts.map +1 -1
  27. package/lib/fuel/index.js +2 -0
  28. package/lib/fuel/index.js.map +1 -1
  29. package/lib/fuel/network.js +1 -1
  30. package/lib/fuel/network.js.map +1 -1
  31. package/lib/fuel/transaction.d.ts +8 -3
  32. package/lib/fuel/transaction.d.ts.map +1 -1
  33. package/lib/fuel/transaction.js +63 -15
  34. package/lib/fuel/transaction.js.map +1 -1
  35. package/lib/fuel/types.d.ts +20 -0
  36. package/lib/fuel/types.d.ts.map +1 -0
  37. package/lib/fuel/types.js +5 -0
  38. package/lib/fuel/types.js.map +1 -0
  39. package/lib/testing/fuel-facet.d.ts.map +1 -1
  40. package/lib/testing/fuel-facet.js +13 -0
  41. package/lib/testing/fuel-facet.js.map +1 -1
  42. package/package.json +9 -5
  43. package/src/aptos/aptos-plugin.ts +38 -32
  44. package/src/fuel/asset-processor.ts +122 -0
  45. package/src/fuel/base-processor.ts +16 -21
  46. package/src/fuel/codegen/codegen.ts +74 -16
  47. package/src/fuel/context.ts +22 -8
  48. package/src/fuel/fuel-plugin.ts +16 -33
  49. package/src/fuel/fuel-processor.ts +32 -22
  50. package/src/fuel/index.ts +3 -1
  51. package/src/fuel/network.ts +1 -1
  52. package/src/fuel/transaction.ts +76 -26
  53. package/src/fuel/types.ts +23 -0
  54. package/src/testing/fuel-facet.ts +14 -0
@@ -1,4 +1,4 @@
1
- import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
1
+ import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import {
3
3
  AccountConfig,
4
4
  ContractConfig,
@@ -12,7 +12,7 @@ import {
12
12
  MoveOwnerType,
13
13
  ProcessConfigResponse,
14
14
  ProcessResult,
15
- StartRequest,
15
+ StartRequest
16
16
  } from '@sentio/protos'
17
17
 
18
18
  import { ServerError, Status } from 'nice-grpc'
@@ -24,7 +24,7 @@ import { AptosChainId } from '@sentio/chain'
24
24
  import { AptosResourcesContext } from './context.js'
25
25
  import {
26
26
  AptosResourceProcessorTemplate,
27
- AptosResourceProcessorTemplateState,
27
+ AptosResourceProcessorTemplateState
28
28
  } from './aptos-resource-processor-template.js'
29
29
  import { AptosNetwork } from './network.js'
30
30
 
@@ -38,7 +38,7 @@ export class AptosPlugin extends Plugin {
38
38
  handlers: Handlers = {
39
39
  aptosEventHandlers: [],
40
40
  aptosCallHandlers: [],
41
- aptosResourceHandlers: [],
41
+ aptosResourceHandlers: []
42
42
  }
43
43
 
44
44
  async start(request: StartRequest) {
@@ -57,7 +57,7 @@ export class AptosPlugin extends Plugin {
57
57
  {
58
58
  address: instance.contract?.address || '',
59
59
  network: <AptosNetwork>instance.contract?.chainId || AptosNetwork.MAIN_NET,
60
- startVersion: instance.startBlock || 0n,
60
+ startVersion: instance.startBlock || 0n
61
61
  },
62
62
  NoopContext
63
63
  )
@@ -68,7 +68,7 @@ export class AptosPlugin extends Plugin {
68
68
  const handlers: Handlers = {
69
69
  aptosEventHandlers: [],
70
70
  aptosCallHandlers: [],
71
- aptosResourceHandlers: [],
71
+ aptosResourceHandlers: []
72
72
  }
73
73
  for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
74
74
  const contractConfig = ContractConfig.fromPartial({
@@ -77,9 +77,9 @@ export class AptosPlugin extends Plugin {
77
77
  name: aptosProcessor.moduleName,
78
78
  chainId: aptosProcessor.getChainId(),
79
79
  address: aptosProcessor.config.address,
80
- abi: '',
80
+ abi: ''
81
81
  },
82
- startBlock: aptosProcessor.config.startVersion,
82
+ startBlock: aptosProcessor.config.startVersion
83
83
  })
84
84
  // 1. Prepare event handlers
85
85
  for (const handler of aptosProcessor.eventHandlers) {
@@ -88,11 +88,11 @@ export class AptosPlugin extends Plugin {
88
88
  filters: handler.filters.map((f) => {
89
89
  return {
90
90
  type: f.type,
91
- account: f.account || '',
91
+ account: f.account || ''
92
92
  }
93
93
  }),
94
94
  fetchConfig: handler.fetchConfig,
95
- handlerId,
95
+ handlerId
96
96
  }
97
97
  contractConfig.moveEventConfigs.push(eventHandlerConfig)
98
98
  }
@@ -107,11 +107,11 @@ export class AptosPlugin extends Plugin {
107
107
  typeArguments: filter.typeArguments || [],
108
108
  withTypeArguments: !!filter.typeArguments,
109
109
  includeFailed: filter.includeFailed || false,
110
- publicKeyPrefix: filter.publicKeyPrefix || '',
110
+ publicKeyPrefix: filter.publicKeyPrefix || ''
111
111
  }
112
112
  }),
113
113
  fetchConfig: handler.fetchConfig,
114
- handlerId,
114
+ handlerId
115
115
  }
116
116
  contractConfig.moveCallConfigs.push(functionHandlerConfig)
117
117
  }
@@ -122,7 +122,7 @@ export class AptosPlugin extends Plugin {
122
122
  const accountConfig = AccountConfig.fromPartial({
123
123
  address: aptosProcessor.config.address,
124
124
  chainId: aptosProcessor.getChainId(),
125
- startBlock: aptosProcessor.config.startVersion,
125
+ startBlock: aptosProcessor.config.startVersion
126
126
  })
127
127
  for (const handler of aptosProcessor.resourcesHandlers) {
128
128
  const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
@@ -133,11 +133,11 @@ export class AptosPlugin extends Plugin {
133
133
  minutesInterval: handler.timeIntervalInMinutes,
134
134
  slot: 0,
135
135
  slotInterval: handler.versionInterval,
136
- fetchConfig: undefined,
136
+ fetchConfig: undefined
137
137
  },
138
138
  type: handler.type || '',
139
139
  ownerType: MoveOwnerType.ADDRESS,
140
- fetchConfig: undefined,
140
+ fetchConfig: undefined
141
141
  })
142
142
  }
143
143
  config.accountConfigs.push(accountConfig)
@@ -168,15 +168,16 @@ export class AptosPlugin extends Plugin {
168
168
  const event = binding.data.aptEvent
169
169
 
170
170
  for (const handlerId of binding.handlerIds) {
171
- // only support aptos event for now
172
- promises.push(
173
- this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {
174
- throw new ServerError(
175
- Status.INTERNAL,
176
- 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
177
- )
178
- })
179
- )
171
+ const promise = this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {
172
+ throw new ServerError(
173
+ Status.INTERNAL,
174
+ 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
175
+ )
176
+ })
177
+ if (GLOBAL_CONFIG.execution.sequential) {
178
+ await promise
179
+ }
180
+ promises.push(promise)
180
181
  }
181
182
  return mergeProcessResults(await Promise.all(promises))
182
183
  }
@@ -189,14 +190,16 @@ export class AptosPlugin extends Plugin {
189
190
 
190
191
  const promises: Promise<ProcessResult>[] = []
191
192
  for (const handlerId of binding.handlerIds) {
192
- promises.push(
193
- this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {
194
- throw new ServerError(
195
- Status.INTERNAL,
196
- 'error processing resource: ' + JSON.stringify(resource) + '\n' + errorString(e)
197
- )
198
- })
199
- )
193
+ const promise = this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {
194
+ throw new ServerError(
195
+ Status.INTERNAL,
196
+ 'error processing resource: ' + JSON.stringify(resource) + '\n' + errorString(e)
197
+ )
198
+ })
199
+ if (GLOBAL_CONFIG.execution.sequential) {
200
+ await promise
201
+ }
202
+ promises.push(promise)
200
203
  }
201
204
  return mergeProcessResults(await Promise.all(promises))
202
205
  }
@@ -213,6 +216,9 @@ export class AptosPlugin extends Plugin {
213
216
  const promise = this.handlers.aptosCallHandlers[handlerId](call).catch((e) => {
214
217
  throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
215
218
  })
219
+ if (GLOBAL_CONFIG.execution.sequential) {
220
+ await promise
221
+ }
216
222
  promises.push(promise)
217
223
  }
218
224
  return mergeProcessResults(await Promise.all(promises))
@@ -0,0 +1,122 @@
1
+ import { CallHandler, FuelBaseProcessor, FuelProcessorState } from './types.js'
2
+ import { Data_FuelCall, FuelAssetHandlerConfig_AssetFilter } from '@sentio/protos'
3
+ import { FuelNetwork, getRpcEndpoint } from './network.js'
4
+ import { FuelContext } from './context.js'
5
+ import { decodeFuelTransaction } from './transaction.js'
6
+ import { Provider } from '@fuel-ts/account'
7
+ import { InputType, OutputType } from '@fuel-ts/transactions'
8
+
9
+ export class FuelAssetProcessor implements FuelBaseProcessor<FuelAssetProcessorConfig> {
10
+ callHandlers: CallHandler<Data_FuelCall>[] = []
11
+ private provider: Provider
12
+
13
+ static bind(config: FuelAssetProcessorConfig): FuelAssetProcessor {
14
+ const processor = new FuelAssetProcessor(config)
15
+ FuelProcessorState.INSTANCE.addValue(processor)
16
+ return processor
17
+ }
18
+
19
+ constructor(readonly config: FuelAssetProcessorConfig) {}
20
+
21
+ async configure(): Promise<void> {
22
+ const url = getRpcEndpoint(this.config.chainId)
23
+ this.provider = await Provider.create(url)
24
+ }
25
+
26
+ onTransfer(filter: TransferFilter, handler: (transfers: FuelTransfer, ctx: FuelContext) => void | Promise<void>) {
27
+ const filters: FuelAssetHandlerConfig_AssetFilter[] = []
28
+
29
+ const assetIds = arrayify(filter.assetId)
30
+ const froms = arrayify(filter.from)
31
+ const tos = arrayify(filter.to)
32
+
33
+ for (const assetId of assetIds) {
34
+ for (const from of froms) {
35
+ for (const to of tos) {
36
+ filters.push({
37
+ assetId: assetId,
38
+ fromAddress: from,
39
+ toAddress: to
40
+ })
41
+ }
42
+ }
43
+ }
44
+
45
+ const callHandler = {
46
+ handler: async (call: Data_FuelCall) => {
47
+ const gqlTransaction = call.transaction
48
+ const tx = decodeFuelTransaction(gqlTransaction, this.provider)
49
+
50
+ const transfer: FuelTransfer = {
51
+ from: [],
52
+ to: []
53
+ }
54
+ for (const input of tx.transaction.inputs || []) {
55
+ if (input.type == InputType.Coin) {
56
+ transfer.from.push({
57
+ address: input.owner,
58
+ assetId: input.assetId
59
+ })
60
+ }
61
+ }
62
+
63
+ for (const output of tx.transaction.outputs || []) {
64
+ if (output.type == OutputType.Coin) {
65
+ const value = output.amount.toString(10)
66
+ transfer.to.push({
67
+ address: output.to,
68
+ amount: BigInt(value),
69
+ assetId: output.assetId
70
+ })
71
+ }
72
+ }
73
+
74
+ const assetId = transfer.from[0].assetId || ''
75
+
76
+ const ctx = new FuelContext(this.config.chainId, assetId, this.config.name ?? '', tx)
77
+ await handler(transfer, ctx)
78
+ return ctx.stopAndGetResult()
79
+ },
80
+ assetConfig: {
81
+ filters
82
+ }
83
+ }
84
+ this.callHandlers.push(callHandler)
85
+ return this
86
+ }
87
+ }
88
+
89
+ export type FuelAssetProcessorConfig = {
90
+ name?: string
91
+ chainId: FuelNetwork
92
+ startBlock?: bigint
93
+ endBlock?: bigint
94
+ }
95
+
96
+ export type TransferFilter = {
97
+ from?: string | string[]
98
+ to?: string | string[]
99
+ assetId?: string | string[]
100
+ }
101
+
102
+ export type FuelTransfer = {
103
+ from: {
104
+ assetId: string
105
+ address: string
106
+ }[]
107
+ to: {
108
+ address: string
109
+ amount: bigint
110
+ assetId: string
111
+ }[]
112
+ }
113
+
114
+ function arrayify(value?: string | string[]): Array<string | undefined> {
115
+ if (value) {
116
+ if (Array.isArray(value)) {
117
+ return value.length > 0 ? value : [undefined]
118
+ }
119
+ return [value]
120
+ }
121
+ return [undefined]
122
+ }
@@ -1,38 +1,33 @@
1
- import { FuelProcessor, FuelProcessorConfig, FuelProcessorState } from './fuel-processor.js'
2
- import { JsonAbi } from 'fuels'
3
- import { FuelCall, FuelContext } from './context.js'
4
- import { FuelFetchConfig } from './transaction.js'
1
+ import { FuelProcessor, FuelProcessorConfig } from './fuel-processor.js'
2
+ import { JsonAbi } from '@fuel-ts/abi-coder'
3
+ import { FuelCall } from './context.js'
5
4
  import { FuelChainId } from '@sentio/chain'
6
-
5
+ import { FuelLog, FuelProcessorState } from './types.js'
7
6
 
8
7
  export abstract class FuelAbstractProcessor extends FuelProcessor {
9
-
10
8
  protected constructor(abi: JsonAbi, config?: FuelProcessorConfig) {
11
9
  if (!config) {
12
10
  config = {
13
11
  chainId: FuelChainId.FUEL_MAINNET,
14
- address: ''
12
+ address: '*'
15
13
  }
16
14
  }
17
15
  config.abi = abi
18
16
  super(config)
19
17
  FuelProcessorState.INSTANCE.addValue(this)
20
18
  }
21
-
22
- protected onCallMethod<T extends Array<any>, R>(method: string, fn: (call: TypedCall<T, R>, ctx: FuelContext) => (void | Promise<void>), config: FuelFetchConfig): this {
23
- const nameFilter = method
24
- const handler =async (call: FuelCall, ctx: FuelContext) => {
25
- await fn({
26
- args: call.functionScopes[0].getCallConfig().args as T,
27
- returnValue: call.value as R
28
- }, ctx)
29
- }
30
- return super.onCall(nameFilter, handler, config)
31
- }
32
-
33
19
  }
34
20
 
35
- export type TypedCall<T extends Array<any>, R> = {
21
+ export class TypedCall<T extends Array<any>, R> {
36
22
  args: T
37
23
  returnValue: R
38
- }
24
+ argsObject?: Record<string, any>
25
+ logs?: FuelLog[]
26
+
27
+ constructor(call: FuelCall) {
28
+ this.args = call.functionScopes[0].getCallConfig().args as T
29
+ this.returnValue = call.value as R
30
+ this.argsObject = call.args
31
+ this.logs = call.logs
32
+ }
33
+ }
@@ -15,7 +15,22 @@ export async function codegen(abisDir: string, outDir: string) {
15
15
  }
16
16
 
17
17
  function patchImport(contents: string) {
18
- return contents.replace(/from\s+['"](\..+)['"]/g, `from '\$1.js'`)
18
+ return contents
19
+ .replace(
20
+ `import { Interface, Contract, ContractFactory } from "fuels";`,
21
+ `import { Contract, } from "@fuel-ts/program";
22
+ import { ContractFactory } from "@fuel-ts/contract";
23
+ import { Interface } from "@fuel-ts/abi-coder";`
24
+ )
25
+ .replace(
26
+ `import type { Provider, Account, AbstractAddress, BytesLike, DeployContractOptions, StorageSlot } from "fuels";
27
+ `,
28
+ `import type { Provider, Account } from "@fuel-ts/account";
29
+ import type { AbstractAddress, BytesLike } from "@fuel-ts/interfaces";
30
+ import type { DeployContractOptions } from "@fuel-ts/contract";
31
+ import type { StorageSlot } from "@fuel-ts/transactions";`
32
+ )
33
+ .replace(/from\s+['"](\..+)['"]/g, `from '\$1.js'`)
19
34
  }
20
35
 
21
36
  function patchEnumType(contents: string) {
@@ -65,38 +80,63 @@ async function codegenInternal(abisDir: string, outDir: string): Promise<number>
65
80
 
66
81
  mkdirp.sync(outDir)
67
82
  mkdirp.sync(path.join(outDir, 'factories'))
68
-
83
+ let count = 0
69
84
  abiTypeGen.files.forEach((file) => {
70
85
  if (!file.path.endsWith('.hex.ts')) {
71
86
  let content = patchImport(file.contents)
72
87
  content = patchEnumType(content)
73
88
  writeFileSync(file.path, content)
89
+ count++
74
90
  }
75
91
  })
76
92
 
93
+ // for (const file of abiTypeGen.files) {
94
+ // const jsonAbi: JsonAbi = JSON.parse(file.contents)
95
+ // for (const logType of jsonAbi.loggedTypes) {
96
+ // logType.loggedType.name
97
+ //
98
+ // }
99
+ // }
100
+
77
101
  for (const abi of abiTypeGen.abis) {
78
102
  const name = abi.name.endsWith('Abi') ? abi.name.slice(0, -3) : abi.name
79
103
  const filePath = path.join(outDir, `${name}Processor.ts`)
80
104
  const importedTypes = collectImportedTypes(abi.types)
81
105
 
106
+ const logTypes: Record<string, string> = {}
107
+ for (const logType of abi.rawContents.loggedTypes) {
108
+ // @ts-ignore - we know that the type is in the abi
109
+ const t = abi.types.find((t) => t.rawAbiType.typeId == logType.loggedType?.type)
110
+ // @ts-ignore - we know that the type is in the abi
111
+ logTypes[logType.logId] = t?.attributes?.outputLabel
112
+ }
113
+
82
114
  const content = `/* Autogenerated file. Do not edit manually. */
83
115
 
84
116
  /* tslint:disable */
85
117
  /* eslint-disable */
86
118
 
87
- import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig} from '@sentio/sdk/fuel'
119
+ import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall} from '@sentio/sdk/fuel'
88
120
  import {${abi.name}__factory } from './factories/${abi.name}__factory.js'
89
121
  import {${abi.commonTypesInUse.join(',')}} from './common.js'
90
122
  import {${importedTypes.join(',')}} from './${abi.name}.js'
91
123
 
92
- import type {
93
- BigNumberish,
94
- BN,
95
- BytesLike,
96
- } from 'fuels';
124
+ import type { BigNumberish, BN } from '@fuel-ts/math';
125
+ import type { BytesLike } from '@fuel-ts/interfaces';
97
126
 
98
127
 
99
128
  namespace ${name} {
129
+ export abstract class CallWithLogs<T extends Array<any>, R> extends TypedCall<T, R> {
130
+ ${Object.entries(logTypes)
131
+ .map(
132
+ ([k, v]) =>
133
+ ` getLog${k}(): Array<${v}> {
134
+ return this.logs?.filter(l => l.logId == ${k})?.map(l => l.decodedLog) as Array<${v}>
135
+ }`
136
+ )
137
+ .join('\n')}
138
+ }
139
+
100
140
  ${abi.functions.map(genCallType).join('\n')}
101
141
  }
102
142
 
@@ -105,25 +145,43 @@ export class ${name}Processor extends FuelAbstractProcessor {
105
145
  super(${abi.name}__factory.abi, config)
106
146
  }
107
147
 
108
- static bind(config?: FuelProcessorConfig) {
109
- return new ${name}Processor(config)
148
+ static bind(config: FuelProcessorConfig) {
149
+ return new ${name}Processor({
150
+ name: '${name}',
151
+ ...config,
152
+ })
110
153
  }
111
154
 
112
155
  ${abi.functions.map((f) => genOnCallFunction(name, f)).join('\n')}
113
156
  }
114
157
  `
115
158
  writeFileSync(filePath, content)
159
+ count++
116
160
  }
117
161
 
118
- return allABIFiles.length
162
+ return count
119
163
  }
120
164
 
121
165
  function genCallType(f: IFunction) {
122
166
  const name = upperFirst(f.name)
167
+ const argMap: Record<string, string> = {}
168
+ const argTypes = f.attributes.inputs.split(',').map((t) => t.trim())
169
+ f.rawAbiFunction.inputs.forEach((input, idx) => {
170
+ argMap[input.name] = argTypes[idx]
171
+ })
172
+
123
173
  return `
124
- export interface ${name}Call extends TypedCall<[${f.attributes.inputs}], ${f.attributes.output}> {
125
- args: [${f.attributes.inputs}]
126
- returnValue: ${f.attributes.output}
174
+ export class ${name}Call extends CallWithLogs<[${argTypes.join(', ')}], ${f.attributes.output}> {
175
+ declare args: [${argTypes.join(', ')}]
176
+ declare returnValue: ${f.attributes.output}
177
+ declare argsObject: {
178
+ ${Object.entries(argMap)
179
+ .map(([k, v]) => `${k}: ${v}`)
180
+ .join(', ')}
181
+ }
182
+ constructor(call: FuelCall) {
183
+ super(call)
184
+ }
127
185
  }
128
186
  `
129
187
  }
@@ -131,8 +189,8 @@ function genCallType(f: IFunction) {
131
189
  function genOnCallFunction(contractName: string, f: IFunction) {
132
190
  const name = upperFirst(f.name)
133
191
  return `
134
- onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config: FuelFetchConfig) {
135
- super.onCallMethod('${f.name}', handler, config)
192
+ onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config?: FuelFetchConfig) {
193
+ super.onCall('${f.name}', (call, ctx) => handler(new ${contractName}.${name}Call(call), ctx), config)
136
194
  }`
137
195
  }
138
196
 
@@ -1,15 +1,29 @@
1
1
  import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
2
2
  import { ChainId } from '@sentio/chain'
3
3
  import { RecordMetaData } from '@sentio/protos'
4
- import { InvocationCallResult } from 'fuels'
4
+ import { InvocationCallResult, InvocationScopeLike } from '@fuel-ts/program'
5
5
  import { FuelTransaction } from './transaction.js'
6
+ import type { CallResult } from '@fuel-ts/account'
7
+ import { FuelLog } from './types.js'
6
8
 
7
- export type FuelCall = InvocationCallResult
9
+ export class FuelCall extends InvocationCallResult {
10
+ constructor(
11
+ funcScopes: InvocationScopeLike | Array<InvocationScopeLike>,
12
+ callResult: CallResult,
13
+ isMultiCall: boolean,
14
+ readonly args?: Record<string, any>,
15
+ readonly logs?: FuelLog[]
16
+ ) {
17
+ super(funcScopes, callResult, isMultiCall)
18
+ }
19
+ }
8
20
 
9
21
  export class FuelContext extends BaseContext {
10
22
  constructor(
11
- readonly transaction: FuelTransaction | null,
12
- readonly chainId: ChainId
23
+ readonly chainId: ChainId,
24
+ readonly contractAddress: string,
25
+ readonly contractName: string,
26
+ readonly transaction: FuelTransaction | null
13
27
  ) {
14
28
  super({})
15
29
  }
@@ -20,14 +34,14 @@ export class FuelContext extends BaseContext {
20
34
 
21
35
  protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
22
36
  return {
23
- address: this.transaction?.id || '',
24
- contractName: this.transaction?.id || '', // TODO
25
- blockNumber: 0n,
37
+ address: this.contractAddress,
38
+ contractName: this.contractName,
39
+ blockNumber: BigInt(this.transaction?.blockNumber || 0),
26
40
  transactionIndex: 0,
27
41
  transactionHash: this.transaction?.id || '', // TODO
28
42
  chainId: this.getChainId(),
29
43
  name: name,
30
- logIndex: 0,
44
+ logIndex: -1,
31
45
  labels: normalizeLabels(labels)
32
46
  }
33
47
  }
@@ -10,9 +10,10 @@ import {
10
10
  } from '@sentio/protos'
11
11
 
12
12
  import { ServerError, Status } from 'nice-grpc'
13
- import { GlobalProcessorState } from '../eth/base-processor.js'
14
13
  import { TemplateInstanceState } from '../core/template.js'
15
- import { FuelProcessorState } from './fuel-processor.js'
14
+ import { FuelAssetProcessor } from './asset-processor.js'
15
+ import { FuelProcessorState } from './types.js'
16
+ import { FuelProcessor } from './fuel-processor.js'
16
17
 
17
18
  interface Handlers {
18
19
  callHandlers: ((trace: Data_FuelCall) => Promise<ProcessResult>)[]
@@ -36,58 +37,40 @@ export class FuelPlugin extends Plugin {
36
37
  contract: {
37
38
  name: processor.config.name,
38
39
  chainId: processor.config.chainId.toString(),
39
- address: processor.config.address,
40
+ address: processor.config.address || '*',
40
41
  abi: ''
41
42
  },
42
43
  startBlock: processor.config.startBlock,
43
44
  endBlock: processor.config.endBlock
44
45
  })
45
-
46
46
  for (const callHandler of processor.callHandlers) {
47
47
  const handlerId = handlers.callHandlers.push(callHandler.handler) - 1
48
- const fetchConfig = {
49
- handlerId,
50
- filters: callHandler.fetchConfig.filters || []
48
+ if (processor instanceof FuelProcessor) {
49
+ const fetchConfig = {
50
+ handlerId,
51
+ filters: callHandler.fetchConfig?.filters || []
52
+ }
53
+ contractConfig.fuelCallConfigs.push(fetchConfig)
54
+ } else if (processor instanceof FuelAssetProcessor) {
55
+ const assetConfig = callHandler.assetConfig
56
+ contractConfig.assetConfigs.push({
57
+ filters: assetConfig?.filters || [],
58
+ handlerId
59
+ })
51
60
  }
52
- contractConfig.fuelCallConfigs.push(fetchConfig)
53
61
  }
54
62
 
55
63
  // Finish up a contract
56
64
  config.contractConfigs.push(contractConfig)
57
65
  }
58
66
 
59
- for (const processor of GlobalProcessorState.INSTANCE.getValues()) {
60
- const chainId = processor.getChainId()
61
-
62
- const contractConfig = ContractConfig.fromPartial({
63
- processorType: USER_PROCESSOR,
64
- contract: {
65
- name: processor.config.name,
66
- chainId: chainId.toString(),
67
- address: processor.config.address, // can only be *
68
- abi: ''
69
- },
70
- startBlock: processor.config.startBlock,
71
- endBlock: processor.config.endBlock
72
- })
73
-
74
- config.contractConfigs.push(contractConfig)
75
- }
76
-
77
67
  this.handlers = handlers
78
68
  }
79
69
 
80
70
  supportedHandlers = [HandlerType.FUEL_CALL]
81
71
 
82
72
  processBinding(request: DataBinding): Promise<ProcessResult> {
83
- // return Promise.resolve(undefined);
84
73
  switch (request.handlerType) {
85
- // case HandlerType.FUEL_LOG:
86
- // return this.processLog(request)
87
- // case HandlerType.FUEL_TRACE:
88
- // return this.processTrace(request)
89
- // case HandlerType.FUEL_BLOCK:
90
- // return this.processBlock(request)
91
74
  case HandlerType.FUEL_CALL:
92
75
  return this.processTransaction(request)
93
76
  default: