@sentio/sdk 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base-processor.d.ts +3 -3
- package/lib/base-processor.js +3 -0
- package/lib/base-processor.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +43 -20
- package/lib/gen/processor/protos/processor.js +187 -40
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.d.ts +2 -2
- package/lib/service.js +5 -2
- 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/package.json +1 -1
- package/src/base-processor.ts +6 -3
- package/src/gen/processor/protos/processor.ts +226 -57
- package/src/service.ts +16 -13
- package/src/solana-processor.ts +3 -2
- package/src/test/erc20.test.ts +9 -11
- package/src/test/metric-utils.ts +3 -3
package/lib/base-processor.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ 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
8
|
export declare class EventsHandler {
|
|
9
9
|
filters: EventFilter[];
|
|
10
|
-
handler: (event: Log) => Promise<
|
|
10
|
+
handler: (event: Log) => Promise<ProcessResult>;
|
|
11
11
|
}
|
|
12
12
|
export declare abstract class BaseProcessor<TContract extends BaseContract, TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>> {
|
|
13
|
-
blockHandlers: ((block: Block) => Promise<
|
|
13
|
+
blockHandlers: ((block: Block) => Promise<ProcessResult>)[];
|
|
14
14
|
eventHandlers: EventsHandler[];
|
|
15
15
|
name: string;
|
|
16
16
|
config: BindInternalOptions;
|
package/lib/base-processor.js
CHANGED
|
@@ -73,11 +73,13 @@ class BaseProcessor {
|
|
|
73
73
|
return {
|
|
74
74
|
gauges: ctx.gauges,
|
|
75
75
|
counters: ctx.counters,
|
|
76
|
+
logs: [],
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
return {
|
|
79
80
|
gauges: [],
|
|
80
81
|
counters: [],
|
|
82
|
+
logs: [],
|
|
81
83
|
};
|
|
82
84
|
},
|
|
83
85
|
});
|
|
@@ -92,6 +94,7 @@ class BaseProcessor {
|
|
|
92
94
|
return {
|
|
93
95
|
gauges: ctx.gauges,
|
|
94
96
|
counters: ctx.counters,
|
|
97
|
+
logs: [],
|
|
95
98
|
};
|
|
96
99
|
});
|
|
97
100
|
return this;
|
|
@@ -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,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAoB,EAAE,CAAA;IAEnC,IAAI,CAAQ;IACZ,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,O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C,uBAAuB,EAAE,CAAA;QAEnD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,WAAW,KAAY;YAClD,MAAM,GAAG,GAAG,IAAI,iBAAO,CAAgC,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;YAC/F,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YACzB,OAAO;gBACL,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,IAAI,EAAE,EAAE;aACT,CAAA;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,WAAW,CAAC,OAAmF;QACpG,MAAM,QAAQ,GAAkB,EAAE,CAAA;QAClC,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAA;QAElD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE;YACrC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;SAC1C;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,GAAG;YACpC,OAAO,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAC1B,CAAC,EAAE,QAAQ,CAAC,CAAA;IACd,CAAC;CACF;AAlHD,sCAkHC","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'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => 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\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"]}
|
|
@@ -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;
|
|
@@ -70,32 +79,32 @@ export interface ProcessLogsRequest {
|
|
|
70
79
|
logBindings: LogBinding[];
|
|
71
80
|
}
|
|
72
81
|
export interface ProcessLogsResponse {
|
|
73
|
-
result:
|
|
82
|
+
result: ProcessResult | undefined;
|
|
74
83
|
configUpdated: boolean;
|
|
75
84
|
}
|
|
76
85
|
export interface ProcessTracesRequest {
|
|
77
86
|
logBindings: LogBinding[];
|
|
78
87
|
}
|
|
79
88
|
export interface ProcessTracesResponse {
|
|
80
|
-
result:
|
|
89
|
+
result: ProcessResult | undefined;
|
|
81
90
|
}
|
|
82
91
|
export interface ProcessTransactionsRequest {
|
|
83
|
-
transaction:
|
|
92
|
+
transaction: RawTransaction | undefined;
|
|
84
93
|
}
|
|
85
94
|
export interface ProcessInstructionsRequest {
|
|
86
95
|
instructions: Instruction[];
|
|
87
96
|
}
|
|
88
97
|
export interface ProcessTransactionsResponse {
|
|
89
|
-
result:
|
|
98
|
+
result: ProcessResult | undefined;
|
|
90
99
|
}
|
|
91
100
|
export interface ProcessInstructionsResponse {
|
|
92
|
-
result:
|
|
101
|
+
result: ProcessResult | undefined;
|
|
93
102
|
}
|
|
94
103
|
export interface ProcessBlocksRequest {
|
|
95
104
|
blockBindings: BlockBinding[];
|
|
96
105
|
}
|
|
97
106
|
export interface ProcessBlocksResponse {
|
|
98
|
-
result:
|
|
107
|
+
result: ProcessResult | undefined;
|
|
99
108
|
}
|
|
100
109
|
export interface LogBinding {
|
|
101
110
|
log: RawLog | undefined;
|
|
@@ -111,7 +120,7 @@ export interface TraceBinding {
|
|
|
111
120
|
export interface RawTrace {
|
|
112
121
|
raw: Uint8Array;
|
|
113
122
|
}
|
|
114
|
-
export interface
|
|
123
|
+
export interface RawTransaction {
|
|
115
124
|
txHash: string;
|
|
116
125
|
raw: Uint8Array;
|
|
117
126
|
programAccountId: string;
|
|
@@ -129,9 +138,10 @@ export interface BlockBinding {
|
|
|
129
138
|
export interface RawBlock {
|
|
130
139
|
raw: Uint8Array;
|
|
131
140
|
}
|
|
132
|
-
export interface
|
|
141
|
+
export interface ProcessResult {
|
|
133
142
|
gauges: GaugeResult[];
|
|
134
143
|
counters: CounterResult[];
|
|
144
|
+
logs: LogResult[];
|
|
135
145
|
}
|
|
136
146
|
export interface RecordMetaData {
|
|
137
147
|
contractAddress: string;
|
|
@@ -171,6 +181,12 @@ export interface CounterResult {
|
|
|
171
181
|
add: boolean;
|
|
172
182
|
runtimeInfo: RuntimeInfo | undefined;
|
|
173
183
|
}
|
|
184
|
+
export interface LogResult {
|
|
185
|
+
metadata: RecordMetaData | undefined;
|
|
186
|
+
level: LogLevel;
|
|
187
|
+
message: string;
|
|
188
|
+
runtimeInfo: RuntimeInfo | undefined;
|
|
189
|
+
}
|
|
174
190
|
export declare const ProjectConfig: {
|
|
175
191
|
encode(message: ProjectConfig, writer?: _m0.Writer): _m0.Writer;
|
|
176
192
|
decode(input: _m0.Reader | Uint8Array, length?: number): ProjectConfig;
|
|
@@ -353,12 +369,12 @@ export declare const RawTrace: {
|
|
|
353
369
|
toJSON(message: RawTrace): unknown;
|
|
354
370
|
fromPartial(object: DeepPartial<RawTrace>): RawTrace;
|
|
355
371
|
};
|
|
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<
|
|
372
|
+
export declare const RawTransaction: {
|
|
373
|
+
encode(message: RawTransaction, writer?: _m0.Writer): _m0.Writer;
|
|
374
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): RawTransaction;
|
|
375
|
+
fromJSON(object: any): RawTransaction;
|
|
376
|
+
toJSON(message: RawTransaction): unknown;
|
|
377
|
+
fromPartial(object: DeepPartial<RawTransaction>): RawTransaction;
|
|
362
378
|
};
|
|
363
379
|
export declare const Instruction: {
|
|
364
380
|
encode(message: Instruction, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -381,12 +397,12 @@ export declare const RawBlock: {
|
|
|
381
397
|
toJSON(message: RawBlock): unknown;
|
|
382
398
|
fromPartial(object: DeepPartial<RawBlock>): RawBlock;
|
|
383
399
|
};
|
|
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<
|
|
400
|
+
export declare const ProcessResult: {
|
|
401
|
+
encode(message: ProcessResult, writer?: _m0.Writer): _m0.Writer;
|
|
402
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): ProcessResult;
|
|
403
|
+
fromJSON(object: any): ProcessResult;
|
|
404
|
+
toJSON(message: ProcessResult): unknown;
|
|
405
|
+
fromPartial(object: DeepPartial<ProcessResult>): ProcessResult;
|
|
390
406
|
};
|
|
391
407
|
export declare const RecordMetaData: {
|
|
392
408
|
encode(message: RecordMetaData, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -437,6 +453,13 @@ export declare const CounterResult: {
|
|
|
437
453
|
toJSON(message: CounterResult): unknown;
|
|
438
454
|
fromPartial(object: DeepPartial<CounterResult>): CounterResult;
|
|
439
455
|
};
|
|
456
|
+
export declare const LogResult: {
|
|
457
|
+
encode(message: LogResult, writer?: _m0.Writer): _m0.Writer;
|
|
458
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): LogResult;
|
|
459
|
+
fromJSON(object: any): LogResult;
|
|
460
|
+
toJSON(message: LogResult): unknown;
|
|
461
|
+
fromPartial(object: DeepPartial<LogResult>): LogResult;
|
|
462
|
+
};
|
|
440
463
|
export declare type ProcessorDefinition = typeof ProcessorDefinition;
|
|
441
464
|
export declare const ProcessorDefinition: {
|
|
442
465
|
readonly name: "Processor";
|