Skip to content

Commit

Permalink
lib support
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharyakir committed Mar 12, 2024
1 parent 3cdb848 commit 310f67f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/components/ContractBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/useInBrowserCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/lib/useLoadContractInfo.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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"),
};
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib/useLoadContractProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -53,7 +53,7 @@ export function useLoadContractProof() {
{
enabled:
!!contractAddress &&
!!contractInfo?.codeCellHash.base64 &&
!!contractInfo?.codeCellToCompileBase64 &&
publishProofStatus === "initial",
retry: 2,
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/usePublishProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/lib/useSubmitSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 310f67f

Please sign in to comment.