From 4ac0aeb816af81db7e0c9d79119649d281649e6d Mon Sep 17 00:00:00 2001 From: 0xverin <104152026+0xverin@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:41:58 +0800 Subject: [PATCH] p-939 Add balances moving script (#2982) * Optimize initApi * add move scripts * add prettier&&gitignore * rococo * add preimage hash * format json file * using forceBatch * adding totalissuance * changing to balances.transfer * rename script * add account_index --- scripts/ts-utils/.gitignore | 5 + scripts/ts-utils/.prettierrc | 7 + scripts/ts-utils/batch-transfer.ts | 101 ++++++++ scripts/ts-utils/endpoint.json | 4 - scripts/ts-utils/initApis.ts | 31 ++- scripts/ts-utils/move-vcregistry-snapshot.ts | 123 +++++---- scripts/ts-utils/package.json | 46 ++-- scripts/ts-utils/pnpm-lock.yaml | 252 +++++++++++++++++++ scripts/ts-utils/setup-enclave.ts | 70 +++--- scripts/ts-utils/transfer-to-whitelist.ts | 24 +- scripts/ts-utils/transfer.ts | 48 ++-- 11 files changed, 532 insertions(+), 179 deletions(-) create mode 100644 scripts/ts-utils/.gitignore create mode 100644 scripts/ts-utils/.prettierrc create mode 100644 scripts/ts-utils/batch-transfer.ts delete mode 100644 scripts/ts-utils/endpoint.json diff --git a/scripts/ts-utils/.gitignore b/scripts/ts-utils/.gitignore new file mode 100644 index 0000000000..a23ef09c02 --- /dev/null +++ b/scripts/ts-utils/.gitignore @@ -0,0 +1,5 @@ +# Ignore all JSON files +*.json + +# But don't ignore tsconfig.json +!tsconfig.json \ No newline at end of file diff --git a/scripts/ts-utils/.prettierrc b/scripts/ts-utils/.prettierrc new file mode 100644 index 0000000000..71abf38349 --- /dev/null +++ b/scripts/ts-utils/.prettierrc @@ -0,0 +1,7 @@ +{ + "trailingComma": "es5", + "singleQuote": true, + "printWidth": 120, + "tabWidth": 4, + "semi": true +} diff --git a/scripts/ts-utils/batch-transfer.ts b/scripts/ts-utils/batch-transfer.ts new file mode 100644 index 0000000000..edb5f9ff92 --- /dev/null +++ b/scripts/ts-utils/batch-transfer.ts @@ -0,0 +1,101 @@ +// run: pnpm exec ts-node batch-transfer.ts + +import { initApi } from './initApis'; +const fs = require('fs'); +const path = require('path'); +const prettier = require('prettier'); +import colors from 'colors'; + +// maximal calls are 1000 per batch +const BATCH_SIZE = 750; +async function encodeExtrinsic() { + // params: source chain endpoint, destination chain endpoint + const { sourceApi, destinationAPI } = await initApi( + 'wss://rpc.litmus-parachain.litentry.io', + 'wss://rpc.litentry-parachain.litentry.io' + ); + console.log(colors.green('Fetching system accounts entries...')); + + const entries = await sourceApi.query.system.account.entries(); + console.log(colors.green('system account entries length:'), entries.length); + + let totalIssuance = BigInt(0); + let account_index = 0; + + const data = entries.map((res: any) => { + const account = res[0].toHuman(); + const data = res[1].toHuman(); + const free = BigInt(data.data.free.replace(/,/g, '')); + const reserved = BigInt(data.data.reserved.replace(/,/g, '')); + const totalBalance = free + reserved; + totalIssuance += totalBalance; + account_index++; + return { + index: account_index, + account: account, + free: free.toString(), + reserved: reserved.toString(), + totalBalance: totalBalance.toString(), + }; + }); + + console.log('totalIssuance:', totalIssuance.toString()); + + const filename = `system-accounts-entries-litmus-${new Date().toISOString().slice(0, 10)}.json`; + const filepath = path.join(__dirname, filename); + const formattedData = prettier.format(JSON.stringify(data), { + parser: 'json', + printWidth: 120, + tabWidth: 2, + singleQuote: true, + trailingComma: 'es5', + }); + fs.writeFileSync(filepath, formattedData); + console.log(colors.green(`Data saved to ${filename} successfully.`)); + + let txs: any[] = []; + let i = 0; + let hexData = []; + const extrinsicsData = []; + + while (data.length > 0) { + const batch = data.splice(0, BATCH_SIZE); + const batchTxs = batch.map((entry: any) => + destinationAPI.tx.balances.transfer(entry.account[0], entry.totalBalance) + ); + txs = txs.concat(batchTxs); + if (data.length === 0 || txs.length >= BATCH_SIZE) { + i++; + const extrinsics = destinationAPI.tx.utility.forceBatch(batchTxs); + extrinsicsData.push({ batch: i, extrinsics: extrinsics.toHex() }); + + hexData = [ + [ + { + totalIssuance: totalIssuance.toString(), + }, + ], + extrinsicsData, + ]; + txs = []; + if (data.length === 0) { + const extrinsicsFilename = `extrinsics-${new Date().toISOString().slice(0, 10)}.json`; + const extrinsicsFilepath = path.join(__dirname, extrinsicsFilename); + + const formattedHexData = prettier.format(JSON.stringify(hexData), { + parser: 'json', + printWidth: 120, + tabWidth: 2, + singleQuote: true, + trailingComma: 'es5', + }); + + fs.writeFileSync(extrinsicsFilepath, formattedHexData); + console.log(colors.green(`Extrinsics saved to ${extrinsicsFilename} successfully.`)); + } + } + } + process.exit(); +} + +encodeExtrinsic(); diff --git a/scripts/ts-utils/endpoint.json b/scripts/ts-utils/endpoint.json deleted file mode 100644 index 91e6232bc3..0000000000 --- a/scripts/ts-utils/endpoint.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "fetchEndpoint": "ws://localhost:9944", - "defaultEndpoint": "ws://localhost:9944" -} diff --git a/scripts/ts-utils/initApis.ts b/scripts/ts-utils/initApis.ts index 7aa7e6e503..e844e48c9d 100644 --- a/scripts/ts-utils/initApis.ts +++ b/scripts/ts-utils/initApis.ts @@ -1,22 +1,21 @@ -const { ApiPromise, WsProvider } = require("@polkadot/api"); +const { ApiPromise, WsProvider } = require('@polkadot/api'); const { cryptoWaitReady } = require('@polkadot/util-crypto'); -const { fetchEndpoint, defaultEndpoint } = require('./endpoint.json'); -import colors from "colors"; -//fetchApi is used to fetch data from the chain -const wsFetchProvider = new WsProvider(fetchEndpoint); +import colors from 'colors'; -//defaultAPI is used to send transactions to the chain -const wsDefaultProvider = new WsProvider(defaultEndpoint); +/* + * @param fromEndpoint - the endpoint of the source chain + * @param toEndpoint - the endpoint of the destination chain + */ -export const initApi = async () => { - console.log(colors.green("init api...")) - const fetchApi = await ApiPromise.create({ provider: wsFetchProvider }); - const defaultAPI = await ApiPromise.create({ provider: wsDefaultProvider }); - await cryptoWaitReady(); - console.log(colors.green("api is ready")) - - return { fetchApi, defaultAPI }; -} +export const initApi = async (fromEndpoint: string, toEndpoint: string) => { + const sourceProvider = new WsProvider(fromEndpoint); + const destinationProvider = new WsProvider(toEndpoint); + const sourceApi = await ApiPromise.create({ provider: sourceProvider }); + const destinationAPI = await ApiPromise.create({ provider: destinationProvider }); + await cryptoWaitReady(); + console.log(colors.green('api is ready')); + return { sourceApi, destinationAPI }; +}; diff --git a/scripts/ts-utils/move-vcregistry-snapshot.ts b/scripts/ts-utils/move-vcregistry-snapshot.ts index 1e19369674..fddcfd39f8 100644 --- a/scripts/ts-utils/move-vcregistry-snapshot.ts +++ b/scripts/ts-utils/move-vcregistry-snapshot.ts @@ -1,80 +1,75 @@ // run: pnpm exec ts-node move-vcregistry-snapshot.ts -import { initApi } from "./initApis"; -const fs = require("fs"); -const path = require("path"); -const prettier = require("prettier"); -import colors from "colors"; +import { initApi } from './initApis'; +const fs = require('fs'); +const path = require('path'); +const prettier = require('prettier'); +import colors from 'colors'; //set the maximal calls are 500 per batch const BATCH_SIZE = 500; async function encodeExtrinsic() { - const { fetchApi, defaultAPI } = await initApi(); - console.log(colors.green("get vcRegistry entries...")); + // params: source chain endpoint, destination chain endpoint + const { sourceApi, destinationAPI } = await initApi('ws://localhost:9944', 'ws://localhost:9944'); + console.log(colors.green('get vcRegistry entries...')); - const entries = await fetchApi.query.vcManagement.vcRegistry.entries(); - const data = entries.map((res: any) => { - return { index: res[0].toHuman(), vc: res[1].toHuman() }; - }); + const entries = await sourceApi.query.vcManagement.vcRegistry.entries(); + const data = entries.map((res: any) => { + return { index: res[0].toHuman(), vc: res[1].toHuman() }; + }); - const filename = `VCRegistry-${new Date().toISOString().slice(0, 10)}.json`; - const filepath = path.join(__dirname, filename); - const formattedData = prettier.format(JSON.stringify(data), { - parser: "json", - printWidth: 120, - tabWidth: 2, - singleQuote: true, - trailingComma: "es5", - }); - fs.writeFileSync(filepath, formattedData); - console.log(colors.green(`Data saved to ${filename} successfully.`)); + const filename = `VCRegistry-${new Date().toISOString().slice(0, 10)}.json`; + const filepath = path.join(__dirname, filename); + const formattedData = prettier.format(JSON.stringify(data), { + parser: 'json', + printWidth: 120, + tabWidth: 2, + singleQuote: true, + trailingComma: 'es5', + }); + fs.writeFileSync(filepath, formattedData); + console.log(colors.green(`Data saved to ${filename} successfully.`)); - let txs: any[] = []; - console.log(colors.green("vcRegistry data length"), data.length); - let i = 0; - const hexData = []; + let txs: any[] = []; + console.log(colors.green('vcRegistry data length'), data.length); + let i = 0; + const hexData = []; - while (data.length > 0) { - const batch = data.splice(0, BATCH_SIZE); - const batchTxs = batch.map((entry: any) => - defaultAPI.tx.vcManagement.addVcRegistryItem( - entry.index[0], - entry.vc.subject, - entry.vc.assertion, - entry.vc.hash_ - ) - ); - txs = txs.concat(batchTxs); - if (data.length === 0 || txs.length >= BATCH_SIZE) { - i++; - const extrinsics = defaultAPI.tx.utility.batch(batchTxs); - hexData.push({ batch: i, extrinsics: extrinsics.toHex() }); - // console.log(colors.green(`extrinsic ${i} encode`), extrinsics.toHex()); - txs = []; - if (data.length === 0) { - const extrinsicsFilename = `extrinsics-${new Date() - .toISOString() - .slice(0, 10)}.json`; - const extrinsicsFilepath = path.join(__dirname, extrinsicsFilename); + while (data.length > 0) { + const batch = data.splice(0, BATCH_SIZE); + const batchTxs = batch.map((entry: any) => + destinationAPI.tx.vcManagement.addVcRegistryItem( + entry.index[0], + entry.vc.subject, + entry.vc.assertion, + entry.vc.hash_ + ) + ); + txs = txs.concat(batchTxs); + if (data.length === 0 || txs.length >= BATCH_SIZE) { + i++; + const extrinsics = destinationAPI.tx.utility.batch(batchTxs); + hexData.push({ batch: i, extrinsics: extrinsics.toHex() }); + // console.log(colors.green(`extrinsic ${i} encode`), extrinsics.toHex()); + txs = []; + if (data.length === 0) { + const extrinsicsFilename = `extrinsics-${new Date().toISOString().slice(0, 10)}.json`; + const extrinsicsFilepath = path.join(__dirname, extrinsicsFilename); - const formattedHexData = prettier.format(JSON.stringify(hexData), { - parser: "json", - printWidth: 120, - tabWidth: 2, - singleQuote: true, - trailingComma: "es5", - }); + const formattedHexData = prettier.format(JSON.stringify(hexData), { + parser: 'json', + printWidth: 120, + tabWidth: 2, + singleQuote: true, + trailingComma: 'es5', + }); - fs.writeFileSync(extrinsicsFilepath, formattedHexData); - console.log( - colors.green( - `Extrinsics saved to ${extrinsicsFilename} successfully.` - ) - ); - } + fs.writeFileSync(extrinsicsFilepath, formattedHexData); + console.log(colors.green(`Extrinsics saved to ${extrinsicsFilename} successfully.`)); + } + } } - } - process.exit(); + process.exit(); } encodeExtrinsic(); diff --git a/scripts/ts-utils/package.json b/scripts/ts-utils/package.json index 9ad510e5bb..81295adfe9 100644 --- a/scripts/ts-utils/package.json +++ b/scripts/ts-utils/package.json @@ -1,24 +1,26 @@ { - "name": "ts-utils", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@polkadot/api": "^10.3.1", - "colors": "^1.4.0", - "exceljs": "^4.3.0", - "prettier": "^2.8.7", - "ts-node": "^10.9.1", - "typescript": "^5.0.4" - }, - "devDependencies": { - "@types/node": "^18.15.11" - }, - "packageManager": "pnpm@8.7.6" + "name": "ts-utils", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "format": "pnpm exec prettier --write '**.ts'" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@polkadot/api": "^10.3.1", + "@polkadot/util-crypto": "^13.0.2", + "colors": "^1.4.0", + "ethers": "^6.13.2", + "exceljs": "^4.3.0", + "prettier": "^2.8.7", + "ts-node": "^10.9.1", + "typescript": "^5.0.4" + }, + "devDependencies": { + "@types/node": "^18.15.11" + }, + "packageManager": "pnpm@8.7.6" } diff --git a/scripts/ts-utils/pnpm-lock.yaml b/scripts/ts-utils/pnpm-lock.yaml index 9ef3369754..0090449d59 100644 --- a/scripts/ts-utils/pnpm-lock.yaml +++ b/scripts/ts-utils/pnpm-lock.yaml @@ -8,9 +8,15 @@ dependencies: '@polkadot/api': specifier: ^10.3.1 version: 10.3.1 + '@polkadot/util-crypto': + specifier: ^13.0.2 + version: 13.0.2(@polkadot/util@13.0.2) colors: specifier: ^1.4.0 version: 1.4.0 + ethers: + specifier: ^6.13.2 + version: 6.13.2 exceljs: specifier: ^4.3.0 version: 4.3.0 @@ -31,6 +37,10 @@ devDependencies: packages: + /@adraffy/ens-normalize@1.10.1: + resolution: {integrity: sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==} + dev: false + /@cspotcode/source-map-support@0.8.1: resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} @@ -77,10 +87,32 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: false + /@noble/curves@1.2.0: + resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} + dependencies: + '@noble/hashes': 1.3.2 + dev: false + + /@noble/curves@1.5.0: + resolution: {integrity: sha512-J5EKamIHnKPyClwVrzmaf5wSdQXgdHcPZIZLu3bwnbeCx8/7NPK5q2ZBWF+5FvYGByjiQQsJYX6jfgB2wDPn3A==} + dependencies: + '@noble/hashes': 1.4.0 + dev: false + /@noble/hashes@1.3.0: resolution: {integrity: sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==} dev: false + /@noble/hashes@1.3.2: + resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} + engines: {node: '>= 16'} + dev: false + + /@noble/hashes@1.4.0: + resolution: {integrity: sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==} + engines: {node: '>= 16'} + dev: false + /@noble/secp256k1@1.7.1: resolution: {integrity: sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==} dev: false @@ -185,6 +217,15 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/networks@13.0.2: + resolution: {integrity: sha512-ABAL+vug/gIwkdFEzeh87JoJd0YKrxSYg/HjUrZ+Zis2ucxQEKpvtCpJ34ku+YrjacBfVqIAkkwd3ZdIPGq9aQ==} + engines: {node: '>=18'} + dependencies: + '@polkadot/util': 13.0.2 + '@substrate/ss58-registry': 1.49.0 + tslib: 2.6.3 + dev: false + /@polkadot/rpc-augment@10.3.1: resolution: {integrity: sha512-XqKKEZsubailM1pWAoHJhPt5Tw+jMcMKdbWlzrjhuyKvoQ4KNBGUA6zOeOVL+z3BH/SCNkLQSm2xAFy28w5Now==} engines: {node: '>=14'} @@ -320,6 +361,24 @@ packages: tweetnacl: 1.0.3 dev: false + /@polkadot/util-crypto@13.0.2(@polkadot/util@13.0.2): + resolution: {integrity: sha512-woUsJJ6zd/caL7U+D30a5oM/+WK9iNI00Y8aNUHSj6Zq/KPzK9uqDBaLGWwlgrejoMQkxxiU2X0f2LzP15AtQg==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': 13.0.2 + dependencies: + '@noble/curves': 1.5.0 + '@noble/hashes': 1.4.0 + '@polkadot/networks': 13.0.2 + '@polkadot/util': 13.0.2 + '@polkadot/wasm-crypto': 7.3.2(@polkadot/util@13.0.2)(@polkadot/x-randomvalues@13.0.2) + '@polkadot/wasm-util': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/x-bigint': 13.0.2 + '@polkadot/x-randomvalues': 13.0.2(@polkadot/util@13.0.2)(@polkadot/wasm-util@7.3.2) + '@scure/base': 1.1.7 + tslib: 2.6.3 + dev: false + /@polkadot/util@11.1.3: resolution: {integrity: sha512-Gsqzv1/fSoypS5tnJkM+NJQeT7O4iYlSniubUJnaZVOKsIbueTS1bMQ1y3/h8ISxbKBtICW5cZ6zCej6Q/jC3w==} engines: {node: '>=14'} @@ -333,6 +392,19 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/util@13.0.2: + resolution: {integrity: sha512-/6bS9sfhJLhs8QuqWaR1eRapzfDdGC5XAQZEPL9NN5sTTA7HxWos8rVleai0UERm8QUMabjZ9rK9KpzbXl7ojg==} + engines: {node: '>=18'} + dependencies: + '@polkadot/x-bigint': 13.0.2 + '@polkadot/x-global': 13.0.2 + '@polkadot/x-textdecoder': 13.0.2 + '@polkadot/x-textencoder': 13.0.2 + '@types/bn.js': 5.1.5 + bn.js: 5.2.1 + tslib: 2.6.3 + dev: false + /@polkadot/wasm-bridge@7.0.3(@polkadot/util@11.1.3)(@polkadot/x-randomvalues@11.1.3): resolution: {integrity: sha512-q5qyhkGE9lHQmThNg6G5zCM4gYip2KtmR+De/URX7yWAO6snsinFqt066RFVuHvX1hZijrYSe/BGQABAUtH4pw==} engines: {node: '>=14.0.0'} @@ -345,6 +417,19 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/wasm-bridge@7.3.2(@polkadot/util@13.0.2)(@polkadot/x-randomvalues@13.0.2): + resolution: {integrity: sha512-AJEXChcf/nKXd5Q/YLEV5dXQMle3UNT7jcXYmIffZAo/KI394a+/24PaISyQjoNC0fkzS1Q8T5pnGGHmXiVz2g==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': '*' + '@polkadot/x-randomvalues': '*' + dependencies: + '@polkadot/util': 13.0.2 + '@polkadot/wasm-util': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/x-randomvalues': 13.0.2(@polkadot/util@13.0.2)(@polkadot/wasm-util@7.3.2) + tslib: 2.6.3 + dev: false + /@polkadot/wasm-crypto-asmjs@7.0.3(@polkadot/util@11.1.3): resolution: {integrity: sha512-ldMZjowYywn0Uj7jSr8a21rrlFFq/jWhCXVl21/KDcYGdFEfIajqbcrO5cHoT6w95sQgAwMWJwwDClXOaBjc/Q==} engines: {node: '>=14.0.0'} @@ -355,6 +440,16 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/wasm-crypto-asmjs@7.3.2(@polkadot/util@13.0.2): + resolution: {integrity: sha512-QP5eiUqUFur/2UoF2KKKYJcesc71fXhQFLT3D4ZjG28Mfk2ZPI0QNRUfpcxVQmIUpV5USHg4geCBNuCYsMm20Q==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': '*' + dependencies: + '@polkadot/util': 13.0.2 + tslib: 2.6.3 + dev: false + /@polkadot/wasm-crypto-init@7.0.3(@polkadot/util@11.1.3)(@polkadot/x-randomvalues@11.1.3): resolution: {integrity: sha512-W4ClfPrzOTqiX0x4h6rXjCt8UsVsbg3zU7LJFFjeLgrguPoKTLGw4h5O1rR2H7EuMFbuqdztzJn3qTjBcR03Cg==} engines: {node: '>=14.0.0'} @@ -370,6 +465,22 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/wasm-crypto-init@7.3.2(@polkadot/util@13.0.2)(@polkadot/x-randomvalues@13.0.2): + resolution: {integrity: sha512-FPq73zGmvZtnuJaFV44brze3Lkrki3b4PebxCy9Fplw8nTmisKo9Xxtfew08r0njyYh+uiJRAxPCXadkC9sc8g==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': '*' + '@polkadot/x-randomvalues': '*' + dependencies: + '@polkadot/util': 13.0.2 + '@polkadot/wasm-bridge': 7.3.2(@polkadot/util@13.0.2)(@polkadot/x-randomvalues@13.0.2) + '@polkadot/wasm-crypto-asmjs': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/wasm-crypto-wasm': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/wasm-util': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/x-randomvalues': 13.0.2(@polkadot/util@13.0.2)(@polkadot/wasm-util@7.3.2) + tslib: 2.6.3 + dev: false + /@polkadot/wasm-crypto-wasm@7.0.3(@polkadot/util@11.1.3): resolution: {integrity: sha512-FRjUADiA3wMkjJqQLgB0v9rbSADcb2PY/6dJi06iza9m41HebTN3x7f5D3gWTCfgJjzWLAPchY2Hwsa0WpTQkw==} engines: {node: '>=14.0.0'} @@ -381,6 +492,17 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/wasm-crypto-wasm@7.3.2(@polkadot/util@13.0.2): + resolution: {integrity: sha512-15wd0EMv9IXs5Abp1ZKpKKAVyZPhATIAHfKsyoWCEFDLSOA0/K0QGOxzrAlsrdUkiKZOq7uzSIgIDgW8okx2Mw==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': '*' + dependencies: + '@polkadot/util': 13.0.2 + '@polkadot/wasm-util': 7.3.2(@polkadot/util@13.0.2) + tslib: 2.6.3 + dev: false + /@polkadot/wasm-crypto@7.0.3(@polkadot/util@11.1.3)(@polkadot/x-randomvalues@11.1.3): resolution: {integrity: sha512-mOCLCaL9cyrU72PCc9nMNAj3zdvOzau5mOGJjLahIz+mqlHAoAmEXCAJvJ2qCo7OFl8QiDToAEGhdDWQfiHUyg==} engines: {node: '>=14.0.0'} @@ -398,6 +520,23 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/wasm-crypto@7.3.2(@polkadot/util@13.0.2)(@polkadot/x-randomvalues@13.0.2): + resolution: {integrity: sha512-+neIDLSJ6jjVXsjyZ5oLSv16oIpwp+PxFqTUaZdZDoA2EyFRQB8pP7+qLsMNk+WJuhuJ4qXil/7XiOnZYZ+wxw==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': '*' + '@polkadot/x-randomvalues': '*' + dependencies: + '@polkadot/util': 13.0.2 + '@polkadot/wasm-bridge': 7.3.2(@polkadot/util@13.0.2)(@polkadot/x-randomvalues@13.0.2) + '@polkadot/wasm-crypto-asmjs': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/wasm-crypto-init': 7.3.2(@polkadot/util@13.0.2)(@polkadot/x-randomvalues@13.0.2) + '@polkadot/wasm-crypto-wasm': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/wasm-util': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/x-randomvalues': 13.0.2(@polkadot/util@13.0.2)(@polkadot/wasm-util@7.3.2) + tslib: 2.6.3 + dev: false + /@polkadot/wasm-util@7.0.3(@polkadot/util@11.1.3): resolution: {integrity: sha512-L9U5nSbzr5xa2YSpveP/zZxhOB6i8ibssK+ihuG+7SICYtTC0B9wJp/UnjP/c6bEDlMV3yWiNXJPBTJMGmkmIQ==} engines: {node: '>=14.0.0'} @@ -408,6 +547,16 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/wasm-util@7.3.2(@polkadot/util@13.0.2): + resolution: {integrity: sha512-bmD+Dxo1lTZyZNxbyPE380wd82QsX+43mgCm40boyKrRppXEyQmWT98v/Poc7chLuskYb6X8IQ6lvvK2bGR4Tg==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': '*' + dependencies: + '@polkadot/util': 13.0.2 + tslib: 2.6.3 + dev: false + /@polkadot/x-bigint@11.1.3: resolution: {integrity: sha512-fRUUHfW9VFsXT7sLUUY7gSu8v+PvzNLRwvjnp+Ly8vFx9LTLuVGFCi+mpysuRTaPpqZZJlzBJ3fST7xTGh67Pg==} engines: {node: '>=14'} @@ -416,6 +565,14 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/x-bigint@13.0.2: + resolution: {integrity: sha512-h2jKT/UaxiEal8LhQeH6+GCjO7GwEqVAD2SNYteCOXff6yNttqAZYJuHZsndbVjVNwqRNf8D5q/zZkD0HUd6xQ==} + engines: {node: '>=18'} + dependencies: + '@polkadot/x-global': 13.0.2 + tslib: 2.6.3 + dev: false + /@polkadot/x-fetch@11.1.3: resolution: {integrity: sha512-+Z0RxxsN7+l2ZmmDdHqOo0kgqvjXJ1bw8CwTVnq3t9nPgZKn2pC3Fq3xdj/sRWiLuf/UhgCxKfYfMmt5ek4kIg==} engines: {node: '>=14'} @@ -432,6 +589,13 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/x-global@13.0.2: + resolution: {integrity: sha512-OoNIXLB5y8vIKpk4R+XmpDPhipNXWSUvEwUnpQT7NAxNLmzgMq1FhbrwBWWPRNHPrQonp7mqxV/X+v5lv1HW/g==} + engines: {node: '>=18'} + dependencies: + tslib: 2.6.3 + dev: false + /@polkadot/x-randomvalues@11.1.3: resolution: {integrity: sha512-kZjbRgxokMR9UTodZQKs6s3C/Q2YgeizcxpDCghM/VdvQUE8OVBGNzduF7SvBvQyg2Qbg8jMcSxXOY7UgcOWSg==} engines: {node: '>=14'} @@ -440,6 +604,19 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/x-randomvalues@13.0.2(@polkadot/util@13.0.2)(@polkadot/wasm-util@7.3.2): + resolution: {integrity: sha512-SGj+L0H/7TWZtSmtkWlixO4DFzXDdluI0UscN2h285os2Ns8PnmBbue+iJ8PVSzpY1BOxd66gvkkpboPz+jXFQ==} + engines: {node: '>=18'} + peerDependencies: + '@polkadot/util': 13.0.2 + '@polkadot/wasm-util': '*' + dependencies: + '@polkadot/util': 13.0.2 + '@polkadot/wasm-util': 7.3.2(@polkadot/util@13.0.2) + '@polkadot/x-global': 13.0.2 + tslib: 2.6.3 + dev: false + /@polkadot/x-textdecoder@11.1.3: resolution: {integrity: sha512-NhOjuXVfYRMw9l0VhCtZOtcWefZth58p5KpVOrFyJZd12fTsoMO5/746K7QoAjWRrLQTJ/LHCEKCtWww0LwVPw==} engines: {node: '>=14'} @@ -448,6 +625,14 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/x-textdecoder@13.0.2: + resolution: {integrity: sha512-mauglOkTJxLGmLwLc3J5Jlq/W+SHP53eiy3F8/8JxxfnXrZKgWoQXGpvXYPjFnMZj0MzDSy/6GjyGWnDCgdQFA==} + engines: {node: '>=18'} + dependencies: + '@polkadot/x-global': 13.0.2 + tslib: 2.6.3 + dev: false + /@polkadot/x-textencoder@11.1.3: resolution: {integrity: sha512-7DmqjlPN8aQexLUKwoHeadihpUnW8hjpXEru+aEDxjgq9XIxPvb++NeBK+Mra9RzzZRuiT/K5z16HlwKN//ewg==} engines: {node: '>=14'} @@ -456,6 +641,14 @@ packages: tslib: 2.5.0 dev: false + /@polkadot/x-textencoder@13.0.2: + resolution: {integrity: sha512-Lq08H2OnVXj97uaOwg7tcmRS7a4VJYkHEeWO4FyEMOk6P6lU6W8OVNjjxG0se9PCEgmyZPUDbJI//1ynzP4cXw==} + engines: {node: '>=18'} + dependencies: + '@polkadot/x-global': 13.0.2 + tslib: 2.6.3 + dev: false + /@polkadot/x-ws@11.1.3: resolution: {integrity: sha512-omNU2mIVX997HiHm2YxEdJdyCFnv+oTyKWZd0+FdS47rdfhVwD+H9/bS+rtQ9lIqfhODdGmw3fG//gq1KpYJcw==} engines: {node: '>=14'} @@ -472,6 +665,10 @@ packages: resolution: {integrity: sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==} dev: false + /@scure/base@1.1.7: + resolution: {integrity: sha512-PPNYBslrLNNUQ/Yad37MHYsNQtK67EhWb6WtSvNLLPo7SdVZgkUjD6Dg+5On7zNwmskf8OX7I7Nx5oN+MIWE0g==} + dev: false + /@substrate/connect-extension-protocol@1.0.1: resolution: {integrity: sha512-161JhCC1csjH3GE5mPLEd7HbWtwNSPJBg3p1Ksz9SFlTzj/bgEwudiRN2y5i0MoLGCIJRYKyKGMxVnd29PzNjg==} requiresBuild: true @@ -495,6 +692,10 @@ packages: resolution: {integrity: sha512-qZYpuE6n+mwew+X71dOur/CbMXj6rNW27o63JeJwdQH/GvcSKm3JLNhd+bGzwUKg0D/zD30Qc6p4JykArzM+tA==} dev: false + /@substrate/ss58-registry@1.49.0: + resolution: {integrity: sha512-leW6Ix4LD7XgvxT7+aobPWSw+WvPcN2Rxof1rmd0mNC5t2n99k1N7UNEvz7YEFSOUeHWmKIY7F5q8KeIqYoHfA==} + dev: false + /@tsconfig/node10@1.0.9: resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} dev: false @@ -517,6 +718,12 @@ packages: '@types/node': 18.15.11 dev: false + /@types/bn.js@5.1.5: + resolution: {integrity: sha512-V46N0zwKRF5Q00AZ6hWtN0T8gGmDUaUzLWQvHFo5yThtVwK/VCenFY3wXVbOvNfajEpsTfQM4IN9k/d6gUVX3A==} + dependencies: + '@types/node': 18.15.13 + dev: false + /@types/node@14.18.48: resolution: {integrity: sha512-iL0PIMwejpmuVHgfibHpfDwOdsbmB50wr21X71VnF5d7SsBF7WK+ZvP/SCcFm7Iwb9iiYSap9rlrdhToNAWdxg==} dev: false @@ -524,6 +731,10 @@ packages: /@types/node@18.15.11: resolution: {integrity: sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==} + /@types/node@18.15.13: + resolution: {integrity: sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==} + dev: false + /acorn-walk@8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} @@ -535,6 +746,10 @@ packages: hasBin: true dev: false + /aes-js@4.0.0-beta.5: + resolution: {integrity: sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==} + dev: false + /archiver-utils@2.1.0: resolution: {integrity: sha512-bEL/yUb/fNNiNTuUz979Z0Yg5L+LzLxGJz8x79lYmR54fmTIb6ob/hNQgkQnIUDWIFjZVQwl9Xs356I6BAMHfw==} engines: {node: '>= 6'} @@ -727,6 +942,22 @@ packages: once: 1.4.0 dev: false + /ethers@6.13.2: + resolution: {integrity: sha512-9VkriTTed+/27BGuY1s0hf441kqwHJ1wtN2edksEtiRvXx+soxRX3iSXTfFqq2+YwrOqbDoTHjIhQnjJRlzKmg==} + engines: {node: '>=14.0.0'} + dependencies: + '@adraffy/ens-normalize': 1.10.1 + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@types/node': 18.15.13 + aes-js: 4.0.0-beta.5 + tslib: 2.4.0 + ws: 8.17.1 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + dev: false + /eventemitter3@4.0.7: resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} requiresBuild: true @@ -1164,10 +1395,18 @@ packages: yn: 3.1.1 dev: false + /tslib@2.4.0: + resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} + dev: false + /tslib@2.5.0: resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} dev: false + /tslib@2.6.3: + resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==} + dev: false + /tweetnacl@1.0.3: resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==} dev: false @@ -1228,6 +1467,19 @@ packages: optional: true dev: false + /ws@8.17.1: + resolution: {integrity: sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + dev: false + /xmlchars@2.2.0: resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==} dev: false diff --git a/scripts/ts-utils/setup-enclave.ts b/scripts/ts-utils/setup-enclave.ts index 829ce280a7..61f303a30d 100644 --- a/scripts/ts-utils/setup-enclave.ts +++ b/scripts/ts-utils/setup-enclave.ts @@ -1,29 +1,27 @@ //run: pnpm exec ts-node setup-enclave.ts $enclaveAccount $mrenclave $accountPassword //example: pnpm exec ts-node setup-enclave.ts 2KWd4sEmYj2VW42L2WUDDRKA4JwnKg76uoQ2keUBUwFHU9Dx a552654d1733c4054a3c7e5e86adf26b5d65c072b57b2550fe763821ebac54c6 123456 -const { Keyring } = require("@polkadot/api"); -import { initApi } from "./initApis"; -const { hexToU8a } = require("@polkadot/util"); -import colors from "colors"; - +const { Keyring } = require('@polkadot/api'); +import { initApi } from './initApis'; +const { hexToU8a } = require('@polkadot/util'); +import colors from 'colors'; //100 token -const transferAmount = "100000000000000"; +const transferAmount = '100000000000000'; const enclaveAccount = process.argv[2]; const mrenclave = process.argv[3]; const block = process.argv[4]; async function transfer(api: any, Alice: any) { - - console.log(colors.green("transfer start...")); + console.log(colors.green('transfer start...')); return new Promise(async (resolve, reject) => { await api.tx.balances .transfer(enclaveAccount, transferAmount) .signAndSend(Alice, ({ status, events, dispatchError }) => { if (status.isInBlock || status.isFinalized) { events.forEach(({ phase, event: { data, method, section } }) => { - if (method === "Transfer" && section === "balances") { - console.log(colors.green("transfer completed")); - resolve("transfer done"); + if (method === 'Transfer' && section === 'balances') { + console.log(colors.green('transfer completed')); + resolve('transfer done'); return; } }); @@ -35,27 +33,25 @@ async function teebagSetAdmin(api: any, Alice: any) { return new Promise(async (resolve, reject) => { // Note: The hardcoded address is that of Alice on dev chain await api.tx.sudo - .sudo(api.tx.teebag.setAdmin("esqZdrqhgH8zy1wqYh1aLKoRyoRWLFbX9M62eKfaTAoK67pJ5")) + .sudo(api.tx.teebag.setAdmin('esqZdrqhgH8zy1wqYh1aLKoRyoRWLFbX9M62eKfaTAoK67pJ5')) .signAndSend(Alice, ({ status, events, dispatchError }) => { if (status.isInBlock || status.isFinalized) { if (dispatchError) { if (dispatchError.isModule) { // for module errors, we have the section indexed, lookup - const decoded = api.registry.findMetaError( - dispatchError.asModule - ); + const decoded = api.registry.findMetaError(dispatchError.asModule); const { docs, name, section } = decoded; - console.log(colors.red(`${section}.${name}: ${docs.join(" ")}`)); - reject("teebag.setAdmin failed"); + console.log(colors.red(`${section}.${name}: ${docs.join(' ')}`)); + reject('teebag.setAdmin failed'); } else { // Other, CannotLookup, BadOrigin, no extra info console.log(dispatchError.toString()); - reject("teebag.setAdmin failed"); + reject('teebag.setAdmin failed'); } } else { - console.log(colors.green("teebag.setAdmin completed")); - resolve("teebag.setAdmin done"); + console.log(colors.green('teebag.setAdmin completed')); + resolve('teebag.setAdmin done'); } } }); @@ -63,27 +59,26 @@ async function teebagSetAdmin(api: any, Alice: any) { } async function teebagSetScheduledEnclave(api: any, Alice: any, block: any) { return new Promise(async (resolve, reject) => { - await api.tx.teebag.setScheduledEnclave("Identity", block, hexToU8a(`0x${mrenclave}`)) + await api.tx.teebag + .setScheduledEnclave('Identity', block, hexToU8a(`0x${mrenclave}`)) .signAndSend(Alice, ({ status, events, dispatchError }) => { if (status.isInBlock || status.isFinalized) { if (dispatchError) { if (dispatchError.isModule) { // for module errors, we have the section indexed, lookup - const decoded = api.registry.findMetaError( - dispatchError.asModule - ); + const decoded = api.registry.findMetaError(dispatchError.asModule); const { docs, name, section } = decoded; - console.log(colors.red(`${section}.${name}: ${docs.join(" ")}`)); - reject("teebag.setScheduledEnclave failed"); + console.log(colors.red(`${section}.${name}: ${docs.join(' ')}`)); + reject('teebag.setScheduledEnclave failed'); } else { // Other, CannotLookup, BadOrigin, no extra info console.log(dispatchError.toString()); - reject("teebag.setScheduledEnclave failed"); + reject('teebag.setScheduledEnclave failed'); } } else { - console.log(colors.green("teebag.setScheduledEnclave completed")); - resolve("teebag.setScheduledEnclave done"); + console.log(colors.green('teebag.setScheduledEnclave completed')); + resolve('teebag.setScheduledEnclave done'); } } }); @@ -92,18 +87,19 @@ async function teebagSetScheduledEnclave(api: any, Alice: any, block: any) { async function main() { // NOTE: If we are using development environment, we can use Alice instead of moving around with keys - const keyring = new Keyring({ type: "sr25519" }); + const keyring = new Keyring({ type: 'sr25519' }); - console.log(colors.green("account unlock...")); + console.log(colors.green('account unlock...')); - const { defaultAPI } = await initApi(); - const Alice = keyring.addFromUri("//Alice", { name: "Alice default" }); + // params: source chain endpoint, destination chain endpoint + const { destinationAPI } = await initApi('ws://localhost:9944', 'ws://localhost:9944'); + const Alice = keyring.addFromUri('//Alice', { name: 'Alice default' }); - await transfer(defaultAPI, Alice); - await teebagSetAdmin(defaultAPI, Alice); - await teebagSetScheduledEnclave(defaultAPI, Alice, block); + await transfer(destinationAPI, Alice); + await teebagSetAdmin(destinationAPI, Alice); + await teebagSetScheduledEnclave(destinationAPI, Alice, block); - console.log(colors.green("done")); + console.log(colors.green('done')); process.exit(); } diff --git a/scripts/ts-utils/transfer-to-whitelist.ts b/scripts/ts-utils/transfer-to-whitelist.ts index c0cf5beb5c..7206cd9638 100644 --- a/scripts/ts-utils/transfer-to-whitelist.ts +++ b/scripts/ts-utils/transfer-to-whitelist.ts @@ -1,6 +1,6 @@ //run: pnpm exec ts-node transfer-to-whitelist.ts -import { initApi } from "./initApis"; +import { initApi } from './initApis'; import colors from 'colors'; let whiteList: any; import * as ExcelJS from 'exceljs'; @@ -8,7 +8,6 @@ import * as ExcelJS from 'exceljs'; const transferAmount = '100000000000000'; function transfer(api: any) { - let txs: any = []; for (let index = 0; index < whiteList.length; index++) { try { @@ -16,16 +15,17 @@ function transfer(api: any) { txs.push(tx); } catch (error: any) { //maybe invalied address or other error remove it from whitelist - console.log(colors.red('transfer Error: '), `${error.message}. Removing ${whiteList[index]} from whiteList.`); + console.log( + colors.red('transfer Error: '), + `${error.message}. Removing ${whiteList[index]} from whiteList.` + ); whiteList.splice(index, 1); index--; } } - const transfer_hex = - api.tx.utility.batchAll(txs) - .toHex() + const transfer_hex = api.tx.utility.batchAll(txs).toHex(); - return transfer_hex + return transfer_hex; } async function main() { @@ -41,13 +41,13 @@ async function main() { // Read the second column of the sheet and skip the first row whiteList = worksheet.getColumn(2).values.slice(1); - const { defaultAPI } = await initApi(); + // params: source chain endpoint, destination chain endpoint + const { sourceApi } = await initApi('ws://localhost:9944', 'ws://localhost:9944'); - const transfer_hex = transfer(defaultAPI); + const transfer_hex = transfer(sourceApi); console.log(colors.green('transfer_hex'), transfer_hex); console.log(colors.green('done')); - process.exit() - + process.exit(); } -main(); \ No newline at end of file +main(); diff --git a/scripts/ts-utils/transfer.ts b/scripts/ts-utils/transfer.ts index 54bf32a67e..093de57ed9 100644 --- a/scripts/ts-utils/transfer.ts +++ b/scripts/ts-utils/transfer.ts @@ -1,39 +1,39 @@ -const { Keyring } = require("@polkadot/api"); -import { initApi } from "./initApis"; -const { hexToU8a } = require("@polkadot/util"); -import colors from "colors"; +const { Keyring } = require('@polkadot/api'); +import { initApi } from './initApis'; +const { hexToU8a } = require('@polkadot/util'); +import colors from 'colors'; // 100 token -const transferAmount = "100000000000000"; +const transferAmount = '100000000000000'; const enclaveAccount = process.argv[2]; async function transfer(api, Alice) { - console.log(colors.green("Transfer start...")); + console.log(colors.green('Transfer start...')); return new Promise((resolve, reject) => { - api.tx.balances - .transfer(enclaveAccount, transferAmount) - .signAndSend(Alice, ({ status, events }) => { - if (status.isInBlock || status.isFinalized) { - events.forEach(({ event: { method, section } }) => { - if (method === "Transfer" && section === "balances") { - console.log(colors.green("Transfer completed")); - resolve("Transfer done"); - return; - } - }); - } - }); + api.tx.balances.transfer(enclaveAccount, transferAmount).signAndSend(Alice, ({ status, events }) => { + if (status.isInBlock || status.isFinalized) { + events.forEach(({ event: { method, section } }) => { + if (method === 'Transfer' && section === 'balances') { + console.log(colors.green('Transfer completed')); + resolve('Transfer done'); + return; + } + }); + } + }); }); } async function main() { - const keyring = new Keyring({ type: "sr25519" }); - const { defaultAPI } = await initApi(); - const Alice = keyring.addFromUri("//Alice", { name: "Alice default" }); + const keyring = new Keyring({ type: 'sr25519' }); - await transfer(defaultAPI, Alice); + // params: source chain endpoint, destination chain endpoint + const { destinationAPI } = await initApi('ws://localhost:9944', 'ws://localhost:9944'); + const Alice = keyring.addFromUri('//Alice', { name: 'Alice default' }); - console.log(colors.green("Done")); + await transfer(destinationAPI, Alice); + + console.log(colors.green('Done')); process.exit(); }