diff --git a/src/config.ts b/src/config.ts index a9a0ab6..e0ece9c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -122,7 +122,7 @@ export const prodBridgeConfig: IBridgeConfig = { bridgeChains: [ { chain: "BSC", - rpcURL: "https://bsc.blockpi.network/v1/rpc/public", + rpcURL: "https://bnb.rpc.subquery.network/public", nativeCoinSymbol: "BNB", intialFund: "50000000000000000", contractAddress: "0x289FDdDce5119C41B82C969135212061D5E7Dce5", diff --git a/src/handler/evm/index.ts b/src/handler/evm/index.ts index 0708f58..82527bb 100644 --- a/src/handler/evm/index.ts +++ b/src/handler/evm/index.ts @@ -64,7 +64,7 @@ export function evmHandler({ nftData: royaltyProxy !== undefined - ? nftDataForHedera(provider, royaltyProxy) + ? nftDataForHedera(provider, royaltyProxy, logger) : nftData(provider, logger), selfIsValidator: selfIsValidator(bc, signer), signClaimData: signClaimData(chainIdent, txSigner, logger), diff --git a/src/handler/evm/utils/nftDataForHedera.ts b/src/handler/evm/utils/nftDataForHedera.ts index 6306276..3564854 100644 --- a/src/handler/evm/utils/nftDataForHedera.ts +++ b/src/handler/evm/utils/nftDataForHedera.ts @@ -1,34 +1,44 @@ import type { JsonRpcProvider } from "ethers"; import { ERC721Royalty__factory } from "../../../contractsTypes/evm"; import { RoyaltyInfoProxy__factory } from "../../../contractsTypes/hedera/RoyaltyInfoProxy__factory"; - -const nftDataForHedera = (provider: JsonRpcProvider, royaltyProxy: string) => { +import type { LogInstance } from "../../types"; +import { retry } from "../../utils"; + +const nftDataForHedera = ( + provider: JsonRpcProvider, + royaltyProxy: string, + logger: LogInstance, +) => { const proxy = RoyaltyInfoProxy__factory.connect(royaltyProxy, provider); return async (tokenId: string, contract: string) => { const nft = ERC721Royalty__factory.connect(contract, provider); - const name = await retryFn( + const name = await retry( () => nft.name(), `Trying to fetch name() for ${contract}`, + logger, ); - const symbol = await retryFn( + const symbol = await retry( () => nft.symbol(), `Trying to fetch symbol() for ${contract}`, + logger, ); - const tokenInfo = await retryFn( + const tokenInfo = await retry( () => proxy.royaltyInfo.staticCall(contract, tokenId), `Trying to fetch royaltyInfo() for ${contract}`, + logger, ); const rinfo = tokenInfo?.[1].tokenInfo[7][0]; // If undefined, set royalty as zero. const royalty = rinfo?.numerator ?? 0n; - const metadata = await retryFn( + const metadata = await retry( () => nft.tokenURI(tokenId), `Trying to fetch tokenURI() for ${contract}`, + logger, ); return { @@ -42,18 +52,3 @@ const nftDataForHedera = (provider: JsonRpcProvider, royaltyProxy: string) => { }; export default nftDataForHedera; - -export async function retryFn( - func: () => Promise, - ctx: string, - retries = 3, -) { - if (retries === 0) { - throw new Error(`Failed ${ctx}`); - } - try { - return await func(); - } catch (e) { - return await retryFn(func, ctx, retries - 1); - } -}