Skip to content

Commit

Permalink
fix(cosmic-swingset): update check-validator.js for Cosmos 0.43.x
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jun 25, 2021
1 parent 8eeec28 commit 7b94577
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions packages/cosmic-swingset/check-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,47 @@ console.log('Fetching current node pubkey...');
const ret2 = spawnSync('ag-chain-cosmos', ['tendermint', 'show-validator']);
const selfPub = ret2.stdout.toString('utf-8').trim();
console.log(selfPub);
console.log('Fetching current node hex...');
const ret3 = spawnSync('ag-cosmos-helper', [
'keys',
'parse',
'--output=json',
selfPub,
]);
const selfParse = ret3.stdout.toString('utf-8');
let selfParseObj;

const selfObj = {};
try {
selfParseObj = JSON.parse(selfParse);
selfObj.pk = JSON.parse(selfPub);
} catch (e) {
console.error('Cannot parse', selfParse);
throw e;
}
console.log('Fetching current node hex...');
const ret3 = spawnSync('ag-cosmos-helper', [
'keys',
'parse',
'--output=json',
selfPub,
]);
const selfParse = ret3.stdout.toString('utf-8');
let selfParseObj;
try {
selfParseObj = JSON.parse(selfParse);
} catch (e) {
console.error('Cannot parse', selfParse);
throw e;
}

const selfHex = selfParseObj.bytes;
console.log(selfHex);
const selfHex = selfParseObj.bytes;
console.log(selfHex);
selfObj.pkHex = selfHex;
}

console.log('Matching pubkeys...');
const lselfHex = selfHex.toLowerCase();
const match = opKeys.find(({ pkHex }) =>
lselfHex.endsWith(pkHex.toLowerCase()),
);
const lselfHex = selfObj.pkHex && selfObj.pkHex.toLowerCase();
const match = opKeys.find(({ pk, pkHex }) => {
if (selfObj.pk && pk) {
if (selfObj.pk['@type'] === pk['@type'] && selfObj.pk.key === pk.key) {
return true;
}
}
if (lselfHex && pkHex) {
if (lselfHex.endsWith(pkHex.toLowerCase())) {
return true;
}
}
return false;
});

if (!match) {
console.log(JSON.stringify(narrow, null, 2));
Expand Down

0 comments on commit 7b94577

Please sign in to comment.