@sentio/sdk 1.19.5 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/aptos-processor.d.ts +7 -6
- package/lib/aptos/aptos-processor.js +5 -10
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/bind-options.d.ts +5 -0
- package/lib/aptos/bind-options.js +7 -1
- package/lib/aptos/bind-options.js.map +1 -1
- package/lib/aptos/context.d.ts +3 -3
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +2 -2
- package/lib/aptos/index.js +2 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos-codegen/codegen.d.ts +11 -0
- package/lib/aptos-codegen/codegen.js +110 -0
- package/lib/aptos-codegen/codegen.js.map +1 -0
- package/lib/cli/build.d.ts +3 -3
- package/lib/cli/build.js +44 -22
- package/lib/cli/build.js.map +1 -1
- package/lib/cli/cli.js +11 -11
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/config.d.ts +0 -7
- package/lib/cli/config.js +9 -4
- package/lib/cli/config.js.map +1 -1
- package/lib/cli/upload.js +1 -1
- package/lib/cli/upload.js.map +1 -1
- package/lib/cli/webpack.config.js +1 -0
- package/lib/processor-runner.js +2 -2
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.js +1 -1
- package/lib/service.js.map +1 -1
- package/lib/{cli/solana-code-gen.d.ts → test-abi-code-gen.d.ts} +0 -0
- package/lib/test-abi-code-gen.js +19 -0
- package/lib/test-abi-code-gen.js.map +1 -0
- package/lib/tests/aptos.test.js +4 -4
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/souffl3.js +16 -23
- package/lib/tests/souffl3.js.map +1 -1
- package/lib/tests/types/aptos/account-4188c8.d.ts +27 -0
- package/lib/tests/types/aptos/account-4188c8.js +137 -0
- package/lib/tests/types/aptos/account-4188c8.js.map +1 -0
- package/lib/tests/types/{basic_1.d.ts → solana/basic_1.d.ts} +0 -0
- package/lib/tests/types/{basic_1.js → solana/basic_1.js} +0 -0
- package/lib/tests/types/solana/basic_1.js.map +1 -0
- package/lib/tests/types/{basic_1_processor.d.ts → solana/basic_1_processor.d.ts} +0 -0
- package/lib/tests/types/{basic_1_processor.js → solana/basic_1_processor.js} +0 -0
- package/lib/tests/types/solana/basic_1_processor.js.map +1 -0
- package/package.json +6 -5
- package/src/aptos/aptos-processor.ts +25 -18
- package/src/aptos/bind-options.ts +6 -0
- package/src/aptos/context.ts +3 -3
- package/src/aptos/index.ts +2 -5
- package/src/aptos-codegen/codegen.ts +128 -0
- package/src/aptos-codegen/codgen.test.ts +11 -0
- package/src/aptos-codegen/tsconfig.json +9 -0
- package/src/cli/build.ts +49 -20
- package/src/cli/cli.ts +12 -12
- package/src/cli/config.ts +9 -9
- package/src/cli/upload.ts +1 -1
- package/src/cli/webpack.config.js +1 -0
- package/src/processor-runner.ts +1 -1
- package/src/service.ts +2 -2
- package/src/test-abi-code-gen.ts +14 -0
- package/src/tests/abis/aptos/0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807.json +389 -0
- package/src/tests/aptos.test.ts +4 -4
- package/src/tests/souffl3.ts +20 -30
- package/src/tests/types/aptos/account-4188c8.ts +241 -0
- package/src/tests/types/{basic_1.ts → solana/basic_1.ts} +0 -0
- package/src/tests/types/{basic_1_processor.ts → solana/basic_1_processor.ts} +0 -0
- package/lib/cli/solana-code-gen.js +0 -19
- package/lib/cli/solana-code-gen.js.map +0 -1
- package/lib/tests/types/basic_1.js.map +0 -1
- package/lib/tests/types/basic_1_processor.js.map +0 -1
- package/src/cli/solana-code-gen.ts +0 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProcessResult } from '../gen';
|
|
2
|
-
import { AptosBindOptions, AptosContext, AptosNetwork,
|
|
2
|
+
import { AptosBindOptions, AptosContext, AptosNetwork, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from '.';
|
|
3
3
|
import type { Event as OldEvent } from 'aptos/src/generated';
|
|
4
4
|
import Long from 'long';
|
|
5
5
|
export declare type Event = OldEvent & {
|
|
@@ -15,7 +15,7 @@ export interface EventFilter {
|
|
|
15
15
|
}
|
|
16
16
|
export interface CallFilter {
|
|
17
17
|
function: string;
|
|
18
|
-
typeArguments
|
|
18
|
+
typeArguments?: string[];
|
|
19
19
|
}
|
|
20
20
|
declare class EventHandler {
|
|
21
21
|
filters: EventFilter[];
|
|
@@ -23,7 +23,7 @@ declare class EventHandler {
|
|
|
23
23
|
}
|
|
24
24
|
declare class CallHandler {
|
|
25
25
|
filters: CallFilter[];
|
|
26
|
-
handler: (call:
|
|
26
|
+
handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>;
|
|
27
27
|
}
|
|
28
28
|
export declare class AptosBaseProcessor {
|
|
29
29
|
name: string;
|
|
@@ -31,9 +31,10 @@ export declare class AptosBaseProcessor {
|
|
|
31
31
|
eventHandlers: EventHandler[];
|
|
32
32
|
callHandlers: CallHandler[];
|
|
33
33
|
constructor(options: AptosBindOptions);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
static bind(options: AptosBindOptions): AptosBaseProcessor;
|
|
35
|
+
onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void): AptosBaseProcessor;
|
|
36
|
+
onEvent(handler: (event: Event, ctx: AptosContext) => void, filter: EventFilter | EventFilter[]): AptosBaseProcessor;
|
|
37
|
+
onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void, filter: CallFilter | CallFilter[]): AptosBaseProcessor;
|
|
37
38
|
private configure;
|
|
38
39
|
getChainId(): string;
|
|
39
40
|
}
|
|
@@ -25,6 +25,9 @@ class AptosBaseProcessor {
|
|
|
25
25
|
this.configure(options);
|
|
26
26
|
global.PROCESSOR_STATE.aptosProcessors.push(this);
|
|
27
27
|
}
|
|
28
|
+
static bind(options) {
|
|
29
|
+
return new AptosBaseProcessor(options);
|
|
30
|
+
}
|
|
28
31
|
onTransaction(handler) {
|
|
29
32
|
const address = this.config.address;
|
|
30
33
|
this.callHandlers.push({
|
|
@@ -66,8 +69,9 @@ class AptosBaseProcessor {
|
|
|
66
69
|
},
|
|
67
70
|
filters: _filters,
|
|
68
71
|
});
|
|
72
|
+
return this;
|
|
69
73
|
}
|
|
70
|
-
|
|
74
|
+
onEntryFunctionCall(handler, filter) {
|
|
71
75
|
let _filters = [];
|
|
72
76
|
if (Array.isArray(filter)) {
|
|
73
77
|
_filters = filter;
|
|
@@ -103,16 +107,7 @@ class AptosBaseProcessor {
|
|
|
103
107
|
address: options.address,
|
|
104
108
|
network: options.network || _1.AptosNetwork.TEST_NET,
|
|
105
109
|
};
|
|
106
|
-
return this;
|
|
107
110
|
}
|
|
108
|
-
//
|
|
109
|
-
// public endBlock(endBlock: Long | number) {
|
|
110
|
-
// if (typeof endBlock === 'number') {
|
|
111
|
-
// endBlock = Long.fromNumber(endBlock)
|
|
112
|
-
// }
|
|
113
|
-
// this.config.endSeqNumber = endBlock
|
|
114
|
-
// return this
|
|
115
|
-
// }
|
|
116
111
|
getChainId() {
|
|
117
112
|
switch (this.config.network) {
|
|
118
113
|
case _1.AptosNetwork.TEST_NET:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,wBAMU;AAGV,gDAAuB;AACvB,0CAAmE;AAoBnE,MAAM,YAAY;IAChB,OAAO,CAAe;IACtB,OAAO,CAA0C;CAClD;AAED,MAAM,WAAW;IACf,OAAO,CAAc;IACrB,OAAO,CAA+D;CACvE;AAED,MAAa,kBAAkB;IAC7B,IAAI,CAAQ;IACZ,MAAM,CAAgB;IACtB,aAAa,GAAmB,EAAE,CAAA;IAClC,YA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,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAA;YACH,CAAC;YACD,OAAO,EAAE,QAAQ;SAClB,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,SAAS,CAAC,OAAyB;QACzC,IAAI,YAAY,GAAG,cAAI,CAAC,IAAI,CAAA;QAC5B,IAAI,OAAO,CAAC,YAAY,EAAE;YACxB,YAAY,GAAG,cAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SACpD;QAED,IAAI,CAAC,MAAM,GAAG;YACZ,YAAY,EAAE,YAAY;YAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,eAAY,CAAC,QAAQ;SAClD,CAAA;IACH,CAAC;IAED,UAAU;QACR,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;YAC3B,KAAK,eAAY,CAAC,QAAQ;gBACxB,OAAO,wBAAgB,CAAA;YACzB,KAAK,eAAY,CAAC,QAAQ;gBACxB,OAAO,wBAAgB,CAAA;SAC1B;IACH,CAAC;CACF;AAzHD,gDAyHC","sourcesContent":["import { ProcessResult } from '../gen'\nimport {\n AptosBindOptions,\n AptosContext,\n AptosNetwork,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n} from '.'\nimport type { Event as OldEvent } from 'aptos/src/generated'\n\nimport Long from 'long'\nimport { APTOS_MAINNET_ID, APTOS_TESTNET_ID } from '../utils/chain'\n\nexport type Event = OldEvent & { version: string }\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: Long\n // endSeqNumber?: Long\n}\n\nexport interface EventFilter {\n type: string\n}\n\nexport interface CallFilter {\n function: string\n typeArguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Event) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: CallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n name: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(options: AptosBindOptions) {\n this.name = options.name || options.address\n this.configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n static bind(options: AptosBindOptions): AptosBaseProcessor {\n return new AptosBaseProcessor(options)\n }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void\n ): AptosBaseProcessor {\n const address = this.config.address\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(address, Long.fromString(tx.version), tx)\n if (tx) {\n handler(tx, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: [],\n })\n return this\n }\n\n public onEvent(\n handler: (event: Event, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[]\n ): AptosBaseProcessor {\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const address = this.config.address\n\n this.eventHandlers.push({\n handler: async function (event) {\n const ctx = new AptosContext(address, Long.fromString(event.version))\n if (event) {\n handler(event, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: CallFilter | CallFilter[]\n ): AptosBaseProcessor {\n let _filters: CallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const address = this.config.address\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(address, Long.fromString(tx.version), tx)\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n handler(payload, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n private configure(options: AptosBindOptions) {\n let startVersion = Long.ZERO\n if (options.startVersion) {\n startVersion = Long.fromValue(options.startVersion)\n }\n\n this.config = {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.TEST_NET,\n }\n }\n\n getChainId(): string {\n switch (this.config.network) {\n case AptosNetwork.TEST_NET:\n return APTOS_TESTNET_ID\n case AptosNetwork.MAIN_NET:\n return APTOS_MAINNET_ID\n }\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AptosBindOptions = exports.AptosNetwork = void 0;
|
|
3
|
+
exports.NamedAptosBindOptions = exports.AptosBindOptions = exports.AptosNetwork = void 0;
|
|
4
4
|
var AptosNetwork;
|
|
5
5
|
(function (AptosNetwork) {
|
|
6
6
|
AptosNetwork[AptosNetwork["MAIN_NET"] = 0] = "MAIN_NET";
|
|
@@ -14,4 +14,10 @@ class AptosBindOptions {
|
|
|
14
14
|
startVersion;
|
|
15
15
|
}
|
|
16
16
|
exports.AptosBindOptions = AptosBindOptions;
|
|
17
|
+
class NamedAptosBindOptions {
|
|
18
|
+
address;
|
|
19
|
+
network = AptosNetwork.TEST_NET;
|
|
20
|
+
startVersion;
|
|
21
|
+
}
|
|
22
|
+
exports.NamedAptosBindOptions = NamedAptosBindOptions;
|
|
17
23
|
//# sourceMappingURL=bind-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-options.js","sourceRoot":"","sources":["../../src/aptos/bind-options.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,WAAW;AACb,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,IAAI,CAAS;IACb,YAAY,CAAgB;CAE7B;AAND,4CAMC","sourcesContent":["import Long from 'long'\n\nexport enum AptosNetwork {\n MAIN_NET = 0,\n TEST_NET = 1,\n // DEV_NET,\n}\n\nexport class AptosBindOptions {\n address: string\n network?: AptosNetwork = AptosNetwork.TEST_NET\n name?: string\n startVersion?: Long | number\n // endBlock?: Long | number\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bind-options.js","sourceRoot":"","sources":["../../src/aptos/bind-options.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,WAAW;AACb,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,IAAI,CAAS;IACb,YAAY,CAAgB;CAE7B;AAND,4CAMC;AAED,MAAa,qBAAqB;IAChC,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,YAAY,CAAgB;CAC7B;AAJD,sDAIC","sourcesContent":["import Long from 'long'\n\nexport enum AptosNetwork {\n MAIN_NET = 0,\n TEST_NET = 1,\n // DEV_NET,\n}\n\nexport class AptosBindOptions {\n address: string\n network?: AptosNetwork = AptosNetwork.TEST_NET\n name?: string\n startVersion?: Long | number\n // endBlock?: Long | number\n}\n\nexport class NamedAptosBindOptions {\n address: string\n network?: AptosNetwork = AptosNetwork.TEST_NET\n startVersion?: Long | number\n}\n"]}
|
package/lib/aptos/context.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import Long from 'long';
|
|
|
2
2
|
import { MetricDescriptor, RecordMetaData } from '../gen';
|
|
3
3
|
import { Labels } from '../core/metadata';
|
|
4
4
|
import { BaseContext } from '../core/context';
|
|
5
|
-
import {
|
|
5
|
+
import { Transaction_UserTransaction } from './';
|
|
6
6
|
export declare class AptosContext extends BaseContext {
|
|
7
7
|
address: string;
|
|
8
8
|
blockNumber: Long;
|
|
9
|
-
transaction:
|
|
10
|
-
constructor(address: string, slot: Long, transaction?:
|
|
9
|
+
transaction: Transaction_UserTransaction;
|
|
10
|
+
constructor(address: string, slot: Long, transaction?: Transaction_UserTransaction);
|
|
11
11
|
getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData;
|
|
12
12
|
}
|
package/lib/aptos/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;AAGA,0CAAiD;AACjD,yCAA+C;AAC/C,6CAA6C;AAG7C,MAAa,YAAa,SAAQ,qBAAW;IAC3C,OAAO,CAAQ;IACf,WAAW,CAAM;IACjB,WAAW,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;AAGA,0CAAiD;AACjD,yCAA+C;AAC/C,6CAA6C;AAG7C,MAAa,YAAa,SAAQ,qBAAW;IAC3C,OAAO,CAAQ;IACf,WAAW,CAAM;IACjB,WAAW,CAA6B;IAExC,YAAY,OAAe,EAAE,IAAU,EAAE,WAAyC;QAChF,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,WAAW,CAAC,UAAwC,EAAE,MAAc;QAClE,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,OAAO;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,wBAAgB;YACzB,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AA1BD,oCA0BC","sourcesContent":["import Long from 'long'\nimport { MetricDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { APTOS_TESTNET_ID } from '../utils/chain'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/context'\nimport { Transaction_UserTransaction } from './'\n\nexport class AptosContext extends BaseContext {\n address: string\n blockNumber: Long\n transaction: Transaction_UserTransaction\n\n constructor(address: string, slot: Long, transaction?: Transaction_UserTransaction) {\n super()\n this.address = address\n this.blockNumber = slot\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n contractAddress: this.address,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: APTOS_TESTNET_ID, // TODO set in context\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
package/lib/aptos/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { Transaction_UserTransaction
|
|
1
|
+
export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated';
|
|
2
2
|
export type { Event, CallFilter, EventFilter } from './aptos-processor';
|
|
3
3
|
export { AptosBaseProcessor } from './aptos-processor';
|
|
4
4
|
export { AptosContext } from './context';
|
|
5
|
-
export { AptosBindOptions, AptosNetwork } from './bind-options';
|
|
5
|
+
export { AptosBindOptions, NamedAptosBindOptions, AptosNetwork } from './bind-options';
|
package/lib/aptos/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AptosNetwork = exports.AptosBindOptions = exports.AptosContext = exports.AptosBaseProcessor = void 0;
|
|
3
|
+
exports.AptosNetwork = exports.NamedAptosBindOptions = exports.AptosBindOptions = exports.AptosContext = exports.AptosBaseProcessor = void 0;
|
|
4
4
|
var aptos_processor_1 = require("./aptos-processor");
|
|
5
5
|
Object.defineProperty(exports, "AptosBaseProcessor", { enumerable: true, get: function () { return aptos_processor_1.AptosBaseProcessor; } });
|
|
6
6
|
var context_1 = require("./context");
|
|
7
7
|
Object.defineProperty(exports, "AptosContext", { enumerable: true, get: function () { return context_1.AptosContext; } });
|
|
8
8
|
var bind_options_1 = require("./bind-options");
|
|
9
9
|
Object.defineProperty(exports, "AptosBindOptions", { enumerable: true, get: function () { return bind_options_1.AptosBindOptions; } });
|
|
10
|
+
Object.defineProperty(exports, "NamedAptosBindOptions", { enumerable: true, get: function () { return bind_options_1.NamedAptosBindOptions; } });
|
|
10
11
|
Object.defineProperty(exports, "AptosNetwork", { enumerable: true, get: function () { return bind_options_1.AptosNetwork; } });
|
|
11
12
|
//# sourceMappingURL=index.js.map
|
package/lib/aptos/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;AAEA,qDAAsD;AAA7C,qHAAA,kBAAkB,OAAA;AAC3B,qCAAwC;AAA/B,uGAAA,YAAY,OAAA;AACrB,+CAAsF;AAA7E,gHAAA,gBAAgB,OAAA;AAAE,qHAAA,qBAAqB,OAAA;AAAE,4GAAA,YAAY,OAAA","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated'\nexport type { Event, CallFilter, EventFilter } from './aptos-processor'\nexport { AptosBaseProcessor } from './aptos-processor'\nexport { AptosContext } from './context'\nexport { AptosBindOptions, NamedAptosBindOptions, AptosNetwork } from './bind-options'\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MoveModuleBytecode } from 'aptos/src/generated';
|
|
2
|
+
interface Config {
|
|
3
|
+
outputDir: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class AptosCodegen {
|
|
6
|
+
modules: MoveModuleBytecode[];
|
|
7
|
+
config: Config;
|
|
8
|
+
constructor(srcFile: string, config: Config);
|
|
9
|
+
generate(): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AptosCodegen = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const prettier_1 = __importDefault(require("prettier"));
|
|
10
|
+
class AptosCodegen {
|
|
11
|
+
modules;
|
|
12
|
+
config;
|
|
13
|
+
constructor(srcFile, config) {
|
|
14
|
+
const json = fs_1.default.readFileSync(srcFile, 'utf-8');
|
|
15
|
+
this.modules = JSON.parse(json);
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
generate() {
|
|
19
|
+
if (!this.modules) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let address;
|
|
23
|
+
for (const module of this.modules) {
|
|
24
|
+
if (module.abi && module.abi.address) {
|
|
25
|
+
address = module.abi.address;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!address) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const imports = `import { aptos } from "@sentio/sdk"`;
|
|
32
|
+
let source = `
|
|
33
|
+
/* Autogenerated file. Do not edit manually. */
|
|
34
|
+
/* tslint:disable */
|
|
35
|
+
/* eslint-disable */
|
|
36
|
+
|
|
37
|
+
/* Generated modules for account ${address} */
|
|
38
|
+
|
|
39
|
+
${imports}
|
|
40
|
+
|
|
41
|
+
${this.modules.map(generateModule).join('\n')}
|
|
42
|
+
`; // source
|
|
43
|
+
source = prettier_1.default.format(source, { parser: 'typescript' });
|
|
44
|
+
fs_1.default.writeFileSync(path_1.default.join(this.config.outputDir, 'account-' + address.slice(2, 8) + '.ts'), source);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.AptosCodegen = AptosCodegen;
|
|
48
|
+
function generateModule(moduleByteCode) {
|
|
49
|
+
if (!moduleByteCode.abi) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
const module = moduleByteCode.abi;
|
|
53
|
+
const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '');
|
|
54
|
+
const events = module.structs.map((e) => generateOnEvents(module, e)).filter((s) => s !== '');
|
|
55
|
+
return `
|
|
56
|
+
export class ${module.name} extends aptos.AptosBaseProcessor {
|
|
57
|
+
static DEFAULT_OPTIONS: aptos.NamedAptosBindOptions = {
|
|
58
|
+
address: "${module.address}",
|
|
59
|
+
network: aptos.AptosNetwork.TEST_NET
|
|
60
|
+
}
|
|
61
|
+
static bind(options = ${module.name}.DEFAULT_OPTIONS): ${module.name} {
|
|
62
|
+
return new ${module.name}({ ...options, name: "${module.name}" })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
${functions.join('\n')}
|
|
66
|
+
|
|
67
|
+
${events.join('\n')}
|
|
68
|
+
}`;
|
|
69
|
+
}
|
|
70
|
+
function generateOnEntryFunctions(module, func) {
|
|
71
|
+
if (!func.is_entry) {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
const camelFuncName = capitalizeFirstChar(camelize(func.name));
|
|
75
|
+
const source = `
|
|
76
|
+
onEntry${camelFuncName}(func: (call: aptos.TransactionPayload_EntryFunctionPayload, ctx: aptos.AptosContext) => void): ${module.name} {
|
|
77
|
+
this.onEntryFunctionCall(func, {
|
|
78
|
+
function: '${module.name}::${func.name}'
|
|
79
|
+
})
|
|
80
|
+
return this
|
|
81
|
+
}`;
|
|
82
|
+
return source;
|
|
83
|
+
}
|
|
84
|
+
function generateOnEvents(module, struct) {
|
|
85
|
+
// for struct that has drop + store
|
|
86
|
+
if (!struct.abilities.includes('drop') || !struct.abilities.includes('store') || !struct.name.endsWith('Event')) {
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
89
|
+
const source = `
|
|
90
|
+
onEvent${struct.name}(func: (event: aptos.Event, ctx: aptos.AptosContext) => void): ${module.name} {
|
|
91
|
+
this.onEvent(func, {
|
|
92
|
+
type: '${module.address}::${module.name}::${struct.name}'
|
|
93
|
+
})
|
|
94
|
+
return this
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
return source;
|
|
98
|
+
}
|
|
99
|
+
function camelize(input) {
|
|
100
|
+
return input
|
|
101
|
+
.split('_')
|
|
102
|
+
.reduce((res, word, i) => i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.substr(1).toLowerCase()}`, '');
|
|
103
|
+
}
|
|
104
|
+
function capitalizeFirstChar(input) {
|
|
105
|
+
if (!input) {
|
|
106
|
+
return input;
|
|
107
|
+
}
|
|
108
|
+
return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '');
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=codegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/codegen.ts"],"names":[],"mappings":";;;;;;AACA,4CAAmB;AACnB,gDAAuB;AAGvB,wDAA+B;AAM/B,MAAa,YAAY;IACvB,OAAO,CAAsB;IAC7B,MAAM,CAAQ;IAEd,YAAY,OAAe,EAAE,MAAc;QACzC,MAAM,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC9C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IA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M,MAAM,GAAG;WACN,MAAM,CAAC,IAAI,kEAAkE,MAAM,CAAC,IAAI;;eAEpF,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;;;;GAI1D,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CACL,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CACf,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,EACvG,EAAE,CACH,CAAA;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAK,CAAA;KACb;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { MoveModuleBytecode } from 'aptos/src/generated'\nimport fs from 'fs'\nimport path from 'path'\nimport { MoveFunction, MoveModule } from 'aptos/src/generated'\nimport { MoveStruct } from 'aptos/src/generated/models/MoveStruct'\nimport prettier from 'prettier'\n\ninterface Config {\n outputDir: string\n}\n\nexport class AptosCodegen {\n modules: MoveModuleBytecode[]\n config: Config\n\n constructor(srcFile: string, config: Config) {\n const json = fs.readFileSync(srcFile, 'utf-8')\n this.modules = JSON.parse(json)\n this.config = config\n }\n\n generate() {\n if (!this.modules) {\n return\n }\n let address: string | undefined\n for (const module of this.modules) {\n if (module.abi && module.abi.address) {\n address = module.abi.address\n }\n }\n if (!address) {\n return\n }\n\n const imports = `import { aptos } from \"@sentio/sdk\"`\n\n let source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n \n /* Generated modules for account ${address} */\n \n ${imports}\n \n ${this.modules.map(generateModule).join('\\n')}\n ` // source\n\n source = prettier.format(source, { parser: 'typescript' })\n fs.writeFileSync(path.join(this.config.outputDir, 'account-' + address.slice(2, 8) + '.ts'), source)\n }\n}\n\nfunction generateModule(moduleByteCode: MoveModuleBytecode) {\n if (!moduleByteCode.abi) {\n return ''\n }\n const module = moduleByteCode.abi\n\n const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')\n const events = module.structs.map((e) => generateOnEvents(module, e)).filter((s) => s !== '')\n\n return `\n export class ${module.name} extends aptos.AptosBaseProcessor {\n static DEFAULT_OPTIONS: aptos.NamedAptosBindOptions = {\n address: \"${module.address}\",\n network: aptos.AptosNetwork.TEST_NET \n }\n static bind(options = ${module.name}.DEFAULT_OPTIONS): ${module.name} {\n return new ${module.name}({ ...options, name: \"${module.name}\" })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n }`\n}\n\nfunction generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: aptos.TransactionPayload_EntryFunctionPayload, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEntryFunctionCall(func, {\n function: '${module.name}::${func.name}'\n })\n return this\n }`\n\n return source\n}\n\nfunction generateOnEvents(module: MoveModule, struct: MoveStruct): string {\n // for struct that has drop + store\n if (!struct.abilities.includes('drop') || !struct.abilities.includes('store') || !struct.name.endsWith('Event')) {\n return ''\n }\n const source = `\n onEvent${struct.name}(func: (event: aptos.Event, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEvent(func, {\n type: '${module.address}::${module.name}::${struct.name}'\n })\n return this\n }\n `\n return source\n}\n\nfunction camelize(input: string): string {\n return input\n .split('_')\n .reduce(\n (res, word, i) =>\n i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.substr(1).toLowerCase()}`,\n ''\n )\n}\n\nfunction capitalizeFirstChar(input: string): string {\n if (!input) {\n return input\n }\n return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')\n}\n"]}
|
package/lib/cli/build.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
1
|
+
export declare function buildProcessor(onlyGen: boolean): Promise<void>;
|
|
2
|
+
export declare function codeGenAptosProcessor(abisDir: string, outDir?: string): void;
|
|
3
3
|
export declare function codeGenEthersProcessor(abisDir: string, ETHERS_TARGET?: string, outDir?: string): Promise<void>;
|
|
4
|
-
export declare function codeGenSolanaProcessor(abisDir: string,
|
|
4
|
+
export declare function codeGenSolanaProcessor(abisDir: string, targetPath?: string): void;
|
package/lib/cli/build.js
CHANGED
|
@@ -3,20 +3,21 @@ 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.codeGenSolanaProcessor = exports.codeGenEthersProcessor = exports.buildProcessor = void 0;
|
|
6
|
+
exports.codeGenSolanaProcessor = exports.codeGenEthersProcessor = exports.codeGenAptosProcessor = exports.buildProcessor = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const codegen_1 = require("../aptos-codegen/codegen");
|
|
12
|
+
// import { EVM, SOLANA, Target } from './config'
|
|
13
|
+
async function buildProcessor(onlyGen) {
|
|
13
14
|
if (!onlyGen) {
|
|
14
15
|
await installDeps();
|
|
15
16
|
}
|
|
16
17
|
// targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
|
|
17
|
-
for (const target
|
|
18
|
-
|
|
19
|
-
}
|
|
18
|
+
// for (const target) {
|
|
19
|
+
await buildProcessorForTarget(onlyGen);
|
|
20
|
+
// }
|
|
20
21
|
if (!onlyGen) {
|
|
21
22
|
const WEBPACK_CONFIG = path_1.default.join(__dirname, 'webpack.config.js');
|
|
22
23
|
await execStep('yarn tsc -p .', 'Compile');
|
|
@@ -24,13 +25,10 @@ async function buildProcessor(onlyGen, targets) {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
exports.buildProcessor = buildProcessor;
|
|
27
|
-
async function buildProcessorForTarget(onlyGen
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
else if (target.chain === config_1.SOLANA) {
|
|
32
|
-
codeGenSolanaProcessor(target.abisDir ?? path_1.default.join('abis', 'solana'));
|
|
33
|
-
}
|
|
28
|
+
async function buildProcessorForTarget(onlyGen) {
|
|
29
|
+
await codeGenEthersProcessor(path_1.default.join('abis', 'evm'));
|
|
30
|
+
codeGenSolanaProcessor(path_1.default.join('abis', 'solana'));
|
|
31
|
+
codeGenAptosProcessor(path_1.default.join('abis', 'aptos'));
|
|
34
32
|
if (onlyGen) {
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
@@ -38,6 +36,25 @@ async function buildProcessorForTarget(onlyGen, target) {
|
|
|
38
36
|
async function installDeps() {
|
|
39
37
|
await execStep('yarn install --ignore-scripts', 'Yarn Install');
|
|
40
38
|
}
|
|
39
|
+
function codeGenAptosProcessor(abisDir, outDir = 'src/types/aptos') {
|
|
40
|
+
if (!fs_1.default.existsSync(abisDir)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const files = fs_1.default.readdirSync(abisDir);
|
|
44
|
+
console.log(chalk_1.default.green('Generated Types for Aptos'));
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
if (path_1.default.extname(file) === '.json') {
|
|
47
|
+
if (!fs_1.default.existsSync(outDir)) {
|
|
48
|
+
fs_1.default.mkdirSync(outDir, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const codegen = new codegen_1.AptosCodegen(path_1.default.join(abisDir, file), {
|
|
52
|
+
outputDir: outDir,
|
|
53
|
+
});
|
|
54
|
+
codegen.generate();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.codeGenAptosProcessor = codeGenAptosProcessor;
|
|
41
58
|
async function codeGenEthersProcessor(abisDir, ETHERS_TARGET = path_1.default.join(__dirname, '../target-ethers-sentio'), outDir = 'src/types/internal') {
|
|
42
59
|
if (!fs_1.default.existsSync(abisDir)) {
|
|
43
60
|
return;
|
|
@@ -53,25 +70,30 @@ async function codeGenEthersProcessor(abisDir, ETHERS_TARGET = path_1.default.jo
|
|
|
53
70
|
if (!haveJson) {
|
|
54
71
|
return;
|
|
55
72
|
}
|
|
73
|
+
console.log(chalk_1.default.green('Generated Types for EVM'));
|
|
56
74
|
// TODO this will fail during postinstall, need to locate real typechain path
|
|
57
75
|
await execStep('yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path_1.default.join(abisDir, '*.json')}`, 'Type definitions gen');
|
|
58
76
|
}
|
|
59
77
|
exports.codeGenEthersProcessor = codeGenEthersProcessor;
|
|
60
|
-
function codeGenSolanaProcessor(abisDir,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
function codeGenSolanaProcessor(abisDir, targetPath = path_1.default.join('src', 'types', 'solana')) {
|
|
79
|
+
if (!fs_1.default.existsSync(abisDir)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const abisFiles = fs_1.default.readdirSync(abisDir);
|
|
83
|
+
if (abisFiles.length > 0) {
|
|
84
|
+
console.log(chalk_1.default.green('Generated Types for Solana'));
|
|
85
|
+
}
|
|
64
86
|
for (const file of abisFiles) {
|
|
65
87
|
if (path_1.default.extname(file) === '.json') {
|
|
66
|
-
if (!fs_1.default.existsSync(
|
|
67
|
-
fs_1.default.mkdirSync(
|
|
88
|
+
if (!fs_1.default.existsSync(targetPath)) {
|
|
89
|
+
fs_1.default.mkdirSync(targetPath, { recursive: true });
|
|
68
90
|
}
|
|
69
|
-
const idlContent = fs_1.default.readFileSync(path_1.default.join(
|
|
91
|
+
const idlContent = fs_1.default.readFileSync(path_1.default.join(abisDir, file), 'utf-8');
|
|
70
92
|
const idlObj = JSON.parse(idlContent);
|
|
71
93
|
const idlName = idlObj.name;
|
|
72
|
-
const idlFile = path_1.default.join(
|
|
94
|
+
const idlFile = path_1.default.join(targetPath, idlName + '.ts');
|
|
73
95
|
fs_1.default.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`);
|
|
74
|
-
fs_1.default.writeFileSync(path_1.default.join(
|
|
96
|
+
fs_1.default.writeFileSync(path_1.default.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj));
|
|
75
97
|
}
|
|
76
98
|
}
|
|
77
99
|
}
|
package/lib/cli/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,gDAAuB;AACvB,4CAAmB;AACnB,iDAAoC;AACpC,qCAA8C;AAEvC,KAAK,UAAU,cAAc,CAAC,OAAgB,EAAE,OAAiB;IACtE,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,WAAW,EAAE,CAAA;KACpB;IAED,oFAAoF;IACpF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,MAAM,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;KAC/C;IAED,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,cAAc,GAAG,cAAI,CAAC,I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AAC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAA;IAE5C,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QAClC,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAChB;IAED,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACjC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAEjC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,IAAI,KAAK,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs'\nimport { exec } from 'child_process'\nimport { EVM, SOLANA, Target } from './config'\n\nexport async function buildProcessor(onlyGen: boolean, targets: Target[]) {\n if (!onlyGen) {\n await installDeps()\n }\n\n // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))\n for (const target of targets) {\n await buildProcessorForTarget(onlyGen, target)\n }\n\n if (!onlyGen) {\n const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')\n await execStep('yarn tsc -p .', 'Compile')\n await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging')\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean, target: Target) {\n if (target.chain === EVM) {\n await codeGenEthersProcessor(target.abisDir ?? path.join('abis', 'evm'))\n } else if (target.chain === SOLANA) {\n codeGenSolanaProcessor(target.abisDir ?? path.join('abis', 'solana'))\n }\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nexport async function codeGenEthersProcessor(\n abisDir: string,\n ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),\n outDir = 'src/types/internal'\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n let haveJson = false\n const files = fs.readdirSync(abisDir)\n for (const file of files) {\n if (file.toLowerCase().endsWith('.json')) {\n haveJson = true\n break\n }\n }\n if (!haveJson) {\n return\n }\n\n // TODO this will fail during postinstall, need to locate real typechain path\n await execStep(\n 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,\n 'Type definitions gen'\n )\n}\n\nexport function codeGenSolanaProcessor(abisDir: string, root = '', targetPath = path.join('src', 'types')) {\n const abisFolder = path.join(root, abisDir)\n const abisFiles = fs.readdirSync(abisFolder)\n const typeFolder = path.join(root, targetPath)\n for (const file of abisFiles) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(typeFolder)) {\n fs.mkdirSync(typeFolder)\n }\n const idlContent = fs.readFileSync(path.join(abisFolder, file), 'utf-8')\n const idlObj = JSON.parse(idlContent)\n const idlName = idlObj.name\n const idlFile = path.join(typeFolder, idlName + '.ts')\n fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)\n fs.writeFileSync(path.join(typeFolder, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))\n }\n }\n}\n\nfunction codeGenSolanaIdlProcessor(idlObj: any): string {\n const idlName = idlObj.name\n const idlNamePascalCase = toPascalCase(idlName)\n const instructions: any[] = idlObj.instructions\n return `import { BorshInstructionCoder, Instruction, Idl, BN } from '@project-serum/anchor'\nimport { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from \"@sentio/sdk\"\nimport { ${idlName}_idl } from \"./${idlName}\"\nimport bs58 from 'bs58'\nimport { PublicKey } from '@solana/web3.js'\n\nexport class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {\n static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {\n if (options && !options.name) {\n options.name = '${idlNamePascalCase}'\n }\n return new ${idlNamePascalCase}Processor(options)\n }\n\n decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {\n const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)\n const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))\n return decodedIns\n }\n\n ${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}\n}\n `\n}\n\nfunction codeGenSolanaInstruction(idlName: string, ins: any): string {\n const instructionName = ins.name\n const argsTypeString = codeGenInstructionArgs(ins.args)\n return `\n on${\n instructionName.charAt(0).toUpperCase() + instructionName.slice(1)\n }(handler: (args: ${argsTypeString}, ctx: SolanaContext) => void): ${idlName}Processor {\n this.onInstruction('${instructionName}', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data as ${argsTypeString}, ctx)\n }\n })\n return this\n }\n `\n}\n\nfunction codeGenInstructionArgs(args: { name: string; type: string }[]): string {\n return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`\n}\n\n// Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104\nfunction mapType(tpe: string): string {\n switch (tpe) {\n case 'publicKey':\n return 'PublicKey'\n case 'bool':\n return 'boolean'\n case 'string':\n return 'string'\n case 'u8':\n case 'i8':\n case 'u16':\n case 'i16':\n case 'u32':\n case 'i32':\n case 'f32':\n case 'f64':\n return 'number'\n case 'u64':\n case 'i64':\n case 'u128':\n case 'i128':\n return 'BN'\n default:\n return 'any'\n }\n}\n\nfunction toPascalCase(str: string) {\n return `${str}`\n .toLowerCase()\n .replace(new RegExp(/[-_]+/, 'g'), ' ')\n .replace(new RegExp(/[^\\w\\s]/, 'g'), '')\n .replace(new RegExp(/\\s+(.)(\\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)\n .replace(new RegExp(/\\w/), (s) => s.toUpperCase())\n}\n\nasync function execStep(cmd: string, stepName: string) {\n const child = exec(cmd)\n console.log(chalk.blue(stepName + ' begin'))\n\n if (!child.stdout || !child.stderr) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(1)\n }\n\n child.stdout.pipe(process.stdout)\n child.stderr.pipe(process.stderr)\n\n await new Promise((resolve) => {\n child.on('close', resolve)\n })\n\n if (child.exitCode) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(child.exitCode)\n }\n console.log(chalk.blue(stepName + ' success'))\n console.log()\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,gDAAuB;AACvB,4CAAmB;AACnB,iDAAoC;AACpC,sDAAuD;AACvD,iDAAiD;AAE1C,KAAK,UAAU,cAAc,CAAC,OAAgB;IACnD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,WAAW,EAAE,CAAA;KACpB;IAED,oFAAoF;IACpF,uBAAuB;IACvB,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAA;IACtC,IAAI;IAEJ,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,cAAc,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;QAChE,MAAM,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC,CAAA;QAC1C,MAAM,QAAQ,CAAC,wBAAwB,GAAG,cAAc,EAAE,WAAW,CAAC,CAAA;KACvE;AACH,CAAC;AAfD,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OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs'\nimport { exec } from 'child_process'\nimport { AptosCodegen } from '../aptos-codegen/codegen'\n// import { EVM, SOLANA, Target } from './config'\n\nexport async function buildProcessor(onlyGen: boolean) {\n if (!onlyGen) {\n await installDeps()\n }\n\n // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))\n // for (const target) {\n await buildProcessorForTarget(onlyGen)\n // }\n\n if (!onlyGen) {\n const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')\n await execStep('yarn tsc -p .', 'Compile')\n await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging')\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean) {\n await codeGenEthersProcessor(path.join('abis', 'evm'))\n codeGenSolanaProcessor(path.join('abis', 'solana'))\n codeGenAptosProcessor(path.join('abis', 'aptos'))\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nexport function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n const files = fs.readdirSync(abisDir)\n\n console.log(chalk.green('Generated Types for Aptos'))\n for (const file of files) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true })\n }\n }\n const codegen = new AptosCodegen(path.join(abisDir, file), {\n outputDir: outDir,\n })\n codegen.generate()\n }\n}\n\nexport async function codeGenEthersProcessor(\n abisDir: string,\n ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),\n outDir = 'src/types/internal'\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n let haveJson = false\n const files = fs.readdirSync(abisDir)\n for (const file of files) {\n if (file.toLowerCase().endsWith('.json')) {\n haveJson = true\n break\n }\n }\n if (!haveJson) {\n return\n }\n\n console.log(chalk.green('Generated Types for EVM'))\n\n // TODO this will fail during postinstall, need to locate real typechain path\n await execStep(\n 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,\n 'Type definitions gen'\n )\n}\n\nexport function codeGenSolanaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n const abisFiles = fs.readdirSync(abisDir)\n\n if (abisFiles.length > 0) {\n console.log(chalk.green('Generated Types for Solana'))\n }\n\n for (const file of abisFiles) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(targetPath)) {\n fs.mkdirSync(targetPath, { recursive: true })\n }\n const idlContent = fs.readFileSync(path.join(abisDir, file), 'utf-8')\n const idlObj = JSON.parse(idlContent)\n const idlName = idlObj.name\n const idlFile = path.join(targetPath, idlName + '.ts')\n fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)\n fs.writeFileSync(path.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))\n }\n }\n}\n\nfunction codeGenSolanaIdlProcessor(idlObj: any): string {\n const idlName = idlObj.name\n const idlNamePascalCase = toPascalCase(idlName)\n const instructions: any[] = idlObj.instructions\n return `import { BorshInstructionCoder, Instruction, Idl, BN } from '@project-serum/anchor'\nimport { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from \"@sentio/sdk\"\nimport { ${idlName}_idl } from \"./${idlName}\"\nimport bs58 from 'bs58'\nimport { PublicKey } from '@solana/web3.js'\n\nexport class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {\n static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {\n if (options && !options.name) {\n options.name = '${idlNamePascalCase}'\n }\n return new ${idlNamePascalCase}Processor(options)\n }\n\n decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {\n const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)\n const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))\n return decodedIns\n }\n\n ${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}\n}\n `\n}\n\nfunction codeGenSolanaInstruction(idlName: string, ins: any): string {\n const instructionName = ins.name\n const argsTypeString = codeGenInstructionArgs(ins.args)\n return `\n on${\n instructionName.charAt(0).toUpperCase() + instructionName.slice(1)\n }(handler: (args: ${argsTypeString}, ctx: SolanaContext) => void): ${idlName}Processor {\n this.onInstruction('${instructionName}', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data as ${argsTypeString}, ctx)\n }\n })\n return this\n }\n `\n}\n\nfunction codeGenInstructionArgs(args: { name: string; type: string }[]): string {\n return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`\n}\n\n// Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104\nfunction mapType(tpe: string): string {\n switch (tpe) {\n case 'publicKey':\n return 'PublicKey'\n case 'bool':\n return 'boolean'\n case 'string':\n return 'string'\n case 'u8':\n case 'i8':\n case 'u16':\n case 'i16':\n case 'u32':\n case 'i32':\n case 'f32':\n case 'f64':\n return 'number'\n case 'u64':\n case 'i64':\n case 'u128':\n case 'i128':\n return 'BN'\n default:\n return 'any'\n }\n}\n\nfunction toPascalCase(str: string) {\n return `${str}`\n .toLowerCase()\n .replace(new RegExp(/[-_]+/, 'g'), ' ')\n .replace(new RegExp(/[^\\w\\s]/, 'g'), '')\n .replace(new RegExp(/\\s+(.)(\\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)\n .replace(new RegExp(/\\w/), (s) => s.toUpperCase())\n}\n\nasync function execStep(cmd: string, stepName: string) {\n const child = exec(cmd)\n console.log(chalk.blue(stepName + ' begin'))\n\n if (!child.stdout || !child.stderr) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(1)\n }\n\n child.stdout.pipe(process.stdout)\n child.stderr.pipe(process.stderr)\n\n await new Promise((resolve) => {\n child.on('close', resolve)\n })\n\n if (child.exitCode) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(child.exitCode)\n }\n console.log(chalk.blue(stepName + ' success'))\n console.log()\n}\n"]}
|
package/lib/cli/cli.js
CHANGED
|
@@ -37,7 +37,7 @@ else {
|
|
|
37
37
|
// For all the commands that need read project configs
|
|
38
38
|
// TODO move them to their own modules
|
|
39
39
|
// Process configs
|
|
40
|
-
let processorConfig = { host: '', project: '', source: '', build: true
|
|
40
|
+
let processorConfig = { host: '', project: '', source: '', build: true };
|
|
41
41
|
// Fist step, read from project yaml file
|
|
42
42
|
try {
|
|
43
43
|
console.log(chalk_1.default.blue('Loading Process config'));
|
|
@@ -67,14 +67,14 @@ else {
|
|
|
67
67
|
if (!processorConfig.source) {
|
|
68
68
|
processorConfig.source = 'src/processor.ts';
|
|
69
69
|
}
|
|
70
|
-
if (!processorConfig.targets) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
if (processorConfig.targets.length === 0) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
70
|
+
// if (!processorConfig.targets) {
|
|
71
|
+
// console.warn('targets is not defined, use EVM as the default target')
|
|
72
|
+
// processorConfig.targets = []
|
|
73
|
+
// }
|
|
74
|
+
// if (processorConfig.targets.length === 0) {
|
|
75
|
+
// // By default evm
|
|
76
|
+
// processorConfig.targets.push({ chain: EVM })
|
|
77
|
+
// }
|
|
78
78
|
}
|
|
79
79
|
catch (e) {
|
|
80
80
|
console.error(e);
|
|
@@ -141,10 +141,10 @@ else {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
else if (mainOptions.command === 'build') {
|
|
144
|
-
(0, build_1.buildProcessor)(false
|
|
144
|
+
(0, build_1.buildProcessor)(false);
|
|
145
145
|
}
|
|
146
146
|
else if (mainOptions.command === 'gen') {
|
|
147
|
-
(0, build_1.buildProcessor)(true
|
|
147
|
+
(0, build_1.buildProcessor)(true);
|
|
148
148
|
}
|
|
149
149
|
else {
|
|
150
150
|
usage();
|