From f7e96f4b6c7a134593bf3457069d277362f4868c Mon Sep 17 00:00:00 2001 From: derpy-duck <115193320+derpy-duck@users.noreply.github.com> Date: Wed, 15 Mar 2023 21:50:19 +0000 Subject: [PATCH] helper --- relayer_engine/pkgs/sdk/src/main/status.ts | 16 +++++++++------- sdk/src/main/status.ts | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/relayer_engine/pkgs/sdk/src/main/status.ts b/relayer_engine/pkgs/sdk/src/main/status.ts index 6bbc6f8..5e658da 100644 --- a/relayer_engine/pkgs/sdk/src/main/status.ts +++ b/relayer_engine/pkgs/sdk/src/main/status.ts @@ -1,6 +1,7 @@ import { ChainId, CHAIN_ID_TO_NAME, + CHAINS, isChain, CONTRACTS, getSignedVAAWithRetry, @@ -140,14 +141,17 @@ export function stringifyInfo(info: DeliveryInfo | RedeliveryInfo): string { return stringifiedInfo } +function getDefaultProvider(network: Network, chainId: ChainId) { + return new ethers.providers.StaticJsonRpcProvider( + RPCS_BY_CHAIN[network][CHAIN_ID_TO_NAME[chainId]] + ) +} + export async function getDeliveryInfoBySourceTx( infoRequest: InfoRequest ): Promise { const sourceChainProvider = - infoRequest.sourceChainProvider || - new ethers.providers.StaticJsonRpcProvider( - RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[infoRequest.sourceChain]] - ) + infoRequest.sourceChainProvider || getDefaultProvider(infoRequest.environment, infoRequest.sourceChain); if (!sourceChainProvider) throw Error( "No default RPC for this chain; pass in your own provider (as sourceChainProvider)" @@ -195,9 +199,7 @@ export async function getDeliveryInfoBySourceTx( if(!isChain(targetChain)) throw Error(`Invalid Chain: ${targetChain}`) const targetChainProvider = infoRequest.targetChainProviders?.get(targetChain) || - new ethers.providers.StaticJsonRpcProvider( - RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[targetChain]] - ) + getDefaultProvider(infoRequest.environment, targetChain) if (!targetChainProvider) throw Error( diff --git a/sdk/src/main/status.ts b/sdk/src/main/status.ts index 6bbc6f8..5e658da 100644 --- a/sdk/src/main/status.ts +++ b/sdk/src/main/status.ts @@ -1,6 +1,7 @@ import { ChainId, CHAIN_ID_TO_NAME, + CHAINS, isChain, CONTRACTS, getSignedVAAWithRetry, @@ -140,14 +141,17 @@ export function stringifyInfo(info: DeliveryInfo | RedeliveryInfo): string { return stringifiedInfo } +function getDefaultProvider(network: Network, chainId: ChainId) { + return new ethers.providers.StaticJsonRpcProvider( + RPCS_BY_CHAIN[network][CHAIN_ID_TO_NAME[chainId]] + ) +} + export async function getDeliveryInfoBySourceTx( infoRequest: InfoRequest ): Promise { const sourceChainProvider = - infoRequest.sourceChainProvider || - new ethers.providers.StaticJsonRpcProvider( - RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[infoRequest.sourceChain]] - ) + infoRequest.sourceChainProvider || getDefaultProvider(infoRequest.environment, infoRequest.sourceChain); if (!sourceChainProvider) throw Error( "No default RPC for this chain; pass in your own provider (as sourceChainProvider)" @@ -195,9 +199,7 @@ export async function getDeliveryInfoBySourceTx( if(!isChain(targetChain)) throw Error(`Invalid Chain: ${targetChain}`) const targetChainProvider = infoRequest.targetChainProviders?.get(targetChain) || - new ethers.providers.StaticJsonRpcProvider( - RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[targetChain]] - ) + getDefaultProvider(infoRequest.environment, targetChain) if (!targetChainProvider) throw Error(