Skip to content

Commit

Permalink
clients/js: chain, rpc, contract-address added to verify-vaa command
Browse files Browse the repository at this point in the history
  • Loading branch information
HamphreyR26 committed May 24, 2024
1 parent af8bbc2 commit d50b36a
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions clients/js/src/cmds/verifyVaa.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// The verify-vaa command invokes the parseAndVerifyVM method on the core contract on Ethereum to verify the specified VAA.
// The verify-vaa command invokes the parseAndVerifyVM method on the core contract on the specified EVM chain to verify the specified VAA.

import { Implementation__factory } from "@certusone/wormhole-sdk/lib/esm/ethers-contracts";
import { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
import {
CONTRACTS,
CHAINS,
assertChain,
assertEVMChain
} from "@certusone/wormhole-sdk/lib/esm/utils/consts";
import { ethers } from "ethers";
import yargs from "yargs";
import { NETWORKS, NETWORK_OPTIONS } from "../consts";
import { assertNetwork } from "../utils";

export const command = "verify-vaa";
export const desc = "Verifies a VAA by querying the core contract on Ethereum";
export const desc = "Verifies a VAA by querying the core contract on the specified EVM chain";
export const builder = (y: typeof yargs) =>
y
.option("vaa", {
Expand All @@ -17,22 +22,41 @@ export const builder = (y: typeof yargs) =>
type: "string",
demandOption: true,
})
.option("network", NETWORK_OPTIONS);
.option("network", NETWORK_OPTIONS)
.option("chain", {
alias: "c",
describe: "chain name",
choices: Object.keys(CHAINS) as ChainName[],
demandOption: true,
} as const)
.option("contract-address", {
alias: "a",
describe: "Contract to verify VAA on (override config)",
type: "string",
demandOption: false,
})
.option("rpc", {
describe: "RPC endpoint",
type: "string",
demandOption: false,
})
export const handler = async (
argv: Awaited<ReturnType<typeof builder>["argv"]>
) => {
const network = argv.network.toUpperCase();
const chain = argv.chain;
assertChain(chain);
assertEVMChain(chain);

const network = (argv.network ?? "mainnet").toUpperCase();
assertNetwork(network);

const buf = Buffer.from(String(argv.vaa), "hex");
const contract_address = CONTRACTS[network].ethereum.core;
const rpc = argv.rpc ?? NETWORKS[network][chain].rpc;
const contract_address = argv["contract-address"] ?? CONTRACTS[network][chain].core;
if (!contract_address) {
throw Error(`Unknown core contract on ${network} for ethereum`);
throw Error(`Unknown core contract on ${network} for ${chain}`);
}

const provider = new ethers.providers.JsonRpcProvider(
NETWORKS[network].ethereum.rpc
);
const buf = Buffer.from(String(argv.vaa), "hex");
const provider = new ethers.providers.JsonRpcProvider(rpc);
const contract = Implementation__factory.connect(contract_address, provider);
const result = await contract.parseAndVerifyVM(buf);
if (result[1]) {
Expand Down

0 comments on commit d50b36a

Please sign in to comment.