From 3112204248e65e05e49cb181aaf6f32a77653718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20M=C3=B8ldrup?= Date: Wed, 29 Nov 2023 10:41:44 +0100 Subject: [PATCH 1/7] Fix error when calling contracts returning BigInt --- front-end-tools/package.json | 2 ++ front-end-tools/src/reading_from_blockchain.ts | 6 +++--- front-end-tools/yarn.lock | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/front-end-tools/package.json b/front-end-tools/package.json index 83b65f62..7368a510 100644 --- a/front-end-tools/package.json +++ b/front-end-tools/package.json @@ -9,6 +9,7 @@ "dependencies": { "@concordium/react-components": "^0.4.0", "@concordium/web-sdk": "^7.1.0", + "json-bigint": "^1.0.0", "moment": "^2.29.4", "react": "^18.1.0", "react-bootstrap": "^2.7.4", @@ -18,6 +19,7 @@ "react-switch": "^7.0.0" }, "devDependencies": { + "@types/json-bigint": "^1", "@types/node": "^18.7.23", "@types/react": "^18.0.9", "@types/react-dom": "^18.0.5", diff --git a/front-end-tools/src/reading_from_blockchain.ts b/front-end-tools/src/reading_from_blockchain.ts index 192c7b0b..c15fd977 100644 --- a/front-end-tools/src/reading_from_blockchain.ts +++ b/front-end-tools/src/reading_from_blockchain.ts @@ -15,7 +15,7 @@ import { Parameter, ReturnValue, } from '@concordium/web-sdk'; - +import JSONbig from 'json-bigint'; import { CONTRACT_SUB_INDEX } from './constants'; /** This function gets the contract info of a smart contract index. */ @@ -175,7 +175,7 @@ export async function read( if (moduleSchema === undefined) { // If no schema is provided return the raw bytes - return JSON.stringify(res.returnValue); + return JSONbig.stringify(res.returnValue); } let returnValue; @@ -199,6 +199,6 @@ export async function read( `Deserializing the returnValue from the '${contractName}.${entryPoint}' method of contract '${contractIndex}' failed.` ); } else { - return JSON.stringify(returnValue); + return JSONbig.stringify(returnValue); } } diff --git a/front-end-tools/yarn.lock b/front-end-tools/yarn.lock index f35370da..0abcfadb 100644 --- a/front-end-tools/yarn.lock +++ b/front-end-tools/yarn.lock @@ -1342,6 +1342,13 @@ __metadata: languageName: node linkType: hard +"@types/json-bigint@npm:^1": + version: 1.0.4 + resolution: "@types/json-bigint@npm:1.0.4" + checksum: bb567bac8d64f541abb3cb716d5c699c460b9aa4a9fc5fc81a3cee9cb57fe8c03914022049dcdadff213972979a5d08267405d55d2ed6aa95d3558f08347008a + languageName: node + linkType: hard + "@types/json-schema@npm:^7.0.9": version: 7.0.15 resolution: "@types/json-schema@npm:7.0.15" @@ -3625,6 +3632,7 @@ __metadata: dependencies: "@concordium/react-components": "npm:^0.4.0" "@concordium/web-sdk": "npm:^7.1.0" + "@types/json-bigint": "npm:^1" "@types/node": "npm:^18.7.23" "@types/react": "npm:^18.0.9" "@types/react-dom": "npm:^18.0.5" @@ -3640,6 +3648,7 @@ __metadata: eslint-plugin-jsx-a11y: "npm:^6.5.1" eslint-plugin-react: "npm:^7.29.4" eslint-plugin-react-hooks: "npm:^4.4.0" + json-bigint: "npm:^1.0.0" moment: "npm:^2.29.4" prettier: "npm:^3.1.0" process: "npm:^0.11.10" From 7091f5d6aa63b3c8ee1f1752d844e9532368b8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20M=C3=B8ldrup?= Date: Wed, 29 Nov 2023 10:50:03 +0100 Subject: [PATCH 2/7] Fix contract method name in errors --- front-end-tools/src/reading_from_blockchain.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/front-end-tools/src/reading_from_blockchain.ts b/front-end-tools/src/reading_from_blockchain.ts index c15fd977..9850f75e 100644 --- a/front-end-tools/src/reading_from_blockchain.ts +++ b/front-end-tools/src/reading_from_blockchain.ts @@ -157,19 +157,21 @@ export async function read( parameter: param, }); + const fullEntryPointName = `${contractName.value}.${entryPoint.value}`; + if (!res || res.tag === 'failure') { const rejectReason = JSON.stringify( ((res as InvokeContractFailedResult)?.reason as RejectedReceive)?.rejectReason ); throw new Error( - `RPC call 'invokeContract' on method '${contractName}.${entryPoint}' of contract '${contractIndex}' failed. + `RPC call 'invokeContract' on method '${fullEntryPointName}' of contract '${contractIndex}' failed. ${rejectReason !== undefined ? `Reject reason: ${rejectReason}` : ''}` ); } if (!res.returnValue) { throw new Error( - `RPC call 'invokeContract' on method '${contractName}.${entryPoint}' of contract '${contractIndex}' returned no return_value` + `RPC call 'invokeContract' on method '${fullEntryPointName}' of contract '${contractIndex}' returned no return_value` ); } @@ -190,13 +192,13 @@ export async function read( ); } catch (e) { throw new Error( - `Deserializing the returnValue from the '${contractName}.${entryPoint}' method of contract '${contractIndex}' failed. Original error: ${e}` + `Deserializing the returnValue from the '${fullEntryPointName}' method of contract '${contractIndex}' failed. Original error: ${e}` ); } if (returnValue === undefined) { throw new Error( - `Deserializing the returnValue from the '${contractName}.${entryPoint}' method of contract '${contractIndex}' failed.` + `Deserializing the returnValue from the '${fullEntryPointName}' method of contract '${contractIndex}' failed.` ); } else { return JSONbig.stringify(returnValue); From 26a68a271d349b770ba282667f2a555fa5793751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20M=C3=B8ldrup?= Date: Wed, 29 Nov 2023 10:53:39 +0100 Subject: [PATCH 3/7] Update CHANGELOG.md --- front-end-tools/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/front-end-tools/CHANGELOG.md b/front-end-tools/CHANGELOG.md index 380d4792..40ec1e93 100644 --- a/front-end-tools/CHANGELOG.md +++ b/front-end-tools/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased changes - Fix error message when specifying input parameter without uploading schema. +- Fix contract method names in error messages. ## 3.0.1 From 871bca0867a326a4f6cbcdd281b9530b701f527c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20M=C3=B8ldrup?= Date: Wed, 29 Nov 2023 13:36:39 +0100 Subject: [PATCH 4/7] Add warning for non reproducible modules --- front-end-tools/src/components/DeployComponent.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/front-end-tools/src/components/DeployComponent.tsx b/front-end-tools/src/components/DeployComponent.tsx index 64bdfdec..a4fc25ad 100644 --- a/front-end-tools/src/components/DeployComponent.tsx +++ b/front-end-tools/src/components/DeployComponent.tsx @@ -56,6 +56,7 @@ export default function DeployComponenet(props: ConnectionProps) { const [transactionErrorDeploy, setTransactionErrorDeploy] = useState(undefined); const [uploadError, setUploadError] = useState(undefined); + const [isReproducibleBuild, setIsReproducibleBuild] = useState(undefined); const [isModuleReferenceAlreadyDeployedStep1, setIsModuleReferenceAlreadyDeployedStep1] = useState(false); const [txHashDeploy, setTxHashDeploy] = useState(undefined); const [base64Module, setBase64Module] = useState(undefined); @@ -131,7 +132,7 @@ export default function DeployComponenet(props: ConnectionProps) { Upload Smart Contract Module File (e.g. myContract.wasm.v1) { const register = form.register('file'); @@ -220,6 +221,10 @@ export default function DeployComponenet(props: ConnectionProps) { ); setEmbeddedModuleSchemaBase64Init(moduleSchemaBase64Embedded); + + // Check if the module was built as a reproducible build. + const buildInfoSection = WebAssembly.Module.customSections(wasmModule, 'concordium-build-info'); + setIsReproducibleBuild(buildInfoSection.length !== 0); } else { setUploadError('Upload module file is undefined'); } @@ -229,6 +234,13 @@ export default function DeployComponenet(props: ConnectionProps) { {uploadError !== undefined && Error: {uploadError}. } + {isReproducibleBuild === false && ( + + Warning: The module was not built as a reproducible build. See the{' '} + cargo-concordium documentation{' '} + for more information. + + )}
{base64Module && moduleReferenceCalculated && ( <> From 88415c99ee396be06ead692ac952c0a947d2c15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20M=C3=B8ldrup?= Date: Wed, 29 Nov 2023 13:42:20 +0100 Subject: [PATCH 5/7] Update CHANGELOG.md --- front-end-tools/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/front-end-tools/CHANGELOG.md b/front-end-tools/CHANGELOG.md index 40ec1e93..03f03cab 100644 --- a/front-end-tools/CHANGELOG.md +++ b/front-end-tools/CHANGELOG.md @@ -2,6 +2,7 @@ - Fix error message when specifying input parameter without uploading schema. - Fix contract method names in error messages. +- Give warning when deploying a module that is not built with the --verifiable flag. ## 3.0.1 From b87638016f35d9ec04eb0993169d97df0adeabc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20M=C3=B8ldrup?= Date: Wed, 29 Nov 2023 14:42:30 +0100 Subject: [PATCH 6/7] Add BigInt fix to CHANGELOG.md --- front-end-tools/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/front-end-tools/CHANGELOG.md b/front-end-tools/CHANGELOG.md index 40ec1e93..41434a7c 100644 --- a/front-end-tools/CHANGELOG.md +++ b/front-end-tools/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased changes - Fix error message when specifying input parameter without uploading schema. +- Fix error when contract calls return BigInts. - Fix contract method names in error messages. ## 3.0.1 From 00beb59f00105eec373299d4a9a24a13414724ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20M=C3=B8ldrup?= Date: Tue, 5 Dec 2023 14:03:27 +0100 Subject: [PATCH 7/7] PR feedback --- front-end-tools/CHANGELOG.md | 2 +- front-end-tools/src/components/DeployComponent.tsx | 12 ++++++++---- front-end-tools/src/components/ReadComponent.tsx | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/front-end-tools/CHANGELOG.md b/front-end-tools/CHANGELOG.md index 03f03cab..b5802a22 100644 --- a/front-end-tools/CHANGELOG.md +++ b/front-end-tools/CHANGELOG.md @@ -2,7 +2,7 @@ - Fix error message when specifying input parameter without uploading schema. - Fix contract method names in error messages. -- Give warning when deploying a module that is not built with the --verifiable flag. +- Give warning when deploying a module that does not have embedded build information. ## 3.0.1 diff --git a/front-end-tools/src/components/DeployComponent.tsx b/front-end-tools/src/components/DeployComponent.tsx index a4fc25ad..39b47821 100644 --- a/front-end-tools/src/components/DeployComponent.tsx +++ b/front-end-tools/src/components/DeployComponent.tsx @@ -223,7 +223,10 @@ export default function DeployComponenet(props: ConnectionProps) { setEmbeddedModuleSchemaBase64Init(moduleSchemaBase64Embedded); // Check if the module was built as a reproducible build. - const buildInfoSection = WebAssembly.Module.customSections(wasmModule, 'concordium-build-info'); + const buildInfoSection = WebAssembly.Module.customSections( + wasmModule, + 'concordium-build-info' + ); setIsReproducibleBuild(buildInfoSection.length !== 0); } else { setUploadError('Upload module file is undefined'); @@ -236,9 +239,10 @@ export default function DeployComponenet(props: ConnectionProps) { {uploadError !== undefined && Error: {uploadError}. } {isReproducibleBuild === false && ( - Warning: The module was not built as a reproducible build. See the{' '} - cargo-concordium documentation{' '} - for more information. + Warning: The module does not have embedded build information. It will likely not be possible to + match this module to source code. See the{' '} + cargo-concordium documentation for + more information. )}
diff --git a/front-end-tools/src/components/ReadComponent.tsx b/front-end-tools/src/components/ReadComponent.tsx index f7f7da05..d6f0f26f 100644 --- a/front-end-tools/src/components/ReadComponent.tsx +++ b/front-end-tools/src/components/ReadComponent.tsx @@ -101,7 +101,7 @@ export default function ReadComponenet(props: ConnectionProps) { setSchemaError('Schema was not uploaded'); return; } - + const readFunctionTemplate = getUpdateContractParameterSchema( toBuffer(schema, 'base64'), ContractName.fromString(smartContractName),