difftreelog
feat(identity) offchain script for pulling and inserting identities
in: master
2 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -31,6 +31,7 @@
"lint": "eslint --ext .ts,.js src/",
"fix": "eslint --ext .ts,.js src/ --fix",
"setup": "ts-node ./src/util/globalSetup.ts",
+ "setIdentities": "ts-node ./src/util/identitySetter.ts",
"test": "yarn setup && mocha --timeout 9999999 -r ts-node/register './src/**/*.*test.ts'",
"testParallelFull": "yarn testParallel && yarn testSequential",
"testParallel": "yarn setup && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",
tests/src/util/identitySetter.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {usingPlaygrounds, Pallets} from './index';56const relayUrl0 = process.argv[2] ?? 'localhost:9844';7const relayUrl = `ws${relayUrl0.includes('localhost')'''s'}://${relayUrl0}`;89const paraUrl0 = process.argv[3] ?? 'localhost:9944';10const paraUrl = `ws${paraUrl0.includes('localhost')'''s'}://${paraUrl0}`;1112const key = process.argv.length > 4 ? process.argv.slice(4).join(' ') : '//Alice';1314// This is a utility for pulling15const setIdentities = async (): Promise<void> => {16 const identities: any[] = [];17 await usingPlaygrounds(async helper => {18 try {19 for(const [key, v] of await helper.getApi().query.identity.identityOf.entries()) {20 const value = v as any;21 if (!value.isSome) continue;22 if (value.unwrap().toHuman().judgements.filter((x: any) => x[1] == 'Reasonable' || x[1] == 'KnownGood').length == 0) continue;23 identities.push([key, value]);24 }25 } catch (error) {26 console.error(error);27 throw Error('Error during fetching identities');28 }29 }, relayUrl);3031 await usingPlaygrounds(async (helper, privateKey) => {32 if (helper.fetchMissingPalletNames([Pallets.Identity]).length != 0) console.error('pallet-identity is not included in parachain.');33 try {34 const superuser = await privateKey(key);35 // todo:collator36 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.dataManagement.setIdentities', [identities]);37 console.log(`Tried to upload ${identities.length} identities. `38 + `Now there are ${(awaithelper.getApi().query.identity.identityOf.keys()).length}.`);39 } catch (error) {40 console.error(error);41 throw Error('Error during setting identities');42 }43 }, paraUrl);44};4546setIdentities().catch(() => process.exit(1));