@sentio/cli 2.0.5 → 2.1.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/cli.js +5 -0
- package/lib/cli.js.map +1 -1
- package/lib/commands/build.d.ts +1 -0
- package/lib/commands/build.js +1 -1
- package/lib/commands/build.js.map +1 -1
- package/lib/commands/run-add.d.ts +1 -0
- package/lib/commands/run-add.js +105 -0
- package/lib/commands/run-add.js.map +1 -0
- package/package.json +8 -6
- package/src/cli.ts +4 -0
- package/src/commands/build.ts +1 -1
- package/src/commands/run-add.ts +112 -0
package/lib/cli.js
CHANGED
|
@@ -11,6 +11,7 @@ import { runVersion } from './commands/run-version.js';
|
|
|
11
11
|
import { runLogin } from './commands/run-login.js';
|
|
12
12
|
import { runUpload } from './commands/run-upload.js';
|
|
13
13
|
import { runTest } from './commands/run-test.js';
|
|
14
|
+
import { runAdd } from './commands/run-add.js';
|
|
14
15
|
const mainDefinitions = [{ name: 'command', defaultOption: true }];
|
|
15
16
|
const mainOptions = commandLineArgs(mainDefinitions, {
|
|
16
17
|
stopAtFirstUnknown: true,
|
|
@@ -31,6 +32,9 @@ else if (mainOptions.command === 'version') {
|
|
|
31
32
|
else if (mainOptions.command === 'test') {
|
|
32
33
|
runTest(argv);
|
|
33
34
|
}
|
|
35
|
+
else if (mainOptions.command === 'add') {
|
|
36
|
+
await runAdd(argv);
|
|
37
|
+
}
|
|
34
38
|
else {
|
|
35
39
|
// For all the commands that need read project configs
|
|
36
40
|
// TODO move them to their own modules
|
|
@@ -106,6 +110,7 @@ function usage() {
|
|
|
106
110
|
'sentio <command> --help\t\tshow detail usage of specific command',
|
|
107
111
|
'sentio login\t\t\t\tlogin to sentio',
|
|
108
112
|
'sentio create\t\t\t\tcreate a template project',
|
|
113
|
+
'sentio add\t\t\t\tadd contract ABI to the project',
|
|
109
114
|
'sentio upload\t\t\t\tbuild and upload processor to sentio',
|
|
110
115
|
'sentio gen\t\t\t\tgenerate abi',
|
|
111
116
|
'sentio build\t\t\t\tgenerate abi and build',
|
package/lib/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,IAAI,MAAM,SAAS,CAAA;AAE1B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,IAAI,MAAM,SAAS,CAAA;AAE1B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,O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AiD;QACjD,IAAI;KACL;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAChB;IAED,IAAI,WAAW,CAAC,OAAO,KAAK,QAAQ,EAAE;QACpC,MAAM,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;KACvC;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;QAC1C,MAAM,sBAAsB,CAAC,IAAI,CAAC,CAAA;KACnC;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;QACxC,MAAM,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;KAC/B;SAAM;QACL,KAAK,EAAE,CAAA;KACR;CACF;AAED,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B;YACE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,8CAA8C;SACxD;QACD;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,kEAAkE;gBAClE,qCAAqC;gBACrC,gDAAgD;gBAChD,mDAAmD;gBACnD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;gBAC5C,8BAA8B;gBAC9B,yCAAyC;aAC1C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { SentioProjectConfig } from './config.js'\nimport chalk from 'chalk'\nimport { buildProcessor, buildProcessorWithArgs } from './commands/build.js'\nimport { runCreate } from './commands/run-create.js'\nimport { runVersion } from './commands/run-version.js'\nimport { runLogin } from './commands/run-login.js'\nimport { runUpload } from './commands/run-upload.js'\nimport { runTest } from './commands/run-test.js'\nimport { runAdd } from './commands/run-add.js'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (!mainOptions.command) {\n usage()\n}\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n await runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(argv)\n} else if (mainOptions.command === 'test') {\n runTest(argv)\n} else if (mainOptions.command === 'add') {\n await runAdd(argv)\n} else {\n // For all the commands that need read project configs\n // TODO move them to their own modules\n\n // Process configs\n let processorConfig: SentioProjectConfig = { host: '', project: '', build: true, debug: false }\n // Fist step, read from project yaml file\n try {\n console.log(chalk.blue('Loading Process config'))\n // TODO correctly located sentio.yaml\n const pwd = process.cwd()\n const packageJson = path.join(pwd, 'package.json')\n if (!fs.existsSync(packageJson)) {\n console.error('package.json not found, please run this command in the root of your project')\n process.exit(1)\n }\n\n const yamlPath = path.join(pwd, 'sentio.yaml')\n if (!fs.existsSync(yamlPath)) {\n console.error('sentio.yaml not found, please create one according to: TODO docs')\n process.exit(1)\n }\n\n processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig\n if (!processorConfig.project === undefined) {\n console.error('Config yaml must have contain a valid project identifier')\n process.exit(1)\n }\n if (processorConfig.build === undefined) {\n processorConfig.build = true\n }\n if (!processorConfig.host) {\n processorConfig.host = 'prod'\n }\n if (processorConfig.debug === undefined) {\n processorConfig.debug = false\n }\n\n // if (!processorConfig.source) {\n // processorConfig.source = 'src/processor.ts'\n // }\n // if (!processorConfig.targets) {\n // console.warn('targets is not defined, use EVM as the default target')\n // processorConfig.targets = []\n // }\n // if (processorConfig.targets.length === 0) {\n // // By default evm\n // processorConfig.targets.push({ chain: EVM })\n // }\n } catch (e) {\n console.error(e)\n process.exit(1)\n }\n\n if (mainOptions.command === 'upload') {\n await runUpload(processorConfig, argv)\n } else if (mainOptions.command === 'build') {\n await buildProcessorWithArgs(argv)\n } else if (mainOptions.command === 'gen') {\n await buildProcessor(true, [])\n } else {\n usage()\n }\n}\n\nfunction usage() {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Manage your project files to Sentio.',\n },\n {\n header: 'Usage',\n content: [\n 'sentio <command> --help\\t\\tshow detail usage of specific command',\n 'sentio login\\t\\t\\t\\tlogin to sentio',\n 'sentio create\\t\\t\\t\\tcreate a template project',\n 'sentio add\\t\\t\\t\\tadd contract ABI to the project',\n 'sentio upload\\t\\t\\t\\tbuild and upload processor to sentio',\n 'sentio gen\\t\\t\\t\\tgenerate abi',\n 'sentio build\\t\\t\\t\\tgenerate abi and build',\n 'sentio test\\t\\t\\t\\trun tests',\n 'sentio version\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
|
package/lib/commands/build.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export declare const buildOptionDefinitions: ({
|
|
|
12
12
|
})[];
|
|
13
13
|
export declare function buildProcessorWithArgs(argv: string[]): Promise<void>;
|
|
14
14
|
export declare function buildProcessor(onlyGen: boolean, options: commandLineArgs.CommandLineOptions): Promise<void>;
|
|
15
|
+
export declare function codegen(): Promise<void>;
|
package/lib/commands/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,eAAe,MAAM,mBAAm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AAC,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 * as process from 'process'\nimport { getPackageRoot } from '../utils.js'\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\n\nexport const buildOptionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'skip-gen',\n type: Boolean,\n description: 'Skip code generation.',\n },\n {\n name: 'skip-deps',\n type: Boolean,\n description: 'Skip dependency enforce.',\n },\n]\n\nexport async function buildProcessorWithArgs(argv: string[]) {\n const options = commandLineArgs(buildOptionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Create a template project',\n content: 'sentio create <name>',\n },\n {\n header: 'Options',\n optionList: buildOptionDefinitions,\n },\n ])\n\n if (options.help) {\n console.log(usage)\n process.exit(0)\n }\n await buildProcessor(false, options)\n}\n\nexport async function buildProcessor(onlyGen: boolean, options: commandLineArgs.CommandLineOptions) {\n if (!options['skip-deps'] && !onlyGen) {\n await installDeps()\n }\n\n if (!options['skip-gen']) {\n await codegen()\n }\n\n if (!onlyGen) {\n let tsupConfig: string\n try {\n tsupConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts')\n } catch (e) {\n console.error(chalk.red(\"Wrong CLI version for sdk, can't find tsup.config.ts\"))\n process.exit(1)\n }\n\n const tsup = path.resolve(getPackageRoot('tsup'), 'dist', 'cli-default.js')\n // await execStep('yarn tsc -p .', 'Compile')\n await execStep(`node ${tsup} --config=${tsupConfig}`, 'Packaging')\n\n const dir = fs.readdirSync(path.join(process.cwd(), 'dist'))\n const generated = dir.filter((d) => d.endsWith('.js')).length\n if (generated < 0) {\n console.error(chalk.red('No filed generated, please check if your processor.ts file'))\n process.exit(1)\n }\n if (generated > 1) {\n console.error(\n chalk.red('Packing failed: '),\n `Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:\nimport('mine.js')\nto\nimport 'mine.js'\n`\n )\n }\n }\n}\n\nexport async function codegen() {\n const outputBase = path.resolve('src', 'types')\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/eth/codegen')\n let input = path.resolve('abis', 'eth')\n let output = path.resolve(outputBase, 'eth')\n if (!fs.existsSync(input)) {\n input = path.resolve('abis', 'evm')\n output = path.resolve(outputBase, 'eth')\n }\n // @ts-ignore dynamic import\n await codegen.codegen(input, output)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/solana/codegen')\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'solana'), path.resolve(outputBase, 'solana'))\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/aptos/codegen')\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'aptos'), path.resolve(outputBase, 'aptos'))\n } catch (e) {\n console.error('code gen error', e)\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runAdd(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import commandLineArgs from 'command-line-args';
|
|
2
|
+
import commandLineUsage from 'command-line-usage';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { codegen } from './build.js';
|
|
7
|
+
// @ts-ignore no types
|
|
8
|
+
import { init } from 'etherscan-api';
|
|
9
|
+
import { AptosClient } from 'aptos-sdk';
|
|
10
|
+
import * as console from 'console';
|
|
11
|
+
import * as process from 'process';
|
|
12
|
+
export async function runAdd(argv) {
|
|
13
|
+
const optionDefinitions = [
|
|
14
|
+
{
|
|
15
|
+
name: 'help',
|
|
16
|
+
alias: 'h',
|
|
17
|
+
type: Boolean,
|
|
18
|
+
description: 'Display this usage guide.',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'chain',
|
|
22
|
+
alias: 'c',
|
|
23
|
+
type: String,
|
|
24
|
+
defaultValue: 'homestead',
|
|
25
|
+
description: 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, or apots, aptos/testnet',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'address',
|
|
29
|
+
defaultOption: true,
|
|
30
|
+
description: 'Address of the contract',
|
|
31
|
+
type: String,
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
const options = commandLineArgs(optionDefinitions, { argv });
|
|
35
|
+
const usage = commandLineUsage([
|
|
36
|
+
{
|
|
37
|
+
header: "Add contract's ABI to the project",
|
|
38
|
+
content: 'sentio add [--chain <chain>] <address>',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
header: 'Options',
|
|
42
|
+
optionList: optionDefinitions,
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
45
|
+
if (options.help || !options.address) {
|
|
46
|
+
console.log(usage);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const chain = options['chain'].toLowerCase();
|
|
50
|
+
const address = options.address;
|
|
51
|
+
if (!address.startsWith('0x')) {
|
|
52
|
+
console.error(chalk.red('Address must start with 0x'));
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
let ethApi;
|
|
56
|
+
let aptosClient;
|
|
57
|
+
switch (chain) {
|
|
58
|
+
case 'aptos':
|
|
59
|
+
aptosClient = new AptosClient('https://mainnet.aptoslabs.com/');
|
|
60
|
+
break;
|
|
61
|
+
case 'aptos/testnet':
|
|
62
|
+
aptosClient = new AptosClient('https://testnet.aptoslabs.com/');
|
|
63
|
+
break;
|
|
64
|
+
case 'mainnet':
|
|
65
|
+
case 'homestead':
|
|
66
|
+
ethApi = init();
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
ethApi = init(undefined, chain);
|
|
70
|
+
}
|
|
71
|
+
const baseErrMsg = chalk.red(`Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`);
|
|
72
|
+
if (aptosClient) {
|
|
73
|
+
try {
|
|
74
|
+
const module = await aptosClient.getAccountModules(address);
|
|
75
|
+
writeToDirectory(JSON.stringify(module), chain, address);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
console.error(baseErrMsg, e);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (ethApi) {
|
|
83
|
+
try {
|
|
84
|
+
const resp = await ethApi.contract.getabi(address);
|
|
85
|
+
if (resp.status !== '1') {
|
|
86
|
+
throw Error(resp.message);
|
|
87
|
+
}
|
|
88
|
+
writeToDirectory(resp.result, chain, address);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.error(baseErrMsg, e);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Run gen
|
|
96
|
+
await codegen();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function writeToDirectory(data, chain, name) {
|
|
100
|
+
const output = path.join('abis', chain, name + '.json');
|
|
101
|
+
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
102
|
+
fs.writeFileSync(output, data);
|
|
103
|
+
console.log(chalk.green('ABI has been downloaded to', output));
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=run-add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-add.js","sourceRoot":"","sources":["../../src/commands/run-add.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,sBAAsB;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAElC,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAc;IACzC,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,MAAM;YACZ,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,gGAAgG;SAC9G;QACD;YACE,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,MAAM;SACb;KACF,CAAA;IAED,MAAM,OAAO,GAAG,eAAe,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5D,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B;YACE,MAAM,EAAE,mCAAmC;YAC3C,OAAO,EAAE,wCAAwC;SAClD;QAC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AC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;gBAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;aAChB;SACF;QAED,IAAI,MAAM,EAAE;YACV,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;gBAClD,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,EAAE;oBACvB,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;iBAC1B;gBACD,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;aAC9C;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;gBAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;aAChB;SACF;QACD,UAAU;QACV,MAAM,OAAO,EAAE,CAAA;KAChB;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa,EAAE,IAAY;IACjE,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,CAAA;IACvD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACvD,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC,CAAA;AAChE,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport chalk from 'chalk'\n\nimport { codegen } from './build.js'\n\n// @ts-ignore no types\nimport { init } from 'etherscan-api'\nimport { AptosClient } from 'aptos-sdk'\nimport * as console from 'console'\nimport * as process from 'process'\n\nexport async function runAdd(argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'chain',\n alias: 'c',\n type: String,\n defaultValue: 'homestead',\n description: 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, or apots, aptos/testnet',\n },\n {\n name: 'address',\n defaultOption: true,\n description: 'Address of the contract',\n type: String,\n },\n ]\n\n const options = commandLineArgs(optionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: \"Add contract's ABI to the project\",\n content: 'sentio add [--chain <chain>] <address>',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n\n if (options.help || !options.address) {\n console.log(usage)\n } else {\n const chain: string = options['chain'].toLowerCase()\n const address: string = options.address\n if (!address.startsWith('0x')) {\n console.error(chalk.red('Address must start with 0x'))\n process.exit(1)\n }\n\n let ethApi\n let aptosClient: AptosClient | undefined\n switch (chain) {\n case 'aptos':\n aptosClient = new AptosClient('https://mainnet.aptoslabs.com/')\n break\n case 'aptos/testnet':\n aptosClient = new AptosClient('https://testnet.aptoslabs.com/')\n break\n case 'mainnet':\n case 'homestead':\n ethApi = init()\n break\n default:\n ethApi = init(undefined, chain)\n }\n\n const baseErrMsg = chalk.red(\n `Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`\n )\n if (aptosClient) {\n try {\n const module = await aptosClient.getAccountModules(address)\n writeToDirectory(JSON.stringify(module), chain, address)\n } catch (e) {\n console.error(baseErrMsg, e)\n process.exit(1)\n }\n }\n\n if (ethApi) {\n try {\n const resp = await ethApi.contract.getabi(address)\n if (resp.status !== '1') {\n throw Error(resp.message)\n }\n writeToDirectory(resp.result, chain, address)\n } catch (e) {\n console.error(baseErrMsg, e)\n process.exit(1)\n }\n }\n // Run gen\n await codegen()\n }\n}\n\nfunction writeToDirectory(data: string, chain: string, name: string) {\n const output = path.join('abis', chain, name + '.json')\n fs.mkdirSync(path.dirname(output), { recursive: true })\n fs.writeFileSync(output, data)\n console.log(chalk.green('ABI has been downloaded to', output))\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "2.0
|
|
6
|
+
"version": "2.1.0",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"compile": "tsc",
|
|
9
9
|
"build": "yarn compile",
|
|
@@ -13,23 +13,25 @@
|
|
|
13
13
|
"pub": "yarn build && yarn publish --no-git-tag-version"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@jest/types": "^29.4.1",
|
|
16
17
|
"@types/jest": "^29.0.0",
|
|
18
|
+
"@types/node": "^18.11.18",
|
|
19
|
+
"aptos-sdk": "npm:@sentio/aptos@^1.6.0",
|
|
20
|
+
"chalk": "^5.2.0",
|
|
17
21
|
"command-line-args": "^5.2.1",
|
|
18
22
|
"command-line-usage": "^6.1.3",
|
|
23
|
+
"etherscan-api": "^10.3.0",
|
|
19
24
|
"express": "^4.18.2",
|
|
20
25
|
"form-data": "^4.0.0",
|
|
21
26
|
"fs-extra": "^11.0.0",
|
|
27
|
+
"jest": "^29.4.1",
|
|
22
28
|
"js-yaml": "^4.1.0",
|
|
23
29
|
"latest-version": "^7.0.0",
|
|
24
30
|
"node-fetch": "^3.3.0",
|
|
25
31
|
"open": "^8.4.0",
|
|
26
|
-
"tsup": "npm:@sentio/tsup@^6.5.0",
|
|
27
|
-
"chalk": "^5.2.0",
|
|
28
|
-
"jest": "^29.4.1",
|
|
29
32
|
"ts-jest": "^29.0.5",
|
|
30
|
-
"@jest/types": "^29.4.1",
|
|
31
33
|
"ts-node": "^10.9.1",
|
|
32
|
-
"
|
|
34
|
+
"tsup": "npm:@sentio/tsup@^6.5.0"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@types/command-line-args": "^5.2.0",
|
package/src/cli.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { runVersion } from './commands/run-version.js'
|
|
|
14
14
|
import { runLogin } from './commands/run-login.js'
|
|
15
15
|
import { runUpload } from './commands/run-upload.js'
|
|
16
16
|
import { runTest } from './commands/run-test.js'
|
|
17
|
+
import { runAdd } from './commands/run-add.js'
|
|
17
18
|
|
|
18
19
|
const mainDefinitions = [{ name: 'command', defaultOption: true }]
|
|
19
20
|
const mainOptions = commandLineArgs(mainDefinitions, {
|
|
@@ -33,6 +34,8 @@ if (mainOptions.command === 'login') {
|
|
|
33
34
|
runVersion(argv)
|
|
34
35
|
} else if (mainOptions.command === 'test') {
|
|
35
36
|
runTest(argv)
|
|
37
|
+
} else if (mainOptions.command === 'add') {
|
|
38
|
+
await runAdd(argv)
|
|
36
39
|
} else {
|
|
37
40
|
// For all the commands that need read project configs
|
|
38
41
|
// TODO move them to their own modules
|
|
@@ -110,6 +113,7 @@ function usage() {
|
|
|
110
113
|
'sentio <command> --help\t\tshow detail usage of specific command',
|
|
111
114
|
'sentio login\t\t\t\tlogin to sentio',
|
|
112
115
|
'sentio create\t\t\t\tcreate a template project',
|
|
116
|
+
'sentio add\t\t\t\tadd contract ABI to the project',
|
|
113
117
|
'sentio upload\t\t\t\tbuild and upload processor to sentio',
|
|
114
118
|
'sentio gen\t\t\t\tgenerate abi',
|
|
115
119
|
'sentio build\t\t\t\tgenerate abi and build',
|
package/src/commands/build.ts
CHANGED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import commandLineArgs from 'command-line-args'
|
|
2
|
+
import commandLineUsage from 'command-line-usage'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import fs from 'fs-extra'
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
|
|
7
|
+
import { codegen } from './build.js'
|
|
8
|
+
|
|
9
|
+
// @ts-ignore no types
|
|
10
|
+
import { init } from 'etherscan-api'
|
|
11
|
+
import { AptosClient } from 'aptos-sdk'
|
|
12
|
+
import * as console from 'console'
|
|
13
|
+
import * as process from 'process'
|
|
14
|
+
|
|
15
|
+
export async function runAdd(argv: string[]) {
|
|
16
|
+
const optionDefinitions = [
|
|
17
|
+
{
|
|
18
|
+
name: 'help',
|
|
19
|
+
alias: 'h',
|
|
20
|
+
type: Boolean,
|
|
21
|
+
description: 'Display this usage guide.',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'chain',
|
|
25
|
+
alias: 'c',
|
|
26
|
+
type: String,
|
|
27
|
+
defaultValue: 'homestead',
|
|
28
|
+
description: 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, or apots, aptos/testnet',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'address',
|
|
32
|
+
defaultOption: true,
|
|
33
|
+
description: 'Address of the contract',
|
|
34
|
+
type: String,
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
const options = commandLineArgs(optionDefinitions, { argv })
|
|
39
|
+
const usage = commandLineUsage([
|
|
40
|
+
{
|
|
41
|
+
header: "Add contract's ABI to the project",
|
|
42
|
+
content: 'sentio add [--chain <chain>] <address>',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
header: 'Options',
|
|
46
|
+
optionList: optionDefinitions,
|
|
47
|
+
},
|
|
48
|
+
])
|
|
49
|
+
|
|
50
|
+
if (options.help || !options.address) {
|
|
51
|
+
console.log(usage)
|
|
52
|
+
} else {
|
|
53
|
+
const chain: string = options['chain'].toLowerCase()
|
|
54
|
+
const address: string = options.address
|
|
55
|
+
if (!address.startsWith('0x')) {
|
|
56
|
+
console.error(chalk.red('Address must start with 0x'))
|
|
57
|
+
process.exit(1)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let ethApi
|
|
61
|
+
let aptosClient: AptosClient | undefined
|
|
62
|
+
switch (chain) {
|
|
63
|
+
case 'aptos':
|
|
64
|
+
aptosClient = new AptosClient('https://mainnet.aptoslabs.com/')
|
|
65
|
+
break
|
|
66
|
+
case 'aptos/testnet':
|
|
67
|
+
aptosClient = new AptosClient('https://testnet.aptoslabs.com/')
|
|
68
|
+
break
|
|
69
|
+
case 'mainnet':
|
|
70
|
+
case 'homestead':
|
|
71
|
+
ethApi = init()
|
|
72
|
+
break
|
|
73
|
+
default:
|
|
74
|
+
ethApi = init(undefined, chain)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const baseErrMsg = chalk.red(
|
|
78
|
+
`Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`
|
|
79
|
+
)
|
|
80
|
+
if (aptosClient) {
|
|
81
|
+
try {
|
|
82
|
+
const module = await aptosClient.getAccountModules(address)
|
|
83
|
+
writeToDirectory(JSON.stringify(module), chain, address)
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error(baseErrMsg, e)
|
|
86
|
+
process.exit(1)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (ethApi) {
|
|
91
|
+
try {
|
|
92
|
+
const resp = await ethApi.contract.getabi(address)
|
|
93
|
+
if (resp.status !== '1') {
|
|
94
|
+
throw Error(resp.message)
|
|
95
|
+
}
|
|
96
|
+
writeToDirectory(resp.result, chain, address)
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error(baseErrMsg, e)
|
|
99
|
+
process.exit(1)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Run gen
|
|
103
|
+
await codegen()
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function writeToDirectory(data: string, chain: string, name: string) {
|
|
108
|
+
const output = path.join('abis', chain, name + '.json')
|
|
109
|
+
fs.mkdirSync(path.dirname(output), { recursive: true })
|
|
110
|
+
fs.writeFileSync(output, data)
|
|
111
|
+
console.log(chalk.green('ABI has been downloaded to', output))
|
|
112
|
+
}
|