Client/js: Simplify edit-vaa command (#3359)

This commit is contained in:
bruce-riley 2023-09-07 14:10:52 -05:00 committed by GitHub
parent 957f3307de
commit edba6449a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 11 deletions

View File

@ -94,8 +94,8 @@ Options:
--signatures, --sigs comma separated list of signatures [string]
--wormscanurl, --wsu url to wormscan entry for the vaa that
includes signatures [string]
--wormscanfile, --wsf json file containing wormscan entry for the
vaa that includes signatures [string]
--wormscan, --ws if specified, will query the wormscan entry
for the vaa to get the signatures [boolean]
--emitter-chain-id, --ec emitter chain id to be used in the vaa
[number]
--emitter-address, --ea emitter address to be used in the vaa[string]

View File

@ -52,11 +52,11 @@ export const builder = (y: typeof yargs) =>
describe: "url to wormscan entry for the vaa that includes signatures",
type: "string",
})
.option("wormscanfile", {
alias: "wsf",
.option("wormscan", {
alias: "ws",
describe:
"json file containing wormscan entry for the vaa that includes signatures",
type: "string",
"if specified, will query the wormscan entry for the vaa to get the signatures",
type: "boolean",
})
.option("emitter-chain-id", {
alias: "ec",
@ -110,7 +110,7 @@ export const handler = async (
numSigs += 1;
}
if (argv.wormscanfile) {
if (argv.wormscan) {
numSigs += 1;
}
@ -124,7 +124,7 @@ export const handler = async (
if (numSigs > 1) {
throw new Error(
`may only specify one of "--signatures", "--wormscanfile", "--wormscanurl" or "--guardian-secret"`
`may only specify one of "--signatures", "--wormscan", "--wormscanurl" or "--guardian-secret"`
);
}
@ -170,10 +170,20 @@ export const handler = async (
signature: s,
guardianSetIndex: i,
}));
} else if (argv.wormscanfile) {
const wormscanData = require(argv.wormscanfile);
} else if (argv.wormscan) {
const wormscanurl =
"https://api.wormscan.io/api/v1/observations/" +
vaa.emitterChain.toString() +
"/" +
vaa.emitterAddress.replace(/^(0x)/, "") +
"/" +
vaa.sequence.toString();
const wormscanData = await axios.get(wormscanurl);
const guardianSet = await getGuardianSet(network, vaa.guardianSetIndex);
vaa.signatures = await getSigsFromWormscanData(wormscanData, guardianSet);
vaa.signatures = await getSigsFromWormscanData(
wormscanData.data,
guardianSet
);
} else if (argv.wormscanurl) {
const wormscanData = await axios.get(argv.wormscanurl);
const guardianSet = await getGuardianSet(network, vaa.guardianSetIndex);