@sentio/sdk 2.15.7-rc.2 → 2.16.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/aptos-plugin.js +3 -14
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/core/template.d.ts +5 -0
- package/lib/core/template.js +6 -0
- package/lib/core/template.js.map +1 -0
- package/lib/eth/base-processor-template.d.ts +1 -4
- package/lib/eth/base-processor-template.js +2 -7
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/eth-plugin.js +6 -1
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/sui/index.d.ts +3 -1
- package/lib/sui/index.js +5 -1
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/sui-object-processor.d.ts +54 -0
- package/lib/sui/sui-object-processor.js +93 -0
- package/lib/sui/sui-object-processor.js.map +1 -0
- package/lib/sui/sui-objects-processor-template.d.ts +34 -0
- package/lib/sui/sui-objects-processor-template.js +88 -0
- package/lib/sui/sui-objects-processor-template.js.map +1 -0
- package/lib/sui/sui-plugin.d.ts +1 -1
- package/lib/sui/sui-plugin.js +21 -2
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +8 -56
- package/lib/sui/sui-processor.js +9 -122
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +4 -3
- package/src/aptos/aptos-plugin.ts +3 -15
- package/src/core/template.ts +6 -0
- package/src/eth/base-processor-template.ts +2 -7
- package/src/eth/eth-plugin.ts +8 -1
- package/src/sui/index.ts +13 -1
- package/src/sui/sui-object-processor.ts +186 -0
- package/src/sui/sui-objects-processor-template.ts +153 -0
- package/src/sui/sui-plugin.ts +29 -2
- package/src/sui/sui-processor.ts +14 -196
@@ -1,5 +1,5 @@
|
|
1
1
|
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
|
2
|
-
import { AccountConfig, ContractConfig, HandlerType,
|
2
|
+
import { AccountConfig, ContractConfig, HandlerType, MoveOwnerType, } from '@sentio/protos';
|
3
3
|
import { ServerError, Status } from 'nice-grpc';
|
4
4
|
import { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js';
|
5
5
|
import { initCoinList } from './ext/coin.js';
|
@@ -73,18 +73,6 @@ export class AptosPlugin extends Plugin {
|
|
73
73
|
});
|
74
74
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
75
75
|
const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1;
|
76
|
-
// TODO move to only use moveIntervalConfigs
|
77
|
-
accountConfig.aptosIntervalConfigs.push({
|
78
|
-
intervalConfig: {
|
79
|
-
handlerId: handlerId,
|
80
|
-
minutes: 0,
|
81
|
-
minutesInterval: handler.timeIntervalInMinutes,
|
82
|
-
slot: 0,
|
83
|
-
slotInterval: handler.versionInterval,
|
84
|
-
fetchConfig: undefined,
|
85
|
-
},
|
86
|
-
type: handler.type || '',
|
87
|
-
});
|
88
76
|
accountConfig.moveIntervalConfigs.push({
|
89
77
|
intervalConfig: {
|
90
78
|
handlerId: handlerId,
|
@@ -95,7 +83,8 @@ export class AptosPlugin extends Plugin {
|
|
95
83
|
fetchConfig: undefined,
|
96
84
|
},
|
97
85
|
type: handler.type || '',
|
98
|
-
ownerType:
|
86
|
+
ownerType: MoveOwnerType.ADDRESS,
|
87
|
+
fetchConfig: undefined,
|
99
88
|
});
|
100
89
|
}
|
101
90
|
config.accountConfigs.push(accountConfig);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,EAMX,8BAA8B,GAC/B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,W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AK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC3E,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;YAClH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n MoveOnIntervalConfig_OwnerType,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\ninterface Handlers {\n aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[]\n aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[]\n aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[]\n}\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n handlers: Handlers = {\n aptosEventHandlers: [],\n aptosCallHandlers: [],\n aptosResourceHandlers: [],\n }\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n aptosEventHandlers: [],\n aptosCallHandlers: [],\n aptosResourceHandlers: [],\n }\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\n })\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = handlers.aptosEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = handlers.aptosCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1\n // TODO move to only use moveIntervalConfigs\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n })\n\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosFunctionCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n case HandlerType.APT_RESOURCE:\n return this.processAptosResource(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosResource(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing resource: ' + JSON.stringify(resource) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.handlers.aptosCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new AptosPlugin())\n"]}
|
1
|
+
{"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,EAGX,aAAa,GAId,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAOxD,MAAM,OAAO,WAAY,SAAQ,MAAM;IACrC,IAAI,GAAW,aAAa,CAAA;IAC5B,QAAQ,GAAa;QACnB,kBAAkB,EAAE,EAAE;QACtB,iBAAiB,EAAE,EAAE;QACrB,qBAAqB,EAAE,EAAE;KAC1B,CAAA;IAED,KAAK,CAAC,KAAK,CAAC,KAAmB;QAC7B,MAAM,YAAY,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,MA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,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE;YAC1B,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,CAAA;SACtE;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA;QAEjC,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE;YAC1C,kCAAkC;YAClC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC3E,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;YAClH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n MoveOwnerType,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\ninterface Handlers {\n aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[]\n aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[]\n aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[]\n}\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n handlers: Handlers = {\n aptosEventHandlers: [],\n aptosCallHandlers: [],\n aptosResourceHandlers: [],\n }\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n aptosEventHandlers: [],\n aptosCallHandlers: [],\n aptosResourceHandlers: [],\n }\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\n })\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = handlers.aptosEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = handlers.aptosCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: MoveOwnerType.ADDRESS,\n fetchConfig: undefined,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosFunctionCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n case HandlerType.APT_RESOURCE:\n return this.processAptosResource(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosResource(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing resource: ' + JSON.stringify(resource) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.handlers.aptosCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new AptosPlugin())\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/core/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD,MAAa,qBAAsB,SAAQ,gBAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;SADlC,qBAAqB","sourcesContent":["import { ListStateStorage } from '@sentio/runtime'\nimport { TemplateInstance } from '@sentio/protos'\n\nexport class TemplateInstanceState extends ListStateStorage<TemplateInstance> {\n static INSTANCE = new TemplateInstanceState()\n}\n"]}
|
@@ -2,7 +2,7 @@ import { BoundContractView, ContractContext, ContractView, EthContext } from './
|
|
2
2
|
import { BaseContract } from 'ethers';
|
3
3
|
import { BaseProcessor } from './base-processor.js';
|
4
4
|
import { BindOptions } from './bind-options.js';
|
5
|
-
import { EthFetchConfig, HandleInterval
|
5
|
+
import { EthFetchConfig, HandleInterval } from '@sentio/protos';
|
6
6
|
import { PromiseOrVoid } from '../core/promises.js';
|
7
7
|
import { ListStateStorage } from '@sentio/runtime';
|
8
8
|
import { BlockParams } from 'ethers/providers';
|
@@ -11,9 +11,6 @@ import { TypedEvent, TypedCallTrace } from './eth.js';
|
|
11
11
|
export declare class ProcessorTemplateProcessorState extends ListStateStorage<BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>> {
|
12
12
|
static INSTANCE: ProcessorTemplateProcessorState;
|
13
13
|
}
|
14
|
-
export declare class TemplateInstanceState extends ListStateStorage<TemplateInstance> {
|
15
|
-
static INSTANCE: TemplateInstanceState;
|
16
|
-
}
|
17
14
|
export declare abstract class BaseProcessorTemplate<TContract extends BaseContract, TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>> {
|
18
15
|
id: number;
|
19
16
|
binds: Set<string>;
|
@@ -1,14 +1,11 @@
|
|
1
1
|
import { getOptionsSignature } from './bind-options.js';
|
2
2
|
import { EthFetchConfig } from '@sentio/protos';
|
3
3
|
import { ListStateStorage } from '@sentio/runtime';
|
4
|
+
import { TemplateInstanceState } from '../core/template.js';
|
4
5
|
class ProcessorTemplateProcessorState extends ListStateStorage {
|
5
6
|
static INSTANCE = new ProcessorTemplateProcessorState();
|
6
7
|
}
|
7
8
|
export { ProcessorTemplateProcessorState };
|
8
|
-
class TemplateInstanceState extends ListStateStorage {
|
9
|
-
static INSTANCE = new TemplateInstanceState();
|
10
|
-
}
|
11
|
-
export { TemplateInstanceState };
|
12
9
|
export class BaseProcessorTemplate {
|
13
10
|
id;
|
14
11
|
binds = new Set();
|
@@ -25,9 +22,7 @@ export class BaseProcessorTemplate {
|
|
25
22
|
* @param ctx
|
26
23
|
*/
|
27
24
|
bind(options, ctx) {
|
28
|
-
|
29
|
-
options.network = ctx.getChainId();
|
30
|
-
}
|
25
|
+
options.network = options.network || ctx.chainId;
|
31
26
|
const sig = getOptionsSignature({
|
32
27
|
address: options.address,
|
33
28
|
network: options.network,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAoC,MAAM,gBAAgB,CAAA;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;
|
1
|
+
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAoC,MAAM,gBAAgB,CAAA;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,MAAa,+BAAgC,SAAQ,gBAEpD;IACC,MAAM,CAAC,QAAQ,GAAG,IAAI,+BAA+B,EAAE,CAAA;;SAH5C,+BAA+B;AAM5C,MAAM,OAAgB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IACzB,aAAa,GAKP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IAER;QACE,IAAI,CAAC,EAAE,GAAG,+BAA+B,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,CAAA;QACrE,+BAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,OAAoB,EAAE,GAAe;QAC/C,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAA;QAChD,MAAM,GAAG,GAAG,mBAAmB,CAAC;YAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB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,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAAsG,EACtG,WAAqC;QAErC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;QAC3G,OAAO,IAAI,CAAA;IACb,CAAC;CAGF","sourcesContent":["import { BoundContractView, ContractContext, ContractView, EthContext } from './context.js'\nimport { BaseContract } from 'ethers'\nimport { BaseProcessor } from './base-processor.js'\nimport { BindOptions, getOptionsSignature } from './bind-options.js'\nimport { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos'\nimport { PromiseOrVoid } from '../core/promises.js'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { BlockParams } from 'ethers/providers'\nimport { DeferredTopicFilter } from 'ethers/contract'\nimport { TypedEvent, TypedCallTrace } from './eth.js'\nimport { TemplateInstanceState } from '../core/template.js'\n\nexport class ProcessorTemplateProcessorState extends ListStateStorage<\n BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>\n> {\n static INSTANCE = new ProcessorTemplateProcessorState()\n}\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: {\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n fetchConfig?: EthFetchConfig\n }[] = []\n traceHandlers: {\n signature: string\n handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n fetchConfig?: EthFetchConfig\n }[] = []\n eventHandlers: {\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: DeferredTopicFilter | DeferredTopicFilter[]\n fetchConfig?: EthFetchConfig\n }[] = []\n\n constructor() {\n this.id = ProcessorTemplateProcessorState.INSTANCE.getValues().length\n ProcessorTemplateProcessorState.INSTANCE.addValue(this)\n }\n\n /**\n * Bind template using {@param options}, using {@param ctx}'s network value if not provided in the option\n * @param options\n * @param ctx\n */\n public bind(options: BindOptions, ctx: EthContext): void {\n options.network = options.network || ctx.chainId\n const sig = getOptionsSignature({\n address: options.address,\n network: options.network,\n })\n if (this.binds.has(sig)) {\n console.log(`Same address can be bind to one template only once, ignore duplicate bind: ${sig}`)\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter, eh.fetchConfig)\n }\n for (const th of this.traceHandlers) {\n processor.onTrace(th.signature, th.handler, th.fetchConfig)\n }\n for (const bh of this.blockHandlers) {\n processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.fetchConfig)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network,\n abi: '',\n },\n startBlock: 0n,\n endBlock: 0n,\n }\n if (options.startBlock) {\n instance.startBlock = BigInt(options.startBlock)\n }\n if (options.endBlock) {\n instance.endBlock = BigInt(options.endBlock)\n }\n TemplateInstanceState.INSTANCE.addValue(instance)\n ctx._res.states.configUpdated = true\n }\n\n public onEvent(\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: Partial<EthFetchConfig>\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000,\n backfillBlockInterval = 4000,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onInterval(\n handler,\n undefined,\n {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n },\n fetchConfig\n )\n }\n\n public onTimeInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillBlockInterval = 240,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },\n undefined,\n fetchConfig\n )\n }\n\n public onInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined,\n fetchConfig: EthFetchConfig | undefined\n ) {\n this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval, fetchConfig })\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ) {\n this.traceHandlers.push({ signature, handler, fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}) })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
|
package/lib/eth/eth-plugin.js
CHANGED
@@ -3,11 +3,12 @@ import { AccountConfig, ContractConfig, HandlerType, } from '@sentio/protos';
|
|
3
3
|
import { ServerError, Status } from 'nice-grpc';
|
4
4
|
import { ProcessorState } from './binds.js';
|
5
5
|
import { AccountProcessorState } from './account-processor-state.js';
|
6
|
-
import { ProcessorTemplateProcessorState
|
6
|
+
import { ProcessorTemplateProcessorState } from './base-processor-template.js';
|
7
7
|
import { GlobalProcessorState } from './base-processor.js';
|
8
8
|
import { validateAndNormalizeAddress } from './eth.js';
|
9
9
|
import { EthChainId } from '../core/chain.js';
|
10
10
|
import { EthContext } from './context.js';
|
11
|
+
import { TemplateInstanceState } from '../core/template.js';
|
11
12
|
export class EthPlugin extends Plugin {
|
12
13
|
name = 'EthPlugin';
|
13
14
|
handlers = {
|
@@ -200,7 +201,11 @@ export class EthPlugin extends Plugin {
|
|
200
201
|
}
|
201
202
|
async start(request) {
|
202
203
|
const ctx = new NoopContext();
|
204
|
+
const allowedChainIds = new Set(Object.values(EthChainId));
|
203
205
|
for (const instance of request.templateInstances) {
|
206
|
+
if (!allowedChainIds.has(instance.contract?.chainId || '')) {
|
207
|
+
continue;
|
208
|
+
}
|
204
209
|
const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId];
|
205
210
|
if (!template) {
|
206
211
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/eth/eth-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAMd,WAAW,GAMZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AASzC,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,aAAa,EAAE,EAAE;QACjB,aAAa,EAA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AC,CAAA;AAEhD,MAAM,WAAY,SAAQ,UAAU;IAClC;QACE,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAChC,CAAC;IAES,eAAe;QACvB,OAAO,EAAE,CAAA;IACX,CAAC;CACF","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n Data_EthTransaction,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\nimport { ProcessorState } from './binds.js'\nimport { AccountProcessorState } from './account-processor-state.js'\nimport { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template.js'\nimport { GlobalProcessorState } from './base-processor.js'\nimport { validateAndNormalizeAddress } from './eth.js'\nimport { EthChainId } from '../core/chain.js'\nimport { EthContext } from './context.js'\n\ninterface Handlers {\n eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[]\n traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[]\n blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[]\n transactionHandlers: ((trace: Data_EthTransaction) => Promise<ProcessResult>)[]\n}\n\nexport class EthPlugin extends Plugin {\n name: string = 'EthPlugin'\n handlers: Handlers = {\n blockHandlers: [],\n eventHandlers: [],\n traceHandlers: [],\n transactionHandlers: [],\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n blockHandlers: [],\n eventHandlers: [],\n traceHandlers: [],\n transactionHandlers: [],\n }\n // This syntax is to copy values instead of using references\n config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]\n\n for (const processor of ProcessorState.INSTANCE.getValues()) {\n // If server favor incremental update this need to change\n // Start basic config for contract\n const chainId = processor.getChainId()\n // this.processorsByChainId.set(chainId, processor)\n\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: validateAndNormalizeAddress(processor.config.address),\n abi: '',\n },\n startBlock: processor.config.startBlock,\n endBlock: processor.config.endBlock,\n })\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1\n // TODO wrap the block handler into one\n\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n fetchConfig: blockHandler.fetchConfig,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = handlers.traceHandlers.push(traceHandler.handler) - 1\n for (const signature of traceHandler.signatures) {\n contractConfig.traceConfigs.push({\n signature: signature,\n handlerId: handlerId,\n fetchConfig: traceHandler.fetchConfig,\n })\n }\n }\n\n // Step 3. Prepare all the event handlers\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n\n // if (!filter.topics) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n // }\n const logFilter: LogFilter = {\n addressType: undefined,\n address: contractConfig.contract?.address && validateAndNormalizeAddress(contractConfig.contract.address),\n topics: [],\n }\n\n for (const ts of topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n contractConfig.logConfigs.push(logConfig)\n }\n\n // Finish up a contract\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of GlobalProcessorState.INSTANCE.getValues()) {\n const chainId = processor.getChainId()\n\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address, // can only be *\n abi: '',\n },\n startBlock: processor.config.startBlock,\n endBlock: processor.config.endBlock,\n })\n\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n fetchConfig: blockHandler.fetchConfig,\n })\n }\n\n for (const transactionHandler of processor.transactionHandler) {\n const handlerId = handlers.transactionHandlers.push(transactionHandler.handler) - 1\n contractConfig.transactionConfig.push({\n handlerId: handlerId,\n fetchConfig: transactionHandler.fetchConfig,\n })\n }\n config.contractConfigs.push(contractConfig)\n }\n\n // part 1.b prepare EVM account processors\n for (const processor of AccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,\n })\n // TODO add interval\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n // if (!filter.topics) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n // }\n let address = undefined\n if (filter.address) {\n address = filter.address.toString()\n }\n const logFilter: LogFilter = {\n addressType: filter.addressType,\n address: address && validateAndNormalizeAddress(address),\n topics: [],\n }\n\n for (const ts of topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n accountConfig.logConfigs.push(logConfig)\n }\n\n config.accountConfigs.push(accountConfig)\n }\n\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE, HandlerType.ETH_TRANSACTION]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n // return Promise.resolve(undefined);\n switch (request.handlerType) {\n case HandlerType.ETH_LOG:\n return this.processLog(request)\n case HandlerType.ETH_TRACE:\n return this.processTrace(request)\n case HandlerType.ETH_BLOCK:\n return this.processBlock(request)\n case HandlerType.ETH_TRANSACTION:\n return this.processTransaction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async start(request: StartRequest) {\n const ctx = new NoopContext()\n for (const instance of request.templateInstances) {\n const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId]\n if (!template) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance)\n }\n if (!instance.contract) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)\n }\n template.bind(\n {\n name: instance.contract.name,\n address: validateAndNormalizeAddress(instance.contract.address),\n network: instance.contract.chainId as EthChainId,\n startBlock: instance.startBlock,\n endBlock: instance.endBlock,\n },\n ctx\n )\n }\n }\n\n stateDiff(config: ProcessConfigResponse): boolean {\n return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length\n }\n\n async processLog(request: DataBinding): Promise<ProcessResult> {\n if (!request.data?.ethLog?.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n const ethLog = request.data.ethLog\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of request.handlerIds) {\n const handler = this.handlers.eventHandlers[handlerId]\n promises.push(\n handler(ethLog).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing log: ' + JSON.stringify(ethLog.log) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTrace?.trace) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be null\")\n }\n const ethTrace = binding.data.ethTrace\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.traceHandlers[handlerId](ethTrace).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processBlock(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethBlock?.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const ethBlock = binding.data.ethBlock\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.blockHandlers[handlerId](ethBlock).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing block: ' + ethBlock.block?.number + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTransaction(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTransaction?.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"transaction can't be null\")\n }\n const ethTransaction = binding.data.ethTransaction\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.transactionHandlers[handlerId](ethTransaction).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new EthPlugin())\n\nclass NoopContext extends EthContext {\n public constructor() {\n super(EthChainId.ETHEREUM, '')\n }\n\n protected getContractName(): string {\n return ''\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/eth/eth-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAMd,WAAW,GAMZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAS3D,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,EAAE;QACjB,mBAAmB,EAAE,EAAE;KACxB,CAAA;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,MAAM,QAAQ,GAAa;YACzB,aAAa,EAAE,EAAE;YACjB,aAAa,EAAE,EAAE;YACjB,aAAa,EAAE,EAAE;YACjB,mBAAmB,EAAE,EAAE;SACxB,CAAA;QACD,4DAA4D;QAC5D,MAA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AAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAChC,CAAC;IAES,eAAe;QACvB,OAAO,EAAE,CAAA;IACX,CAAC;CACF","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n Data_EthTransaction,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\nimport { ProcessorState } from './binds.js'\nimport { AccountProcessorState } from './account-processor-state.js'\nimport { ProcessorTemplateProcessorState } from './base-processor-template.js'\nimport { GlobalProcessorState } from './base-processor.js'\nimport { validateAndNormalizeAddress } from './eth.js'\nimport { EthChainId } from '../core/chain.js'\nimport { EthContext } from './context.js'\nimport { TemplateInstanceState } from '../core/template.js'\n\ninterface Handlers {\n eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[]\n traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[]\n blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[]\n transactionHandlers: ((trace: Data_EthTransaction) => Promise<ProcessResult>)[]\n}\n\nexport class EthPlugin extends Plugin {\n name: string = 'EthPlugin'\n handlers: Handlers = {\n blockHandlers: [],\n eventHandlers: [],\n traceHandlers: [],\n transactionHandlers: [],\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n blockHandlers: [],\n eventHandlers: [],\n traceHandlers: [],\n transactionHandlers: [],\n }\n // This syntax is to copy values instead of using references\n config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]\n\n for (const processor of ProcessorState.INSTANCE.getValues()) {\n // If server favor incremental update this need to change\n // Start basic config for contract\n const chainId = processor.getChainId()\n // this.processorsByChainId.set(chainId, processor)\n\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: validateAndNormalizeAddress(processor.config.address),\n abi: '',\n },\n startBlock: processor.config.startBlock,\n endBlock: processor.config.endBlock,\n })\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1\n // TODO wrap the block handler into one\n\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n fetchConfig: blockHandler.fetchConfig,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = handlers.traceHandlers.push(traceHandler.handler) - 1\n for (const signature of traceHandler.signatures) {\n contractConfig.traceConfigs.push({\n signature: signature,\n handlerId: handlerId,\n fetchConfig: traceHandler.fetchConfig,\n })\n }\n }\n\n // Step 3. Prepare all the event handlers\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n\n // if (!filter.topics) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n // }\n const logFilter: LogFilter = {\n addressType: undefined,\n address: contractConfig.contract?.address && validateAndNormalizeAddress(contractConfig.contract.address),\n topics: [],\n }\n\n for (const ts of topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n contractConfig.logConfigs.push(logConfig)\n }\n\n // Finish up a contract\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of GlobalProcessorState.INSTANCE.getValues()) {\n const chainId = processor.getChainId()\n\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address, // can only be *\n abi: '',\n },\n startBlock: processor.config.startBlock,\n endBlock: processor.config.endBlock,\n })\n\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n fetchConfig: blockHandler.fetchConfig,\n })\n }\n\n for (const transactionHandler of processor.transactionHandler) {\n const handlerId = handlers.transactionHandlers.push(transactionHandler.handler) - 1\n contractConfig.transactionConfig.push({\n handlerId: handlerId,\n fetchConfig: transactionHandler.fetchConfig,\n })\n }\n config.contractConfigs.push(contractConfig)\n }\n\n // part 1.b prepare EVM account processors\n for (const processor of AccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,\n })\n // TODO add interval\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n // if (!filter.topics) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n // }\n let address = undefined\n if (filter.address) {\n address = filter.address.toString()\n }\n const logFilter: LogFilter = {\n addressType: filter.addressType,\n address: address && validateAndNormalizeAddress(address),\n topics: [],\n }\n\n for (const ts of topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n accountConfig.logConfigs.push(logConfig)\n }\n\n config.accountConfigs.push(accountConfig)\n }\n\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE, HandlerType.ETH_TRANSACTION]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n // return Promise.resolve(undefined);\n switch (request.handlerType) {\n case HandlerType.ETH_LOG:\n return this.processLog(request)\n case HandlerType.ETH_TRACE:\n return this.processTrace(request)\n case HandlerType.ETH_BLOCK:\n return this.processBlock(request)\n case HandlerType.ETH_TRANSACTION:\n return this.processTransaction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async start(request: StartRequest) {\n const ctx = new NoopContext()\n const allowedChainIds = new Set<string>(Object.values(EthChainId))\n\n for (const instance of request.templateInstances) {\n if (!allowedChainIds.has(instance.contract?.chainId || '')) {\n continue\n }\n\n const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId]\n if (!template) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance)\n }\n if (!instance.contract) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)\n }\n template.bind(\n {\n name: instance.contract.name,\n address: validateAndNormalizeAddress(instance.contract.address),\n network: instance.contract.chainId as EthChainId,\n startBlock: instance.startBlock,\n endBlock: instance.endBlock,\n },\n ctx\n )\n }\n }\n\n stateDiff(config: ProcessConfigResponse): boolean {\n return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length\n }\n\n async processLog(request: DataBinding): Promise<ProcessResult> {\n if (!request.data?.ethLog?.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n const ethLog = request.data.ethLog\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of request.handlerIds) {\n const handler = this.handlers.eventHandlers[handlerId]\n promises.push(\n handler(ethLog).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing log: ' + JSON.stringify(ethLog.log) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTrace?.trace) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be null\")\n }\n const ethTrace = binding.data.ethTrace\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.traceHandlers[handlerId](ethTrace).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processBlock(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethBlock?.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const ethBlock = binding.data.ethBlock\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.blockHandlers[handlerId](ethBlock).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing block: ' + ethBlock.block?.number + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTransaction(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTransaction?.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"transaction can't be null\")\n }\n const ethTransaction = binding.data.ethTransaction\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.transactionHandlers[handlerId](ethTransaction).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new EthPlugin())\n\nclass NoopContext extends EthContext {\n public constructor() {\n super(EthChainId.ETHEREUM, '')\n }\n\n protected getContractName(): string {\n return ''\n }\n}\n"]}
|
package/lib/sui/index.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
export
|
1
|
+
export { SuiBaseProcessor, type SuiBindOptions } from './sui-processor.js';
|
2
|
+
export { SuiAddressProcessor, SuiObjectProcessor, SuiWrappedObjectProcessor, type SuiObjectBindOptions, } from './sui-object-processor.js';
|
3
|
+
export { SuiObjectsProcessorTemplate, SuiWrappedObjectProcessorTemplate, } from './sui-objects-processor-template.js';
|
2
4
|
export * from './network.js';
|
3
5
|
export * from './context.js';
|
4
6
|
export * from './models.js';
|
package/lib/sui/index.js
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
export
|
1
|
+
export { SuiBaseProcessor } from './sui-processor.js';
|
2
|
+
export { SuiAddressProcessor, SuiObjectProcessor, SuiWrappedObjectProcessor, } from './sui-object-processor.js';
|
3
|
+
export {
|
4
|
+
// SuiAddressProcessorTemplate,
|
5
|
+
SuiObjectsProcessorTemplate, SuiWrappedObjectProcessorTemplate, } from './sui-objects-processor-template.js';
|
2
6
|
export * from './network.js';
|
3
7
|
export * from './context.js';
|
4
8
|
export * from './models.js';
|
package/lib/sui/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sui/index.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAuB,MAAM,oBAAoB,CAAA;AAC1E,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,GAE1B,MAAM,2BAA2B,CAAA;AAElC,OAAO;AACL,+BAA+B;AAC/B,2BAA2B,EAC3B,iCAAiC,GAClC,MAAM,qCAAqC,CAAA;AAE5C,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAG3B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA","sourcesContent":["export { SuiBaseProcessor, type SuiBindOptions } from './sui-processor.js'\nexport {\n SuiAddressProcessor,\n SuiObjectProcessor,\n SuiWrappedObjectProcessor,\n type SuiObjectBindOptions,\n} from './sui-object-processor.js'\n\nexport {\n // SuiAddressProcessorTemplate,\n SuiObjectsProcessorTemplate,\n SuiWrappedObjectProcessorTemplate,\n} from './sui-objects-processor-template.js'\n\nexport * from './network.js'\nexport * from './context.js'\nexport * from './models.js'\n\nexport type { SuiAddress } from './move-types.js'\nexport { BUILTIN_TYPES } from '../move/types.js'\n\nexport * from './move-coder.js'\n\nexport { SuiPlugin } from './sui-plugin.js'\n\nexport { ModuleClient } from './module-client.js'\n\nexport { validateAndNormalizeAddress, isValidSuiAddress } from './utils.js'\n"]}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { Data_SuiObject, HandleInterval, MoveAccountFetchConfig, MoveOwnerType, ProcessResult } from '@sentio/protos';
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
3
|
+
import { SuiNetwork } from './network.js';
|
4
|
+
import { SuiObjectsContext } from './context.js';
|
5
|
+
import { SuiMoveObject } from '@mysten/sui.js';
|
6
|
+
import { PromiseOrVoid } from '../core/index.js';
|
7
|
+
import { IndexConfigure, SuiBindOptions } from './sui-processor.js';
|
8
|
+
export interface SuiObjectBindOptions {
|
9
|
+
objectId: string;
|
10
|
+
network?: SuiNetwork;
|
11
|
+
startCheckpoint?: bigint;
|
12
|
+
baseLabels?: {
|
13
|
+
[key: string]: string;
|
14
|
+
};
|
15
|
+
}
|
16
|
+
interface ObjectHandler {
|
17
|
+
type?: string;
|
18
|
+
versionInterval?: HandleInterval;
|
19
|
+
timeIntervalInMinutes?: HandleInterval;
|
20
|
+
fetchConfig: MoveAccountFetchConfig;
|
21
|
+
handler: (resource: Data_SuiObject) => Promise<ProcessResult>;
|
22
|
+
}
|
23
|
+
export declare const DEFAULT_FETCH_CONFIG: MoveAccountFetchConfig;
|
24
|
+
export declare class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {
|
25
|
+
static INSTANCE: SuiAccountProcessorState;
|
26
|
+
}
|
27
|
+
export interface SuiInternalObjectsBindOptions extends SuiBindOptions {
|
28
|
+
ownerType: MoveOwnerType;
|
29
|
+
}
|
30
|
+
export declare abstract class SuiBaseObjectsProcessor<HandlerType> {
|
31
|
+
config: IndexConfigure;
|
32
|
+
ownerType: MoveOwnerType;
|
33
|
+
objectHandlers: ObjectHandler[];
|
34
|
+
protected constructor(options: SuiInternalObjectsBindOptions);
|
35
|
+
getChainId(): string;
|
36
|
+
protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
37
|
+
onInterval(handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
38
|
+
timeInterval: HandleInterval | undefined, versionInterval: HandleInterval | undefined, type: string | undefined, fetchConfig: Partial<MoveAccountFetchConfig> | undefined): this;
|
39
|
+
onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
40
|
+
onSlotInterval(handler: HandlerType, slotInterval?: number, backfillSlotInterval?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
41
|
+
}
|
42
|
+
export declare class SuiAddressProcessor extends SuiBaseObjectsProcessor<(objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
43
|
+
static bind(options: SuiBindOptions): SuiAddressProcessor;
|
44
|
+
protected doHandle(handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
45
|
+
}
|
46
|
+
export declare class SuiObjectProcessor extends SuiBaseObjectsProcessor<(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
47
|
+
static bind(options: SuiObjectBindOptions): SuiObjectProcessor;
|
48
|
+
protected doHandle(handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
49
|
+
}
|
50
|
+
export declare class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
51
|
+
static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor;
|
52
|
+
protected doHandle(handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
53
|
+
}
|
54
|
+
export {};
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import { MoveOwnerType } from '@sentio/protos';
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
3
|
+
import { SuiObjectsContext } from './context.js';
|
4
|
+
import { configure } from './sui-processor.js';
|
5
|
+
export const DEFAULT_FETCH_CONFIG = {
|
6
|
+
owned: true,
|
7
|
+
};
|
8
|
+
class SuiAccountProcessorState extends ListStateStorage {
|
9
|
+
static INSTANCE = new SuiAccountProcessorState();
|
10
|
+
}
|
11
|
+
export { SuiAccountProcessorState };
|
12
|
+
export class SuiBaseObjectsProcessor {
|
13
|
+
config;
|
14
|
+
ownerType;
|
15
|
+
objectHandlers = [];
|
16
|
+
// static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {
|
17
|
+
// return new SuiBaseObjectsProcessor(options)
|
18
|
+
// }
|
19
|
+
constructor(options) {
|
20
|
+
this.config = configure(options);
|
21
|
+
this.ownerType = options.ownerType;
|
22
|
+
SuiAccountProcessorState.INSTANCE.addValue(this);
|
23
|
+
}
|
24
|
+
getChainId() {
|
25
|
+
return this.config.network;
|
26
|
+
}
|
27
|
+
onInterval(handler, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
28
|
+
timeInterval, versionInterval, type, fetchConfig) {
|
29
|
+
const processor = this;
|
30
|
+
this.objectHandlers.push({
|
31
|
+
handler: async function (data) {
|
32
|
+
const ctx = new SuiObjectsContext(processor.config.network, processor.config.address, data.slot, data.timestamp || new Date(0), processor.config.baseLabels);
|
33
|
+
await processor.doHandle(handler, data, ctx);
|
34
|
+
return ctx.getProcessResult();
|
35
|
+
},
|
36
|
+
timeIntervalInMinutes: timeInterval,
|
37
|
+
versionInterval: versionInterval,
|
38
|
+
type,
|
39
|
+
fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
|
40
|
+
});
|
41
|
+
return this;
|
42
|
+
}
|
43
|
+
onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240, type, fetchConfig) {
|
44
|
+
return this.onInterval(handler, {
|
45
|
+
recentInterval: timeIntervalInMinutes,
|
46
|
+
backfillInterval: backfillTimeIntervalInMinutes,
|
47
|
+
}, undefined, type, fetchConfig);
|
48
|
+
}
|
49
|
+
onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000, type, fetchConfig) {
|
50
|
+
return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval }, type, fetchConfig);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
export class SuiAddressProcessor extends SuiBaseObjectsProcessor {
|
54
|
+
static bind(options) {
|
55
|
+
return new SuiAddressProcessor({ ...options, ownerType: MoveOwnerType.ADDRESS });
|
56
|
+
}
|
57
|
+
doHandle(handler, data, ctx) {
|
58
|
+
return handler(data.objects, ctx);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
export class SuiObjectProcessor extends SuiBaseObjectsProcessor {
|
62
|
+
static bind(options) {
|
63
|
+
return new SuiObjectProcessor({
|
64
|
+
address: options.objectId,
|
65
|
+
network: options.network,
|
66
|
+
startCheckpoint: options.startCheckpoint,
|
67
|
+
ownerType: MoveOwnerType.OBJECT,
|
68
|
+
baseLabels: options.baseLabels,
|
69
|
+
});
|
70
|
+
}
|
71
|
+
doHandle(handler, data, ctx) {
|
72
|
+
if (!data.self) {
|
73
|
+
console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`);
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
return handler(data.self, data.objects, ctx);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
export class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor {
|
80
|
+
static bind(options) {
|
81
|
+
return new SuiWrappedObjectProcessor({
|
82
|
+
address: options.objectId,
|
83
|
+
network: options.network,
|
84
|
+
startCheckpoint: options.startCheckpoint,
|
85
|
+
ownerType: MoveOwnerType.WRAPPED_OBJECT,
|
86
|
+
baseLabels: options.baseLabels,
|
87
|
+
});
|
88
|
+
}
|
89
|
+
doHandle(handler, data, ctx) {
|
90
|
+
return handler(data.objects, ctx);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
//# sourceMappingURL=sui-object-processor.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sui-object-processor.js","sourceRoot":"","sources":["../../src/sui/sui-object-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0D,aAAa,EAAiB,MAAM,gBAAgB,CAAA;AACrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGhD,OAAO,EAAE,SAAS,EAAkC,MAAM,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Ae,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,aAAa,CAAC,MAAM;YAC/B,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAA;IACJ,CAAC;IAES,QAAQ,CAChB,OAA6G,EAC7G,IAAoB,EACpB,GAAsB;QAEtB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,OAAO,CAAC,GAAG,CAAC,6BAA6B,GAAG,CAAC,IAAI,gCAAgC,CAAC,CAAA;YAClF,OAAM;SACP;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAqB,EAAE,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IAClF,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,uBAE9C;IACC,MAAM,CAAC,IAAI,CAAC,OAA6B;QACvC,OAAO,IAAI,yBAAyB,CAAC;YACnC,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,aAAa,CAAC,cAAc;YACvC,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAA;IACJ,CAAC;IAES,QAAQ,CAChB,OAAwF,EACxF,IAAoB,EACpB,GAAsB;QAEtB,OAAO,OAAO,CAAC,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import { Data_SuiObject, HandleInterval, MoveAccountFetchConfig, MoveOwnerType, ProcessResult } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiNetwork } from './network.js'\nimport { SuiObjectsContext } from './context.js'\nimport { SuiMoveObject } from '@mysten/sui.js'\nimport { PromiseOrVoid } from '../core/index.js'\nimport { configure, IndexConfigure, SuiBindOptions } from './sui-processor.js'\n\nexport interface SuiObjectBindOptions {\n objectId: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: { [key: string]: string }\n}\n\ninterface ObjectHandler {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n fetchConfig: MoveAccountFetchConfig\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport const DEFAULT_FETCH_CONFIG: MoveAccountFetchConfig = {\n owned: true,\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nexport interface SuiInternalObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOwnerType\n}\n\nexport abstract class SuiBaseObjectsProcessor<HandlerType> {\n config: IndexConfigure\n ownerType: MoveOwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {\n // return new SuiBaseObjectsProcessor(options)\n // }\n\n protected constructor(options: SuiInternalObjectsBindOptions) {\n this.config = configure(options)\n this.ownerType = options.ownerType\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n // protected abstract transformObjects(objects: SuiMoveObject[]): SuiMoveObject[]\n\n protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid\n\n public onInterval(\n handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined,\n fetchConfig: Partial<MoveAccountFetchConfig> | undefined\n ): this {\n const processor = this\n this.objectHandlers.push({\n handler: async function (data) {\n const ctx = new SuiObjectsContext(\n processor.config.network,\n processor.config.address,\n data.slot,\n data.timestamp || new Date(0),\n processor.config.baseLabels\n )\n await processor.doHandle(handler, data, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type,\n fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },\n })\n return this\n }\n\n public onTimeInterval(\n handler: HandlerType,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type,\n fetchConfig\n )\n }\n\n public onSlotInterval(\n handler: HandlerType,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type,\n fetchConfig\n )\n }\n}\n\nexport class SuiAddressProcessor extends SuiBaseObjectsProcessor<\n (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiBindOptions): SuiAddressProcessor {\n return new SuiAddressProcessor({ ...options, ownerType: MoveOwnerType.ADDRESS })\n }\n\n protected doHandle(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n\nexport class SuiObjectProcessor extends SuiBaseObjectsProcessor<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiObjectProcessor {\n return new SuiObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOwnerType.OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n if (!data.self) {\n console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`)\n return\n }\n return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)\n }\n}\n\nexport class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor {\n return new SuiWrappedObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOwnerType.WRAPPED_OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n"]}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { HandleInterval, MoveAccountFetchConfig } from '@sentio/protos';
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
3
|
+
import { SuiContext, SuiObjectsContext } from './context.js';
|
4
|
+
import { SuiMoveObject } from '@mysten/sui.js';
|
5
|
+
import { PromiseOrVoid } from '../core/index.js';
|
6
|
+
import { SuiBaseObjectsProcessor, SuiObjectBindOptions, SuiObjectProcessor, SuiWrappedObjectProcessor } from './sui-object-processor.js';
|
7
|
+
declare class ObjectHandler<HandlerType> {
|
8
|
+
type?: string;
|
9
|
+
versionInterval?: HandleInterval;
|
10
|
+
timeIntervalInMinutes?: HandleInterval;
|
11
|
+
handler: HandlerType;
|
12
|
+
fetchConfig: MoveAccountFetchConfig;
|
13
|
+
}
|
14
|
+
export declare class SuiAccountProcessorTemplateState extends ListStateStorage<SuiBaseObjectsProcessorTemplate<any, any>> {
|
15
|
+
static INSTANCE: SuiAccountProcessorTemplateState;
|
16
|
+
}
|
17
|
+
export declare abstract class SuiBaseObjectsProcessorTemplate<HandlerType, ProcessorType extends SuiBaseObjectsProcessor<HandlerType>> {
|
18
|
+
id: number;
|
19
|
+
objectHandlers: ObjectHandler<HandlerType>[];
|
20
|
+
binds: Set<string>;
|
21
|
+
protected constructor();
|
22
|
+
abstract createProcessor(options: SuiObjectBindOptions): ProcessorType;
|
23
|
+
bind(options: SuiObjectBindOptions, ctx: SuiContext): void;
|
24
|
+
protected onInterval(handler: HandlerType, timeInterval: HandleInterval | undefined, versionInterval: HandleInterval | undefined, type: string | undefined, fetchConfig: Partial<MoveAccountFetchConfig> | undefined): this;
|
25
|
+
onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
26
|
+
onSlotInterval(handler: HandlerType, slotInterval?: number, backfillSlotInterval?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
27
|
+
}
|
28
|
+
export declare class SuiObjectsProcessorTemplate extends SuiBaseObjectsProcessorTemplate<(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, SuiObjectProcessor> {
|
29
|
+
createProcessor(options: SuiObjectBindOptions): SuiObjectProcessor;
|
30
|
+
}
|
31
|
+
export declare class SuiWrappedObjectProcessorTemplate extends SuiBaseObjectsProcessorTemplate<(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, SuiWrappedObjectProcessor> {
|
32
|
+
createProcessor(options: SuiObjectBindOptions): SuiWrappedObjectProcessor;
|
33
|
+
}
|
34
|
+
export {};
|