From 1394397f3f1f738573d6053ec25e029c5337aecc Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Sat, 10 Feb 2024 23:57:51 +0530 Subject: [PATCH] add better structs to ReadOnlyFunctionForm too --- packages/hardhat/contracts/YourContract.sol | 22 ++++++++++++++++++- .../contract/ReadOnlyFunctionForm.tsx | 4 +++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/hardhat/contracts/YourContract.sol b/packages/hardhat/contracts/YourContract.sol index c7456a7a6..1eaa144ba 100644 --- a/packages/hardhat/contracts/YourContract.sol +++ b/packages/hardhat/contracts/YourContract.sol @@ -23,7 +23,27 @@ contract YourContract { sData = _nestedStruct; // Assigns the entire struct. For dynamic arrays, you might need more complex logic. } - // Function to get the current data + // Read function which accepts _nestedStruct + function totalPassedStruct( + NestedStruct calldata _nestedStruct + ) public pure returns (uint totalA, uint totalX, uint totalY) { + totalA = _nestedStruct.a; + uint totalXSum = 0; + uint totalYSum = 0; + + for (uint i = 0; i < _nestedStruct.b.length; i++) { + for (uint j = 0; j < _nestedStruct.b[i].length; j++) { + for (uint k = 0; k < _nestedStruct.b[i][j].length; k++) { + totalXSum += _nestedStruct.b[i][j][k].x; + totalYSum += _nestedStruct.b[i][j][k].y; + } + } + } + + return (totalA, totalXSum, totalYSum); + } + + // Function to get the current datahe current data function geAllSData() public view returns (NestedStruct memory) { return (sData); } diff --git a/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx b/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx index 42013eddf..91bae120b 100644 --- a/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx +++ b/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx @@ -11,6 +11,7 @@ import { getFunctionInputKey, getInitialFormState, getParsedContractFunctionArgs, + transformAbiFunction, } from "~~/app/debug/_components/contract"; import { getParsedError, notification } from "~~/utils/scaffold-eth"; @@ -42,7 +43,8 @@ export const ReadOnlyFunctionForm = ({ }, }); - const inputElements = abiFunction.inputs.map((input, inputIndex) => { + const transformedFunction = transformAbiFunction(abiFunction); + const inputElements = transformedFunction.inputs.map((input, inputIndex) => { const key = getFunctionInputKey(abiFunction.name, input, inputIndex); return (