Skip to content

Commit

Permalink
Merge pull request #337 from EYBlockchain/lydia/publicMappingToStructs
Browse files Browse the repository at this point in the history
Lydia/public mapping to structs
  • Loading branch information
lydiagarms authored Sep 17, 2024
2 parents 7e41ad7 + 89e3912 commit cf2edef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/codeGenerators/contract/solidity/toContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function codeGenerator(node: any) {
if (!node.declarationType && !!node._newASTPointer?.declarationType)
node.declarationType = node._newASTPointer.declarationType;
// we crop 'struct ContractName.structname' to just 'structname'
if (typeString.includes('struct ')) typeString = typeString.substring(typeString.indexOf(".") + 1);
if (typeString.includes('struct ')) typeString = typeString.replace(/struct\s+\w+\./, '');
typeString = typeString.replace('contract ', ''); // pesky userdefined type 'contract' keword needs to be removed in some cases.
const constant = node.constant ? ' constant' : '';
const visibility = node.visibility ? ` ${node.visibility}` : '';
Expand Down Expand Up @@ -202,6 +202,7 @@ function codeGenerator(node: any) {
if (node.operator === '!'){
return `${node.operator}${codeGenerator(node.subExpression)}`;
}
if (node.prefix === true) return `${node.operator}${codeGenerator(node.subExpression)};`;
return `${codeGenerator(node.subExpression)} ${node.operator};`;

case 'EmitStatement':
Expand Down
1 change: 0 additions & 1 deletion src/transformers/visitors/toContractVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ export default {
if (!path.containsSecret && !path.scope.indicators.internalFunctionInteractsWithSecret) return;
const file = state.circuitAST.files.find((n: any) => n.fileId === node.id);
const circuitParams = file.nodes.find((n: any) => n.nodeType === node.nodeType).parameters.parameters;

state.circuitParams ??= {};
state.circuitParams[path.getUniqueFunctionName()] ??= {};
state.circuitParams[path.getUniqueFunctionName()].parameters = circuitParams;
Expand Down
26 changes: 26 additions & 0 deletions test/contracts/publicMappingtoStruct.zol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: CC0

pragma solidity ^0.8.0;

contract Receipt {

mapping (address => Rct) private total;
secret uint256 a;

struct Rct {
uint256 amount;
uint256 tax;
}


function add(Rct memory myrct, address user) public {
total[user].amount += myrct.amount;
total[user].tax += myrct.tax;
}

function addSecret(secret uint256 param) public {
a += param;
}


}

0 comments on commit cf2edef

Please sign in to comment.