helper
This commit is contained in:
parent
98fb2587bc
commit
f7e96f4b6c
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
ChainId,
|
ChainId,
|
||||||
CHAIN_ID_TO_NAME,
|
CHAIN_ID_TO_NAME,
|
||||||
|
CHAINS,
|
||||||
isChain,
|
isChain,
|
||||||
CONTRACTS,
|
CONTRACTS,
|
||||||
getSignedVAAWithRetry,
|
getSignedVAAWithRetry,
|
||||||
|
@ -140,14 +141,17 @@ export function stringifyInfo(info: DeliveryInfo | RedeliveryInfo): string {
|
||||||
return stringifiedInfo
|
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(
|
export async function getDeliveryInfoBySourceTx(
|
||||||
infoRequest: InfoRequest
|
infoRequest: InfoRequest
|
||||||
): Promise<DeliveryInfo | RedeliveryInfo> {
|
): Promise<DeliveryInfo | RedeliveryInfo> {
|
||||||
const sourceChainProvider =
|
const sourceChainProvider =
|
||||||
infoRequest.sourceChainProvider ||
|
infoRequest.sourceChainProvider || getDefaultProvider(infoRequest.environment, infoRequest.sourceChain);
|
||||||
new ethers.providers.StaticJsonRpcProvider(
|
|
||||||
RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[infoRequest.sourceChain]]
|
|
||||||
)
|
|
||||||
if (!sourceChainProvider)
|
if (!sourceChainProvider)
|
||||||
throw Error(
|
throw Error(
|
||||||
"No default RPC for this chain; pass in your own provider (as sourceChainProvider)"
|
"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}`)
|
if(!isChain(targetChain)) throw Error(`Invalid Chain: ${targetChain}`)
|
||||||
const targetChainProvider =
|
const targetChainProvider =
|
||||||
infoRequest.targetChainProviders?.get(targetChain) ||
|
infoRequest.targetChainProviders?.get(targetChain) ||
|
||||||
new ethers.providers.StaticJsonRpcProvider(
|
getDefaultProvider(infoRequest.environment, targetChain)
|
||||||
RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[targetChain]]
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!targetChainProvider)
|
if (!targetChainProvider)
|
||||||
throw Error(
|
throw Error(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
ChainId,
|
ChainId,
|
||||||
CHAIN_ID_TO_NAME,
|
CHAIN_ID_TO_NAME,
|
||||||
|
CHAINS,
|
||||||
isChain,
|
isChain,
|
||||||
CONTRACTS,
|
CONTRACTS,
|
||||||
getSignedVAAWithRetry,
|
getSignedVAAWithRetry,
|
||||||
|
@ -140,14 +141,17 @@ export function stringifyInfo(info: DeliveryInfo | RedeliveryInfo): string {
|
||||||
return stringifiedInfo
|
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(
|
export async function getDeliveryInfoBySourceTx(
|
||||||
infoRequest: InfoRequest
|
infoRequest: InfoRequest
|
||||||
): Promise<DeliveryInfo | RedeliveryInfo> {
|
): Promise<DeliveryInfo | RedeliveryInfo> {
|
||||||
const sourceChainProvider =
|
const sourceChainProvider =
|
||||||
infoRequest.sourceChainProvider ||
|
infoRequest.sourceChainProvider || getDefaultProvider(infoRequest.environment, infoRequest.sourceChain);
|
||||||
new ethers.providers.StaticJsonRpcProvider(
|
|
||||||
RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[infoRequest.sourceChain]]
|
|
||||||
)
|
|
||||||
if (!sourceChainProvider)
|
if (!sourceChainProvider)
|
||||||
throw Error(
|
throw Error(
|
||||||
"No default RPC for this chain; pass in your own provider (as sourceChainProvider)"
|
"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}`)
|
if(!isChain(targetChain)) throw Error(`Invalid Chain: ${targetChain}`)
|
||||||
const targetChainProvider =
|
const targetChainProvider =
|
||||||
infoRequest.targetChainProviders?.get(targetChain) ||
|
infoRequest.targetChainProviders?.get(targetChain) ||
|
||||||
new ethers.providers.StaticJsonRpcProvider(
|
getDefaultProvider(infoRequest.environment, targetChain)
|
||||||
RPCS_BY_CHAIN[infoRequest.environment][CHAIN_ID_TO_NAME[targetChain]]
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!targetChainProvider)
|
if (!targetChainProvider)
|
||||||
throw Error(
|
throw Error(
|
||||||
|
|
Loading…
Reference in New Issue