@sentio/sdk 1.23.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/aptos-processor.js +6 -18
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +1 -1
- package/lib/aptos/context.js +1 -0
- package/lib/aptos/context.js.map +1 -1
- package/lib/core/base-processor.js +6 -25
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +7 -5
- package/lib/core/context.js +15 -0
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.d.ts +22 -0
- package/lib/core/event-tracker.js +53 -0
- package/lib/core/event-tracker.js.map +1 -0
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +4 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/solana-processor.js +1 -5
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.js +1 -5
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +72 -0
- package/lib/gen/processor/protos/processor.js +481 -2
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/processor-state.d.ts +4 -0
- package/lib/processor-state.js +2 -0
- package/lib/processor-state.js.map +1 -1
- package/lib/service.d.ts +2 -0
- package/lib/service.js +24 -1
- package/lib/service.js.map +1 -1
- package/lib/tests/erc20.js +3 -0
- package/lib/tests/erc20.js.map +1 -1
- package/package.json +1 -1
- package/src/aptos/aptos-processor.ts +6 -18
- package/src/aptos/context.ts +2 -1
- package/src/core/base-processor.ts +5 -25
- package/src/core/context.ts +29 -5
- package/src/core/event-tracker.ts +66 -0
- package/src/core/index.ts +1 -0
- package/src/core/solana-processor.ts +1 -5
- package/src/core/sui-processor.ts +1 -5
- package/src/gen/processor/protos/processor.ts +600 -1
- package/src/processor-state.ts +6 -0
- package/src/service.ts +28 -1
- package/src/tests/erc20.ts +4 -0
@@ -39,13 +39,9 @@ class AptosBaseProcessor {
|
|
39
39
|
handler: async function (tx) {
|
40
40
|
const ctx = new _1.AptosContext(processor.moduleName, processor.config.network, processor.config.address, long_1.default.fromString(tx.version), tx);
|
41
41
|
if (tx) {
|
42
|
-
handler(tx, ctx);
|
42
|
+
await handler(tx, ctx);
|
43
43
|
}
|
44
|
-
return
|
45
|
-
gauges: ctx.gauges,
|
46
|
-
counters: ctx.counters,
|
47
|
-
logs: ctx.logs,
|
48
|
-
};
|
44
|
+
return ctx.getProcessResult();
|
49
45
|
},
|
50
46
|
filters: [],
|
51
47
|
});
|
@@ -71,14 +67,10 @@ class AptosBaseProcessor {
|
|
71
67
|
txn.events = [];
|
72
68
|
for (const evt of events) {
|
73
69
|
const decoded = processor.decodeEvent(evt);
|
74
|
-
handler(decoded, ctx);
|
70
|
+
await handler(decoded, ctx);
|
75
71
|
}
|
76
72
|
}
|
77
|
-
return
|
78
|
-
gauges: ctx.gauges,
|
79
|
-
counters: ctx.counters,
|
80
|
-
logs: ctx.logs,
|
81
|
-
};
|
73
|
+
return ctx.getProcessResult();
|
82
74
|
},
|
83
75
|
filters: _filters,
|
84
76
|
});
|
@@ -102,13 +94,9 @@ class AptosBaseProcessor {
|
|
102
94
|
if (tx) {
|
103
95
|
const payload = tx.payload;
|
104
96
|
const decoded = processor.decodeFunctionPayload(payload);
|
105
|
-
handler(decoded, ctx);
|
97
|
+
await handler(decoded, ctx);
|
106
98
|
}
|
107
|
-
return
|
108
|
-
gauges: ctx.gauges,
|
109
|
-
counters: ctx.counters,
|
110
|
-
logs: ctx.logs,
|
111
|
-
};
|
99
|
+
return ctx.getProcessResult();
|
112
100
|
},
|
113
101
|
filters: _filters,
|
114
102
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,wBASU;AAEV,gDAAuB;AACvB,mCAA6D;AAC7D,sDAAwD;AACxD,uCAAsC;AA6BtC,MAAM,YAAY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C,CAAA;QACxB,MAAM,cAAc,GAAU,EAAE,CAAA;QAEhC,IAAI;YACF,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACvD,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE;gBACpD,sGAAsG;gBACtG,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACnD,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;aACnD;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;YAC7D,OAAO,OAAO,CAAA;SACf;QAED,OAAO,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAoC,CAAA;IAC1F,CAAC;CACF;AA5MD,gDA4MC","sourcesContent":["import { ProcessResult } from '../gen'\nimport {\n AptosBindOptions,\n AptosContext,\n AptosNetwork,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n TypedEntryFunctionPayload,\n TypedEventInstance,\n TypeRegistry,\n} from '.'\n\nimport Long from 'long'\nimport { EventInstance, GLOBAL_TYPE_REGISTRY } from './types'\nimport { parseMoveType } from '../aptos-codegen/typegen'\nimport { getChainId } from './network'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: Long\n // endSeqNumber?: Long\n}\n\n// TODO extends ArgumentsFilter\nexport interface EventFilter {\n type: string\n account?: string\n}\n\nexport interface FunctionNameAndCallFilter extends CallFilter {\n function: string\n}\n\n// TODO extends ArgumentsFilter\nexport interface CallFilter {\n includeFailed?: boolean\n typeArguments?: string[]\n}\n\nexport interface ArgumentsFilter {\n arguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: FunctionNameAndCallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void\n ): AptosBaseProcessor {\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n handler(tx, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: [],\n })\n return this\n }\n\n public onEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[]\n ): AptosBaseProcessor {\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (txn) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(txn.version),\n txn\n )\n if (txn && txn.events) {\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const decoded = processor.decodeEvent(evt as EventInstance)\n handler(decoded, ctx)\n }\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]\n ): AptosBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = processor.decodeFunctionPayload(payload)\n handler(decoded, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n private configure(options: AptosBindOptions) {\n let startVersion = Long.ZERO\n if (options.startVersion) {\n startVersion = Long.fromValue(options.startVersion)\n }\n\n this.config = {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: TypeRegistry) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: TypeRegistry) {\n // should be override by subclass\n }\n\n private decodeEvent(event: EventInstance): EventInstance {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n // TODO check if module is not loaded\n\n const typeDescriptor = parseMoveType(event.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n // TODO check move structure's type param match type args, also maybe\n // use type arguments for decoding\n\n let dataTyped = undefined\n try {\n dataTyped = registry.decode(event.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(event))\n return event\n }\n\n return { ...event, data_typed: dataTyped, type_arguments: typeArguments } as TypedEventInstance<any>\n }\n\n private decodeFunctionPayload(\n payload: TransactionPayload_EntryFunctionPayload\n ): TransactionPayload_EntryFunctionPayload {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const func = registry.getMoveFunction(payload.function)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = parseMoveType(func.params[idx + 1])\n argumentsTyped.push(registry.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload))\n return payload\n }\n\n return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,wBASU;AAEV,gDAAuB;AACvB,mCAA6D;AAC7D,sDAAwD;AACxD,uCAAsC;AA6BtC,MAAM,YAAY;IAChB,OAAO,CAAe;IACtB,OAAO,CAAgE;CACxE;AAED,MAAM,WAAW;IACf,OAAO,CAA6B;IACpC,OAAO,CAA+D;CACvE;AAED,MAAa,kBAAkB;IACpB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IACtB,aAAa,GAAmB,EAAE,CAAA;IAClC,YAAY,GAAkB,EAAE,CAAA;IAEhC,YAAY,UAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QACvB,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,qCAAqC;IACrC,qBAAqB;IACrB,IAAI;IAEG,aAAa,CAClB,OAA8E;QAE9E,sCAAsC;QACtC,qCAAqC;QACrC,4DAA4D;QAC5D,MAAM,SAAS,GAA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,CAAC,KAAK,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;SACxD;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;YAC3D,OAAO,KAAK,CAAA;SACb;QAED,OAAO,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAA6B,CAAA;IACtG,CAAC;IAEO,qBAAqB,CAC3B,OAAgD;QAEhD,MAAM,QAAQ,GAAG,4BAAoB,CAAA;QACrC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;QACxB,MAAM,cAAc,GAAU,EAAE,CAAA;QAEhC,IAAI;YACF,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACvD,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE;gBACpD,sGAAsG;gBACtG,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACnD,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;aACnD;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;YAC7D,OAAO,OAAO,CAAA;SACf;QAED,OAAO,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAoC,CAAA;IAC1F,CAAC;CACF;AAhMD,gDAgMC","sourcesContent":["import { ProcessResult } from '../gen'\nimport {\n AptosBindOptions,\n AptosContext,\n AptosNetwork,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n TypedEntryFunctionPayload,\n TypedEventInstance,\n TypeRegistry,\n} from '.'\n\nimport Long from 'long'\nimport { EventInstance, GLOBAL_TYPE_REGISTRY } from './types'\nimport { parseMoveType } from '../aptos-codegen/typegen'\nimport { getChainId } from './network'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: Long\n // endSeqNumber?: Long\n}\n\n// TODO extends ArgumentsFilter\nexport interface EventFilter {\n type: string\n account?: string\n}\n\nexport interface FunctionNameAndCallFilter extends CallFilter {\n function: string\n}\n\n// TODO extends ArgumentsFilter\nexport interface CallFilter {\n includeFailed?: boolean\n typeArguments?: string[]\n}\n\nexport interface ArgumentsFilter {\n arguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: FunctionNameAndCallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void\n ): AptosBaseProcessor {\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n await handler(tx, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: [],\n })\n return this\n }\n\n public onEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[]\n ): AptosBaseProcessor {\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (txn) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(txn.version),\n txn\n )\n if (txn && txn.events) {\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const decoded = processor.decodeEvent(evt as EventInstance)\n await handler(decoded, ctx)\n }\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]\n ): AptosBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = processor.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n })\n return this\n }\n\n private configure(options: AptosBindOptions) {\n let startVersion = Long.ZERO\n if (options.startVersion) {\n startVersion = Long.fromValue(options.startVersion)\n }\n\n this.config = {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: TypeRegistry) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: TypeRegistry) {\n // should be override by subclass\n }\n\n private decodeEvent(event: EventInstance): EventInstance {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n // TODO check if module is not loaded\n\n const typeDescriptor = parseMoveType(event.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n // TODO check move structure's type param match type args, also maybe\n // use type arguments for decoding\n\n let dataTyped = undefined\n try {\n dataTyped = registry.decode(event.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(event))\n return event\n }\n\n return { ...event, data_typed: dataTyped, type_arguments: typeArguments } as TypedEventInstance<any>\n }\n\n private decodeFunctionPayload(\n payload: TransactionPayload_EntryFunctionPayload\n ): TransactionPayload_EntryFunctionPayload {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const func = registry.getMoveFunction(payload.function)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = parseMoveType(func.params[idx + 1])\n argumentsTyped.push(registry.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload))\n return payload\n }\n\n return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>\n }\n}\n"]}
|
package/lib/aptos/context.d.ts
CHANGED
@@ -10,5 +10,5 @@ export declare class AptosContext extends BaseContext {
|
|
10
10
|
version: Long;
|
11
11
|
transaction: Transaction_UserTransaction;
|
12
12
|
constructor(moduleName: string, network: AptosNetwork, address: string, version: Long, transaction?: Transaction_UserTransaction);
|
13
|
-
getMetaData(descriptor: DataDescriptor
|
13
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
|
14
14
|
}
|
package/lib/aptos/context.js
CHANGED
package/lib/aptos/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;AAGA,yCAA+C;AA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WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAA,oBAAU,EAAC,IAAI,CAAC,OAAO,CAAC;YACjC,cAAc,EAAE,UAAU;YAC1B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AAtCD,oCAsCC","sourcesContent":["import Long from 'long'\nimport { DataDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/context'\nimport { AptosNetwork, Transaction_UserTransaction } from './'\nimport { getChainId } from './network'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: Long\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: Long,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: getChainId(this.network),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
@@ -7,6 +7,7 @@ exports.BaseProcessor = exports.TraceHandler = exports.EventsHandler = void 0;
|
|
7
7
|
const providers_1 = require("@ethersproject/providers");
|
8
8
|
const long_1 = __importDefault(require("long"));
|
9
9
|
const context_1 = require("./context");
|
10
|
+
const gen_1 = require("../gen");
|
10
11
|
class EventsHandler {
|
11
12
|
filters;
|
12
13
|
handler;
|
@@ -76,17 +77,9 @@ class BaseProcessor {
|
|
76
77
|
event.eventSignature = parsed.signature;
|
77
78
|
// TODO fix this bug
|
78
79
|
await handler(event, ctx);
|
79
|
-
return
|
80
|
-
gauges: ctx.gauges,
|
81
|
-
counters: ctx.counters,
|
82
|
-
logs: ctx.logs,
|
83
|
-
};
|
80
|
+
return ctx.getProcessResult();
|
84
81
|
}
|
85
|
-
return {
|
86
|
-
gauges: [],
|
87
|
-
counters: [],
|
88
|
-
logs: [],
|
89
|
-
};
|
82
|
+
return gen_1.ProcessResult.fromPartial({});
|
90
83
|
},
|
91
84
|
});
|
92
85
|
return this;
|
@@ -98,11 +91,7 @@ class BaseProcessor {
|
|
98
91
|
this.blockHandlers.push(async function (block) {
|
99
92
|
const ctx = new context_1.ContractContext(contractName, contractView, chainId, block, undefined);
|
100
93
|
await handler(block, ctx);
|
101
|
-
return
|
102
|
-
gauges: ctx.gauges,
|
103
|
-
counters: ctx.counters,
|
104
|
-
logs: ctx.logs,
|
105
|
-
};
|
94
|
+
return ctx.getProcessResult();
|
106
95
|
});
|
107
96
|
return this;
|
108
97
|
}
|
@@ -126,21 +115,13 @@ class BaseProcessor {
|
|
126
115
|
const contractInterface = contractView.rawContract.interface;
|
127
116
|
const fragment = contractInterface.getFunction(signature);
|
128
117
|
if (!trace.action.input) {
|
129
|
-
return {
|
130
|
-
gauges: [],
|
131
|
-
counters: [],
|
132
|
-
logs: [],
|
133
|
-
};
|
118
|
+
return gen_1.ProcessResult.fromPartial({});
|
134
119
|
}
|
135
120
|
const traceData = '0x' + trace.action.input.slice(10);
|
136
121
|
trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData);
|
137
122
|
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, undefined, trace);
|
138
123
|
await handler(trace, ctx);
|
139
|
-
return
|
140
|
-
gauges: ctx.gauges,
|
141
|
-
counters: ctx.counters,
|
142
|
-
logs: ctx.logs,
|
143
|
-
};
|
124
|
+
return ctx.getProcessResult();
|
144
125
|
},
|
145
126
|
});
|
146
127
|
return this;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAA4E;AAM5E,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAoB,EAAE,CAAA;IACnC,aAAa,GAAmB,EAAE,CAAA;IAElC,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,UAAU,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC;SACxB,CAAA;QACD,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE;gBACzC,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,cAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;aAC5D;iBAAM;gBACL,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;aAC3C;SACF;QACD,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA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S,EACT,KAAK,CACN,CAAA;gBACD,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBACzB,OAAO;oBACL,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;oBACtB,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAA;YACH,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1KD,sCA0KC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log\n )\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined\n )\n await handler(block, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n undefined,\n trace\n )\n await handler(trace, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n })\n return this\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAA4E;AAC5E,gCAAsC;AAKtC,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAoB,EAAE,CAAA;IACnC,aAAa,GAAmB,EAAE,CAAA;IAElC,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,UAAU,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC;SACxB,CA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A;gBACrD,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;gBAE3E,MAAM,GAAG,GAAG,IAAI,yBAAe,CAC7B,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,CACN,CAAA;gBACD,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBACzB,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAtJD,sCAsJC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log\n )\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined\n )\n await handler(block, ctx)\n return ctx.getProcessResult()\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return ProcessResult.fromPartial({})\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n undefined,\n trace\n )\n await handler(trace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n}\n"]}
|
package/lib/core/context.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData } from '../gen';
|
1
|
+
import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData, EventTrackingResult, ProcessResult } from '../gen';
|
2
2
|
import { BaseContract, EventFilter } from 'ethers';
|
3
3
|
import { Block, Log } from '@ethersproject/abstract-provider';
|
4
4
|
import { Meter } from './meter';
|
@@ -10,10 +10,12 @@ export declare abstract class BaseContext {
|
|
10
10
|
gauges: GaugeResult[];
|
11
11
|
counters: CounterResult[];
|
12
12
|
logs: LogResult[];
|
13
|
+
events: EventTrackingResult[];
|
13
14
|
meter: Meter;
|
14
15
|
logger: Logger;
|
15
16
|
protected constructor();
|
16
|
-
|
17
|
+
getProcessResult(): ProcessResult;
|
18
|
+
abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
|
17
19
|
}
|
18
20
|
export declare abstract class EthContext extends BaseContext {
|
19
21
|
chainId: number;
|
@@ -29,7 +31,7 @@ export declare class ContractContext<TContract extends BaseContract, TContractBo
|
|
29
31
|
contract: TContractBoundView;
|
30
32
|
contractName: string;
|
31
33
|
constructor(contractName: string, view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace);
|
32
|
-
getMetaData(descriptor: DataDescriptor
|
34
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
|
33
35
|
}
|
34
36
|
export declare class ContractView<TContract extends BaseContract> {
|
35
37
|
filters: {
|
@@ -55,12 +57,12 @@ export declare class SolanaContext extends BaseContext {
|
|
55
57
|
programName: string;
|
56
58
|
blockNumber: Long;
|
57
59
|
constructor(programName: string, address: string, slot: Long);
|
58
|
-
getMetaData(descriptor: DataDescriptor
|
60
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
|
59
61
|
}
|
60
62
|
export declare class SuiContext extends BaseContext {
|
61
63
|
address: string;
|
62
64
|
moduleName: string;
|
63
65
|
blockNumber: Long;
|
64
66
|
constructor(address: string, slot: Long);
|
65
|
-
getMetaData(descriptor: DataDescriptor
|
67
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
|
66
68
|
}
|
package/lib/core/context.js
CHANGED
@@ -12,12 +12,22 @@ class BaseContext {
|
|
12
12
|
gauges = [];
|
13
13
|
counters = [];
|
14
14
|
logs = [];
|
15
|
+
events = [];
|
15
16
|
meter;
|
16
17
|
logger;
|
17
18
|
constructor() {
|
18
19
|
this.meter = new meter_1.Meter(this);
|
19
20
|
this.logger = new logger_1.Logger(this);
|
20
21
|
}
|
22
|
+
getProcessResult() {
|
23
|
+
const res = {
|
24
|
+
gauges: this.gauges,
|
25
|
+
counters: this.counters,
|
26
|
+
logs: this.logs,
|
27
|
+
events: this.events,
|
28
|
+
};
|
29
|
+
return res;
|
30
|
+
}
|
21
31
|
}
|
22
32
|
exports.BaseContext = BaseContext;
|
23
33
|
class EthContext extends BaseContext {
|
@@ -69,6 +79,7 @@ class ContractContext extends EthContext {
|
|
69
79
|
logIndex: this.log.logIndex,
|
70
80
|
chainId: this.chainId.toString(),
|
71
81
|
dataDescriptor: descriptor,
|
82
|
+
name: descriptor.name,
|
72
83
|
labels: (0, meter_1.normalizeLabels)(labels),
|
73
84
|
};
|
74
85
|
}
|
@@ -82,6 +93,7 @@ class ContractContext extends EthContext {
|
|
82
93
|
logIndex: -1,
|
83
94
|
chainId: this.chainId.toString(),
|
84
95
|
dataDescriptor: descriptor,
|
96
|
+
name: descriptor.name,
|
85
97
|
labels: (0, meter_1.normalizeLabels)(labels),
|
86
98
|
};
|
87
99
|
}
|
@@ -95,6 +107,7 @@ class ContractContext extends EthContext {
|
|
95
107
|
logIndex: -1,
|
96
108
|
chainId: this.chainId.toString(),
|
97
109
|
dataDescriptor: descriptor,
|
110
|
+
name: descriptor.name,
|
98
111
|
labels: (0, meter_1.normalizeLabels)(labels),
|
99
112
|
};
|
100
113
|
}
|
@@ -155,6 +168,7 @@ class SolanaContext extends BaseContext {
|
|
155
168
|
logIndex: 0,
|
156
169
|
chainId: chain_1.SOL_MAINMET_ID,
|
157
170
|
dataDescriptor: descriptor,
|
171
|
+
name: descriptor.name,
|
158
172
|
labels: (0, meter_1.normalizeLabels)(labels),
|
159
173
|
};
|
160
174
|
}
|
@@ -179,6 +193,7 @@ class SuiContext extends BaseContext {
|
|
179
193
|
logIndex: 0,
|
180
194
|
chainId: chain_1.SUI_DEVNET_ID,
|
181
195
|
dataDescriptor: descriptor,
|
196
|
+
name: descriptor.name,
|
182
197
|
labels: (0, meter_1.normalizeLabels)(labels),
|
183
198
|
};
|
184
199
|
}
|
package/lib/core/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":";;;;;;AAGA,mCAAgD;AAChD,gDAAuB;AAEvB,qCAAiC;AAEjC,0CAA8D;AAE9D,MAAsB,WAAW;IAC/B,MAAM,GAAkB,EAAE,CAAA;IAC1B,QAAQ,GAAoB,EAAE,CAAA;IAC9B,IAAI,GAAgB,EAAE,CAAA;IACtB,KAAK,CAAO;IACZ,MAAM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AAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,qBAAa;YACtB,cAAc,EAAE,UAAU;YAC1B,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AAxBD,gCAwBC","sourcesContent":["import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData } from '../gen'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { Meter, normalizeLabels } from './meter'\nimport Long from 'long'\nimport { Trace } from './trace'\nimport { Logger } from './logger'\nimport { Labels } from './metadata'\nimport { SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'\n\nexport abstract class BaseContext {\n gauges: GaugeResult[] = []\n counters: CounterResult[] = []\n logs: LogResult[] = []\n meter: Meter\n logger: Logger\n\n protected constructor() {\n this.meter = new Meter(this)\n this.logger = new Logger(this)\n }\n\n abstract getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData\n}\n\nexport abstract class EthContext extends BaseContext {\n chainId: number\n address: string\n log?: Log\n block?: Block\n trace?: Trace\n blockNumber: Long\n transactionHash?: string\n\n protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {\n super()\n this.chainId = chainId\n this.log = log\n this.block = block\n this.trace = trace\n this.address = address\n if (log) {\n this.blockNumber = Long.fromNumber(log.blockNumber, true)\n this.transactionHash = log.transactionHash\n } else if (block) {\n this.blockNumber = Long.fromNumber(block.number, true)\n } else if (trace) {\n this.blockNumber = Long.fromNumber(trace.blockNumber, true)\n this.transactionHash = trace.transactionHash\n }\n }\n}\n\nexport class ContractContext<\n TContract extends BaseContract,\n TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>\n> extends EthContext {\n contract: TContractBoundView\n contractName: string\n\n constructor(\n contractName: string,\n view: TContractBoundView,\n chainId: number,\n block?: Block,\n log?: Log,\n trace?: Trace\n ) {\n super(chainId, view.rawContract.address, block, log, trace)\n view.context = this\n this.contractName = contractName\n this.contract = view\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n if (this.log) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.log.transactionIndex,\n transactionHash: this.transactionHash || '',\n logIndex: this.log.logIndex,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (this.block) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: -1,\n transactionHash: '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (this.trace) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.trace.transactionPosition,\n transactionHash: this.transactionHash || '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"Invaid ctx argument can't happen\")\n }\n}\n\nexport class ContractView<TContract extends BaseContract> {\n filters: { [name: string]: (...args: Array<any>) => EventFilter }\n protected contract: TContract\n\n constructor(contract: TContract) {\n this.contract = contract\n this.filters = contract.filters\n }\n\n get rawContract() {\n return this.contract\n }\n\n get provider() {\n return this.contract.provider\n }\n}\n\nexport class BoundContractView<TContract extends BaseContract, TContractView extends ContractView<TContract>> {\n protected view: TContractView\n // context will be set right after context creation (in context's constructor)\n context: ContractContext<TContract, BoundContractView<TContract, TContractView>>\n\n constructor(view: TContractView) {\n this.view = view\n }\n\n get rawContract() {\n return this.view.rawContract\n }\n\n get provider() {\n return this.view.provider\n }\n\n get filters() {\n return this.view.filters\n }\n}\n\nexport class SolanaContext extends BaseContext {\n address: string\n programName: string\n blockNumber: Long\n\n constructor(programName: string, address: string, slot: Long) {\n super()\n this.programName = programName\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.programName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO add\n logIndex: 0,\n chainId: SOL_MAINMET_ID, // TODO set in context\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class SuiContext extends BaseContext {\n address: string\n moduleName: string\n blockNumber: Long\n\n constructor(address: string, slot: Long) {\n super()\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO\n logIndex: 0,\n chainId: SUI_DEVNET_ID, // TODO set in context\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":";;;;;;AAWA,mCAAgD;AAChD,gDAAuB;AAEvB,qCAAiC;AAEjC,0CAA8D;AAE9D,MAAsB,WAAW;IAC/B,MAAM,GAAkB,EAAE,CAAA;IAC1B,QAAQ,GAAoB,EAAE,CAAA;IAC9B,IAAI,GAAgB,EAAE,CAAA;IACtB,MAAM,GAA0B,EAAE,CAAA;IAClC,KAAK,CAAO;IACZ,MAAM,CAAQ;IAEd;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED,gBAAgB;QACd,MAAM,GAAG,GAAkB;YACzB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAA;QACD,OAAO,GAAG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B,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,qBAAa;YACtB,cAAc,EAAE,UAAU;YAC1B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AAzBD,gCAyBC","sourcesContent":["import {\n CounterResult,\n GaugeResult,\n LogResult,\n DataDescriptor,\n RecordMetaData,\n EventTrackingResult,\n ProcessResult,\n} from '../gen'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { Meter, normalizeLabels } from './meter'\nimport Long from 'long'\nimport { Trace } from './trace'\nimport { Logger } from './logger'\nimport { Labels } from './metadata'\nimport { SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'\n\nexport abstract class BaseContext {\n gauges: GaugeResult[] = []\n counters: CounterResult[] = []\n logs: LogResult[] = []\n events: EventTrackingResult[] = []\n meter: Meter\n logger: Logger\n\n protected constructor() {\n this.meter = new Meter(this)\n this.logger = new Logger(this)\n }\n\n getProcessResult(): ProcessResult {\n const res: ProcessResult = {\n gauges: this.gauges,\n counters: this.counters,\n logs: this.logs,\n events: this.events,\n }\n return res\n }\n\n abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData\n}\n\nexport abstract class EthContext extends BaseContext {\n chainId: number\n address: string\n log?: Log\n block?: Block\n trace?: Trace\n blockNumber: Long\n transactionHash?: string\n\n protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {\n super()\n this.chainId = chainId\n this.log = log\n this.block = block\n this.trace = trace\n this.address = address\n if (log) {\n this.blockNumber = Long.fromNumber(log.blockNumber, true)\n this.transactionHash = log.transactionHash\n } else if (block) {\n this.blockNumber = Long.fromNumber(block.number, true)\n } else if (trace) {\n this.blockNumber = Long.fromNumber(trace.blockNumber, true)\n this.transactionHash = trace.transactionHash\n }\n }\n}\n\nexport class ContractContext<\n TContract extends BaseContract,\n TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>\n> extends EthContext {\n contract: TContractBoundView\n contractName: string\n\n constructor(\n contractName: string,\n view: TContractBoundView,\n chainId: number,\n block?: Block,\n log?: Log,\n trace?: Trace\n ) {\n super(chainId, view.rawContract.address, block, log, trace)\n view.context = this\n this.contractName = contractName\n this.contract = view\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n if (this.log) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.log.transactionIndex,\n transactionHash: this.transactionHash || '',\n logIndex: this.log.logIndex,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n if (this.block) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: -1,\n transactionHash: '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n if (this.trace) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.trace.transactionPosition,\n transactionHash: this.transactionHash || '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"Invaid ctx argument can't happen\")\n }\n}\n\nexport class ContractView<TContract extends BaseContract> {\n filters: { [name: string]: (...args: Array<any>) => EventFilter }\n protected contract: TContract\n\n constructor(contract: TContract) {\n this.contract = contract\n this.filters = contract.filters\n }\n\n get rawContract() {\n return this.contract\n }\n\n get provider() {\n return this.contract.provider\n }\n}\n\nexport class BoundContractView<TContract extends BaseContract, TContractView extends ContractView<TContract>> {\n protected view: TContractView\n // context will be set right after context creation (in context's constructor)\n context: ContractContext<TContract, BoundContractView<TContract, TContractView>>\n\n constructor(view: TContractView) {\n this.view = view\n }\n\n get rawContract() {\n return this.view.rawContract\n }\n\n get provider() {\n return this.view.provider\n }\n\n get filters() {\n return this.view.filters\n }\n}\n\nexport class SolanaContext extends BaseContext {\n address: string\n programName: string\n blockNumber: Long\n\n constructor(programName: string, address: string, slot: Long) {\n super()\n this.programName = programName\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.programName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO add\n logIndex: 0,\n chainId: SOL_MAINMET_ID, // TODO set in context\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class SuiContext extends BaseContext {\n address: string\n moduleName: string\n blockNumber: Long\n\n constructor(address: string, slot: Long) {\n super()\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO\n logIndex: 0,\n chainId: SUI_DEVNET_ID, // TODO set in context\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { BaseContext } from './context';
|
2
|
+
export interface Event {
|
3
|
+
distinctId: string;
|
4
|
+
payload?: Record<string, string>;
|
5
|
+
}
|
6
|
+
export interface TrackerOptions {
|
7
|
+
totalByDay?: boolean;
|
8
|
+
unique?: boolean;
|
9
|
+
distinctByDays?: number[];
|
10
|
+
}
|
11
|
+
export declare class EventTracker {
|
12
|
+
static DEFAULT_OPTIONS: TrackerOptions;
|
13
|
+
static register(eventName: string, options?: TrackerOptions): EventTracker;
|
14
|
+
eventName: string;
|
15
|
+
options: TrackerOptions;
|
16
|
+
protected constructor(eventName: string, options: TrackerOptions);
|
17
|
+
trackEvent(ctx: BaseContext, event: Event): void;
|
18
|
+
}
|
19
|
+
export declare class AccountEventTracker extends EventTracker {
|
20
|
+
static DEFAULT_OPTIONS: TrackerOptions;
|
21
|
+
static register(eventName?: string, options?: TrackerOptions): AccountEventTracker;
|
22
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AccountEventTracker = exports.EventTracker = void 0;
|
4
|
+
const sdk_1 = require("@sentio/sdk");
|
5
|
+
// Track Event with an identity associate with it
|
6
|
+
class EventTracker {
|
7
|
+
static DEFAULT_OPTIONS = {
|
8
|
+
totalByDay: true,
|
9
|
+
unique: true,
|
10
|
+
};
|
11
|
+
static register(eventName, options) {
|
12
|
+
const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options });
|
13
|
+
global.PROCESSOR_STATE.eventTrackers.push(tracker);
|
14
|
+
return tracker;
|
15
|
+
}
|
16
|
+
eventName;
|
17
|
+
options;
|
18
|
+
constructor(eventName, options) {
|
19
|
+
this.eventName = eventName;
|
20
|
+
this.options = options;
|
21
|
+
}
|
22
|
+
trackEvent(ctx, event) {
|
23
|
+
const res = {
|
24
|
+
metadata: ctx.getMetaData(sdk_1.DataDescriptor.fromPartial({ name: this.eventName }), {}),
|
25
|
+
distinctEntityId: event.distinctId,
|
26
|
+
attributes: JSON.stringify({}),
|
27
|
+
runtimeInfo: undefined,
|
28
|
+
};
|
29
|
+
ctx.events.push(res);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
exports.EventTracker = EventTracker;
|
33
|
+
class AccountEventTracker extends EventTracker {
|
34
|
+
static DEFAULT_OPTIONS = {
|
35
|
+
totalByDay: true,
|
36
|
+
unique: true,
|
37
|
+
distinctByDays: [1, 7, 30],
|
38
|
+
};
|
39
|
+
static register(eventName, options) {
|
40
|
+
if (eventName) {
|
41
|
+
;
|
42
|
+
['user', eventName].join('.');
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
eventName = 'user';
|
46
|
+
}
|
47
|
+
const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options });
|
48
|
+
global.PROCESSOR_STATE.eventTrackers.push(tracker);
|
49
|
+
return tracker;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
exports.AccountEventTracker = AccountEventTracker;
|
53
|
+
//# sourceMappingURL=event-tracker.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"event-tracker.js","sourceRoot":"","sources":["../../src/core/event-tracker.ts"],"names":[],"mappings":";;;AACA,qCAAiE;AAgBjE,iDAAiD;AACjD,MAAa,YAAY;IACvB,MAAM,CAAC,eAAe,GAAmB;QACvC,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;KACb,CAAA;IAED,MAAM,CAAC,QAAQ,CAAC,SAAiB,EAAE,OAAwB;QACzD,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,GAAG,YAAY,CAAC,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAC5F,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClD,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,SAAS,CAAQ;IACjB,OAAO,CAAgB;IACvB,YAAsB,SAAiB,EAAE,OAAuB;QAC9D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,UAAU,CAAC,GAAgB,EAAE,KAAY;QACvC,MAAM,GAAG,GAAwB;YAC/B,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,oBAAc,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;YACnF,gBAAgB,EAAE,KAAK,CAAC,UAAU;YAClC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,WAAW,EAAE,SAAS;SACvB,CAAA;QACD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;;AA3BH,oCA4BC;AAED,MAAa,mBAAoB,SAAQ,YAAY;IACnD,MAAM,CAAC,eAAe,GAAmB;QACvC,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;KAC3B,CAAA;IAED,MAAM,CAAC,QAAQ,CAAC,SAAkB,EAAE,OAAwB;QAC1D,IAAI,SAAS,EAAE;YACb,CAAC;YAAA,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;SAC/B;aAAM;YACL,SAAS,GAAG,MAAM,CAAA;SACnB;QACD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,SAAS,EAAE,EAAE,GAAG,mBAAmB,CAAC,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAC1G,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClD,OAAO,OAAO,CAAA;IAChB,CAAC;;AAhBH,kDAiBC","sourcesContent":["import { BaseContext } from './context'\nimport { DataDescriptor, EventTrackingResult } from '@sentio/sdk'\n\nexport interface Event {\n // The unique identifier of main identity associate with an event\n // .e.g user id / toekn address / account address / contract address id\n //\n distinctId: string\n payload?: Record<string, string>\n}\n\nexport interface TrackerOptions {\n totalByDay?: boolean\n unique?: boolean\n distinctByDays?: number[]\n}\n\n// Track Event with an identity associate with it\nexport class EventTracker {\n static DEFAULT_OPTIONS: TrackerOptions = {\n totalByDay: true,\n unique: true,\n }\n\n static register(eventName: string, options?: TrackerOptions) {\n const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options })\n global.PROCESSOR_STATE.eventTrackers.push(tracker)\n return tracker\n }\n\n eventName: string\n options: TrackerOptions\n protected constructor(eventName: string, options: TrackerOptions) {\n this.eventName = eventName\n this.options = options\n }\n\n trackEvent(ctx: BaseContext, event: Event) {\n const res: EventTrackingResult = {\n metadata: ctx.getMetaData(DataDescriptor.fromPartial({ name: this.eventName }), {}),\n distinctEntityId: event.distinctId,\n attributes: JSON.stringify({}),\n runtimeInfo: undefined,\n }\n ctx.events.push(res)\n }\n}\n\nexport class AccountEventTracker extends EventTracker {\n static DEFAULT_OPTIONS: TrackerOptions = {\n totalByDay: true,\n unique: true,\n distinctByDays: [1, 7, 30],\n }\n\n static register(eventName?: string, options?: TrackerOptions) {\n if (eventName) {\n ;['user', eventName].join('.')\n } else {\n eventName = 'user'\n }\n const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options })\n global.PROCESSOR_STATE.eventTrackers.push(tracker)\n return tracker\n }\n}\n"]}
|
package/lib/core/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export { BigDecimal } from './big-decimal';
|
2
2
|
export { ContractContext, ContractView, BoundContractView, SolanaContext } from './context';
|
3
3
|
export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter';
|
4
|
+
export { EventTracker, AccountEventTracker } from './event-tracker';
|
4
5
|
export { type Numberish, toBigInteger, toMetricValue } from './numberish';
|
5
6
|
export { BindOptions, SolanaBindOptions } from './bind-options';
|
6
7
|
export { BaseProcessor } from './base-processor';
|
package/lib/core/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.SuiBindOptions = exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.SolanaBindOptions = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.MetricDescriptorOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
|
3
|
+
exports.SuiBindOptions = exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.SolanaBindOptions = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.AccountEventTracker = exports.EventTracker = exports.MetricDescriptorOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
|
4
4
|
var big_decimal_1 = require("./big-decimal");
|
5
5
|
Object.defineProperty(exports, "BigDecimal", { enumerable: true, get: function () { return big_decimal_1.BigDecimal; } });
|
6
6
|
var context_1 = require("./context");
|
@@ -15,6 +15,9 @@ Object.defineProperty(exports, "GaugeBinding", { enumerable: true, get: function
|
|
15
15
|
Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return meter_1.Counter; } });
|
16
16
|
Object.defineProperty(exports, "Gauge", { enumerable: true, get: function () { return meter_1.Gauge; } });
|
17
17
|
Object.defineProperty(exports, "MetricDescriptorOptions", { enumerable: true, get: function () { return meter_1.MetricDescriptorOptions; } });
|
18
|
+
var event_tracker_1 = require("./event-tracker");
|
19
|
+
Object.defineProperty(exports, "EventTracker", { enumerable: true, get: function () { return event_tracker_1.EventTracker; } });
|
20
|
+
Object.defineProperty(exports, "AccountEventTracker", { enumerable: true, get: function () { return event_tracker_1.AccountEventTracker; } });
|
18
21
|
var numberish_1 = require("./numberish");
|
19
22
|
Object.defineProperty(exports, "toBigInteger", { enumerable: true, get: function () { return numberish_1.toBigInteger; } });
|
20
23
|
Object.defineProperty(exports, "toMetricValue", { enumerable: true, get: function () { return numberish_1.toMetricValue; } });
|
package/lib/core/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAAjC,yGAAA,UAAU,OAAA;AACnB,qCAA2F;AAAlF,0GAAA,eAAe,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AACxE,iCAAsG;AAA7F,uGAAA,cAAc,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,gHAAA,uBAAuB,OAAA;AACrF,yCAAyE;AAAhD,yGAAA,YAAY,OAAA;AAAE,0GAAA,aAAa,OAAA;AAEpD,+CAA+D;AAAtD,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAEvC,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,iDAAkE;AAAzD,iHAAA,gBAAgB,OAAA;AAAE,+GAAA,cAAc,OAAA","sourcesContent":["export { BigDecimal } from './big-decimal'\nexport { ContractContext, ContractView, BoundContractView, SolanaContext } from './context'\nexport { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter'\nexport { type Numberish, toBigInteger, toMetricValue } from './numberish'\n\nexport { BindOptions, SolanaBindOptions } from './bind-options'\n\nexport { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { SuiBaseProcessor, SuiBindOptions } from './sui-processor'\n// export * from '../aptos'\n\nexport type { TypedCallTrace, Trace } from './trace'\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAAjC,yGAAA,UAAU,OAAA;AACnB,qCAA2F;AAAlF,0GAAA,eAAe,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AACxE,iCAAsG;AAA7F,uGAAA,cAAc,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,gHAAA,uBAAuB,OAAA;AACrF,iDAAmE;AAA1D,6GAAA,YAAY,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAC1C,yCAAyE;AAAhD,yGAAA,YAAY,OAAA;AAAE,0GAAA,aAAa,OAAA;AAEpD,+CAA+D;AAAtD,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAEvC,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,iDAAkE;AAAzD,iHAAA,gBAAgB,OAAA;AAAE,+GAAA,cAAc,OAAA","sourcesContent":["export { BigDecimal } from './big-decimal'\nexport { ContractContext, ContractView, BoundContractView, SolanaContext } from './context'\nexport { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter'\nexport { EventTracker, AccountEventTracker } from './event-tracker'\nexport { type Numberish, toBigInteger, toMetricValue } from './numberish'\n\nexport { BindOptions, SolanaBindOptions } from './bind-options'\n\nexport { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { SuiBaseProcessor, SuiBindOptions } from './sui-processor'\n// export * from '../aptos'\n\nexport type { TypedCallTrace, Trace } from './trace'\n"]}
|
@@ -61,11 +61,7 @@ class SolanaBaseProcessor {
|
|
61
61
|
handleInstruction(parsedInstruction, accounts, handler, slot) {
|
62
62
|
const ctx = new context_1.SolanaContext(this.contractName, this.address, slot);
|
63
63
|
handler(parsedInstruction, ctx, accounts);
|
64
|
-
return
|
65
|
-
gauges: ctx.gauges,
|
66
|
-
counters: ctx.counters,
|
67
|
-
logs: ctx.logs,
|
68
|
-
};
|
64
|
+
return ctx.getProcessResult();
|
69
65
|
}
|
70
66
|
isBind() {
|
71
67
|
return this.address !== null;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../../src/core/solana-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAyC;AACzC,gDAAuB;AAWvB,MAAa,mBAAmB;IACvB,qBAAqB,GAA0C,IAAI,GAAG,EAAE,CAAA;IAC/E,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,YAAY,CAAQ;IACpB,uBAAuB,CAAS;IAChC,MAAM,GAAmB,EAAE,SAAS,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACnD,iBAAiB,CAAgD;IACjE,qBAAqB,CAAkE;IAEvF,YAAY,OAA0B;QACpC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,MAAM,CAAC,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAED,IAAI,CAAC,OAA0B;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAA;QACtC,IAAI,CAAC,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,IAAI,KAAK,CAAA;QACvE,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,IAAI,CAAC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,CAAC,SAAS,GAAG,SAAS,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA3FD,kDA2FC","sourcesContent":["import { ProcessResult } from '../gen'\nimport { SolanaContext } from './context'\nimport Long from 'long'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './bind-options'\n\ntype IndexConfigure = {\n startSlot: Long\n endSlot?: Long\n}\n\nexport type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void\n\nexport class SolanaBaseProcessor {\n public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()\n address: string\n endpoint: string\n contractName: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: new Long(0) }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.solanaProcessors.push(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n innerInstruction(flag: boolean) {\n this.processInnerInstruction = flag\n return this\n }\n\n public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHandlerMap.set(instructionName, handler)\n\n return this\n }\n\n public getParsedInstruction(ins: string | { type: string; info: any }): Instruction | null {\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n return this.fromParsedInstruction ? this.fromParsedInstruction(ins as { type: string; info: any }) : null\n }\n if (this.decodeInstruction != null) {\n return this.decodeInstruction(ins as string)\n }\n }\n return null\n }\n\n public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {\n return this.instructionHandlerMap.get(parsedInstruction.name)\n }\n\n public handleInstruction(\n parsedInstruction: Instruction,\n accounts: string[],\n handler: SolanaInstructionHandler,\n slot: Long\n ): ProcessResult {\n const ctx = new SolanaContext(this.contractName, this.address, slot)\n handler(parsedInstruction, ctx, accounts)\n return ctx.getProcessResult()\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSlot = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSlot = endBlock\n return this\n }\n}\n"]}
|
@@ -33,11 +33,7 @@ class SuiBaseProcessor {
|
|
33
33
|
if (txn) {
|
34
34
|
this.transactionHanlder(txn, ctx);
|
35
35
|
}
|
36
|
-
return
|
37
|
-
gauges: ctx.gauges,
|
38
|
-
counters: ctx.counters,
|
39
|
-
logs: ctx.logs,
|
40
|
-
};
|
36
|
+
return ctx.getProcessResult();
|
41
37
|
}
|
42
38
|
startSlot(startSlot) {
|
43
39
|
if (typeof startSlot === 'number') {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAsC;AAEtC,gDAAuB;AAOvB,MAAa,cAAc;IACzB,OAAO,CAAQ;IACf,2BAA2B;IAC3B,gBAAgB;IAChB,UAAU,CAAgB;CAE3B;AAND,wCAMC;AAED,MAAa,gBAAgB;IACpB,kBAAkB,CAA6C;IACt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,CAAC,CAAA;SACnC;QACD,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAEM,aAAa,CAAC,OAAoD;QACvE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,iBAAiB,CAAC,GAAQ,EAAE,IAAU;QAC3C,MAAM,GAAG,GAAG,IAAI,oBAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAE9C,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,SAAS,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1CD,4CA0CC","sourcesContent":["import { SuiContext } from './context'\nimport { ProcessResult } from '../gen'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport class SuiBindOptions {\n address: string\n // network?: Networkish = 1\n // name?: string\n startBlock?: Long | number\n // endBlock?: Long | number\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n\n constructor(name: string, options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n global.PROCESSOR_STATE.suiProcessors.push(this)\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n this.transactionHanlder = handler\n return this\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return ctx.getProcessResult()\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
|