@sentio/sdk 1.37.5-rc.1 → 1.37.5-rc.3
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/builtin/internal/EACAggregatorProxy.d.ts +8 -8
- package/lib/builtin/internal/ERC1155.d.ts +8 -8
- package/lib/builtin/internal/ERC20.d.ts +6 -6
- package/lib/builtin/internal/ERC20Bytes.d.ts +4 -4
- package/lib/builtin/internal/ERC721.d.ts +6 -6
- package/lib/builtin/internal/WETH9.d.ts +8 -8
- package/lib/builtin/internal/common.d.ts +5 -5
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +24 -24
- package/lib/builtin/internal/erc1155_processor.d.ts +9 -9
- package/lib/builtin/internal/erc20_processor.d.ts +19 -19
- package/lib/builtin/internal/erc20bytes_processor.d.ts +10 -10
- package/lib/builtin/internal/erc721_processor.d.ts +15 -15
- package/lib/builtin/internal/weth9_processor.d.ts +12 -12
- package/lib/core/account-processor.js +2 -2
- package/lib/core/account-processor.js.map +1 -1
- package/lib/core/base-processor.d.ts +4 -4
- package/lib/core/base-processor.js +19 -6
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +3 -2
- package/lib/core/context.js +5 -3
- package/lib/core/context.js.map +1 -1
- package/lib/core/eth-plugin.js +12 -30
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/exporter.d.ts +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/metadata.d.ts +1 -1
- package/lib/core/numberish.d.ts +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/promise-or-void.d.ts +1 -1
- package/lib/testing/test-processor-server.js +6 -3
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +4 -4
- package/src/core/account-processor.ts +3 -3
- package/src/core/base-processor.ts +30 -10
- package/src/core/context.ts +6 -3
- package/src/core/eth-plugin.ts +24 -32
- package/src/testing/test-processor-server.ts +6 -3
|
@@ -6,43 +6,43 @@ import { ERC20Bytes } from "./index";
|
|
|
6
6
|
import { ApprovalEvent, ApprovalEventFilter, TransferEvent, TransferEventFilter } from "./ERC20Bytes";
|
|
7
7
|
export interface NameCallObject {
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type NameCallTrace = TypedCallTrace<[], NameCallObject>;
|
|
10
10
|
export interface ApproveCallObject {
|
|
11
11
|
spender: string;
|
|
12
12
|
value: BigNumber;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
14
|
+
export type ApproveCallTrace = TypedCallTrace<[
|
|
15
15
|
string,
|
|
16
16
|
BigNumber
|
|
17
17
|
], ApproveCallObject>;
|
|
18
18
|
export interface TotalSupplyCallObject {
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type TotalSupplyCallTrace = TypedCallTrace<[], TotalSupplyCallObject>;
|
|
21
21
|
export interface TransferFromCallObject {
|
|
22
22
|
from: string;
|
|
23
23
|
to: string;
|
|
24
24
|
value: BigNumber;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type TransferFromCallTrace = TypedCallTrace<[
|
|
27
27
|
string,
|
|
28
28
|
string,
|
|
29
29
|
BigNumber
|
|
30
30
|
], TransferFromCallObject>;
|
|
31
31
|
export interface DecimalsCallObject {
|
|
32
32
|
}
|
|
33
|
-
export
|
|
33
|
+
export type DecimalsCallTrace = TypedCallTrace<[], DecimalsCallObject>;
|
|
34
34
|
export interface BalanceOfCallObject {
|
|
35
35
|
who: string;
|
|
36
36
|
}
|
|
37
|
-
export
|
|
37
|
+
export type BalanceOfCallTrace = TypedCallTrace<[string], BalanceOfCallObject>;
|
|
38
38
|
export interface SymbolCallObject {
|
|
39
39
|
}
|
|
40
|
-
export
|
|
40
|
+
export type SymbolCallTrace = TypedCallTrace<[], SymbolCallObject>;
|
|
41
41
|
export interface TransferCallObject {
|
|
42
42
|
to: string;
|
|
43
43
|
value: BigNumber;
|
|
44
44
|
}
|
|
45
|
-
export
|
|
45
|
+
export type TransferCallTrace = TypedCallTrace<[
|
|
46
46
|
string,
|
|
47
47
|
BigNumber
|
|
48
48
|
], TransferCallObject>;
|
|
@@ -50,7 +50,7 @@ export interface AllowanceCallObject {
|
|
|
50
50
|
owner: string;
|
|
51
51
|
spender: string;
|
|
52
52
|
}
|
|
53
|
-
export
|
|
53
|
+
export type AllowanceCallTrace = TypedCallTrace<[
|
|
54
54
|
string,
|
|
55
55
|
string
|
|
56
56
|
], AllowanceCallObject>;
|
|
@@ -71,7 +71,7 @@ export declare class ERC20BytesBoundContractView extends BoundContractView<ERC20
|
|
|
71
71
|
symbol(overrides?: CallOverrides): Promise<string>;
|
|
72
72
|
allowance(owner: PromiseOrValue<string>, spender: PromiseOrValue<string>, overrides?: CallOverrides): Promise<BigNumber>;
|
|
73
73
|
}
|
|
74
|
-
export
|
|
74
|
+
export type ERC20BytesContext = ContractContext<ERC20Bytes, ERC20BytesBoundContractView>;
|
|
75
75
|
export declare class ERC20BytesProcessorTemplate extends BaseProcessorTemplate<ERC20Bytes, ERC20BytesBoundContractView> {
|
|
76
76
|
bindInternal(options: BindOptions): ERC20BytesProcessor;
|
|
77
77
|
onEventApproval(handler: (event: ApprovalEvent, ctx: ERC20BytesContext) => void, filter?: ApprovalEventFilter | ApprovalEventFilter[]): this;
|
|
@@ -8,44 +8,44 @@ export interface ApproveCallObject {
|
|
|
8
8
|
to: string;
|
|
9
9
|
tokenId: BigNumber;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export type ApproveCallTrace = TypedCallTrace<[
|
|
12
12
|
string,
|
|
13
13
|
BigNumber
|
|
14
14
|
], ApproveCallObject>;
|
|
15
15
|
export interface TotalSupplyCallObject {
|
|
16
16
|
}
|
|
17
|
-
export
|
|
17
|
+
export type TotalSupplyCallTrace = TypedCallTrace<[], TotalSupplyCallObject>;
|
|
18
18
|
export interface BalanceOfCallObject {
|
|
19
19
|
owner: string;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type BalanceOfCallTrace = TypedCallTrace<[string], BalanceOfCallObject>;
|
|
22
22
|
export interface GetApprovedCallObject {
|
|
23
23
|
tokenId: BigNumber;
|
|
24
24
|
}
|
|
25
|
-
export
|
|
25
|
+
export type GetApprovedCallTrace = TypedCallTrace<[
|
|
26
26
|
BigNumber
|
|
27
27
|
], GetApprovedCallObject>;
|
|
28
28
|
export interface IsApprovedForAllCallObject {
|
|
29
29
|
owner: string;
|
|
30
30
|
operator: string;
|
|
31
31
|
}
|
|
32
|
-
export
|
|
32
|
+
export type IsApprovedForAllCallTrace = TypedCallTrace<[
|
|
33
33
|
string,
|
|
34
34
|
string
|
|
35
35
|
], IsApprovedForAllCallObject>;
|
|
36
36
|
export interface NameCallObject {
|
|
37
37
|
}
|
|
38
|
-
export
|
|
38
|
+
export type NameCallTrace = TypedCallTrace<[], NameCallObject>;
|
|
39
39
|
export interface OwnerOfCallObject {
|
|
40
40
|
tokenId: BigNumber;
|
|
41
41
|
}
|
|
42
|
-
export
|
|
42
|
+
export type OwnerOfCallTrace = TypedCallTrace<[BigNumber], OwnerOfCallObject>;
|
|
43
43
|
export interface SafeTransferFrom_address_address_uint256CallObject {
|
|
44
44
|
from: string;
|
|
45
45
|
to: string;
|
|
46
46
|
tokenId: BigNumber;
|
|
47
47
|
}
|
|
48
|
-
export
|
|
48
|
+
export type SafeTransferFrom_address_address_uint256CallTrace = TypedCallTrace<[
|
|
49
49
|
string,
|
|
50
50
|
string,
|
|
51
51
|
BigNumber
|
|
@@ -56,7 +56,7 @@ export interface SafeTransferFrom_address_address_uint256_bytesCallObject {
|
|
|
56
56
|
tokenId: BigNumber;
|
|
57
57
|
data: string;
|
|
58
58
|
}
|
|
59
|
-
export
|
|
59
|
+
export type SafeTransferFrom_address_address_uint256_bytesCallTrace = TypedCallTrace<[
|
|
60
60
|
string,
|
|
61
61
|
string,
|
|
62
62
|
BigNumber,
|
|
@@ -66,29 +66,29 @@ export interface SetApprovalForAllCallObject {
|
|
|
66
66
|
operator: string;
|
|
67
67
|
_approved: boolean;
|
|
68
68
|
}
|
|
69
|
-
export
|
|
69
|
+
export type SetApprovalForAllCallTrace = TypedCallTrace<[
|
|
70
70
|
string,
|
|
71
71
|
boolean
|
|
72
72
|
], SetApprovalForAllCallObject>;
|
|
73
73
|
export interface SupportsInterfaceCallObject {
|
|
74
74
|
interfaceId: string;
|
|
75
75
|
}
|
|
76
|
-
export
|
|
76
|
+
export type SupportsInterfaceCallTrace = TypedCallTrace<[
|
|
77
77
|
string
|
|
78
78
|
], SupportsInterfaceCallObject>;
|
|
79
79
|
export interface SymbolCallObject {
|
|
80
80
|
}
|
|
81
|
-
export
|
|
81
|
+
export type SymbolCallTrace = TypedCallTrace<[], SymbolCallObject>;
|
|
82
82
|
export interface TokenURICallObject {
|
|
83
83
|
tokenId: BigNumber;
|
|
84
84
|
}
|
|
85
|
-
export
|
|
85
|
+
export type TokenURICallTrace = TypedCallTrace<[BigNumber], TokenURICallObject>;
|
|
86
86
|
export interface TransferFromCallObject {
|
|
87
87
|
from: string;
|
|
88
88
|
to: string;
|
|
89
89
|
tokenId: BigNumber;
|
|
90
90
|
}
|
|
91
|
-
export
|
|
91
|
+
export type TransferFromCallTrace = TypedCallTrace<[
|
|
92
92
|
string,
|
|
93
93
|
string,
|
|
94
94
|
BigNumber
|
|
@@ -116,7 +116,7 @@ export declare class ERC721BoundContractView extends BoundContractView<ERC721, E
|
|
|
116
116
|
symbol(overrides?: CallOverrides): Promise<string>;
|
|
117
117
|
tokenURI(tokenId: PromiseOrValue<BigNumberish>, overrides?: CallOverrides): Promise<string>;
|
|
118
118
|
}
|
|
119
|
-
export
|
|
119
|
+
export type ERC721Context = ContractContext<ERC721, ERC721BoundContractView>;
|
|
120
120
|
export declare class ERC721ProcessorTemplate extends BaseProcessorTemplate<ERC721, ERC721BoundContractView> {
|
|
121
121
|
bindInternal(options: BindOptions): ERC721Processor;
|
|
122
122
|
onEventApproval(handler: (event: ApprovalEvent, ctx: ERC721Context) => void, filter?: ApprovalEventFilter | ApprovalEventFilter[]): this;
|
|
@@ -6,24 +6,24 @@ import { WETH9 } from "./index";
|
|
|
6
6
|
import { ApprovalEvent, ApprovalEventFilter, TransferEvent, TransferEventFilter, DepositEvent, DepositEventFilter, WithdrawalEvent, WithdrawalEventFilter } from "./WETH9";
|
|
7
7
|
export interface NameCallObject {
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type NameCallTrace = TypedCallTrace<[], NameCallObject>;
|
|
10
10
|
export interface ApproveCallObject {
|
|
11
11
|
guy: string;
|
|
12
12
|
wad: BigNumber;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
14
|
+
export type ApproveCallTrace = TypedCallTrace<[
|
|
15
15
|
string,
|
|
16
16
|
BigNumber
|
|
17
17
|
], ApproveCallObject>;
|
|
18
18
|
export interface TotalSupplyCallObject {
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type TotalSupplyCallTrace = TypedCallTrace<[], TotalSupplyCallObject>;
|
|
21
21
|
export interface TransferFromCallObject {
|
|
22
22
|
src: string;
|
|
23
23
|
dst: string;
|
|
24
24
|
wad: BigNumber;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type TransferFromCallTrace = TypedCallTrace<[
|
|
27
27
|
string,
|
|
28
28
|
string,
|
|
29
29
|
BigNumber
|
|
@@ -31,30 +31,30 @@ export declare type TransferFromCallTrace = TypedCallTrace<[
|
|
|
31
31
|
export interface WithdrawCallObject {
|
|
32
32
|
wad: BigNumber;
|
|
33
33
|
}
|
|
34
|
-
export
|
|
34
|
+
export type WithdrawCallTrace = TypedCallTrace<[BigNumber], WithdrawCallObject>;
|
|
35
35
|
export interface DecimalsCallObject {
|
|
36
36
|
}
|
|
37
|
-
export
|
|
37
|
+
export type DecimalsCallTrace = TypedCallTrace<[], DecimalsCallObject>;
|
|
38
38
|
export interface BalanceOfCallObject {
|
|
39
39
|
}
|
|
40
|
-
export
|
|
40
|
+
export type BalanceOfCallTrace = TypedCallTrace<[string], BalanceOfCallObject>;
|
|
41
41
|
export interface SymbolCallObject {
|
|
42
42
|
}
|
|
43
|
-
export
|
|
43
|
+
export type SymbolCallTrace = TypedCallTrace<[], SymbolCallObject>;
|
|
44
44
|
export interface TransferCallObject {
|
|
45
45
|
dst: string;
|
|
46
46
|
wad: BigNumber;
|
|
47
47
|
}
|
|
48
|
-
export
|
|
48
|
+
export type TransferCallTrace = TypedCallTrace<[
|
|
49
49
|
string,
|
|
50
50
|
BigNumber
|
|
51
51
|
], TransferCallObject>;
|
|
52
52
|
export interface DepositCallObject {
|
|
53
53
|
}
|
|
54
|
-
export
|
|
54
|
+
export type DepositCallTrace = TypedCallTrace<[], DepositCallObject>;
|
|
55
55
|
export interface AllowanceCallObject {
|
|
56
56
|
}
|
|
57
|
-
export
|
|
57
|
+
export type AllowanceCallTrace = TypedCallTrace<[
|
|
58
58
|
string,
|
|
59
59
|
string
|
|
60
60
|
], AllowanceCallObject>;
|
|
@@ -75,7 +75,7 @@ export declare class WETH9BoundContractView extends BoundContractView<WETH9, WET
|
|
|
75
75
|
symbol(overrides?: CallOverrides): Promise<string>;
|
|
76
76
|
allowance(arg0: PromiseOrValue<string>, arg1: PromiseOrValue<string>, overrides?: CallOverrides): Promise<BigNumber>;
|
|
77
77
|
}
|
|
78
|
-
export
|
|
78
|
+
export type WETH9Context = ContractContext<WETH9, WETH9BoundContractView>;
|
|
79
79
|
export declare class WETH9ProcessorTemplate extends BaseProcessorTemplate<WETH9, WETH9BoundContractView> {
|
|
80
80
|
bindInternal(options: BindOptions): WETH9Processor;
|
|
81
81
|
onEventApproval(handler: (event: ApprovalEvent, ctx: WETH9Context) => void, filter?: ApprovalEventFilter | ApprovalEventFilter[]): this;
|
|
@@ -121,9 +121,9 @@ class AccountProcessor {
|
|
|
121
121
|
const config = this.config;
|
|
122
122
|
this.eventHandlers.push({
|
|
123
123
|
filters: _filters,
|
|
124
|
-
handler: async function (
|
|
124
|
+
handler: async function (data) {
|
|
125
|
+
const log = data.log;
|
|
125
126
|
const ctx = new context_1.AccountContext(chainId, config.address, undefined, log);
|
|
126
|
-
// let event: Event = <Event>deepCopy(log);
|
|
127
127
|
const event = log;
|
|
128
128
|
const parsed = ERC20_CONTRACT.interface.parseLog(log);
|
|
129
129
|
if (parsed) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-processor.js","sourceRoot":"","sources":["../../src/core/account-processor.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAClD,kDAAqE;AACrE,qCAAuE;AAEvE,wDAAqD;AAGrD,uCAA0C;AAM1C,MAAa,qBAAsB,SAAQ,0BAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;AAD/C,sDAEC;AAED,MAAM,cAAc,GAAG,yBAAc,CAAC,OAAO,CAAC,EAAE,EAAE,mBAAa,CAAC,CAAA;AAChE,MAAM,eAAe,GAAG,0BAAe,CAAC,OAAO,CAAC,EAAE,EAAE,mBAAa,CAAC,CAAA;AAElE,MAAa,gBAAgB;IAC3B,MAAM,CAAoB;IAC1B,aAAa,GAAoB,EAAE,CAAA;IAEnC,MAAM,CAAC,IAAI,CAAC,MAA0B;QACpC,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC9C,qBAAqB,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAsB,MAA0B;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,UAAU;QACf,OAAO,IAAA,sBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,OAAO,CAAA;IACrD,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CACf,OAA0E,EAC1E,kBAA4B,EAAE;QAE9B,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,EAAE,CAAC,OAAe,EAAE,EAAE,CA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AAC,CAAA;oBACpF,CAAC,CAAA;oBACD,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;oBACzB,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAA;oBAEvC,oBAAoB;oBACpB,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;oBACzB,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;iBAC9B;gBACD,OAAO,mBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;YACtC,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AApMD,4CAoMC","sourcesContent":["import { ListStateStorage } from '@sentio/runtime'\nimport { ERC20__factory, ERC721__factory } from '../builtin/internal'\nimport { AddressType, DummyProvider, ProcessResult } from '@sentio/sdk'\nimport { AccountBindOptions } from './bind-options'\nimport { getNetwork } from '@ethersproject/providers'\nimport { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20'\nimport { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721'\nimport { AccountContext } from './context'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor'\n\nexport class AccountProcessorState extends ListStateStorage<AccountProcessor> {\n static INSTANCE = new AccountProcessorState()\n}\n\nconst ERC20_CONTRACT = ERC20__factory.connect('', DummyProvider)\nconst ERC721_CONTRACT = ERC721__factory.connect('', DummyProvider)\n\nexport class AccountProcessor {\n config: AccountBindOptions\n eventHandlers: EventsHandler[] = []\n\n static bind(config: AccountBindOptions): AccountProcessor {\n const processor = new AccountProcessor(config)\n AccountProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n protected constructor(config: AccountBindOptions) {\n this.config = config\n }\n\n public getChainId(): number {\n return getNetwork(this.config.network || 1).chainId\n }\n\n /**\n * Register custom handler function to process erc20 transfer event to this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n */\n onERC20TransferIn(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = []\n ) {\n return this.onERC20(handler, tokensAddresses, (address: string) =>\n ERC20_CONTRACT.filters.Transfer(null, this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process erc20 transfer event from this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n */\n onERC20TransferOut(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = []\n ) {\n return this.onERC20(handler, tokensAddresses, (address: string) =>\n ERC20_CONTRACT.filters.Transfer(this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process erc20 mint for this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n */\n onERC20Minted(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = []\n ) {\n return this.onERC20(handler, tokensAddresses, (address: string) =>\n ERC20_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)\n )\n }\n\n private onERC20(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n defaultFilter: (address: string) => AddressOrTypeEventFilter\n ) {\n return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20)\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event to this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n */\n onERC721TransferIn(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[]\n ) {\n return this.onERC721(handler, collections, (address: string) =>\n ERC721_CONTRACT.filters.Transfer(null, this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event from this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n */\n onERC721TransferOut(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[]\n ) {\n return this.onERC721(handler, collections, (address: string) =>\n ERC721_CONTRACT.filters.Transfer(this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process ERC721 mint for this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n */\n onERC721Minted(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[] = []\n ) {\n return this.onERC721(handler, collections, (address: string) =>\n ERC721_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)\n )\n }\n\n private onERC721(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter\n ) {\n return this.onERC(handler, collections, defaultFilter, AddressType.ERC721)\n }\n\n private onERC(\n handler: (event: any, ctx: AccountContext) => PromiseOrVoid,\n contractAddresses: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n addressType: AddressType\n ) {\n const filters = []\n for (const token of contractAddresses) {\n const filter = defaultFilter(this.config.address)\n filter.address = token\n filters.push(filter)\n }\n if (!filters.length) {\n const filter = defaultFilter(this.config.address)\n filter.address = undefined\n filter.addressType = addressType\n filters.push(filter)\n }\n return this.onEvent(handler, filters)\n }\n\n protected onEvent(\n handler: (event: Event, ctx: AccountContext) => PromiseOrVoid,\n filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: AddressOrTypeEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n let hasVaildConfig = false\n for (const filter of _filters) {\n if (filter.address) {\n hasVaildConfig = true\n break\n }\n if (filter.topics && filter.topics.length) {\n hasVaildConfig = true\n break\n }\n }\n\n if (!hasVaildConfig) {\n throw Error('no valid config has been found for this account')\n }\n\n const config = this.config\n\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new AccountContext(chainId, config.address, undefined, log)\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = ERC20_CONTRACT.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return ERC20_CONTRACT.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\n return this\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"account-processor.js","sourceRoot":"","sources":["../../src/core/account-processor.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAClD,kDAAqE;AACrE,qCAAuE;AAEvE,wDAAqD;AAGrD,uCAA0C;AAM1C,MAAa,qBAAsB,SAAQ,0BAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;AAD/C,sDAEC;AAED,MAAM,cAAc,GAAG,yBAAc,CAAC,OAAO,CAAC,EAAE,EAAE,mBAAa,CAAC,CAAA;AAChE,MAAM,eAAe,GAAG,0BAAe,CAAC,OAAO,CAAC,EAAE,EAAE,mBAAa,CAAC,CAAA;AAElE,MAAa,gBAAgB;IAC3B,MAAM,CAAoB;IAC1B,aAAa,GAAoB,EAAE,CAAA;IAEnC,MAAM,CAAC,IAAI,CAAC,MAA0B;QACpC,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC9C,qBAAqB,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAsB,MAA0B;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,UAAU;QACf,OAAO,IAAA,sBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,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,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;oBACxB,KAAK,CAAC,MAAM,GAAG,CAAC,IAAe,EAAE,MAAmB,EAAE,EAAE;wBACtD,OAAO,cAAc,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;oBACpF,CAAC,CAAA;oBACD,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;oBACzB,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAA;oBAEvC,oBAAoB;oBACpB,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;oBACzB,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;iBAC9B;gBACD,OAAO,mBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;YACtC,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AApMD,4CAoMC","sourcesContent":["import { ListStateStorage } from '@sentio/runtime'\nimport { ERC20__factory, ERC721__factory } from '../builtin/internal'\nimport { AddressType, DummyProvider, ProcessResult } from '@sentio/sdk'\nimport { AccountBindOptions } from './bind-options'\nimport { getNetwork } from '@ethersproject/providers'\nimport { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20'\nimport { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721'\nimport { AccountContext } from './context'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor'\n\nexport class AccountProcessorState extends ListStateStorage<AccountProcessor> {\n static INSTANCE = new AccountProcessorState()\n}\n\nconst ERC20_CONTRACT = ERC20__factory.connect('', DummyProvider)\nconst ERC721_CONTRACT = ERC721__factory.connect('', DummyProvider)\n\nexport class AccountProcessor {\n config: AccountBindOptions\n eventHandlers: EventsHandler[] = []\n\n static bind(config: AccountBindOptions): AccountProcessor {\n const processor = new AccountProcessor(config)\n AccountProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n protected constructor(config: AccountBindOptions) {\n this.config = config\n }\n\n public getChainId(): number {\n return getNetwork(this.config.network || 1).chainId\n }\n\n /**\n * Register custom handler function to process erc20 transfer event to this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n */\n onERC20TransferIn(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = []\n ) {\n return this.onERC20(handler, tokensAddresses, (address: string) =>\n ERC20_CONTRACT.filters.Transfer(null, this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process erc20 transfer event from this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n */\n onERC20TransferOut(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = []\n ) {\n return this.onERC20(handler, tokensAddresses, (address: string) =>\n ERC20_CONTRACT.filters.Transfer(this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process erc20 mint for this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n */\n onERC20Minted(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = []\n ) {\n return this.onERC20(handler, tokensAddresses, (address: string) =>\n ERC20_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)\n )\n }\n\n private onERC20(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n defaultFilter: (address: string) => AddressOrTypeEventFilter\n ) {\n return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20)\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event to this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n */\n onERC721TransferIn(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[]\n ) {\n return this.onERC721(handler, collections, (address: string) =>\n ERC721_CONTRACT.filters.Transfer(null, this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event from this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n */\n onERC721TransferOut(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[]\n ) {\n return this.onERC721(handler, collections, (address: string) =>\n ERC721_CONTRACT.filters.Transfer(this.config.address)\n )\n }\n\n /**\n * Register custom handler function to process ERC721 mint for this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n */\n onERC721Minted(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[] = []\n ) {\n return this.onERC721(handler, collections, (address: string) =>\n ERC721_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)\n )\n }\n\n private onERC721(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter\n ) {\n return this.onERC(handler, collections, defaultFilter, AddressType.ERC721)\n }\n\n private onERC(\n handler: (event: any, ctx: AccountContext) => PromiseOrVoid,\n contractAddresses: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n addressType: AddressType\n ) {\n const filters = []\n for (const token of contractAddresses) {\n const filter = defaultFilter(this.config.address)\n filter.address = token\n filters.push(filter)\n }\n if (!filters.length) {\n const filter = defaultFilter(this.config.address)\n filter.address = undefined\n filter.addressType = addressType\n filters.push(filter)\n }\n return this.onEvent(handler, filters)\n }\n\n protected onEvent(\n handler: (event: Event, ctx: AccountContext) => PromiseOrVoid,\n filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: AddressOrTypeEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n let hasVaildConfig = false\n for (const filter of _filters) {\n if (filter.address) {\n hasVaildConfig = true\n break\n }\n if (filter.topics && filter.topics.length) {\n hasVaildConfig = true\n break\n }\n }\n\n if (!hasVaildConfig) {\n throw Error('no valid config has been found for this account')\n }\n\n const config = this.config\n\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (data) {\n const log = data.log as Event\n const ctx = new AccountContext(chainId, config.address, undefined, log)\n const event: Event = log\n const parsed = ERC20_CONTRACT.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return ERC20_CONTRACT.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\n return this\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Block, Log } from '@ethersproject/providers';
|
|
2
2
|
import { BaseContract, Event, EventFilter } from '@ethersproject/contracts';
|
|
3
3
|
import { BoundContractView, ContractContext, ContractView } from './context';
|
|
4
|
-
import { AddressType, HandleInterval, ProcessResult } from '@sentio/protos';
|
|
4
|
+
import { AddressType, Data_EthBlock, Data_EthLog, Data_EthTrace, HandleInterval, ProcessResult } from '@sentio/protos';
|
|
5
5
|
import { BindInternalOptions, BindOptions } from './bind-options';
|
|
6
6
|
import { PromiseOrVoid } from '../promise-or-void';
|
|
7
7
|
import { Trace } from './trace';
|
|
@@ -10,16 +10,16 @@ export interface AddressOrTypeEventFilter extends EventFilter {
|
|
|
10
10
|
}
|
|
11
11
|
export declare class EventsHandler {
|
|
12
12
|
filters: AddressOrTypeEventFilter[];
|
|
13
|
-
handler: (event:
|
|
13
|
+
handler: (event: Data_EthLog) => Promise<ProcessResult>;
|
|
14
14
|
}
|
|
15
15
|
export declare class TraceHandler {
|
|
16
16
|
signature: string;
|
|
17
|
-
handler: (trace:
|
|
17
|
+
handler: (trace: Data_EthTrace) => Promise<ProcessResult>;
|
|
18
18
|
}
|
|
19
19
|
export declare class BlockHandlder {
|
|
20
20
|
blockInterval?: HandleInterval;
|
|
21
21
|
timeIntervalInMinutes?: HandleInterval;
|
|
22
|
-
handler: (block:
|
|
22
|
+
handler: (block: Data_EthBlock) => Promise<ProcessResult>;
|
|
23
23
|
}
|
|
24
24
|
export declare abstract class BaseProcessor<TContract extends BaseContract, TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>> {
|
|
25
25
|
blockHandlers: BlockHandlder[];
|
|
@@ -4,6 +4,7 @@ exports.BaseProcessor = exports.BlockHandlder = exports.TraceHandler = exports.E
|
|
|
4
4
|
const providers_1 = require("@ethersproject/providers");
|
|
5
5
|
const context_1 = require("./context");
|
|
6
6
|
const protos_1 = require("@sentio/protos");
|
|
7
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
7
8
|
class EventsHandler {
|
|
8
9
|
filters;
|
|
9
10
|
handler;
|
|
@@ -55,9 +56,13 @@ class BaseProcessor {
|
|
|
55
56
|
const processor = this;
|
|
56
57
|
this.eventHandlers.push({
|
|
57
58
|
filters: _filters,
|
|
58
|
-
handler: async function (
|
|
59
|
+
handler: async function (data) {
|
|
60
|
+
if (!data.log) {
|
|
61
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Log is empty');
|
|
62
|
+
}
|
|
63
|
+
const log = data.log;
|
|
59
64
|
const contractView = processor.CreateBoundContractView();
|
|
60
|
-
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, log);
|
|
65
|
+
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, log, undefined, data.timestamp);
|
|
61
66
|
// let event: Event = <Event>deepCopy(log);
|
|
62
67
|
const event = log;
|
|
63
68
|
const parsed = contractView.rawContract.interface.parseLog(log);
|
|
@@ -94,9 +99,13 @@ class BaseProcessor {
|
|
|
94
99
|
const processor = this;
|
|
95
100
|
const contractName = this.config.name;
|
|
96
101
|
this.blockHandlers.push({
|
|
97
|
-
handler: async function (
|
|
102
|
+
handler: async function (data) {
|
|
103
|
+
if (!data.block) {
|
|
104
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Block is empty');
|
|
105
|
+
}
|
|
106
|
+
const block = data.block;
|
|
98
107
|
const contractView = processor.CreateBoundContractView();
|
|
99
|
-
const ctx = new context_1.ContractContext(contractName, contractView, chainId, block, undefined);
|
|
108
|
+
const ctx = new context_1.ContractContext(contractName, contractView, chainId, block, undefined, undefined, new Date(block.timestamp * 1000));
|
|
100
109
|
await handler(block, ctx);
|
|
101
110
|
return ctx.getProcessResult();
|
|
102
111
|
},
|
|
@@ -121,16 +130,20 @@ class BaseProcessor {
|
|
|
121
130
|
const processor = this;
|
|
122
131
|
this.traceHandlers.push({
|
|
123
132
|
signature,
|
|
124
|
-
handler: async function (
|
|
133
|
+
handler: async function (data) {
|
|
125
134
|
const contractView = processor.CreateBoundContractView();
|
|
126
135
|
const contractInterface = contractView.rawContract.interface;
|
|
127
136
|
const fragment = contractInterface.getFunction(signature);
|
|
137
|
+
if (!data.trace) {
|
|
138
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'trace is null');
|
|
139
|
+
}
|
|
140
|
+
const trace = data.trace;
|
|
128
141
|
if (!trace.action.input) {
|
|
129
142
|
return protos_1.ProcessResult.fromPartial({});
|
|
130
143
|
}
|
|
131
144
|
const traceData = '0x' + trace.action.input.slice(10);
|
|
132
145
|
trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData);
|
|
133
|
-
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, undefined, trace);
|
|
146
|
+
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, undefined, trace, data.timestamp);
|
|
134
147
|
await handler(trace, ctx);
|
|
135
148
|
return ctx.getProcessResult();
|
|
136
149
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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BAAiB,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;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"]}
|
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;AACA,wDAAiE;AAGjE,uCAA4E;AAC5E,2CAAsH;AAItH,yCAA+C;AAM/C,MAAa,aAAa;I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CAAC,SAAS,CAAA;gBAC5D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;gBACzD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;oBACf,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAA;iBAChE;gBACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAc,CAAA;gBACjC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE;oBACvB,OAAO,sBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;iBACrC;gBACD,MAAM,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;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,EACL,IAAI,CAAC,SAAS,CACf,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;AAzMD,sCAyMC","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, Data_EthBlock, Data_EthLog, Data_EthTrace, HandleInterval, ProcessResult } from '@sentio/protos'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\nimport { ServerError, Status } from 'nice-grpc'\n\nexport interface AddressOrTypeEventFilter extends EventFilter {\n addressType?: AddressType\n}\n\nexport class EventsHandler {\n filters: AddressOrTypeEventFilter[]\n handler: (event: Data_EthLog) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Data_EthTrace) => Promise<ProcessResult>\n}\n\nexport class BlockHandlder {\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (block: Data_EthBlock) => 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 (data: Data_EthLog) {\n if (!data.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')\n }\n const log = data.log as Log\n\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log,\n undefined,\n data.timestamp\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 (data: Data_EthBlock) {\n if (!data.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\n const block = data.block as Block\n\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined,\n undefined,\n new Date(block.timestamp * 1000)\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 (data: Data_EthTrace) {\n const contractView = processor.CreateBoundContractView()\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!data.trace) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'trace is null')\n }\n const trace = data.trace as Trace\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 data.timestamp\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
|
@@ -12,7 +12,8 @@ export declare abstract class EthContext extends BaseContext {
|
|
|
12
12
|
trace?: Trace;
|
|
13
13
|
blockNumber: bigint | number;
|
|
14
14
|
transactionHash?: string;
|
|
15
|
-
|
|
15
|
+
timestamp: Date;
|
|
16
|
+
protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace, timestamp?: Date);
|
|
16
17
|
protected abstract getContractName(): string;
|
|
17
18
|
getMetaData(name: string, labels: Labels): RecordMetaData;
|
|
18
19
|
}
|
|
@@ -23,7 +24,7 @@ export declare class AccountContext extends EthContext {
|
|
|
23
24
|
export declare class ContractContext<TContract extends BaseContract, TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>> extends EthContext {
|
|
24
25
|
contract: TContractBoundView;
|
|
25
26
|
contractName: string;
|
|
26
|
-
constructor(contractName: string, view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace);
|
|
27
|
+
constructor(contractName: string, view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace, timestamp?: Date);
|
|
27
28
|
protected getContractName(): string;
|
|
28
29
|
}
|
|
29
30
|
export declare class ContractView<TContract extends BaseContract> {
|
package/lib/core/context.js
CHANGED
|
@@ -12,13 +12,15 @@ class EthContext extends base_context_1.BaseContext {
|
|
|
12
12
|
trace;
|
|
13
13
|
blockNumber;
|
|
14
14
|
transactionHash;
|
|
15
|
-
|
|
15
|
+
timestamp;
|
|
16
|
+
constructor(chainId, address, block, log, trace, timestamp) {
|
|
16
17
|
super();
|
|
17
18
|
this.chainId = chainId;
|
|
18
19
|
this.log = log;
|
|
19
20
|
this.block = block;
|
|
20
21
|
this.trace = trace;
|
|
21
22
|
this.address = address;
|
|
23
|
+
this.timestamp = timestamp || new Date(0);
|
|
22
24
|
if (log) {
|
|
23
25
|
this.blockNumber = log.blockNumber;
|
|
24
26
|
this.transactionHash = log.transactionHash;
|
|
@@ -87,8 +89,8 @@ exports.AccountContext = AccountContext;
|
|
|
87
89
|
class ContractContext extends EthContext {
|
|
88
90
|
contract;
|
|
89
91
|
contractName;
|
|
90
|
-
constructor(contractName, view, chainId, block, log, trace) {
|
|
91
|
-
super(chainId, view.rawContract.address, block, log, trace);
|
|
92
|
+
constructor(contractName, view, chainId, block, log, trace, timestamp) {
|
|
93
|
+
super(chainId, view.rawContract.address, block, log, trace, timestamp);
|
|
92
94
|
view.context = this;
|
|
93
95
|
this.contractName = contractName;
|
|
94
96
|
this.contract = view;
|
package/lib/core/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":";;;AAGA,mCAAyC;AAGzC,0CAA0C;AAC1C,iDAA4C;AAE5C,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log } from '@ethersproject/abstract-provider'\nimport { normalizeLabels } from './meter'\nimport { Trace } from './trace'\nimport { Labels } from './metadata'\nimport { CHAIN_IDS } from '../utils/chain'\nimport { BaseContext } from './base-context'\n\nexport abstract class EthContext extends BaseContext {\n chainId: number\n address: string\n log?: Log\n block?: Block\n trace?: Trace\n blockNumber: bigint | number\n transactionHash?: string\n timestamp: Date\n\n protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace, timestamp?: Date) {\n super()\n this.chainId = chainId\n this.log = log\n this.block = block\n this.trace = trace\n this.address = address\n this.timestamp = timestamp || new Date(0)\n if (log) {\n this.blockNumber = log.blockNumber\n this.transactionHash = log.transactionHash\n } else if (block) {\n this.blockNumber = block.number\n } else if (trace) {\n this.blockNumber = trace.blockNumber\n this.transactionHash = trace.transactionHash\n }\n }\n\n protected abstract getContractName(): string\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n if (this.log) {\n return {\n address: this.address,\n contractName: this.getContractName(),\n blockNumber: BigInt(this.blockNumber),\n transactionIndex: this.log.transactionIndex,\n transactionHash: this.transactionHash || '',\n logIndex: this.log.logIndex,\n chainId: this.chainId.toString(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n if (this.block) {\n return {\n address: this.address,\n contractName: this.getContractName(),\n blockNumber: BigInt(this.blockNumber),\n transactionIndex: -1,\n transactionHash: '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n if (this.trace) {\n return {\n address: this.address,\n contractName: this.getContractName(),\n blockNumber: BigInt(this.blockNumber),\n transactionIndex: this.trace.transactionPosition,\n transactionHash: this.transactionHash || '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"Invaid ctx argument can't happen\")\n }\n}\n\nexport class AccountContext extends EthContext {\n constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {\n super(chainId, address, block, log, trace)\n }\n protected getContractName(): string {\n return 'account'\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 timestamp?: Date\n ) {\n super(chainId, view.rawContract.address, block, log, trace, timestamp)\n view.context = this\n this.contractName = contractName\n this.contract = view\n }\n\n protected getContractName(): string {\n return this.contractName\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 SuiContext extends BaseContext {\n address: string\n moduleName: string\n blockNumber: bigint\n\n constructor(address: string, slot: bigint) {\n super()\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(name: string, 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: CHAIN_IDS.SUI_DEVNET, // TODO set in context\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|