Skip to content

Commit

Permalink
Merge pull request #202 from ton-blockchain/ton_latests
Browse files Browse the repository at this point in the history
Support library code cells
  • Loading branch information
EmelyanenkoK authored Mar 12, 2024
2 parents e1c9c3c + 310f67f commit d3995ae
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 28 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"react-qr-code": "^2.0.8",
"react-router-dom": "^6.4.2",
"source-map-explorer": "^2.5.3",
"ton": "^13.4.1",
"ton-core": "^0.49.0",
"ton": "^13.9.0",
"ton-core": "^0.53.0",
"tvm-disassembler": "^2.0.2",
"web-tree-sitter": "^0.20.7",
"zustand": "^4.1.3"
Expand Down
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
32 changes: 27 additions & 5 deletions src/lib/useLoadContractInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, fromNano, Cell } 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 @@ -10,6 +10,16 @@ type CellHash = {
hex: string;
};

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");
}

return null;
}

export function useLoadContractInfo() {
const { contractAddress } = useContractAddress();

Expand All @@ -24,11 +34,18 @@ export function useLoadContractInfo() {

const b = await client.getBalance(_address);

const libraryHash = tryLoadLibraryCodeCellHash(codeCell);

let decompiled;
try {
decompiled = fromCode(codeCell);
} catch (e) {
decompiled = e?.toString();

if (libraryHash) {
decompiled = "Library contract";
} else {
try {
decompiled = fromCode(codeCell);
} catch (e) {
decompiled = e?.toString();
}
}

const codeCellHash = codeCell.hash();
Expand All @@ -45,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

1 comment on commit d3995ae

@Aho38wkw

This comment was marked as spam.

Please sign in to comment.