From 310f67f1062cc8e080410d61691774a78159ff09 Mon Sep 17 00:00:00 2001 From: Shahar Yakir Date: Tue, 12 Mar 2024 16:32:14 +0000 Subject: [PATCH] lib support --- src/components/ContractBlock.tsx | 22 ++++++++++++++++++++++ src/lib/useInBrowserCompilation.ts | 2 +- src/lib/useLoadContractInfo.ts | 11 ++++++++--- src/lib/useLoadContractProof.ts | 4 ++-- src/lib/usePublishProof.ts | 2 +- src/lib/useSubmitSources.ts | 4 ++-- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/components/ContractBlock.tsx b/src/components/ContractBlock.tsx index 8d97f2d..2408990 100644 --- a/src/components/ContractBlock.tsx +++ b/src/components/ContractBlock.tsx @@ -39,6 +39,11 @@ export function ContractBlock() { data?.dataCellHash.hex, ); + const [displayLibraryHash, toggleDisplayLibraryHash] = useToggle( + data?.libraryHash.base64, + data?.libraryHash.hex, + ); + if (data) { dataRows.push({ title: "Address", @@ -72,6 +77,23 @@ export function ContractBlock() { }, tooltip: true, }); + + if (data?.libraryHash.base64) { + dataRows.push({ + title: "Library Code Cell Hash", + value: displayLibraryHash ?? "", + showIcon: true, + onClick: () => { + toggleDisplayLibraryHash(); + }, + tooltip: true, + }); + dataRows.push({ + title: "", + value: "", + showIcon: true, + }); + } } return ( diff --git a/src/lib/useInBrowserCompilation.ts b/src/lib/useInBrowserCompilation.ts index b946791..e170530 100644 --- a/src/lib/useInBrowserCompilation.ts +++ b/src/lib/useInBrowserCompilation.ts @@ -85,7 +85,7 @@ export function useInBrowserCompilation() { const codeCell = Cell.fromBoc(Buffer.from(result.codeBoc, "base64"))[0]; setLoading(false); - contractData?.codeCellHash.base64 === codeCell.hash().toString("base64") && + contractData?.codeCellToCompileBase64 === codeCell.hash().toString("base64") && setHash(codeCell.hash().toString("base64")); sendAnalyticsEvent(AnalyticsAction.IN_BROWSER_COMPILE_SUCCESS); diff --git a/src/lib/useLoadContractInfo.ts b/src/lib/useLoadContractInfo.ts index 566c23e..d1d74d5 100644 --- a/src/lib/useLoadContractInfo.ts +++ b/src/lib/useLoadContractInfo.ts @@ -1,4 +1,4 @@ -import { Address, fromNano, Cell, CellType, BitReader } from "ton"; +import { Address, fromNano, Cell, CellType, BitReader, beginCell, BitString } from "ton"; import { useQuery } from "@tanstack/react-query"; import { fromCode } from "tvm-disassembler"; @@ -14,7 +14,7 @@ export function tryLoadLibraryCodeCellHash(exoticCodeCell: Cell) { if (exoticCodeCell.isExotic && exoticCodeCell.type == CellType.Library) { const br = new BitReader(exoticCodeCell.bits); br.loadBits(8); - return Buffer.from(br.loadBits(br.remaining).toString(), "hex").toString("base64"); + return Buffer.from(br.loadBits(br.remaining).toString(), "hex"); } return null; @@ -39,7 +39,7 @@ export function useLoadContractInfo() { let decompiled; if (libraryHash) { - decompiled = "Library contract\nLibrary code cell hash: " + libraryHash; + decompiled = "Library contract"; } else { try { decompiled = fromCode(codeCell); @@ -62,6 +62,11 @@ export function useLoadContractInfo() { } as CellHash, decompiled, balance: fromNano(b), + libraryHash: { + base64: libraryHash?.toString("base64"), + hex: libraryHash?.toString("hex"), + }, + codeCellToCompileBase64: (libraryHash ?? codeCellHash).toString("base64"), }; }); diff --git a/src/lib/useLoadContractProof.ts b/src/lib/useLoadContractProof.ts index 35eb3de..eb3b733 100644 --- a/src/lib/useLoadContractProof.ts +++ b/src/lib/useLoadContractProof.ts @@ -36,7 +36,7 @@ export function useLoadContractProof() { }; } - const ipfsLink = await getProofIpfsLink(contractInfo!.codeCellHash.base64); + const ipfsLink = await getProofIpfsLink(contractInfo!.codeCellToCompileBase64); if (!ipfsLink) { return { hasOnchainProof: false, ipfsLink }; @@ -53,7 +53,7 @@ export function useLoadContractProof() { { enabled: !!contractAddress && - !!contractInfo?.codeCellHash.base64 && + !!contractInfo?.codeCellToCompileBase64 && publishProofStatus === "initial", retry: 2, }, diff --git a/src/lib/usePublishProof.ts b/src/lib/usePublishProof.ts index 8186a17..21c0086 100644 --- a/src/lib/usePublishProof.ts +++ b/src/lib/usePublishProof.ts @@ -13,7 +13,7 @@ export function usePublishProof() { const { data: sourcesRegistryData } = useLoadSourcesRegistryInfo(); const { sendTXN, data, clearTXN } = useSendTXN("publishProof", async (count: number) => { - const ipfsLink = await getProofIpfsLink(contractInfo!.codeCellHash.base64); + const ipfsLink = await getProofIpfsLink(contractInfo!.codeCellToCompileBase64); if (count > 20) { return "error"; diff --git a/src/lib/useSubmitSources.ts b/src/lib/useSubmitSources.ts index 82d1d07..64ebd1e 100644 --- a/src/lib/useSubmitSources.ts +++ b/src/lib/useSubmitSources.ts @@ -62,7 +62,7 @@ export function useSubmitSources() { const mutation = useCustomMutation(["submitSources"], async () => { if (!contractAddress) return; - if (!contractInfo?.codeCellHash.base64) return; + if (!contractInfo?.codeCellToCompileBase64) return; if (!hasFiles()) return; if (!verifierRegistryConfig) return; if (!walletAddress) { @@ -90,7 +90,7 @@ export function useSubmitSources() { compiler, compilerSettings, knownContractAddress: contractAddress, - knownContractHash: contractInfo.codeCellHash.base64, + knownContractHash: contractInfo.codeCellToCompileBase64, sources: files.map((u) => ({ includeInCommand: u.includeInCommand, isEntrypoint: u.isEntrypoint,