@prosopo/scripts 1.0.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +4 -3
  2. package/dist/cli/index.d.ts.map +1 -1
  3. package/dist/cli/index.js +47 -168
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/contract/import.d.ts.map +1 -1
  6. package/dist/contract/import.js +62 -120
  7. package/dist/contract/import.js.map +1 -1
  8. package/dist/contract/index.d.ts +1 -2
  9. package/dist/contract/index.d.ts.map +1 -1
  10. package/dist/contract/index.js +1 -2
  11. package/dist/contract/index.js.map +1 -1
  12. package/dist/index.d.ts +4 -4
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +4 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/scripts/addCopyrightNotice.js +43 -43
  17. package/dist/scripts/addCopyrightNotice.js.map +1 -1
  18. package/dist/scripts/bytesToHex.js +3 -5
  19. package/dist/scripts/bytesToHex.js.map +1 -1
  20. package/dist/scripts/convertAccount.js +4 -4
  21. package/dist/scripts/convertAccount.js.map +1 -1
  22. package/dist/scripts/encodeDecode.js +51 -28
  23. package/dist/scripts/encodeDecode.js.map +1 -1
  24. package/dist/scripts/generateMnemonic.js +6 -6
  25. package/dist/scripts/generateMnemonic.js.map +1 -1
  26. package/dist/scripts/getBlock.js +3 -3
  27. package/dist/scripts/getBlock.js.map +1 -1
  28. package/dist/scripts/getContractInfoOf.js +15 -15
  29. package/dist/scripts/getContractInfoOf.js.map +1 -1
  30. package/dist/scripts/getExistentialDeposit.js +9 -9
  31. package/dist/scripts/getExistentialDeposit.js.map +1 -1
  32. package/dist/scripts/getRandomProvider.js +9 -12
  33. package/dist/scripts/getRandomProvider.js.map +1 -1
  34. package/dist/scripts/hash.js +6 -6
  35. package/dist/scripts/hash.js.map +1 -1
  36. package/dist/scripts/hexToBytes.js +2 -2
  37. package/dist/scripts/hexToBytes.js.map +1 -1
  38. package/dist/scripts/setVersion.d.ts +1 -1
  39. package/dist/scripts/setVersion.d.ts.map +1 -1
  40. package/dist/scripts/setVersion.js +41 -40
  41. package/dist/scripts/setVersion.js.map +1 -1
  42. package/dist/scripts/sign.js +19 -19
  43. package/dist/scripts/sign.js.map +1 -1
  44. package/dist/setup/index.d.ts +2 -4
  45. package/dist/setup/index.d.ts.map +1 -1
  46. package/dist/setup/index.js +2 -4
  47. package/dist/setup/index.js.map +1 -1
  48. package/dist/setup/provider.d.ts +2 -3
  49. package/dist/setup/provider.d.ts.map +1 -1
  50. package/dist/setup/provider.js +8 -73
  51. package/dist/setup/provider.js.map +1 -1
  52. package/dist/setup/setup.d.ts.map +1 -1
  53. package/dist/setup/setup.js +45 -49
  54. package/dist/setup/setup.js.map +1 -1
  55. package/dist/util/exec.d.ts.map +1 -1
  56. package/dist/util/exec.js +8 -8
  57. package/dist/util/exec.js.map +1 -1
  58. package/dist/util/fluxLogDappDetails.js +4 -4
  59. package/dist/util/fluxLogDappDetails.js.map +1 -1
  60. package/dist/util/index.d.ts +4 -4
  61. package/dist/util/index.d.ts.map +1 -1
  62. package/dist/util/index.js +4 -4
  63. package/dist/util/index.js.map +1 -1
  64. package/dist/util/loadContractFiles.d.ts +1 -1
  65. package/dist/util/loadContractFiles.d.ts.map +1 -1
  66. package/dist/util/loadContractFiles.js +15 -15
  67. package/dist/util/loadContractFiles.js.map +1 -1
  68. package/dist/util/updateEnv.d.ts +1 -1
  69. package/dist/util/updateEnv.d.ts.map +1 -1
  70. package/dist/util/updateEnv.js +18 -18
  71. package/dist/util/updateEnv.js.map +1 -1
  72. package/env.staging +2 -0
  73. package/package.json +66 -73
  74. package/dist/contract/deploy/dapp.d.ts +0 -3
  75. package/dist/contract/deploy/dapp.d.ts.map +0 -1
  76. package/dist/contract/deploy/dapp.js +0 -26
  77. package/dist/contract/deploy/dapp.js.map +0 -1
  78. package/dist/contract/deploy/index.d.ts +0 -3
  79. package/dist/contract/deploy/index.d.ts.map +0 -1
  80. package/dist/contract/deploy/index.js +0 -3
  81. package/dist/contract/deploy/index.js.map +0 -1
  82. package/dist/contract/deploy/protocol.d.ts +0 -3
  83. package/dist/contract/deploy/protocol.d.ts.map +0 -1
  84. package/dist/contract/deploy/protocol.js +0 -53
  85. package/dist/contract/deploy/protocol.js.map +0 -1
  86. package/dist/contract/fundDapps.d.ts +0 -21
  87. package/dist/contract/fundDapps.d.ts.map +0 -1
  88. package/dist/contract/fundDapps.js +0 -50
  89. package/dist/contract/fundDapps.js.map +0 -1
  90. package/dist/contract/sources/dapp/411053b7ec79cc77f5ec9f5eb18610b24daaaaf0/dapp.json +0 -648
  91. package/dist/contract/transferContract.d.ts +0 -6
  92. package/dist/contract/transferContract.d.ts.map +0 -1
  93. package/dist/contract/transferContract.js +0 -142
  94. package/dist/contract/transferContract.js.map +0 -1
  95. package/dist/scripts/getStorage.d.ts +0 -2
  96. package/dist/scripts/getStorage.d.ts.map +0 -1
  97. package/dist/scripts/getStorage.js +0 -25
  98. package/dist/scripts/getStorage.js.map +0 -1
  99. package/dist/scripts/sendFunds.d.ts +0 -2
  100. package/dist/scripts/sendFunds.d.ts.map +0 -1
  101. package/dist/scripts/sendFunds.js +0 -22
  102. package/dist/scripts/sendFunds.js.map +0 -1
  103. package/dist/setup/dapp.d.ts +0 -5
  104. package/dist/setup/dapp.d.ts.map +0 -1
  105. package/dist/setup/dapp.js +0 -65
  106. package/dist/setup/dapp.js.map +0 -1
  107. package/dist/setup/funds.d.ts +0 -8
  108. package/dist/setup/funds.d.ts.map +0 -1
  109. package/dist/setup/funds.js +0 -50
  110. 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
- - A unix-style environment (Linux, MacOS, WSL2)
8
- - [Docker](https://docs.docker.com/get-docker/)
9
- - [Node.js](https://nodejs.org/en/download/)
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AA8CA,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,iBA2O/C"}
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 { LogLevel, getLogger } from '@prosopo/common';
2
- import { NetworkConfigSchema, NetworkNamesSchema, decodeProcaptchaOutput, networks as getNetworks, } from '@prosopo/types';
3
- import { deployDapp, deployProtocol } from '../contract/deploy/index.js';
4
- import { exec } from '../util/index.js';
5
- import { run as fundDapps } from '../contract/fundDapps.js';
6
- import { get } from '@prosopo/util';
7
- import { getContractNames, getContractsDir, getProtocolDistDir, getScriptsPkgDir } from '@prosopo/config';
8
- import { getEnv, loadEnv } from '@prosopo/cli';
9
- import { getLogLevel } from '@prosopo/common';
10
- import { hideBin } from 'yargs/helpers';
11
- import { importContract } from '../contract/index.js';
12
- import { isHex } from '@polkadot/util';
13
- import { setup } from '../setup/index.js';
14
- import { run as transferContract } from '../contract/transferContract.js';
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('logLevel', {
28
- describe: 'set log level',
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), 'CLI');
21
+ const log = getLogger(getLogLevel(parsed.logLevel), "CLI");
32
22
  await yargs(hideBin(args))
33
- .usage('Usage: $0 [global options] <command> [options]')
34
- .command('deploy_protocol', 'Deploy the prosopo protocol contract', (yargs) => yargs
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: 'setup',
80
- describe: 'Setup the development environment by registering a provider, staking, loading a data set and then registering a dapp and staking.',
81
- builder: (yargs) => yargs.option('force', {
82
- type: 'boolean',
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: 'Force provider re-registration and dataset setup',
35
+ desc: "Force provider re-registration and dataset setup",
85
36
  }),
86
37
  handler: async (argv) => {
87
- log.info('Running setup scripts');
38
+ log.info("Running setup scripts");
88
39
  await setup(!!argv.force);
89
40
  },
90
41
  })
91
42
  .command({
92
- command: 'import_contract',
93
- describe: 'Import a contract into the contract package.',
43
+ command: "import_contract",
44
+ describe: "Import a contract into the contract package.",
94
45
  builder: (yargs) => yargs
95
- .option('in', {
96
- type: 'string',
46
+ .option("in", {
47
+ type: "string",
97
48
  demandOption: true,
98
49
  desc: "The path to the contract's abi",
99
50
  })
100
- .option('out', {
101
- type: 'string',
51
+ .option("out", {
52
+ type: "string",
102
53
  demandOption: true,
103
- desc: 'The path to the output directory',
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: 'import_all_contracts',
111
- describe: 'Update all contracts into the contract package.',
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: 'token <tokenHex>',
194
- describe: 'Decode a Procaptcha token to the JSON output format',
195
- builder: (yargs) => yargs.positional('tokenHex', {
196
- describe: 'a Procaptcha token to decode',
197
- type: 'string',
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.tokenHex)) {
202
- log.error('Token must be a hex string');
203
- process.exit(1);
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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EACH,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,QAAQ,IAAI,WAAW,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,GAAG,IAAI,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,UAAU,MAAM,0BAA0B,CAAA;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AAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACzD;iBAAM;gBACN,GAAG,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;gBACrC,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;aAC7C;QACF,CAAC;KACD,CAAC,CAAC,IAAI,CAAC;AACV,CAAC;AACD,WAAW,CAAC,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+NrE;AAuBD,eAAe,cAAc,CAAA"}
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"}
@@ -1,91 +1,27 @@
1
- import { ProsopoEnvError } from '@prosopo/common';
2
- import { exec } from '../util/index.js';
3
- import { lodash } from '@prosopo/util/lodash';
4
- import fs from 'fs';
5
- import path from 'path';
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('FS.FILE_NOT_FOUND', {
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: 'build-extrinsic',
98
- defaultExportName: 'extrinsics',
33
+ dir: "build-extrinsic",
34
+ defaultExportName: "extrinsics",
99
35
  },
100
36
  {
101
- dir: 'constructors',
37
+ dir: "constructors",
102
38
  },
103
39
  {
104
- dir: 'contract-info',
40
+ dir: "contract-info",
105
41
  exports: [
106
42
  {
107
- name: 'ContractAbi',
43
+ name: "ContractAbi",
108
44
  },
109
45
  {
110
- name: 'ContractFile',
46
+ name: "ContractFile",
111
47
  },
112
48
  ],
113
49
  },
114
50
  {
115
- dir: 'contracts',
116
- defaultExportName: 'contract',
51
+ dir: "contracts",
52
+ defaultExportName: "contract",
117
53
  },
118
54
  {
119
- dir: 'data',
55
+ dir: "data",
120
56
  },
121
57
  {
122
- dir: 'event-data',
58
+ dir: "event-data",
123
59
  },
124
60
  {
125
- dir: 'events',
61
+ dir: "events",
126
62
  },
127
63
  {
128
- dir: 'mixed-methods',
129
- defaultExportName: 'methods',
64
+ dir: "mixed-methods",
65
+ defaultExportName: "methods",
130
66
  },
131
67
  {
132
- dir: 'query',
133
- defaultExportName: 'query',
68
+ dir: "query",
69
+ defaultExportName: "query",
134
70
  },
135
71
  {
136
- dir: 'tx-sign-and-send',
137
- defaultExportName: 'tx',
72
+ dir: "tx-sign-and-send",
73
+ defaultExportName: "tx",
138
74
  },
139
75
  ];
140
- let file = '';
141
- typeChainExports.forEach((typeChainExport) => {
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('FS.INVALID_DIR_FORMAT', {
146
- context: { error: `Expected 1 file in ${dirPath}, found ${files.length}` },
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('FS.FILE_NOT_FOUND', { context: { error: `No file found in ${dirPath}` } });
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('.ts')) {
154
- file = replaceExtension(file, 'js');
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.forEach((namedExport) => {
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, 'ts');
170
- const typesArgumentsFileContent = fs.readFileSync(`${src}/types-arguments/${fileTs}`, 'utf8');
171
- const typesReturnsFileContent = fs.readFileSync(`${src}/types-returns/${fileTs}`, 'utf8');
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(() => 'types-arguments')];
187
- returnTypes.forEach((entry) => {
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('types-arguments');
130
+ locations.push("types-arguments");
191
131
  }
192
132
  else {
193
- locations.push('types-returns');
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 === 'type' || entry.category === 'interface' ? ' type' : '';
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('\n'));
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('assert');
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
  };