@sentio/sdk 1.8.0 → 1.8.2
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/base-processor.d.ts +10 -3
- package/lib/base-processor.js +31 -1
- package/lib/base-processor.js.map +1 -1
- package/lib/context.d.ts +15 -11
- package/lib/context.js +21 -13
- package/lib/context.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +56 -21
- package/lib/gen/processor/protos/processor.js +269 -51
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/meter.d.ts +4 -4
- package/lib/meter.js +11 -0
- package/lib/meter.js.map +1 -1
- package/lib/service.d.ts +4 -2
- package/lib/service.js +39 -4
- package/lib/service.js.map +1 -1
- package/lib/solana-processor.d.ts +2 -2
- package/lib/solana-processor.js +1 -0
- package/lib/solana-processor.js.map +1 -1
- package/lib/test/erc20.test.js +9 -11
- package/lib/test/erc20.test.js.map +1 -1
- package/lib/test/metric-utils.d.ts +3 -3
- package/lib/test/metric-utils.js.map +1 -1
- package/lib/trace.d.ts +35 -0
- package/lib/trace.js +22 -0
- package/lib/trace.js.map +1 -0
- package/package.json +1 -1
- package/src/base-processor.ts +40 -3
- package/src/context.ts +23 -14
- package/src/gen/processor/protos/processor.ts +330 -70
- package/src/meter.ts +19 -8
- package/src/service.ts +59 -15
- package/src/solana-processor.ts +3 -2
- package/src/test/erc20.test.ts +9 -11
- package/src/test/metric-utils.ts +3 -3
- package/src/trace.ts +64 -0
package/lib/base-processor.d.ts
CHANGED
|
@@ -2,16 +2,22 @@ import { Event } from '@ethersproject/contracts';
|
|
|
2
2
|
import { Block, Log } from '@ethersproject/providers';
|
|
3
3
|
import { BaseContract, EventFilter } from '@ethersproject/contracts';
|
|
4
4
|
import { BoundContractView, Context, ContractView } from './context';
|
|
5
|
-
import {
|
|
5
|
+
import { ProcessResult } from './gen/processor/protos/processor';
|
|
6
6
|
import { BindInternalOptions, BindOptions } from './bind-options';
|
|
7
7
|
import { PromiseOrVoid } from './promise-or-void';
|
|
8
|
+
import { Trace } from './trace';
|
|
8
9
|
export declare class EventsHandler {
|
|
9
10
|
filters: EventFilter[];
|
|
10
|
-
handler: (event: Log) => Promise<
|
|
11
|
+
handler: (event: Log) => Promise<ProcessResult>;
|
|
12
|
+
}
|
|
13
|
+
export declare class TraceHandler {
|
|
14
|
+
signature: string;
|
|
15
|
+
handler: (trace: Trace) => Promise<ProcessResult>;
|
|
11
16
|
}
|
|
12
17
|
export declare abstract class BaseProcessor<TContract extends BaseContract, TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>> {
|
|
13
|
-
blockHandlers: ((block: Block) => Promise<
|
|
18
|
+
blockHandlers: ((block: Block) => Promise<ProcessResult>)[];
|
|
14
19
|
eventHandlers: EventsHandler[];
|
|
20
|
+
traceHandlers: TraceHandler[];
|
|
15
21
|
name: string;
|
|
16
22
|
config: BindInternalOptions;
|
|
17
23
|
constructor(config: BindOptions);
|
|
@@ -20,4 +26,5 @@ export declare abstract class BaseProcessor<TContract extends BaseContract, TBou
|
|
|
20
26
|
onEvent(handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid, filter: EventFilter | EventFilter[]): this;
|
|
21
27
|
onBlock(handler: (block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
22
28
|
onAllEvents(handler: (event: Log, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
29
|
+
onTrace(signature: string, handler: (trace: Trace, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
23
30
|
}
|
package/lib/base-processor.js
CHANGED
|
@@ -3,18 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BaseProcessor = exports.EventsHandler = void 0;
|
|
6
|
+
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 ethers_1 = require("ethers");
|
|
10
11
|
class EventsHandler {
|
|
11
12
|
filters;
|
|
12
13
|
handler;
|
|
13
14
|
}
|
|
14
15
|
exports.EventsHandler = EventsHandler;
|
|
16
|
+
class TraceHandler {
|
|
17
|
+
signature;
|
|
18
|
+
handler;
|
|
19
|
+
}
|
|
20
|
+
exports.TraceHandler = TraceHandler;
|
|
15
21
|
class BaseProcessor {
|
|
16
22
|
blockHandlers = [];
|
|
17
23
|
eventHandlers = [];
|
|
24
|
+
traceHandlers = [];
|
|
18
25
|
name;
|
|
19
26
|
config;
|
|
20
27
|
constructor(config) {
|
|
@@ -73,11 +80,13 @@ class BaseProcessor {
|
|
|
73
80
|
return {
|
|
74
81
|
gauges: ctx.gauges,
|
|
75
82
|
counters: ctx.counters,
|
|
83
|
+
logs: [],
|
|
76
84
|
};
|
|
77
85
|
}
|
|
78
86
|
return {
|
|
79
87
|
gauges: [],
|
|
80
88
|
counters: [],
|
|
89
|
+
logs: [],
|
|
81
90
|
};
|
|
82
91
|
},
|
|
83
92
|
});
|
|
@@ -92,6 +101,7 @@ class BaseProcessor {
|
|
|
92
101
|
return {
|
|
93
102
|
gauges: ctx.gauges,
|
|
94
103
|
counters: ctx.counters,
|
|
104
|
+
logs: [],
|
|
95
105
|
};
|
|
96
106
|
});
|
|
97
107
|
return this;
|
|
@@ -106,6 +116,26 @@ class BaseProcessor {
|
|
|
106
116
|
return handler(log, ctx);
|
|
107
117
|
}, _filters);
|
|
108
118
|
}
|
|
119
|
+
onTrace(signature, handler) {
|
|
120
|
+
const chainId = this.getChainId();
|
|
121
|
+
const contractView = this.CreateBoundContractView();
|
|
122
|
+
this.traceHandlers.push({
|
|
123
|
+
signature,
|
|
124
|
+
handler: async function (trace) {
|
|
125
|
+
const contractInterface = contractView.rawContract.interface;
|
|
126
|
+
const fragment = contractInterface.getFunction(signature);
|
|
127
|
+
trace.args = contractInterface._abiCoder.decode(fragment.inputs, ethers_1.utils.hexDataSlice(trace.action.input, 4));
|
|
128
|
+
const ctx = new context_1.Context(contractView, chainId, undefined, undefined, trace);
|
|
129
|
+
await handler(trace, ctx);
|
|
130
|
+
return {
|
|
131
|
+
gauges: ctx.gauges,
|
|
132
|
+
counters: ctx.counters,
|
|
133
|
+
logs: [],
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
109
139
|
}
|
|
110
140
|
exports.BaseProcessor = BaseProcessor;
|
|
111
141
|
//# sourceMappingURL=base-processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../src/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAAoE;AAKpE,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../src/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAAoE;AAKpE,mCAA8B;AAE9B,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,IAAI,CAAQ;IACZ,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EA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MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAK,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;gBAE3G,MAAM,GAAG,GAAG,IAAI,iBAAO,CAAgC,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;gBAC1G,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,EAAE;iBACT,CAAA;YACH,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA7ID,sCA6IC","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, Context, ContractView } from './context'\nimport { ProcessResult } from './gen/processor/protos/processor'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from './promise-or-void'\nimport { Trace } from './trace'\nimport { utils } from 'ethers'\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 name: string\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: Context<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 this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, log)\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: [],\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: Context<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, block, undefined)\n await handler(block, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: [],\n }\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: Context<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 public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\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 trace.args = contractInterface._abiCoder.decode(fragment.inputs, utils.hexDataSlice(trace.action.input, 4))\n\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, undefined, trace)\n await handler(trace, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: [],\n }\n },\n })\n return this\n }\n}\n"]}
|
package/lib/context.d.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import { CounterResult, GaugeResult } from './gen/processor/protos/processor';
|
|
1
|
+
import { CounterResult, GaugeResult, LogResult } from './gen/processor/protos/processor';
|
|
2
2
|
import { BaseContract, EventFilter } from 'ethers';
|
|
3
3
|
import { Block, Log } from '@ethersproject/abstract-provider';
|
|
4
4
|
import { Meter } from './meter';
|
|
5
5
|
import Long from 'long';
|
|
6
|
-
|
|
6
|
+
import { Trace } from './trace';
|
|
7
|
+
export declare class BaseContext {
|
|
8
|
+
gauges: GaugeResult[];
|
|
9
|
+
counters: CounterResult[];
|
|
10
|
+
logs: LogResult[];
|
|
11
|
+
meter: Meter;
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
export declare class EthContext extends BaseContext {
|
|
7
15
|
chainId: number;
|
|
8
16
|
log?: Log;
|
|
9
17
|
block?: Block;
|
|
18
|
+
trace?: Trace;
|
|
10
19
|
blockNumber: Long;
|
|
11
|
-
|
|
12
|
-
counters: CounterResult[];
|
|
13
|
-
meter: Meter;
|
|
14
|
-
constructor(chainId: number, block?: Block, log?: Log);
|
|
20
|
+
constructor(chainId: number, block?: Block, log?: Log, trace?: Trace);
|
|
15
21
|
}
|
|
16
22
|
export declare class Context<TContract extends BaseContract, TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>> extends EthContext {
|
|
17
23
|
contract: TContractBoundView;
|
|
18
|
-
|
|
24
|
+
address: string;
|
|
25
|
+
constructor(view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace);
|
|
19
26
|
}
|
|
20
27
|
export declare class ContractView<TContract extends BaseContract> {
|
|
21
28
|
filters: {
|
|
@@ -36,10 +43,7 @@ export declare class BoundContractView<TContract extends BaseContract, TContract
|
|
|
36
43
|
[name: string]: (...args: any[]) => EventFilter;
|
|
37
44
|
};
|
|
38
45
|
}
|
|
39
|
-
export declare class SolanaContext {
|
|
40
|
-
gauges: GaugeResult[];
|
|
41
|
-
counters: CounterResult[];
|
|
42
|
-
meter: Meter;
|
|
46
|
+
export declare class SolanaContext extends BaseContext {
|
|
43
47
|
address: string;
|
|
44
48
|
constructor(address: string);
|
|
45
49
|
}
|
package/lib/context.js
CHANGED
|
@@ -3,18 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.EthContext = void 0;
|
|
6
|
+
exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.EthContext = exports.BaseContext = void 0;
|
|
7
7
|
const meter_1 = require("./meter");
|
|
8
8
|
const long_1 = __importDefault(require("long"));
|
|
9
|
-
class
|
|
9
|
+
class BaseContext {
|
|
10
|
+
gauges = [];
|
|
11
|
+
counters = [];
|
|
12
|
+
logs = [];
|
|
13
|
+
meter;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.meter = new meter_1.Meter(this);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BaseContext = BaseContext;
|
|
19
|
+
class EthContext extends BaseContext {
|
|
10
20
|
chainId;
|
|
11
21
|
log;
|
|
12
22
|
block;
|
|
23
|
+
trace;
|
|
13
24
|
blockNumber;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
meter;
|
|
17
|
-
constructor(chainId, block, log) {
|
|
25
|
+
constructor(chainId, block, log, trace) {
|
|
26
|
+
super();
|
|
18
27
|
this.chainId = chainId;
|
|
19
28
|
this.log = log;
|
|
20
29
|
this.block = block;
|
|
@@ -24,16 +33,17 @@ class EthContext {
|
|
|
24
33
|
else if (block) {
|
|
25
34
|
this.blockNumber = long_1.default.fromNumber(block.number);
|
|
26
35
|
}
|
|
27
|
-
this.meter = new meter_1.Meter(this);
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
exports.EthContext = EthContext;
|
|
31
39
|
class Context extends EthContext {
|
|
32
40
|
contract;
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
address;
|
|
42
|
+
constructor(view, chainId, block, log, trace) {
|
|
43
|
+
super(chainId, block, log, trace);
|
|
35
44
|
view.context = this;
|
|
36
45
|
this.contract = view;
|
|
46
|
+
this.address = view.rawContract.address;
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
exports.Context = Context;
|
|
@@ -70,12 +80,10 @@ class BoundContractView {
|
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
exports.BoundContractView = BoundContractView;
|
|
73
|
-
class SolanaContext {
|
|
74
|
-
gauges = [];
|
|
75
|
-
counters = [];
|
|
76
|
-
meter;
|
|
83
|
+
class SolanaContext extends BaseContext {
|
|
77
84
|
address;
|
|
78
85
|
constructor(address) {
|
|
86
|
+
super();
|
|
79
87
|
this.meter = new meter_1.Meter(this);
|
|
80
88
|
this.address = address;
|
|
81
89
|
}
|
package/lib/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;;;;AAGA,mCAA+B;AAC/B,gDAAuB;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;;;;AAGA,mCAA+B;AAC/B,gDAAuB;AAGvB,MAAa,WAAW;IACtB,MAAM,GAAkB,EAAE,CAAA;IAC1B,QAAQ,GAAoB,EAAE,CAAA;IAC9B,IAAI,GAAgB,EAAE,CAAA;IACtB,KAAK,CAAO;IAEZ;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;CACF;AATD,kCASC;AAED,MAAa,UAAW,SAAQ,WAAW;IACzC,OAAO,CAAQ;IACf,GAAG,CAAM;IACT,KAAK,CAAQ;IACb,KAAK,CAAQ;IACb,WAAW,CAAM;IAEjB,YAAY,OAAe,EAAE,KAAa,EAAE,GAAS,EAAE,KAAa;QAClE,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,WAAW,GAAG,cAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;SACpD;aAAM,IAAI,KAAK,EAAE;YAChB,IAAI,CAAC,WAAW,GAAG,cAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;SACjD;IACH,CAAC;CACF;AAlBD,gCAkBC;AAED,MAAa,OAGX,SAAQ,UAAU;IAClB,QAAQ,CAAoB;IAC5B,OAAO,CAAQ;IAEf,YAAY,IAAwB,EAAE,OAAe,EAAE,KAAa,EAAE,GAAS,EAAE,KAAa;QAC5F,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAA;IACzC,CAAC;CACF;AAbD,0BAaC;AAED,MAAa,YAAY;IACvB,OAAO,CAA0D;IACvD,QAAQ,CAAW;IAE7B,YAAY,QAAmB;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAA;IACjC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAA;IAC/B,CAAC;CACF;AAhBD,oCAgBC;AAED,MAAa,iBAAiB;IAClB,IAAI,CAAe;IAC7B,8EAA8E;IAC9E,OAAO,CAAiE;IAExE,YAAY,IAAmB;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAA;IAC9B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAA;IAC3B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAA;IAC1B,CAAC;CACF;AApBD,8CAoBC;AAED,MAAa,aAAc,SAAQ,WAAW;IAC5C,OAAO,CAAQ;IAEf,YAAY,OAAe;QACzB,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AARD,sCAQC","sourcesContent":["import { CounterResult, GaugeResult, LogResult } from './gen/processor/protos/processor'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { Meter } from './meter'\nimport Long from 'long'\nimport { Trace } from './trace'\n\nexport class BaseContext {\n gauges: GaugeResult[] = []\n counters: CounterResult[] = []\n logs: LogResult[] = []\n meter: Meter\n\n constructor() {\n this.meter = new Meter(this)\n }\n}\n\nexport class EthContext extends BaseContext {\n chainId: number\n log?: Log\n block?: Block\n trace?: Trace\n blockNumber: Long\n\n constructor(chainId: number, block?: Block, log?: Log, trace?: Trace) {\n super()\n this.chainId = chainId\n this.log = log\n this.block = block\n if (log) {\n this.blockNumber = Long.fromNumber(log.blockNumber)\n } else if (block) {\n this.blockNumber = Long.fromNumber(block.number)\n }\n }\n}\n\nexport class Context<\n TContract extends BaseContract,\n TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>\n> extends EthContext {\n contract: TContractBoundView\n address: string\n\n constructor(view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace) {\n super(chainId, block, log, trace)\n view.context = this\n this.contract = view\n this.address = view.rawContract.address\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: Context<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\n constructor(address: string) {\n super()\n this.meter = new Meter(this)\n this.address = address\n }\n}\n"]}
|
|
@@ -13,6 +13,15 @@ export declare enum HandlerType {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function handlerTypeFromJSON(object: any): HandlerType;
|
|
15
15
|
export declare function handlerTypeToJSON(object: HandlerType): string;
|
|
16
|
+
export declare enum LogLevel {
|
|
17
|
+
DEBUG = 0,
|
|
18
|
+
INFO = 1,
|
|
19
|
+
WARNING = 2,
|
|
20
|
+
ERROR = 3,
|
|
21
|
+
UNRECOGNIZED = -1
|
|
22
|
+
}
|
|
23
|
+
export declare function logLevelFromJSON(object: any): LogLevel;
|
|
24
|
+
export declare function logLevelToJSON(object: LogLevel): string;
|
|
16
25
|
export interface ProjectConfig {
|
|
17
26
|
name: string;
|
|
18
27
|
version: string;
|
|
@@ -28,6 +37,7 @@ export interface ContractConfig {
|
|
|
28
37
|
contract: ContractInfo | undefined;
|
|
29
38
|
blockConfigs: BlockHandlerConfig[];
|
|
30
39
|
logConfigs: LogHandlerConfig[];
|
|
40
|
+
traceConfigs: TraceHandlerConfig[];
|
|
31
41
|
startBlock: Long;
|
|
32
42
|
endBlock: Long;
|
|
33
43
|
instructionConfig: InstructionHandlerConfig | undefined;
|
|
@@ -51,6 +61,10 @@ export interface StartRequest {
|
|
|
51
61
|
export interface BlockHandlerConfig {
|
|
52
62
|
handlerId: number;
|
|
53
63
|
}
|
|
64
|
+
export interface TraceHandlerConfig {
|
|
65
|
+
signature: string;
|
|
66
|
+
handlerId: number;
|
|
67
|
+
}
|
|
54
68
|
export interface LogHandlerConfig {
|
|
55
69
|
filters: LogFilter[];
|
|
56
70
|
handlerId: number;
|
|
@@ -70,32 +84,32 @@ export interface ProcessLogsRequest {
|
|
|
70
84
|
logBindings: LogBinding[];
|
|
71
85
|
}
|
|
72
86
|
export interface ProcessLogsResponse {
|
|
73
|
-
result:
|
|
87
|
+
result: ProcessResult | undefined;
|
|
74
88
|
configUpdated: boolean;
|
|
75
89
|
}
|
|
76
90
|
export interface ProcessTracesRequest {
|
|
77
|
-
|
|
91
|
+
traceBindings: TraceBinding[];
|
|
78
92
|
}
|
|
79
93
|
export interface ProcessTracesResponse {
|
|
80
|
-
result:
|
|
94
|
+
result: ProcessResult | undefined;
|
|
81
95
|
}
|
|
82
96
|
export interface ProcessTransactionsRequest {
|
|
83
|
-
transaction:
|
|
97
|
+
transaction: RawTransaction | undefined;
|
|
84
98
|
}
|
|
85
99
|
export interface ProcessInstructionsRequest {
|
|
86
100
|
instructions: Instruction[];
|
|
87
101
|
}
|
|
88
102
|
export interface ProcessTransactionsResponse {
|
|
89
|
-
result:
|
|
103
|
+
result: ProcessResult | undefined;
|
|
90
104
|
}
|
|
91
105
|
export interface ProcessInstructionsResponse {
|
|
92
|
-
result:
|
|
106
|
+
result: ProcessResult | undefined;
|
|
93
107
|
}
|
|
94
108
|
export interface ProcessBlocksRequest {
|
|
95
109
|
blockBindings: BlockBinding[];
|
|
96
110
|
}
|
|
97
111
|
export interface ProcessBlocksResponse {
|
|
98
|
-
result:
|
|
112
|
+
result: ProcessResult | undefined;
|
|
99
113
|
}
|
|
100
114
|
export interface LogBinding {
|
|
101
115
|
log: RawLog | undefined;
|
|
@@ -111,7 +125,7 @@ export interface TraceBinding {
|
|
|
111
125
|
export interface RawTrace {
|
|
112
126
|
raw: Uint8Array;
|
|
113
127
|
}
|
|
114
|
-
export interface
|
|
128
|
+
export interface RawTransaction {
|
|
115
129
|
txHash: string;
|
|
116
130
|
raw: Uint8Array;
|
|
117
131
|
programAccountId: string;
|
|
@@ -129,9 +143,10 @@ export interface BlockBinding {
|
|
|
129
143
|
export interface RawBlock {
|
|
130
144
|
raw: Uint8Array;
|
|
131
145
|
}
|
|
132
|
-
export interface
|
|
146
|
+
export interface ProcessResult {
|
|
133
147
|
gauges: GaugeResult[];
|
|
134
148
|
counters: CounterResult[];
|
|
149
|
+
logs: LogResult[];
|
|
135
150
|
}
|
|
136
151
|
export interface RecordMetaData {
|
|
137
152
|
contractAddress: string;
|
|
@@ -171,6 +186,12 @@ export interface CounterResult {
|
|
|
171
186
|
add: boolean;
|
|
172
187
|
runtimeInfo: RuntimeInfo | undefined;
|
|
173
188
|
}
|
|
189
|
+
export interface LogResult {
|
|
190
|
+
metadata: RecordMetaData | undefined;
|
|
191
|
+
level: LogLevel;
|
|
192
|
+
message: string;
|
|
193
|
+
runtimeInfo: RuntimeInfo | undefined;
|
|
194
|
+
}
|
|
174
195
|
export declare const ProjectConfig: {
|
|
175
196
|
encode(message: ProjectConfig, writer?: _m0.Writer): _m0.Writer;
|
|
176
197
|
decode(input: _m0.Reader | Uint8Array, length?: number): ProjectConfig;
|
|
@@ -227,6 +248,13 @@ export declare const BlockHandlerConfig: {
|
|
|
227
248
|
toJSON(message: BlockHandlerConfig): unknown;
|
|
228
249
|
fromPartial(object: DeepPartial<BlockHandlerConfig>): BlockHandlerConfig;
|
|
229
250
|
};
|
|
251
|
+
export declare const TraceHandlerConfig: {
|
|
252
|
+
encode(message: TraceHandlerConfig, writer?: _m0.Writer): _m0.Writer;
|
|
253
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): TraceHandlerConfig;
|
|
254
|
+
fromJSON(object: any): TraceHandlerConfig;
|
|
255
|
+
toJSON(message: TraceHandlerConfig): unknown;
|
|
256
|
+
fromPartial(object: DeepPartial<TraceHandlerConfig>): TraceHandlerConfig;
|
|
257
|
+
};
|
|
230
258
|
export declare const LogHandlerConfig: {
|
|
231
259
|
encode(message: LogHandlerConfig, writer?: _m0.Writer): _m0.Writer;
|
|
232
260
|
decode(input: _m0.Reader | Uint8Array, length?: number): LogHandlerConfig;
|
|
@@ -353,12 +381,12 @@ export declare const RawTrace: {
|
|
|
353
381
|
toJSON(message: RawTrace): unknown;
|
|
354
382
|
fromPartial(object: DeepPartial<RawTrace>): RawTrace;
|
|
355
383
|
};
|
|
356
|
-
export declare const
|
|
357
|
-
encode(message:
|
|
358
|
-
decode(input: _m0.Reader | Uint8Array, length?: number):
|
|
359
|
-
fromJSON(object: any):
|
|
360
|
-
toJSON(message:
|
|
361
|
-
fromPartial(object: DeepPartial<
|
|
384
|
+
export declare const RawTransaction: {
|
|
385
|
+
encode(message: RawTransaction, writer?: _m0.Writer): _m0.Writer;
|
|
386
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): RawTransaction;
|
|
387
|
+
fromJSON(object: any): RawTransaction;
|
|
388
|
+
toJSON(message: RawTransaction): unknown;
|
|
389
|
+
fromPartial(object: DeepPartial<RawTransaction>): RawTransaction;
|
|
362
390
|
};
|
|
363
391
|
export declare const Instruction: {
|
|
364
392
|
encode(message: Instruction, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -381,12 +409,12 @@ export declare const RawBlock: {
|
|
|
381
409
|
toJSON(message: RawBlock): unknown;
|
|
382
410
|
fromPartial(object: DeepPartial<RawBlock>): RawBlock;
|
|
383
411
|
};
|
|
384
|
-
export declare const
|
|
385
|
-
encode(message:
|
|
386
|
-
decode(input: _m0.Reader | Uint8Array, length?: number):
|
|
387
|
-
fromJSON(object: any):
|
|
388
|
-
toJSON(message:
|
|
389
|
-
fromPartial(object: DeepPartial<
|
|
412
|
+
export declare const ProcessResult: {
|
|
413
|
+
encode(message: ProcessResult, writer?: _m0.Writer): _m0.Writer;
|
|
414
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): ProcessResult;
|
|
415
|
+
fromJSON(object: any): ProcessResult;
|
|
416
|
+
toJSON(message: ProcessResult): unknown;
|
|
417
|
+
fromPartial(object: DeepPartial<ProcessResult>): ProcessResult;
|
|
390
418
|
};
|
|
391
419
|
export declare const RecordMetaData: {
|
|
392
420
|
encode(message: RecordMetaData, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -437,6 +465,13 @@ export declare const CounterResult: {
|
|
|
437
465
|
toJSON(message: CounterResult): unknown;
|
|
438
466
|
fromPartial(object: DeepPartial<CounterResult>): CounterResult;
|
|
439
467
|
};
|
|
468
|
+
export declare const LogResult: {
|
|
469
|
+
encode(message: LogResult, writer?: _m0.Writer): _m0.Writer;
|
|
470
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): LogResult;
|
|
471
|
+
fromJSON(object: any): LogResult;
|
|
472
|
+
toJSON(message: LogResult): unknown;
|
|
473
|
+
fromPartial(object: DeepPartial<LogResult>): LogResult;
|
|
474
|
+
};
|
|
440
475
|
export declare type ProcessorDefinition = typeof ProcessorDefinition;
|
|
441
476
|
export declare const ProcessorDefinition: {
|
|
442
477
|
readonly name: "Processor";
|