From d50c71b36aed7f1c0b4ad1f843dffc715521a367 Mon Sep 17 00:00:00 2001 From: satheesh Date: Fri, 14 Jun 2024 16:33:11 +0400 Subject: [PATCH 1/5] Updated archive RPC for XDC --- src/constants/chain-info.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constants/chain-info.ts b/src/constants/chain-info.ts index e9b1774c8..bb45bf339 100644 --- a/src/constants/chain-info.ts +++ b/src/constants/chain-info.ts @@ -114,7 +114,7 @@ export const ChainInfo: ChainInfo = { networkName: "xdc", networkLabel: "XDC Network", explorerUrl: "https://xdcscan.io", - rpcUrl: "https://rpc.ankr.com/xdc", + rpcUrl: "https://tradetrustrpc.xdcrpc.com", nativeCurrency: { name: "XDC", symbol: "XDC", @@ -128,7 +128,7 @@ export const ChainInfo: ChainInfo = { networkName: "xdcapothem", networkLabel: "XDC Testnet Apothem", explorerUrl: "https://apothem.xdcscan.io", - rpcUrl: "https://rpc.ankr.com/xdc_testnet", + rpcUrl: "https://tradetrustarpc.xdcrpc.com", nativeCurrency: { name: "XDCt", symbol: "XDCt", From 905b9b7b1e0a6db1759f8ef6fff06da461dfb53e Mon Sep 17 00:00:00 2001 From: satheesh Date: Fri, 14 Jun 2024 18:53:11 +0400 Subject: [PATCH 2/5] Added blockNumber config for endorsement chain --- package-lock.json | 5 ++--- package.json | 18 +++++++++--------- .../useEndorsementChain/fetchEscrowTransfer.ts | 10 +++++++--- .../fetchTokenTransfer.integration.test.ts | 1 + .../useEndorsementChain/fetchTokenTransfer.ts | 8 ++++++-- .../useEndorsementChain/useEndorsementChain.ts | 2 +- src/constants/chain-info.ts | 7 +++++-- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index a81a003f4..370af78d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -118,7 +118,7 @@ "path-browserify": "^1.0.1", "postcss": "^8.4.6", "postcss-cli": "^8.3.1", - "prettier": "^2.3.1", + "prettier": "^2.8.8", "process": "^0.11.10", "redux-devtools-extension": "^2.13.9", "shelljs": "^0.8.5", @@ -22266,8 +22266,7 @@ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "extraneous": true, "os": [ - "darwin", - "linux" + "darwin" ], "engines": { "node": "^8.16.0 || ^10.6.0 || >=11.0.0" diff --git a/package.json b/package.json index 5878d38d6..9017bde99 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,7 @@ "compression-webpack-plugin": "^6.1.1", "concurrently": "^6.2.0", "copy-webpack-plugin": "^6.4.1", + "crypto-browserify": "^3.12.0", "css-loader": "^5.2.6", "cypress": "^13.7.1", "cypress-file-upload": "^5.0.8", @@ -147,33 +148,32 @@ "identity-obj-proxy": "^3.0.0", "jest": "^26.6.3", "jest-environment-jsdom-sixteen": "^2.0.0", + "magic-sdk": "^10.0.0", "nodemon": "^2.0.7", "npm-run-all": "^4.1.5", + "os-browserify": "^0.3.0", + "path-browserify": "^1.0.1", "postcss": "^8.4.6", "postcss-cli": "^8.3.1", - "prettier": "^2.3.1", + "prettier": "^2.8.8", "process": "^0.11.10", "redux-devtools-extension": "^2.13.9", "shelljs": "^0.8.5", "sitemap": "^7.1.1", "storybook": "^8.0.4", + "stream-browserify": "^3.0.0", "style-loader": "^2.0.0", "tailwindcss": "^3.0.23", "testcafe": "^2.3.0", "ts-jest": "^26.0.0", + "ts-node": "^10.9.2", "typescript": "^4.3.2", + "vm-browserify": "^1.1.2", "wait-on": "^5.3.0", "webpack": "^5.91.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^5.0.4", - "webpack-env": "^0.8.0", - "stream-browserify": "^3.0.0", - "os-browserify": "^0.3.0", - "vm-browserify": "^1.1.2", - "crypto-browserify": "^3.12.0", - "path-browserify": "^1.0.1", - "magic-sdk": "^10.0.0", - "ts-node": "^10.9.2" + "webpack-env": "^0.8.0" }, "engines": { "node": "18.x", diff --git a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts index 6a5fd3003..82c25598e 100644 --- a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts +++ b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts @@ -2,6 +2,7 @@ import { providers } from "ethers"; import { TitleEscrow, TitleEscrow__factory } from "@tradetrust-tt/token-registry/contracts"; import { TitleEscrowTransferEvent } from "../../../types"; import { EventFragment, Result } from "ethers/lib/utils"; +import { ChainId,ChainInfo } from "../../../constants/chain-info"; export const fetchEscrowTransfers = async ( provider: providers.Provider, @@ -24,9 +25,10 @@ export const fetchOwnerTransfers = async ( titleEscrowContract: TitleEscrow, provider: providers.Provider ): Promise => { + const chainId:ChainId = (await provider.getNetwork()).chainId; + const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; const ownerChangeFilter = titleEscrowContract.filters.BeneficiaryTransfer(null, null); - const ownerChangeLogs = await provider.getLogs({ ...ownerChangeFilter, fromBlock: 0 }); - + const ownerChangeLogs = await provider.getLogs({ ...ownerChangeFilter, fromBlock: fromBlockNumber }); const ownerChangeLogsParsed = getParsedLogs(ownerChangeLogs, titleEscrowContract); return ownerChangeLogsParsed.map((event) => ({ type: "TRANSFER_BENEFICIARY", @@ -71,7 +73,9 @@ export const fetchHolderTransfers = async ( provider: providers.Provider ): Promise => { const holderChangeFilter = titleEscrowContract.filters.HolderTransfer(null, null); - const holderChangeLogs = await provider.getLogs({ ...holderChangeFilter, fromBlock: 0 }); + const chainId:ChainId = (await provider.getNetwork()).chainId; + const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; + const holderChangeLogs = await provider.getLogs({ ...holderChangeFilter, fromBlock: fromBlockNumber }); const holderChangeLogsParsed = getParsedLogs(holderChangeLogs, titleEscrowContract); return holderChangeLogsParsed.map((event) => ({ type: "TRANSFER_HOLDER", diff --git a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts index 99e74e771..999573c03 100644 --- a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts +++ b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts @@ -24,6 +24,7 @@ describe("Fetch Token Transfers", () => { ); if (!tokenRegistry) throw new Error("Unable to connect to token registry: Test Failed"); const tokenTransfers = await fetchTokenTransfers( + amoyProvider, tokenRegistry, "0xe8b9fb84485cbf9dd59eabe1dcddf44d9e3ff820aedb7d02a138ef4a116f0ec9" ); diff --git a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts index 20ea15f36..c9a30c16d 100644 --- a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts +++ b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts @@ -1,11 +1,13 @@ import { TradeTrustToken } from "@tradetrust-tt/token-registry/contracts"; import { TypedEvent } from "@tradetrust-tt/token-registry/dist/contracts/common"; import { LogDescription } from "ethers/lib/utils"; -import { BurnAddress, InitialAddress } from "../../../constants/chain-info"; +import { ChainId,ChainInfo,BurnAddress, InitialAddress } from "../../../constants/chain-info"; import { TokenTransferEvent, TokenTransferEventType } from "../../../types"; import { sortLogChain } from "./helpers"; +import { providers } from "ethers"; export const fetchTokenTransfers = async ( + provider: providers.Provider, tokenRegistry: TradeTrustToken, tokenId: string ): Promise => { @@ -13,7 +15,9 @@ export const fetchTokenTransfers = async ( const tokenRegistryAddress = tokenRegistry.address; const identifyTokenTransferEvents = identifyTokenTransferEventsFunction(tokenRegistryAddress); const transferLogFilter = tokenRegistry.filters.Transfer(null, null, tokenId); - const logs = await tokenRegistry.queryFilter(transferLogFilter, 0); + const chainId:ChainId = (await provider.getNetwork()).chainId; + const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; + const logs = await tokenRegistry.queryFilter(transferLogFilter, fromBlockNumber); if (logs.length === 0) { throw new Error("Unminted Title Escrow"); } diff --git a/src/common/hooks/useEndorsementChain/useEndorsementChain.ts b/src/common/hooks/useEndorsementChain/useEndorsementChain.ts index c7f051eb3..83b49fa41 100644 --- a/src/common/hooks/useEndorsementChain/useEndorsementChain.ts +++ b/src/common/hooks/useEndorsementChain/useEndorsementChain.ts @@ -31,7 +31,7 @@ export const useEndorsementChain = ( setEndorsementChain(undefined); setPending(true); try { - const tokenLogs = await fetchTokenTransfers(tokenRegistry, tokenId); + const tokenLogs = await fetchTokenTransfers(provider,tokenRegistry, tokenId); const escrowAddress = await retrieveTitleEscrowAddressOnFactory(tokenRegistry, tokenId, providerOrSigner); const titleEscrowLogs = await fetchEscrowTransfers(provider, escrowAddress); const transferEvents = mergeTransfers([...titleEscrowLogs, ...tokenLogs]); diff --git a/src/constants/chain-info.ts b/src/constants/chain-info.ts index bb45bf339..d3b060d90 100644 --- a/src/constants/chain-info.ts +++ b/src/constants/chain-info.ts @@ -6,6 +6,7 @@ export interface ChainInfoObject { chainId: ChainId; networkName: string; // network name that aligns with existing NETWORK_NAME networkLabel: string; + blockNumber?: number; explorerUrl: string; rpcUrl?: string; nativeCurrency?: { @@ -113,8 +114,9 @@ export const ChainInfo: ChainInfo = { iconImage: "/static/images/networks/xdc.png", networkName: "xdc", networkLabel: "XDC Network", + blockNumber: 60000000, explorerUrl: "https://xdcscan.io", - rpcUrl: "https://tradetrustrpc.xdcrpc.com", + rpcUrl: "https://rpc.ankr.com/xdc", nativeCurrency: { name: "XDC", symbol: "XDC", @@ -127,8 +129,9 @@ export const ChainInfo: ChainInfo = { iconImage: "/static/images/networks/xdc.png", networkName: "xdcapothem", networkLabel: "XDC Testnet Apothem", + blockNumber: 50000000, explorerUrl: "https://apothem.xdcscan.io", - rpcUrl: "https://tradetrustarpc.xdcrpc.com", + rpcUrl: "https://rpc.ankr.com/xdc_testnet", nativeCurrency: { name: "XDCt", symbol: "XDCt", From b4e3e736eeec88ef40597300403cf553877eac4d Mon Sep 17 00:00:00 2001 From: satheesh Date: Fri, 14 Jun 2024 19:15:32 +0400 Subject: [PATCH 3/5] Added blockNumber config for endorsement chain - updated tests --- .../fetchEscrowTransfer.integration.test.ts | 11 +++++---- .../fetchEscrowTransfer.ts | 23 +++++++++++-------- .../fetchTokenTransfer.integration.test.ts | 4 +++- .../useEndorsementChain/fetchTokenTransfer.ts | 9 ++++---- .../useEndorsementChain.ts | 8 ++++--- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts index cffd9501d..eb74b60e0 100644 --- a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts +++ b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts @@ -12,14 +12,15 @@ const mockUseProviderContext = useProviderContext as jest.Mock; describe("Fetch Escrow Transfers", () => { jest.setTimeout(15000); - + beforeAll(() => { mockUseProviderContext.mockReturnValue({ provider: amoyProvider, providerOrSigner: amoyProvider }); }); describe("fetch from title escrow transfers", () => { it("should return parsed transfer logs in valid format", async () => { - const escrowTransfers = await fetchEscrowTransfers(amoyProvider, "0x1F6D8888Fc6B75E10b1840620E8229C3C487a925"); + const blockNo = 6000000; + const escrowTransfers = await fetchEscrowTransfers(amoyProvider, "0x1F6D8888Fc6B75E10b1840620E8229C3C487a925",blockNo); expect(escrowTransfers).toEqual([ { type: "TRANSFER_HOLDER", @@ -211,7 +212,8 @@ describe("Fetch Escrow Transfers", () => { describe("fetch from title escrow owner transfers", () => { it("should return parsed transfer logs for beneficiary in valid format", async () => { const titleEscrow = TitleEscrow__factory.connect("0x1F6D8888Fc6B75E10b1840620E8229C3C487a925", amoyProvider); - const ownerTransfers = await fetchOwnerTransfers(titleEscrow, amoyProvider); + const blockNo = 6000000; + const ownerTransfers = await fetchOwnerTransfers(titleEscrow, amoyProvider,blockNo); expect(ownerTransfers).toEqual([ { type: "TRANSFER_BENEFICIARY", @@ -248,7 +250,8 @@ describe("Fetch Escrow Transfers", () => { describe("fetch from title escrow holder transfers", () => { it("should return parsed transfer logs for holder in valid format", async () => { const titleEscrow = TitleEscrow__factory.connect("0x1F6D8888Fc6B75E10b1840620E8229C3C487a925", amoyProvider); - const holderTransfers = await fetchHolderTransfers(titleEscrow, amoyProvider); + const blockNo = 6000000; + const holderTransfers = await fetchHolderTransfers(titleEscrow, amoyProvider,blockNo); expect(holderTransfers).toEqual([ { type: "TRANSFER_HOLDER", diff --git a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts index 82c25598e..0ca16ac78 100644 --- a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts +++ b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts @@ -2,18 +2,19 @@ import { providers } from "ethers"; import { TitleEscrow, TitleEscrow__factory } from "@tradetrust-tt/token-registry/contracts"; import { TitleEscrowTransferEvent } from "../../../types"; import { EventFragment, Result } from "ethers/lib/utils"; -import { ChainId,ChainInfo } from "../../../constants/chain-info"; +import { ChainId, ChainInfo } from "../../../constants/chain-info"; export const fetchEscrowTransfers = async ( provider: providers.Provider, - address: string + address: string, + fromBlockNumber: number ): Promise => { const titleEscrowContract = TitleEscrow__factory.connect(address, provider); const isTitleEscrow = await titleEscrowContract.supportsInterface("0x079dff60"); if (!isTitleEscrow) throw new Error(`Contract ${address} is not a title escrow contract`); // https://ethereum.stackexchange.com/questions/109326/combine-multiple-event-filters-in-ethersjs - const holderChangeLogsDeferred = await fetchHolderTransfers(titleEscrowContract, provider); - const ownerChangeLogsDeferred = await fetchOwnerTransfers(titleEscrowContract, provider); + const holderChangeLogsDeferred = await fetchHolderTransfers(titleEscrowContract, provider, fromBlockNumber); + const ownerChangeLogsDeferred = await fetchOwnerTransfers(titleEscrowContract, provider, fromBlockNumber); const [holderChangeLogs, ownerChangeLogs] = await Promise.all([holderChangeLogsDeferred, ownerChangeLogsDeferred]); return [...holderChangeLogs, ...ownerChangeLogs]; }; @@ -23,10 +24,11 @@ export const fetchEscrowTransfers = async ( */ export const fetchOwnerTransfers = async ( titleEscrowContract: TitleEscrow, - provider: providers.Provider + provider: providers.Provider, + fromBlockNumber: number ): Promise => { - const chainId:ChainId = (await provider.getNetwork()).chainId; - const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; + // const chainId: ChainId = (await provider.getNetwork()).chainId; + // const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; const ownerChangeFilter = titleEscrowContract.filters.BeneficiaryTransfer(null, null); const ownerChangeLogs = await provider.getLogs({ ...ownerChangeFilter, fromBlock: fromBlockNumber }); const ownerChangeLogsParsed = getParsedLogs(ownerChangeLogs, titleEscrowContract); @@ -70,11 +72,12 @@ export const getParsedLogs = (logs: providers.Log[], titleEscrow: TitleEscrow): */ export const fetchHolderTransfers = async ( titleEscrowContract: TitleEscrow, - provider: providers.Provider + provider: providers.Provider, + fromBlockNumber: number ): Promise => { const holderChangeFilter = titleEscrowContract.filters.HolderTransfer(null, null); - const chainId:ChainId = (await provider.getNetwork()).chainId; - const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; + // const chainId: ChainId = (await provider.getNetwork()).chainId; + // const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; const holderChangeLogs = await provider.getLogs({ ...holderChangeFilter, fromBlock: fromBlockNumber }); const holderChangeLogsParsed = getParsedLogs(holderChangeLogs, titleEscrowContract); return holderChangeLogsParsed.map((event) => ({ diff --git a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts index 999573c03..ddc3d1017 100644 --- a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts +++ b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.integration.test.ts @@ -22,11 +22,13 @@ describe("Fetch Token Transfers", () => { "0x71D28767662cB233F887aD2Bb65d048d760bA694", amoyProvider ); + const blockNo = 6000000; if (!tokenRegistry) throw new Error("Unable to connect to token registry: Test Failed"); const tokenTransfers = await fetchTokenTransfers( amoyProvider, tokenRegistry, - "0xe8b9fb84485cbf9dd59eabe1dcddf44d9e3ff820aedb7d02a138ef4a116f0ec9" + "0xe8b9fb84485cbf9dd59eabe1dcddf44d9e3ff820aedb7d02a138ef4a116f0ec9", + blockNo ); expect(tokenTransfers).toEqual([ { diff --git a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts index c9a30c16d..54889f0cd 100644 --- a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts +++ b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts @@ -1,7 +1,7 @@ import { TradeTrustToken } from "@tradetrust-tt/token-registry/contracts"; import { TypedEvent } from "@tradetrust-tt/token-registry/dist/contracts/common"; import { LogDescription } from "ethers/lib/utils"; -import { ChainId,ChainInfo,BurnAddress, InitialAddress } from "../../../constants/chain-info"; +import { ChainId, ChainInfo, BurnAddress, InitialAddress } from "../../../constants/chain-info"; import { TokenTransferEvent, TokenTransferEventType } from "../../../types"; import { sortLogChain } from "./helpers"; import { providers } from "ethers"; @@ -9,14 +9,15 @@ import { providers } from "ethers"; export const fetchTokenTransfers = async ( provider: providers.Provider, tokenRegistry: TradeTrustToken, - tokenId: string + tokenId: string, + fromBlockNumber: number ): Promise => { // Fetch transfer logs from token registry const tokenRegistryAddress = tokenRegistry.address; const identifyTokenTransferEvents = identifyTokenTransferEventsFunction(tokenRegistryAddress); const transferLogFilter = tokenRegistry.filters.Transfer(null, null, tokenId); - const chainId:ChainId = (await provider.getNetwork()).chainId; - const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; + // const chainId: ChainId = (await provider.getNetwork()).chainId; + // const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; const logs = await tokenRegistry.queryFilter(transferLogFilter, fromBlockNumber); if (logs.length === 0) { throw new Error("Unminted Title Escrow"); diff --git a/src/common/hooks/useEndorsementChain/useEndorsementChain.ts b/src/common/hooks/useEndorsementChain/useEndorsementChain.ts index 83b49fa41..12fd7dfa0 100644 --- a/src/common/hooks/useEndorsementChain/useEndorsementChain.ts +++ b/src/common/hooks/useEndorsementChain/useEndorsementChain.ts @@ -8,7 +8,7 @@ import { fetchTokenTransfers } from "./fetchTokenTransfer"; import { getEndorsementChain } from "./retrieveEndorsementChain"; import { retrieveTitleEscrowAddressOnFactory } from "../useTitleEscrowContract"; import { getErrorMessage } from "../../utils/errorHandling"; - +import { ChainId,ChainInfo } from "../../../constants/chain-info"; export const useEndorsementChain = ( tokenRegistryAddress: string, tokenId: string @@ -31,9 +31,11 @@ export const useEndorsementChain = ( setEndorsementChain(undefined); setPending(true); try { - const tokenLogs = await fetchTokenTransfers(provider,tokenRegistry, tokenId); + const chainId: ChainId = (await provider.getNetwork()).chainId; + const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; + const tokenLogs = await fetchTokenTransfers(provider, tokenRegistry, tokenId,fromBlockNumber); const escrowAddress = await retrieveTitleEscrowAddressOnFactory(tokenRegistry, tokenId, providerOrSigner); - const titleEscrowLogs = await fetchEscrowTransfers(provider, escrowAddress); + const titleEscrowLogs = await fetchEscrowTransfers(provider, escrowAddress,fromBlockNumber); const transferEvents = mergeTransfers([...titleEscrowLogs, ...tokenLogs]); const retrievedEndorsementChain = await getEndorsementChain(provider, transferEvents); setEndorsementChain(retrievedEndorsementChain); From c10f9e1e09f07cdba501ca3f03bf7af86aa5cddd Mon Sep 17 00:00:00 2001 From: satheesh Date: Fri, 14 Jun 2024 19:59:05 +0400 Subject: [PATCH 4/5] Updated code --- package.json | 20 +++++++++---------- .../fetchEscrowTransfer.ts | 5 ----- .../useEndorsementChain/fetchTokenTransfer.ts | 4 +--- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 9017bde99..f33625941 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,6 @@ "compression-webpack-plugin": "^6.1.1", "concurrently": "^6.2.0", "copy-webpack-plugin": "^6.4.1", - "crypto-browserify": "^3.12.0", "css-loader": "^5.2.6", "cypress": "^13.7.1", "cypress-file-upload": "^5.0.8", @@ -148,32 +147,33 @@ "identity-obj-proxy": "^3.0.0", "jest": "^26.6.3", "jest-environment-jsdom-sixteen": "^2.0.0", - "magic-sdk": "^10.0.0", "nodemon": "^2.0.7", "npm-run-all": "^4.1.5", - "os-browserify": "^0.3.0", - "path-browserify": "^1.0.1", "postcss": "^8.4.6", "postcss-cli": "^8.3.1", - "prettier": "^2.8.8", + "prettier": "^2.3.1", "process": "^0.11.10", "redux-devtools-extension": "^2.13.9", "shelljs": "^0.8.5", "sitemap": "^7.1.1", "storybook": "^8.0.4", - "stream-browserify": "^3.0.0", "style-loader": "^2.0.0", "tailwindcss": "^3.0.23", "testcafe": "^2.3.0", "ts-jest": "^26.0.0", - "ts-node": "^10.9.2", "typescript": "^4.3.2", - "vm-browserify": "^1.1.2", "wait-on": "^5.3.0", "webpack": "^5.91.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^5.0.4", - "webpack-env": "^0.8.0" + "webpack-env": "^0.8.0", + "stream-browserify": "^3.0.0", + "os-browserify": "^0.3.0", + "vm-browserify": "^1.1.2", + "crypto-browserify": "^3.12.0", + "path-browserify": "^1.0.1", + "magic-sdk": "^10.0.0", + "ts-node": "^10.9.2" }, "engines": { "node": "18.x", @@ -185,4 +185,4 @@ "optionalDependencies": { "fsevents": "^2.3.2" } -} +} \ No newline at end of file diff --git a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts index 0ca16ac78..3b21908ea 100644 --- a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts +++ b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.ts @@ -2,7 +2,6 @@ import { providers } from "ethers"; import { TitleEscrow, TitleEscrow__factory } from "@tradetrust-tt/token-registry/contracts"; import { TitleEscrowTransferEvent } from "../../../types"; import { EventFragment, Result } from "ethers/lib/utils"; -import { ChainId, ChainInfo } from "../../../constants/chain-info"; export const fetchEscrowTransfers = async ( provider: providers.Provider, @@ -27,8 +26,6 @@ export const fetchOwnerTransfers = async ( provider: providers.Provider, fromBlockNumber: number ): Promise => { - // const chainId: ChainId = (await provider.getNetwork()).chainId; - // const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; const ownerChangeFilter = titleEscrowContract.filters.BeneficiaryTransfer(null, null); const ownerChangeLogs = await provider.getLogs({ ...ownerChangeFilter, fromBlock: fromBlockNumber }); const ownerChangeLogsParsed = getParsedLogs(ownerChangeLogs, titleEscrowContract); @@ -76,8 +73,6 @@ export const fetchHolderTransfers = async ( fromBlockNumber: number ): Promise => { const holderChangeFilter = titleEscrowContract.filters.HolderTransfer(null, null); - // const chainId: ChainId = (await provider.getNetwork()).chainId; - // const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; const holderChangeLogs = await provider.getLogs({ ...holderChangeFilter, fromBlock: fromBlockNumber }); const holderChangeLogsParsed = getParsedLogs(holderChangeLogs, titleEscrowContract); return holderChangeLogsParsed.map((event) => ({ diff --git a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts index 54889f0cd..7d0533d54 100644 --- a/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts +++ b/src/common/hooks/useEndorsementChain/fetchTokenTransfer.ts @@ -1,7 +1,7 @@ import { TradeTrustToken } from "@tradetrust-tt/token-registry/contracts"; import { TypedEvent } from "@tradetrust-tt/token-registry/dist/contracts/common"; import { LogDescription } from "ethers/lib/utils"; -import { ChainId, ChainInfo, BurnAddress, InitialAddress } from "../../../constants/chain-info"; +import { BurnAddress, InitialAddress } from "../../../constants/chain-info"; import { TokenTransferEvent, TokenTransferEventType } from "../../../types"; import { sortLogChain } from "./helpers"; import { providers } from "ethers"; @@ -16,8 +16,6 @@ export const fetchTokenTransfers = async ( const tokenRegistryAddress = tokenRegistry.address; const identifyTokenTransferEvents = identifyTokenTransferEventsFunction(tokenRegistryAddress); const transferLogFilter = tokenRegistry.filters.Transfer(null, null, tokenId); - // const chainId: ChainId = (await provider.getNetwork()).chainId; - // const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; const logs = await tokenRegistry.queryFilter(transferLogFilter, fromBlockNumber); if (logs.length === 0) { throw new Error("Unminted Title Escrow"); From aa55485432123b082f33060d54934093bdd53baf Mon Sep 17 00:00:00 2001 From: satheesh Date: Fri, 14 Jun 2024 20:00:09 +0400 Subject: [PATCH 5/5] Updated code --- package.json | 2 +- .../fetchEscrowTransfer.integration.test.ts | 11 +++++++---- .../hooks/useEndorsementChain/useEndorsementChain.ts | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index f33625941..5878d38d6 100644 --- a/package.json +++ b/package.json @@ -185,4 +185,4 @@ "optionalDependencies": { "fsevents": "^2.3.2" } -} \ No newline at end of file +} diff --git a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts index eb74b60e0..c3858275e 100644 --- a/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts +++ b/src/common/hooks/useEndorsementChain/fetchEscrowTransfer.integration.test.ts @@ -12,7 +12,6 @@ const mockUseProviderContext = useProviderContext as jest.Mock; describe("Fetch Escrow Transfers", () => { jest.setTimeout(15000); - beforeAll(() => { mockUseProviderContext.mockReturnValue({ provider: amoyProvider, providerOrSigner: amoyProvider }); }); @@ -20,7 +19,11 @@ describe("Fetch Escrow Transfers", () => { describe("fetch from title escrow transfers", () => { it("should return parsed transfer logs in valid format", async () => { const blockNo = 6000000; - const escrowTransfers = await fetchEscrowTransfers(amoyProvider, "0x1F6D8888Fc6B75E10b1840620E8229C3C487a925",blockNo); + const escrowTransfers = await fetchEscrowTransfers( + amoyProvider, + "0x1F6D8888Fc6B75E10b1840620E8229C3C487a925", + blockNo + ); expect(escrowTransfers).toEqual([ { type: "TRANSFER_HOLDER", @@ -213,7 +216,7 @@ describe("Fetch Escrow Transfers", () => { it("should return parsed transfer logs for beneficiary in valid format", async () => { const titleEscrow = TitleEscrow__factory.connect("0x1F6D8888Fc6B75E10b1840620E8229C3C487a925", amoyProvider); const blockNo = 6000000; - const ownerTransfers = await fetchOwnerTransfers(titleEscrow, amoyProvider,blockNo); + const ownerTransfers = await fetchOwnerTransfers(titleEscrow, amoyProvider, blockNo); expect(ownerTransfers).toEqual([ { type: "TRANSFER_BENEFICIARY", @@ -251,7 +254,7 @@ describe("Fetch Escrow Transfers", () => { it("should return parsed transfer logs for holder in valid format", async () => { const titleEscrow = TitleEscrow__factory.connect("0x1F6D8888Fc6B75E10b1840620E8229C3C487a925", amoyProvider); const blockNo = 6000000; - const holderTransfers = await fetchHolderTransfers(titleEscrow, amoyProvider,blockNo); + const holderTransfers = await fetchHolderTransfers(titleEscrow, amoyProvider, blockNo); expect(holderTransfers).toEqual([ { type: "TRANSFER_HOLDER", diff --git a/src/common/hooks/useEndorsementChain/useEndorsementChain.ts b/src/common/hooks/useEndorsementChain/useEndorsementChain.ts index 12fd7dfa0..11d57ceda 100644 --- a/src/common/hooks/useEndorsementChain/useEndorsementChain.ts +++ b/src/common/hooks/useEndorsementChain/useEndorsementChain.ts @@ -8,7 +8,7 @@ import { fetchTokenTransfers } from "./fetchTokenTransfer"; import { getEndorsementChain } from "./retrieveEndorsementChain"; import { retrieveTitleEscrowAddressOnFactory } from "../useTitleEscrowContract"; import { getErrorMessage } from "../../utils/errorHandling"; -import { ChainId,ChainInfo } from "../../../constants/chain-info"; +import { ChainId, ChainInfo } from "../../../constants/chain-info"; export const useEndorsementChain = ( tokenRegistryAddress: string, tokenId: string @@ -33,9 +33,9 @@ export const useEndorsementChain = ( try { const chainId: ChainId = (await provider.getNetwork()).chainId; const fromBlockNumber = ChainInfo[chainId]?.blockNumber ?? 0; - const tokenLogs = await fetchTokenTransfers(provider, tokenRegistry, tokenId,fromBlockNumber); + const tokenLogs = await fetchTokenTransfers(provider, tokenRegistry, tokenId, fromBlockNumber); const escrowAddress = await retrieveTitleEscrowAddressOnFactory(tokenRegistry, tokenId, providerOrSigner); - const titleEscrowLogs = await fetchEscrowTransfers(provider, escrowAddress,fromBlockNumber); + const titleEscrowLogs = await fetchEscrowTransfers(provider, escrowAddress, fromBlockNumber); const transferEvents = mergeTransfers([...titleEscrowLogs, ...tokenLogs]); const retrievedEndorsementChain = await getEndorsementChain(provider, transferEvents); setEndorsementChain(retrievedEndorsementChain);