clients: allow custom block range for relayer status (#3188)

This commit is contained in:
derpy-duck 2023-07-13 10:09:46 -04:00 committed by GitHub
parent 8120772e95
commit 70dd001ba3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View File

@ -315,14 +315,16 @@ Options:
```sh
Positionals:
network Network [choices: "mainnet", "testnet", "devnet"]
chain Source chain
network Network [choices: "mainnet", "testnet", "devnet"]
chain Source chain
[choices: "unset", "solana", "ethereum", "terra", "bsc", "polygon",
"avalanche", "oasis", "algorand", "aurora", "fantom", "karura", "acala",
"klaytn", "celo", "near", "moonbeam", "neon", "terra2", "injective",
"osmosis", "sui", "aptos", "arbitrum", "optimism", "gnosis", "pythnet",
"xpla", "btc", "base", "sei", "wormchain", "sepolia"]
tx Source transaction hash [string]
tx Source transaction hash [string]
block-start Starting Block Range, i.e. -2048 [string]
block-end Ending Block Range, i.e. latest [string]
Options:
--help Show help [boolean]

View File

@ -4,7 +4,7 @@ import {
assertChain,
} from "@certusone/wormhole-sdk/lib/esm/utils/consts";
import { relayer, Network } from "@certusone/wormhole-sdk";
import yargs from "yargs";
import yargs, { string } from "yargs";
import { CONTRACTS, NETWORKS } from "../consts";
import { assertNetwork } from "../utils";
import { impossible } from "../vaa";
@ -29,6 +29,14 @@ export const builder = (y: typeof yargs) =>
describe: "Source transaction hash",
type: "string",
demandOption: true,
} as const)
.positional("block-start", {
describe: "Starting Block Range, i.e. -2048",
type: "string",
} as const)
.positional("block-end", {
describe: "Ending Block Range, i.e. latest",
type: "string",
} as const);
export const handler = async (
argv: Awaited<ReturnType<typeof builder>["argv"]>
@ -55,12 +63,35 @@ export const handler = async (
)
);
}
const targetChainBlockRanges = new Map<
ChainName,
[ethers.providers.BlockTag, ethers.providers.BlockTag]
>();
const getBlockTag = (tagString: string): ethers.providers.BlockTag => {
if (+tagString) return parseInt(tagString);
return tagString;
};
for (const key in NETWORKS[network]) {
targetChainBlockRanges.set(key as ChainName, [
getBlockTag(argv["block-start"] || "-2048"),
getBlockTag(argv["block-end"] || "latest"),
]);
}
const info = await relayer.getWormholeRelayerInfo(chain, argv.tx, {
environment: network,
sourceChainProvider,
targetChainProviders,
targetChainBlockRanges,
});
console.log(relayer.stringifyWormholeRelayerInfo(info));
if (
info.targetChainStatus.events[0].status ===
relayer.DeliveryStatus.DeliveryDidntHappenWithinRange
) {
console.log(
"Try using the '--block-start' and '--block-end' flags to specify a different block range"
);
}
};