Skip to content

Commit

Permalink
chore(mx): mx changes
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Sep 6, 2024
1 parent 2acebf2 commit 971d3f8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<THandler>,
Expand Down Expand Up @@ -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,
Expand All @@ -89,6 +93,7 @@ export async function listenEvents(
tokenId: ev.tokenId,
transactionHash: ev.transactionHash,
lockTxChain: chain.chainIdent,
imgUri: imgUri,
};
log.trace(inft);

Expand Down
1 change: 1 addition & 0 deletions src/handler/multiversx/utils/signClaimData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 2 additions & 16 deletions src/handler/ton/utils/nftData.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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");
}
1 change: 1 addition & 0 deletions src/handler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type TNftTransferDetailsObject = {
nftType: string;
fee: string;
lockTxChain: string;
imgUri?: string;
};

export type LockEventIter = (event: LockEvent) => Promise<void>;
Expand Down
16 changes: 16 additions & 0 deletions src/handler/utils.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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");
}

0 comments on commit 971d3f8

Please sign in to comment.