@sentio/sdk 1.37.3-rc.1 → 1.37.4-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.
|
@@ -51,11 +51,12 @@ class BaseProcessor {
|
|
|
51
51
|
else {
|
|
52
52
|
_filters.push(filter);
|
|
53
53
|
}
|
|
54
|
-
const contractView = this.CreateBoundContractView();
|
|
55
54
|
const contractName = this.config.name;
|
|
55
|
+
const processor = this;
|
|
56
56
|
this.eventHandlers.push({
|
|
57
57
|
filters: _filters,
|
|
58
58
|
handler: async function (log) {
|
|
59
|
+
const contractView = processor.CreateBoundContractView();
|
|
59
60
|
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, log);
|
|
60
61
|
// let event: Event = <Event>deepCopy(log);
|
|
61
62
|
const event = log;
|
|
@@ -90,10 +91,11 @@ class BaseProcessor {
|
|
|
90
91
|
}
|
|
91
92
|
onInterval(handler, timeInterval, blockInterval) {
|
|
92
93
|
const chainId = this.getChainId();
|
|
93
|
-
const
|
|
94
|
+
const processor = this;
|
|
94
95
|
const contractName = this.config.name;
|
|
95
96
|
this.blockHandlers.push({
|
|
96
97
|
handler: async function (block) {
|
|
98
|
+
const contractView = processor.CreateBoundContractView();
|
|
97
99
|
const ctx = new context_1.ContractContext(contractName, contractView, chainId, block, undefined);
|
|
98
100
|
await handler(block, ctx);
|
|
99
101
|
return ctx.getProcessResult();
|
|
@@ -115,11 +117,12 @@ class BaseProcessor {
|
|
|
115
117
|
}
|
|
116
118
|
onTrace(signature, handler) {
|
|
117
119
|
const chainId = this.getChainId();
|
|
118
|
-
const contractView = this.CreateBoundContractView();
|
|
119
120
|
const contractName = this.config.name;
|
|
121
|
+
const processor = this;
|
|
120
122
|
this.traceHandlers.push({
|
|
121
123
|
signature,
|
|
122
124
|
handler: async function (trace) {
|
|
125
|
+
const contractView = processor.CreateBoundContractView();
|
|
123
126
|
const contractInterface = contractView.rawContract.interface;
|
|
124
127
|
const fragment = contractInterface.getFunction(signature);
|
|
125
128
|
if (!trace.action.input) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;AACA,wDAAiE;AAGjE,uCAA4E;AAC5E,2CAA2E;AAS3E,MAAa,aAAa;IACxB,OAAO,CAA4B;IACnC,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAa,aAAa;IACxB,aAAa,CAAiB;IAC9B,qBAAqB,CAAiB;IACtC,OAAO,CAA0C;CAClD;AAJD,sCAIC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAoB,EAAE,CAAA;IACnC,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,EAAE;SACf,CAAA;QACD,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;SACnD;QACD,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;SAC/C;IACH,CAAC;IAIM,UAAU;QACf,OAAO,IAAA,sBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAA;IAChD,CAAC;IAEM,OAAO,CACZ,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AAM,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;AAjLD,sCAiLC","sourcesContent":["import { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, Event, EventFilter } from '@ethersproject/contracts'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { AddressType, HandleInterval, ProcessResult } from '@sentio/protos'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport interface AddressOrTypeEventFilter extends EventFilter {\n addressType?: AddressType\n}\n\nexport class EventsHandler {\n filters: AddressOrTypeEventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport class BlockHandlder {\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (block: Block) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: BlockHandlder[] = []\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: 0n,\n }\n if (config.startBlock) {\n this.config.startBlock = BigInt(config.startBlock)\n }\n if (config.endBlock) {\n this.config.endBlock = BigInt(config.endBlock)\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 return this.onBlockInterval(handler)\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000,\n backfillBlockInterval = 4000\n ) {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },\n undefined\n )\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push({\n handler: 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 timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\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"]}
|
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;AACA,wDAAiE;AAGjE,uCAA4E;AAC5E,2CAA2E;AAS3E,MAAa,aAAa;IACxB,OAAO,CAA4B;IACnC,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;I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A;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;AAtLD,sCAsLC","sourcesContent":["import { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, Event, EventFilter } from '@ethersproject/contracts'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { AddressType, HandleInterval, ProcessResult } from '@sentio/protos'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport interface AddressOrTypeEventFilter extends EventFilter {\n addressType?: AddressType\n}\n\nexport class EventsHandler {\n filters: AddressOrTypeEventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport class BlockHandlder {\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (block: Block) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: BlockHandlder[] = []\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: 0n,\n }\n if (config.startBlock) {\n this.config.startBlock = BigInt(config.startBlock)\n }\n if (config.endBlock) {\n this.config.endBlock = BigInt(config.endBlock)\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 contractName = this.config.name\n const processor = this\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const contractView = processor.CreateBoundContractView()\n\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 return this.onBlockInterval(handler)\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000,\n backfillBlockInterval = 4000\n ) {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },\n undefined\n )\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ) {\n const chainId = this.getChainId()\n const processor = this\n const contractName = this.config.name\n\n this.blockHandlers.push({\n handler: async function (block: Block) {\n const contractView = processor.CreateBoundContractView()\n\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 timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\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 contractName = this.config.name\n const processor = this\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractView = processor.CreateBoundContractView()\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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/sdk",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.37.
|
|
4
|
+
"version": "1.37.4-rc.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
|
|
7
7
|
"compile": "tsc -p . && cp src/utils/*.csv lib/utils",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@ethersproject/providers": "~5.7.0",
|
|
21
21
|
"@sentio/cli": "^1.0.0",
|
|
22
|
-
"@sentio/protos": "^1.37.
|
|
23
|
-
"@sentio/runtime": "^1.37.
|
|
22
|
+
"@sentio/protos": "^1.37.4-rc.1",
|
|
23
|
+
"@sentio/runtime": "^1.37.4-rc.1",
|
|
24
24
|
"@typechain/ethers-v5": "^10.0.0",
|
|
25
25
|
"bignumber.js": "^9.1.0",
|
|
26
26
|
"command-line-args": "^5.2.1",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"typedoc": {
|
|
58
58
|
"entryPoint": "./src/index.ts"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "3eb53f4125983b37e81ea4160eee95c1932ce965"
|
|
61
61
|
}
|
|
@@ -73,11 +73,13 @@ export abstract class BaseProcessor<
|
|
|
73
73
|
_filters.push(filter)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const contractView = this.CreateBoundContractView()
|
|
77
76
|
const contractName = this.config.name
|
|
77
|
+
const processor = this
|
|
78
78
|
this.eventHandlers.push({
|
|
79
79
|
filters: _filters,
|
|
80
80
|
handler: async function (log) {
|
|
81
|
+
const contractView = processor.CreateBoundContractView()
|
|
82
|
+
|
|
81
83
|
const ctx = new ContractContext<TContract, TBoundContractView>(
|
|
82
84
|
contractName,
|
|
83
85
|
contractView,
|
|
@@ -139,11 +141,13 @@ export abstract class BaseProcessor<
|
|
|
139
141
|
blockInterval: HandleInterval | undefined
|
|
140
142
|
) {
|
|
141
143
|
const chainId = this.getChainId()
|
|
142
|
-
const
|
|
144
|
+
const processor = this
|
|
143
145
|
const contractName = this.config.name
|
|
144
146
|
|
|
145
147
|
this.blockHandlers.push({
|
|
146
148
|
handler: async function (block: Block) {
|
|
149
|
+
const contractView = processor.CreateBoundContractView()
|
|
150
|
+
|
|
147
151
|
const ctx = new ContractContext<TContract, TBoundContractView>(
|
|
148
152
|
contractName,
|
|
149
153
|
contractView,
|
|
@@ -177,12 +181,13 @@ export abstract class BaseProcessor<
|
|
|
177
181
|
handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
|
|
178
182
|
) {
|
|
179
183
|
const chainId = this.getChainId()
|
|
180
|
-
const contractView = this.CreateBoundContractView()
|
|
181
184
|
const contractName = this.config.name
|
|
185
|
+
const processor = this
|
|
182
186
|
|
|
183
187
|
this.traceHandlers.push({
|
|
184
188
|
signature,
|
|
185
189
|
handler: async function (trace: Trace) {
|
|
190
|
+
const contractView = processor.CreateBoundContractView()
|
|
186
191
|
const contractInterface = contractView.rawContract.interface
|
|
187
192
|
const fragment = contractInterface.getFunction(signature)
|
|
188
193
|
if (!trace.action.input) {
|