123456789import {encodeAddress} from '@polkadot/keyring';10import {usingPlaygrounds} from '@unique/test-utils/util.js';11import {getIdentities, getSubs, getSupers, constructSubInfo} from './identitySetter.js';1213const relay1Url = process.argv[2] ?? 'ws://localhost:9844';14const relay2Url = process.argv[3] ?? 'ws://localhost:9844';1516async function pullIdentities(relayUrl: string): Promise<[any[], any[]]> {17 const identities: any[] = [];18 const subs: any[] = [];1920 await usingPlaygrounds(async helper => {21 try {22 23 for(const [key, value] of await getIdentities(helper)) {24 25 if(value.toHuman().judgements.filter((x: any) => x[1] == 'Reasonable' || x[1] == 'KnownGood').length == 0) continue;26 identities.push([key, value]);27 }2829 const supersOfSubs = await getSupers(helper);3031 32 for(const [key, value] of await getSubs(helper)) {33 34 if(identities.find((x: any) => x[0] == key) == -1) continue;35 subs.push(constructSubInfo(key, value, supersOfSubs));36 }37 } catch (error) {38 console.error(error);39 throw Error(`Error during fetching identities on ${relayUrl}`);40 }41 }, relayUrl);4243 return [identities, subs];44}454647const checkRelayIdentities = async (): Promise<void> => {48 const [identitiesOnRelay1, subIdentitiesOnRelay1] = await pullIdentities(relay1Url);49 const [identitiesOnRelay2, subIdentitiesOnRelay2] = await pullIdentities(relay2Url);5051 console.log('identities counts:\t', identitiesOnRelay1.length, identitiesOnRelay2.length);52 console.log('sub-identities counts:\t', subIdentitiesOnRelay1.length, subIdentitiesOnRelay2.length);53 console.log();5455 try {56 const matchingAddresses: string[] = [];57 const inequalIdentities: {[name: string]: [any, any]} = {};5859 for(const [key1, value1] of identitiesOnRelay1) {60 const address = encodeAddress(key1);61 const identity2 = identitiesOnRelay2.find(([key2, _value2]) => address === encodeAddress(key2));62 if(!identity2) continue;63 matchingAddresses.push(address);6465 66 const [_key2, value2] = identity2;67 if(JSON.stringify(value1.info) === JSON.stringify(value2.info)) continue;68 inequalIdentities[address] = [value1, value2];69 }7071 72737475767778 console.log(`Accounts with identities on both relays:\t${matchingAddresses.length}`);79 console.log(`Sub-identities with conflicting information:\t${Object.entries(inequalIdentities).length}`);80 console.log();8182 const inequalSubIdentities = [];83 let matchesFound = 0;84 for(const address of matchingAddresses) {85 const sub1 = subIdentitiesOnRelay1.find(([key1, _value1]) => address === encodeAddress(key1));86 if(!sub1) continue;87 const sub2 = subIdentitiesOnRelay2.find(([key2, _value2]) => address === encodeAddress(key2));88 if(!sub2) continue;8990 const [value1, value2] = [sub1[1], sub2[1]];91 matchesFound++;9293 if(JSON.stringify(value1[1]) === JSON.stringify(value2[1])) {94 continue;95 }96 inequalSubIdentities.push([value1, value2]);97 }9899 100101102103104105 console.log(`Accounts with sub-identities on both relays:\t${matchesFound}`);106 console.log(`Of them, those with conflicting sub-identities:\t${inequalSubIdentities.length}`);107 } catch (error) {108 console.error(error);109 throw Error('Error during comparison');110 }111};112113if(process.argv[1] === module.filename)114 checkRelayIdentities().catch(() => process.exit(1));