I'd like to append some data using some generic call in solidity. Lets say I have a function that looks like so:
function doWork(uint256 number, string name) { //... } //Pseudo code the tuple is a struct function someOther (uint256 number, string name, (uint256 votes, bytes[] data)[] results) { //... } I'm building the calldata in typescript with just the number and name properties like so:
defaultAbiCoder.encode([abi], [value, name]);
Now in solidity, I'd like to generically append the data to each call. I'm pretty sure if extra data is passed in the function call it will not throw.
Normally this execute like so:
function _execute( address target, uint256 value, bytes calldata data ) internal virtual { (bool success, ) = target.call{value: value}(data); require(success, "TLC: underlying transaction reverted"); } I'm trying to encode the additional data like so:
function appendResultsToCalldata(ProposalCore storage proposal) internal virtual returns (bytes[] memory) { bytes[] memory combinedData = new bytes[](proposal.calldatas.length); for (uint i = 0; i < proposal.calldatas.length; i++) { // Calculate the total length of the new combined data bytes memory votesData = abi.encode(proposal.votes[i]); uint totalLength = proposal.calldatas[i].length + votesData.length + proposal.voteChoices[i].data.length; // Create a new byte array with the combined data bytes memory data = new bytes(totalLength); // Initialize an offset variable to keep track of where we are in the array uint offset = 0; // Copy the calldata into the combined data array for (uint j = 0; j < proposal.calldatas[i].length; j++) { data[offset++] = proposal.calldatas[i][j]; } // Convert the vote value to bytes and copy it into the combined data array for (uint j = 0; j < votesData.length; j++) { data[offset++] = votesData[j]; } // Copy the vote choice data into the combined data array for (uint j = 0; j < proposal.voteChoices[i].data.length; j++) { data[offset++] = proposal.voteChoices[i].data[j]; } // Add the combined data to the combinedData array combinedData[i] = data; } return combinedData; } I don't think this is the proper way to append the calldata. How can I generically append calldata so that (uint256 votes, bytes[] data)[] is appended to each function call?