From 971d3f8ca98a90db5e6e616413f8d5c576632550 Mon Sep 17 00:00:00 2001 From: D Date: Fri, 6 Sep 2024 18:22:30 +0500 Subject: [PATCH] chore(mx): mx changes --- src/handler/index.ts | 7 ++++++- src/handler/multiversx/utils/signClaimData.ts | 1 + src/handler/ton/utils/nftData.ts | 18 ++---------------- src/handler/types.ts | 1 + src/handler/utils.ts | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/handler/index.ts b/src/handler/index.ts index 2c4fd95a..f85ebe0b 100644 --- a/src/handler/index.ts +++ b/src/handler/index.ts @@ -2,6 +2,7 @@ import { setTimeout } from "node:timers/promises"; import type { EntityManager } from "@mikro-orm/sqlite"; import type { MutexInterface } from "async-mutex"; import type { AxiosInstance } from "axios"; +import axios from "axios"; import type { TSupportedChainTypes, TSupportedChains } from "../config"; import type { BridgeStorage } from "../contractsTypes/evm"; import { LockedEvent } from "../persistence/entities/locked"; @@ -13,7 +14,7 @@ import type { TNftTransferDetailsObject, TStakingHandler, } from "./types"; -import { retry } from "./utils"; +import { fetchHttpOrIpfs, retry } from "./utils"; export async function listenEvents( chains: Array, @@ -73,6 +74,9 @@ export async function listenEvents( ev.destinationChain, ); + const imgUri = (await fetchHttpOrIpfs(nftDetails.metadata, axios.create())) + .image; + const inft: TNftTransferDetailsObject = { destinationChain: ev.destinationChain, destinationUserAddress: ev.destinationUserAddress, @@ -89,6 +93,7 @@ export async function listenEvents( tokenId: ev.tokenId, transactionHash: ev.transactionHash, lockTxChain: chain.chainIdent, + imgUri: imgUri, }; log.trace(inft); diff --git a/src/handler/multiversx/utils/signClaimData.ts b/src/handler/multiversx/utils/signClaimData.ts index c5a645c7..e4f289a9 100644 --- a/src/handler/multiversx/utils/signClaimData.ts +++ b/src/handler/multiversx/utils/signClaimData.ts @@ -57,6 +57,7 @@ export default async function signClaimData( new Field(new BytesValue(Buffer.from(buf.nftType)), "nft_type"), new Field(new BigUIntValue(buf.fee), "fee"), new Field(new BytesValue(Buffer.from(buf.lockTxChain)), "lock_tx_chain"), + new Field(new BytesValue(Buffer.from(buf.imgUri || "")), "img_uri"), ]); const data = new BinaryCodec().encodeNested(claimDataArgs); diff --git a/src/handler/ton/utils/nftData.ts b/src/handler/ton/utils/nftData.ts index ec7f2623..8aaf54e8 100644 --- a/src/handler/ton/utils/nftData.ts +++ b/src/handler/ton/utils/nftData.ts @@ -1,8 +1,9 @@ import { Address, type TonClient } from "@ton/ton"; -import axios, { type AxiosInstance } from "axios"; +import axios from "axios"; import { raise } from ".."; import { NftCollection } from "../../../contractsTypes/ton/tonNftCollection"; import { NftItem } from "../../../contractsTypes/ton/tonNftContract"; +import { fetchHttpOrIpfs } from "../../utils"; export default async function nftData( tokenId: string, @@ -70,18 +71,3 @@ export default async function nftData( royalty: BigInt(royalty), }; } - -async function fetchHttpOrIpfs(uri: string, http: AxiosInstance) { - const url = new URL(uri); - if (url.protocol === "http:" || url.protocol === "https:") { - const response = await http.get(uri); - return response.data; - } - if (url.protocol === "ipfs:") { - const response = await http.get( - `https://ipfs.io/ipfs/${uri.replace("ipfs://", "")}`, - ); - return response.data; - } - throw new Error("Unsupported protocol"); -} diff --git a/src/handler/types.ts b/src/handler/types.ts index 4a92c6c6..5bfa4ddd 100644 --- a/src/handler/types.ts +++ b/src/handler/types.ts @@ -25,6 +25,7 @@ export type TNftTransferDetailsObject = { nftType: string; fee: string; lockTxChain: string; + imgUri?: string; }; export type LockEventIter = (event: LockEvent) => Promise; diff --git a/src/handler/utils.ts b/src/handler/utils.ts index c5195044..cd98c88a 100644 --- a/src/handler/utils.ts +++ b/src/handler/utils.ts @@ -1,4 +1,5 @@ import { setTimeout } from "node:timers/promises"; +import type { AxiosInstance } from "axios"; import { JsonRpcProvider, Wallet } from "ethers"; import { ERC20Staking__factory, ERC20__factory } from "../contractsTypes/evm"; import type { IGeneratedWallets, IStakingConfig } from "../types"; @@ -109,3 +110,18 @@ export async function stakeTokens( throw new Error("Failed to stake"); } } + +export async function fetchHttpOrIpfs(uri: string, http: AxiosInstance) { + const url = new URL(uri); + if (url.protocol === "http:" || url.protocol === "https:") { + const response = await http.get(uri); + return response.data; + } + if (url.protocol === "ipfs:") { + const response = await http.get( + `https://ipfs.io/ipfs/${uri.replace("ipfs://", "")}`, + ); + return response.data; + } + throw new Error("Unsupported protocol"); +}