@prosopo/scripts 1.0.2 → 2.0.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/README.md +4 -3
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +47 -168
- package/dist/cli/index.js.map +1 -1
- package/dist/contract/import.d.ts.map +1 -1
- package/dist/contract/import.js +62 -120
- package/dist/contract/import.js.map +1 -1
- package/dist/contract/index.d.ts +1 -2
- package/dist/contract/index.d.ts.map +1 -1
- package/dist/contract/index.js +1 -2
- package/dist/contract/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/scripts/addCopyrightNotice.js +43 -43
- package/dist/scripts/addCopyrightNotice.js.map +1 -1
- package/dist/scripts/bytesToHex.js +3 -5
- package/dist/scripts/bytesToHex.js.map +1 -1
- package/dist/scripts/convertAccount.js +4 -4
- package/dist/scripts/convertAccount.js.map +1 -1
- package/dist/scripts/encodeDecode.js +51 -28
- package/dist/scripts/encodeDecode.js.map +1 -1
- package/dist/scripts/generateMnemonic.js +6 -6
- package/dist/scripts/generateMnemonic.js.map +1 -1
- package/dist/scripts/getBlock.js +3 -3
- package/dist/scripts/getBlock.js.map +1 -1
- package/dist/scripts/getContractInfoOf.js +15 -15
- package/dist/scripts/getContractInfoOf.js.map +1 -1
- package/dist/scripts/getExistentialDeposit.js +9 -9
- package/dist/scripts/getExistentialDeposit.js.map +1 -1
- package/dist/scripts/getRandomProvider.js +9 -12
- package/dist/scripts/getRandomProvider.js.map +1 -1
- package/dist/scripts/hash.js +6 -6
- package/dist/scripts/hash.js.map +1 -1
- package/dist/scripts/hexToBytes.js +2 -2
- package/dist/scripts/hexToBytes.js.map +1 -1
- package/dist/scripts/setVersion.d.ts +1 -1
- package/dist/scripts/setVersion.d.ts.map +1 -1
- package/dist/scripts/setVersion.js +41 -40
- package/dist/scripts/setVersion.js.map +1 -1
- package/dist/scripts/sign.js +19 -19
- package/dist/scripts/sign.js.map +1 -1
- package/dist/setup/index.d.ts +2 -4
- package/dist/setup/index.d.ts.map +1 -1
- package/dist/setup/index.js +2 -4
- package/dist/setup/index.js.map +1 -1
- package/dist/setup/provider.d.ts +2 -3
- package/dist/setup/provider.d.ts.map +1 -1
- package/dist/setup/provider.js +8 -73
- package/dist/setup/provider.js.map +1 -1
- package/dist/setup/setup.d.ts.map +1 -1
- package/dist/setup/setup.js +45 -49
- package/dist/setup/setup.js.map +1 -1
- package/dist/util/exec.d.ts.map +1 -1
- package/dist/util/exec.js +8 -8
- package/dist/util/exec.js.map +1 -1
- package/dist/util/fluxLogDappDetails.js +4 -4
- package/dist/util/fluxLogDappDetails.js.map +1 -1
- package/dist/util/index.d.ts +4 -4
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +4 -4
- package/dist/util/index.js.map +1 -1
- package/dist/util/loadContractFiles.d.ts +1 -1
- package/dist/util/loadContractFiles.d.ts.map +1 -1
- package/dist/util/loadContractFiles.js +15 -15
- package/dist/util/loadContractFiles.js.map +1 -1
- package/dist/util/updateEnv.d.ts +1 -1
- package/dist/util/updateEnv.d.ts.map +1 -1
- package/dist/util/updateEnv.js +18 -18
- package/dist/util/updateEnv.js.map +1 -1
- package/env.staging +2 -0
- package/package.json +67 -73
- package/dist/contract/deploy/dapp.d.ts +0 -3
- package/dist/contract/deploy/dapp.d.ts.map +0 -1
- package/dist/contract/deploy/dapp.js +0 -26
- package/dist/contract/deploy/dapp.js.map +0 -1
- package/dist/contract/deploy/index.d.ts +0 -3
- package/dist/contract/deploy/index.d.ts.map +0 -1
- package/dist/contract/deploy/index.js +0 -3
- package/dist/contract/deploy/index.js.map +0 -1
- package/dist/contract/deploy/protocol.d.ts +0 -3
- package/dist/contract/deploy/protocol.d.ts.map +0 -1
- package/dist/contract/deploy/protocol.js +0 -53
- package/dist/contract/deploy/protocol.js.map +0 -1
- package/dist/contract/fundDapps.d.ts +0 -21
- package/dist/contract/fundDapps.d.ts.map +0 -1
- package/dist/contract/fundDapps.js +0 -50
- package/dist/contract/fundDapps.js.map +0 -1
- package/dist/contract/sources/dapp/411053b7ec79cc77f5ec9f5eb18610b24daaaaf0/dapp.json +0 -648
- package/dist/contract/transferContract.d.ts +0 -6
- package/dist/contract/transferContract.d.ts.map +0 -1
- package/dist/contract/transferContract.js +0 -142
- package/dist/contract/transferContract.js.map +0 -1
- package/dist/scripts/getStorage.d.ts +0 -2
- package/dist/scripts/getStorage.d.ts.map +0 -1
- package/dist/scripts/getStorage.js +0 -25
- package/dist/scripts/getStorage.js.map +0 -1
- package/dist/scripts/sendFunds.d.ts +0 -2
- package/dist/scripts/sendFunds.d.ts.map +0 -1
- package/dist/scripts/sendFunds.js +0 -22
- package/dist/scripts/sendFunds.js.map +0 -1
- package/dist/setup/dapp.d.ts +0 -5
- package/dist/setup/dapp.d.ts.map +0 -1
- package/dist/setup/dapp.js +0 -65
- package/dist/setup/dapp.js.map +0 -1
- package/dist/setup/funds.d.ts +0 -8
- package/dist/setup/funds.d.ts.map +0 -1
- package/dist/setup/funds.js +0 -50
- package/dist/setup/funds.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ This package contains the scripts and configuration for setting up a development
|
|
|
4
4
|
|
|
5
5
|
## Prerequisites
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- A unix-style environment (Linux, MacOS, WSL2)
|
|
8
|
+
- [Docker](https://docs.docker.com/get-docker/)
|
|
9
|
+
- [Node.js](https://nodejs.org/en/download/)
|
|
10
10
|
|
|
11
11
|
## Dev Setup
|
|
12
12
|
|
|
@@ -131,6 +131,7 @@ This is shorthand for the following command:
|
|
|
131
131
|
```bash
|
|
132
132
|
npm run -w @prosopo/scripts cli deploy_protocol --update_env
|
|
133
133
|
```
|
|
134
|
+
|
|
134
135
|
Specify the current working directory if you are running from a different location.
|
|
135
136
|
|
|
136
137
|
```bash
|
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AA8BA,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,iBAqF/C"}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,208 +1,87 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
import { updateEnvFiles } from '../util/index.js';
|
|
16
|
-
import path from 'path';
|
|
17
|
-
import setVersion from '../scripts/setVersion.js';
|
|
18
|
-
import yargs from 'yargs';
|
|
19
|
-
import z from 'zod';
|
|
20
|
-
const rootDir = path.resolve('.');
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { isHex } from "@polkadot/util";
|
|
3
|
+
import { getEnv, loadEnv } from "@prosopo/cli";
|
|
4
|
+
import { LogLevel, getLogger } from "@prosopo/common";
|
|
5
|
+
import { getLogLevel } from "@prosopo/common";
|
|
6
|
+
import { getScriptsPkgDir } from "@prosopo/config";
|
|
7
|
+
import { decodeProcaptchaOutput, encodeProcaptchaOutput } from "@prosopo/types";
|
|
8
|
+
import yargs from "yargs";
|
|
9
|
+
import { hideBin } from "yargs/helpers";
|
|
10
|
+
import { importContract } from "../contract/index.js";
|
|
11
|
+
import setVersion from "../scripts/setVersion.js";
|
|
12
|
+
import { setup } from "../setup/index.js";
|
|
13
|
+
import { exec } from "../util/index.js";
|
|
14
|
+
const rootDir = path.resolve(".");
|
|
21
15
|
loadEnv(rootDir);
|
|
22
|
-
const TransferNetworkSchema = z.object({
|
|
23
|
-
network: z.string(),
|
|
24
|
-
address: z.string(),
|
|
25
|
-
});
|
|
26
16
|
export async function processArgs(args) {
|
|
27
|
-
const parsed = await yargs(hideBin(args)).option(
|
|
28
|
-
describe:
|
|
17
|
+
const parsed = await yargs(hideBin(args)).option("logLevel", {
|
|
18
|
+
describe: "set log level",
|
|
29
19
|
choices: Object.keys(LogLevel.enum),
|
|
30
20
|
}).argv;
|
|
31
|
-
const log = getLogger(getLogLevel(parsed.logLevel),
|
|
21
|
+
const log = getLogger(getLogLevel(parsed.logLevel), "CLI");
|
|
32
22
|
await yargs(hideBin(args))
|
|
33
|
-
.usage(
|
|
34
|
-
.command(
|
|
35
|
-
.option('update_env', {
|
|
36
|
-
type: 'boolean',
|
|
37
|
-
demandOption: false,
|
|
38
|
-
desc: 'Update env files with the new contract address',
|
|
39
|
-
default: false,
|
|
40
|
-
})
|
|
41
|
-
.option('deployer', {
|
|
42
|
-
type: 'string',
|
|
43
|
-
demandOption: false,
|
|
44
|
-
desc: `The account prefix that will deploy the contract. Specifying PROVIDER will cause the
|
|
45
|
-
script to look for PROVIDER_JSON in the env file. Specifying DEPLOYER will cause the script to
|
|
46
|
-
look for DEPLOYER_JSON in the env file. Defaults to undefined.`,
|
|
47
|
-
default: undefined,
|
|
48
|
-
})
|
|
49
|
-
.option('cwd', {
|
|
50
|
-
type: 'string',
|
|
51
|
-
demandOption: false,
|
|
52
|
-
desc: `The working directory from which env files will be updated`,
|
|
53
|
-
default: undefined,
|
|
54
|
-
}), async (argv) => {
|
|
55
|
-
const protocolContractAddress = await deployProtocol(process.env.PROSOPO_CAPTCHA_WASM_PATH, process.env.PROSOPO_CAPTCHA_ABI_PATH, argv.deployer);
|
|
56
|
-
log.info('contract address', protocolContractAddress);
|
|
57
|
-
if (argv.update_env) {
|
|
58
|
-
await updateEnvFiles(['PROSOPO_CONTRACT_ADDRESS', 'NEXT_PUBLIC_PROSOPO_CONTRACT_ADDRESS'], protocolContractAddress.toString(), log, argv.cwd);
|
|
59
|
-
}
|
|
60
|
-
}, [])
|
|
61
|
-
.command('deploy_dapp', 'Deploy the prosopo dapp example contract', (yargs) => yargs.option('update_env', {
|
|
62
|
-
type: 'boolean',
|
|
63
|
-
demandOption: false,
|
|
64
|
-
desc: 'Update env files with the new contract address',
|
|
65
|
-
default: false,
|
|
66
|
-
}), async (argv) => {
|
|
67
|
-
const dappContractAddress = await deployDapp();
|
|
68
|
-
log.info('contract address', dappContractAddress);
|
|
69
|
-
if (argv.update_env) {
|
|
70
|
-
await updateEnvFiles(['PROSOPO_SITE_KEY', 'NEXT_PUBLIC_PROSOPO_SITE_KEY'], dappContractAddress.toString(), log);
|
|
71
|
-
}
|
|
72
|
-
}, [])
|
|
73
|
-
.command('create_env_files', 'Copies the env.xyz files to .env.xyz', (yargs) => yargs, async () => {
|
|
23
|
+
.usage("Usage: $0 [global options] <command> [options]")
|
|
24
|
+
.command("create_env_files", "Copies the env.xyz files to .env.xyz", (yargs) => yargs, async () => {
|
|
74
25
|
const env = getEnv();
|
|
75
26
|
const scripts = getScriptsPkgDir();
|
|
76
27
|
await exec(`cp -v ${scripts}/env.${env} ${scripts}/.env.${env}`);
|
|
77
28
|
}, [])
|
|
78
29
|
.command({
|
|
79
|
-
command:
|
|
80
|
-
describe:
|
|
81
|
-
builder: (yargs) => yargs.option(
|
|
82
|
-
type:
|
|
30
|
+
command: "setup",
|
|
31
|
+
describe: "Setup the development environment by registering a provider, staking, loading a data set and then registering a dapp and staking.",
|
|
32
|
+
builder: (yargs) => yargs.option("force", {
|
|
33
|
+
type: "boolean",
|
|
83
34
|
demandOption: false,
|
|
84
|
-
desc:
|
|
35
|
+
desc: "Force provider re-registration and dataset setup",
|
|
85
36
|
}),
|
|
86
37
|
handler: async (argv) => {
|
|
87
|
-
log.info(
|
|
38
|
+
log.info("Running setup scripts");
|
|
88
39
|
await setup(!!argv.force);
|
|
89
40
|
},
|
|
90
41
|
})
|
|
91
42
|
.command({
|
|
92
|
-
command:
|
|
93
|
-
describe:
|
|
43
|
+
command: "import_contract",
|
|
44
|
+
describe: "Import a contract into the contract package.",
|
|
94
45
|
builder: (yargs) => yargs
|
|
95
|
-
.option(
|
|
96
|
-
type:
|
|
46
|
+
.option("in", {
|
|
47
|
+
type: "string",
|
|
97
48
|
demandOption: true,
|
|
98
49
|
desc: "The path to the contract's abi",
|
|
99
50
|
})
|
|
100
|
-
.option(
|
|
101
|
-
type:
|
|
51
|
+
.option("out", {
|
|
52
|
+
type: "string",
|
|
102
53
|
demandOption: true,
|
|
103
|
-
desc:
|
|
54
|
+
desc: "The path to the output directory",
|
|
104
55
|
}),
|
|
105
56
|
handler: async (argv) => {
|
|
106
57
|
await importContract(argv.in, argv.out);
|
|
107
58
|
},
|
|
108
59
|
})
|
|
109
60
|
.command({
|
|
110
|
-
command:
|
|
111
|
-
describe:
|
|
112
|
-
builder: (yargs) => yargs,
|
|
113
|
-
handler: async () => {
|
|
114
|
-
const contracts = getContractNames();
|
|
115
|
-
for (const contract of contracts) {
|
|
116
|
-
const inDir = `${getProtocolDistDir()}/${contract}`;
|
|
117
|
-
await exec(`node dist/cli/index.js import_contract --in=${inDir} --out=${getContractsDir()}/${contract}/src`);
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
})
|
|
121
|
-
.command({
|
|
122
|
-
command: 'fund_dapps',
|
|
123
|
-
describe: 'Fund the dapps if they are unfunded',
|
|
124
|
-
builder: (yargs) => yargs,
|
|
125
|
-
handler: async () => {
|
|
126
|
-
const atlasUri = process.env._DEV_ONLY_ATLAS_URI;
|
|
127
|
-
fundDapps(atlasUri)
|
|
128
|
-
.then((result) => {
|
|
129
|
-
log.info(result);
|
|
130
|
-
process.exit(0);
|
|
131
|
-
})
|
|
132
|
-
.catch((e) => {
|
|
133
|
-
console.error(e);
|
|
134
|
-
process.exit(1);
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
})
|
|
138
|
-
.command({
|
|
139
|
-
command: 'transfer_contract',
|
|
140
|
-
describe: 'Transfer dapps and providers from one contract to another',
|
|
141
|
-
builder: (yargs) => yargs
|
|
142
|
-
.option('transfer-from', {
|
|
143
|
-
type: 'string',
|
|
144
|
-
demandOption: true,
|
|
145
|
-
desc: 'The name of the network and the contract address to transfer from `{ network, address }`',
|
|
146
|
-
})
|
|
147
|
-
.option('transfer-to', {
|
|
148
|
-
type: 'string',
|
|
149
|
-
demandOption: false,
|
|
150
|
-
desc: 'The name of the network and the contract address to transfer to `{ network, address }`',
|
|
151
|
-
})
|
|
152
|
-
.option('transfer-providers', {
|
|
153
|
-
type: 'boolean',
|
|
154
|
-
demandOption: true,
|
|
155
|
-
desc: 'Whether to transfer providers or not',
|
|
156
|
-
default: false,
|
|
157
|
-
})
|
|
158
|
-
.option('transfer-dapps', {
|
|
159
|
-
type: 'boolean',
|
|
160
|
-
demandOption: true,
|
|
161
|
-
desc: 'Whether to transfer dapps or not',
|
|
162
|
-
default: false,
|
|
163
|
-
}),
|
|
164
|
-
handler: async (argv) => {
|
|
165
|
-
log.debug(argv);
|
|
166
|
-
const atlasUri = process.env._DEV_ONLY_ATLAS_URI;
|
|
167
|
-
const transferFrom = TransferNetworkSchema.parse(JSON.parse(argv.transferFrom));
|
|
168
|
-
const networks = getNetworks();
|
|
169
|
-
const transferFromNetworkName = NetworkNamesSchema.parse(transferFrom.network);
|
|
170
|
-
const transferFromNetwork = NetworkConfigSchema.parse(get(networks, transferFrom.network));
|
|
171
|
-
transferFromNetwork.contract.address = transferFrom.address;
|
|
172
|
-
let transferToNetwork = undefined;
|
|
173
|
-
let transferToNetworkName = undefined;
|
|
174
|
-
if (argv.transferTo !== undefined) {
|
|
175
|
-
const transferTo = TransferNetworkSchema.parse(JSON.parse(argv.transferFrom));
|
|
176
|
-
transferToNetwork = NetworkConfigSchema.parse(get(networks, transferTo.network));
|
|
177
|
-
transferToNetwork.contract.address = transferFrom.address;
|
|
178
|
-
transferToNetworkName = NetworkNamesSchema.parse(transferToNetworkName);
|
|
179
|
-
}
|
|
180
|
-
const transferConfig = { dapps: argv.transferDapps, providers: argv.transferProviders };
|
|
181
|
-
await transferContract(transferFromNetworkName, transferFromNetwork, transferConfig, transferToNetworkName, transferToNetwork, atlasUri);
|
|
182
|
-
},
|
|
183
|
-
})
|
|
184
|
-
.command({
|
|
185
|
-
command: 'version',
|
|
186
|
-
describe: 'Set the version of packages',
|
|
187
|
-
builder: (yargs) => yargs.option('v', { type: 'string', demandOption: true }),
|
|
61
|
+
command: "version",
|
|
62
|
+
describe: "Set the version of packages",
|
|
63
|
+
builder: (yargs) => yargs.option("v", { type: "string", demandOption: true }),
|
|
188
64
|
handler: async (argv) => {
|
|
189
65
|
await setVersion(String(argv.v));
|
|
190
66
|
},
|
|
191
67
|
})
|
|
192
68
|
.command({
|
|
193
|
-
command:
|
|
194
|
-
describe:
|
|
195
|
-
builder: (yargs) => yargs.positional(
|
|
196
|
-
describe:
|
|
197
|
-
type:
|
|
69
|
+
command: "token <token>",
|
|
70
|
+
describe: "Encode or Decode a Procaptcha token to the JSON output format",
|
|
71
|
+
builder: (yargs) => yargs.positional("token", {
|
|
72
|
+
describe: "a Procaptcha token to decode",
|
|
73
|
+
type: "string",
|
|
198
74
|
demandOption: true,
|
|
199
75
|
}),
|
|
200
76
|
handler: async (argv) => {
|
|
201
|
-
if (!isHex(argv.
|
|
202
|
-
log.
|
|
203
|
-
|
|
77
|
+
if (!isHex(argv.token)) {
|
|
78
|
+
log.debug("Encoding token to hex");
|
|
79
|
+
log.info(encodeProcaptchaOutput(JSON.parse(argv.token)));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
log.debug("Decoding token from hex");
|
|
83
|
+
log.info(decodeProcaptchaOutput(argv.token));
|
|
204
84
|
}
|
|
205
|
-
log.info(decodeProcaptchaOutput(argv.tokenHex));
|
|
206
85
|
},
|
|
207
86
|
}).argv;
|
|
208
87
|
}
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAc/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAElC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEjB,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAc;IAC/C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE;QAC5D,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;KACnC,CAAC,CAAC,IAAI,CAAC;IAER,MAAM,GAAG,GAAG,SAAS,CAAC,WAAW,CAA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C,OAAO,CAAC,IAAI,CAAC;KACvB,IAAI,CAAC,GAAG,EAAE;IACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAChB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/contract/import.ts"],"names":[],"mappings":"AAwCA,iBAAe,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBA+
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/contract/import.ts"],"names":[],"mappings":"AAwCA,iBAAe,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBA+KrE;AAuBD,eAAe,cAAc,CAAC"}
|
package/dist/contract/import.js
CHANGED
|
@@ -1,91 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ProsopoEnvError } from "@prosopo/common";
|
|
4
|
+
import { lodash } from "@prosopo/util/lodash";
|
|
5
|
+
import { exec } from "../util/index.js";
|
|
6
6
|
const replaceExtension = (file, ext) => {
|
|
7
|
-
const parts = file.split(
|
|
7
|
+
const parts = file.split(".");
|
|
8
8
|
parts.pop();
|
|
9
9
|
parts.push(ext);
|
|
10
|
-
return parts.join(
|
|
10
|
+
return parts.join(".");
|
|
11
11
|
};
|
|
12
12
|
async function importContract(pathToAbis, pathToOutput) {
|
|
13
13
|
const verbose = false;
|
|
14
14
|
pathToAbis = path.relative(process.cwd(), pathToAbis);
|
|
15
15
|
pathToOutput = path.relative(process.cwd(), pathToOutput);
|
|
16
16
|
if (!fs.existsSync(pathToAbis))
|
|
17
|
-
throw new ProsopoEnvError(
|
|
17
|
+
throw new ProsopoEnvError("FS.FILE_NOT_FOUND", {
|
|
18
18
|
context: { error: `Path to ABIs does not exist: ${pathToAbis}` },
|
|
19
19
|
});
|
|
20
20
|
await exec(`mkdir -p ${pathToOutput}`);
|
|
21
|
-
const cmd = `npx typechain-polkadot --in ${pathToAbis} --out ${pathToOutput}`;
|
|
21
|
+
const cmd = `npx @prosopo/typechain-polkadot --in ${pathToAbis} --out ${pathToOutput}`;
|
|
22
22
|
await exec(cmd);
|
|
23
23
|
const name = path.basename(pathToAbis);
|
|
24
24
|
await exec(`cp ${pathToAbis}/${name}.json ${pathToOutput}/${name}.json`);
|
|
25
|
-
const walk = (dir) => {
|
|
26
|
-
const files = fs.readdirSync(dir);
|
|
27
|
-
for (const file of files) {
|
|
28
|
-
const filePath = path.join(dir, file);
|
|
29
|
-
const stat = fs.statSync(filePath);
|
|
30
|
-
if (stat.isDirectory()) {
|
|
31
|
-
walk(filePath);
|
|
32
|
-
}
|
|
33
|
-
else if (filePath.endsWith('.ts')) {
|
|
34
|
-
const regex = /(import(?:(?!from).)+from\s+)(['"]\.[./\w-]+['"])(\s+assert\s+\{[^}]*\})?/gs;
|
|
35
|
-
const fileContents = fs.readFileSync(filePath, 'utf8');
|
|
36
|
-
let replaced = fileContents.replace(regex, (match, p1, p2, p3) => {
|
|
37
|
-
const start = p1.toString();
|
|
38
|
-
const srcQuoted = p2.toString();
|
|
39
|
-
const src = getPath(srcQuoted);
|
|
40
|
-
const extension = getExtension(src);
|
|
41
|
-
if (verbose)
|
|
42
|
-
console.log(`src: ${src}`);
|
|
43
|
-
if (verbose)
|
|
44
|
-
console.log(`extension: ${extension}`);
|
|
45
|
-
if (verbose)
|
|
46
|
-
console.log('p3: ', p3);
|
|
47
|
-
let result = '';
|
|
48
|
-
if (extension === 'js') {
|
|
49
|
-
return match;
|
|
50
|
-
}
|
|
51
|
-
else if (extension === 'json') {
|
|
52
|
-
if ((p3 ?? '').includes('assert')) {
|
|
53
|
-
return match;
|
|
54
|
-
}
|
|
55
|
-
result = `${start}'${src}' assert { type: 'json' }`;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
result = `${start}'${src}.js'`;
|
|
59
|
-
}
|
|
60
|
-
if (verbose)
|
|
61
|
-
console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`);
|
|
62
|
-
return `${result}`;
|
|
63
|
-
});
|
|
64
|
-
replaced = replaced.replace(/\n(.*)\n(\s*)\/\/\s*@ts-ignore/g, (match, p1, p2) => {
|
|
65
|
-
if (p1.includes('eslint-disable-next-line'))
|
|
66
|
-
return match;
|
|
67
|
-
const result = `\n${p1}\n${p2}// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n${p2}// @ts-ignore`;
|
|
68
|
-
if (verbose)
|
|
69
|
-
console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`);
|
|
70
|
-
return result;
|
|
71
|
-
});
|
|
72
|
-
replaced = replaced.replace(/: EventRecord\)/g, (match) => {
|
|
73
|
-
const result = `: EventRecord[])`;
|
|
74
|
-
if (verbose)
|
|
75
|
-
console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`);
|
|
76
|
-
return result;
|
|
77
|
-
});
|
|
78
|
-
replaced = replaced.replace(/import\s+type\s+\{\s*EventRecord\s*\}\s+from\s+['"]@polkadot\/api\/submittable["']/g, (match) => {
|
|
79
|
-
const result = `import type { EventRecord } from '@polkadot/types/interfaces'`;
|
|
80
|
-
if (verbose)
|
|
81
|
-
console.log(`Replacing \n\t${match}\nwith\n\t${result}\nin ${filePath}`);
|
|
82
|
-
return result;
|
|
83
|
-
});
|
|
84
|
-
fs.writeFileSync(filePath, replaced);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
walk(pathToOutput);
|
|
89
25
|
const _ = lodash();
|
|
90
26
|
const writeIndexJsFiles = (src) => {
|
|
91
27
|
const typeChainDirs = fs.readdirSync(src).filter((file) => {
|
|
@@ -94,122 +30,128 @@ async function importContract(pathToAbis, pathToOutput) {
|
|
|
94
30
|
const rootExports = [];
|
|
95
31
|
const typeChainExports = [
|
|
96
32
|
{
|
|
97
|
-
dir:
|
|
98
|
-
defaultExportName:
|
|
33
|
+
dir: "build-extrinsic",
|
|
34
|
+
defaultExportName: "extrinsics",
|
|
99
35
|
},
|
|
100
36
|
{
|
|
101
|
-
dir:
|
|
37
|
+
dir: "constructors",
|
|
102
38
|
},
|
|
103
39
|
{
|
|
104
|
-
dir:
|
|
40
|
+
dir: "contract-info",
|
|
105
41
|
exports: [
|
|
106
42
|
{
|
|
107
|
-
name:
|
|
43
|
+
name: "ContractAbi",
|
|
108
44
|
},
|
|
109
45
|
{
|
|
110
|
-
name:
|
|
46
|
+
name: "ContractFile",
|
|
111
47
|
},
|
|
112
48
|
],
|
|
113
49
|
},
|
|
114
50
|
{
|
|
115
|
-
dir:
|
|
116
|
-
defaultExportName:
|
|
51
|
+
dir: "contracts",
|
|
52
|
+
defaultExportName: "contract",
|
|
117
53
|
},
|
|
118
54
|
{
|
|
119
|
-
dir:
|
|
55
|
+
dir: "data",
|
|
120
56
|
},
|
|
121
57
|
{
|
|
122
|
-
dir:
|
|
58
|
+
dir: "event-data",
|
|
123
59
|
},
|
|
124
60
|
{
|
|
125
|
-
dir:
|
|
61
|
+
dir: "events",
|
|
126
62
|
},
|
|
127
63
|
{
|
|
128
|
-
dir:
|
|
129
|
-
defaultExportName:
|
|
64
|
+
dir: "mixed-methods",
|
|
65
|
+
defaultExportName: "methods",
|
|
130
66
|
},
|
|
131
67
|
{
|
|
132
|
-
dir:
|
|
133
|
-
defaultExportName:
|
|
68
|
+
dir: "query",
|
|
69
|
+
defaultExportName: "query",
|
|
134
70
|
},
|
|
135
71
|
{
|
|
136
|
-
dir:
|
|
137
|
-
defaultExportName:
|
|
72
|
+
dir: "tx-sign-and-send",
|
|
73
|
+
defaultExportName: "tx",
|
|
138
74
|
},
|
|
139
75
|
];
|
|
140
|
-
let file =
|
|
141
|
-
|
|
76
|
+
let file = "";
|
|
77
|
+
for (const typeChainExport of typeChainExports) {
|
|
142
78
|
const dirPath = `${src}/${typeChainExport.dir}`;
|
|
143
79
|
const files = fs.readdirSync(dirPath);
|
|
144
80
|
if (files.length !== 1) {
|
|
145
|
-
throw new ProsopoEnvError(
|
|
146
|
-
context: {
|
|
81
|
+
throw new ProsopoEnvError("FS.INVALID_DIR_FORMAT", {
|
|
82
|
+
context: {
|
|
83
|
+
error: `Expected 1 file in ${dirPath}, found ${files.length}`,
|
|
84
|
+
},
|
|
147
85
|
});
|
|
148
86
|
}
|
|
149
|
-
file = files[0] ||
|
|
150
|
-
if (file ===
|
|
151
|
-
throw new ProsopoEnvError(
|
|
87
|
+
file = files[0] || "";
|
|
88
|
+
if (file === "") {
|
|
89
|
+
throw new ProsopoEnvError("FS.FILE_NOT_FOUND", {
|
|
90
|
+
context: { error: `No file found in ${dirPath}` },
|
|
91
|
+
});
|
|
152
92
|
}
|
|
153
|
-
if (file.endsWith(
|
|
154
|
-
file = replaceExtension(file,
|
|
93
|
+
if (file.endsWith(".ts")) {
|
|
94
|
+
file = replaceExtension(file, "js");
|
|
155
95
|
}
|
|
156
96
|
if (typeChainExport.defaultExportName !== undefined) {
|
|
157
97
|
const name = _.upperFirst(_.camelCase(typeChainExport.defaultExportName || typeChainExport.dir));
|
|
158
98
|
rootExports.push(`export { default as ${name} } from './${typeChainExport.dir}/${file}'`);
|
|
159
99
|
}
|
|
160
100
|
if (typeChainExport.exports !== undefined) {
|
|
161
|
-
typeChainExport.exports
|
|
162
|
-
const alias = namedExport.alias ? ` as ${namedExport.alias}` :
|
|
101
|
+
for (const namedExport of typeChainExport.exports) {
|
|
102
|
+
const alias = namedExport.alias ? ` as ${namedExport.alias}` : "";
|
|
163
103
|
rootExports.push(`export { ${namedExport.name}${alias} } from './${typeChainExport.dir}/${file}'`);
|
|
164
|
-
}
|
|
104
|
+
}
|
|
165
105
|
}
|
|
166
|
-
}
|
|
106
|
+
}
|
|
167
107
|
rootExports.push(`export * from './shared/utils.js'`);
|
|
168
108
|
const regex = /export\s+([a-z]+)\s+(\w+)/g;
|
|
169
|
-
const fileTs = replaceExtension(file,
|
|
170
|
-
const typesArgumentsFileContent = fs.readFileSync(`${src}/types-arguments/${fileTs}`,
|
|
171
|
-
const typesReturnsFileContent = fs.readFileSync(`${src}/types-returns/${fileTs}`,
|
|
109
|
+
const fileTs = replaceExtension(file, "ts");
|
|
110
|
+
const typesArgumentsFileContent = fs.readFileSync(`${src}/types-arguments/${fileTs}`, "utf8");
|
|
111
|
+
const typesReturnsFileContent = fs.readFileSync(`${src}/types-returns/${fileTs}`, "utf8");
|
|
172
112
|
const argumentTypes = Array.from(typesArgumentsFileContent.matchAll(regex)).map((match) => {
|
|
173
113
|
return {
|
|
174
|
-
name: match[2] ||
|
|
175
|
-
category: match[1] ||
|
|
114
|
+
name: match[2] || "",
|
|
115
|
+
category: match[1] || "",
|
|
176
116
|
};
|
|
177
117
|
});
|
|
178
118
|
const returnTypes = Array.from(typesReturnsFileContent.matchAll(regex)).map((match) => {
|
|
179
119
|
return {
|
|
180
|
-
name: match[2] ||
|
|
181
|
-
category: match[1] ||
|
|
120
|
+
name: match[2] || "",
|
|
121
|
+
category: match[1] || "",
|
|
182
122
|
};
|
|
183
123
|
});
|
|
184
124
|
const argumentTypeNames = argumentTypes.map((entry) => entry.name);
|
|
185
125
|
const uniqueTypes = [...argumentTypes];
|
|
186
|
-
const locations = [...argumentTypes.map(() =>
|
|
187
|
-
|
|
126
|
+
const locations = [...argumentTypes.map(() => "types-arguments")];
|
|
127
|
+
for (const entry of returnTypes) {
|
|
188
128
|
if (!argumentTypeNames.includes(entry.name)) {
|
|
189
129
|
uniqueTypes.push(entry);
|
|
190
|
-
locations.push(
|
|
130
|
+
locations.push("types-arguments");
|
|
191
131
|
}
|
|
192
132
|
else {
|
|
193
|
-
locations.push(
|
|
133
|
+
locations.push("types-returns");
|
|
194
134
|
}
|
|
195
|
-
}
|
|
135
|
+
}
|
|
196
136
|
uniqueTypes.forEach((entry, i) => {
|
|
197
137
|
const location = locations[i];
|
|
198
|
-
const prefix = entry.category ===
|
|
138
|
+
const prefix = entry.category === "type" || entry.category === "interface"
|
|
139
|
+
? " type"
|
|
140
|
+
: "";
|
|
199
141
|
rootExports.push(`export${prefix} { ${entry.name} } from './${location}/${file}'`);
|
|
200
142
|
});
|
|
201
|
-
fs.writeFileSync(`${src}/index.ts`, rootExports.join(
|
|
143
|
+
fs.writeFileSync(`${src}/index.ts`, rootExports.join("\n"));
|
|
202
144
|
};
|
|
203
145
|
writeIndexJsFiles(pathToOutput);
|
|
204
146
|
}
|
|
205
147
|
const getExtension = (str) => {
|
|
206
|
-
const i = str.indexOf(
|
|
148
|
+
const i = str.indexOf("assert");
|
|
207
149
|
if (i >= 0) {
|
|
208
150
|
str = str.slice(0, i);
|
|
209
151
|
}
|
|
210
|
-
const arr = str.split(
|
|
152
|
+
const arr = str.split(".");
|
|
211
153
|
if (arr.length <= 1) {
|
|
212
|
-
return
|
|
154
|
+
return "";
|
|
213
155
|
}
|
|
214
156
|
return arr.pop();
|
|
215
157
|
};
|