diff --git a/apps/contracts/contracts/Zengo.sol b/apps/contracts/contracts/Zengo.sol index 660b304..8a0d729 100644 --- a/apps/contracts/contracts/Zengo.sol +++ b/apps/contracts/contracts/Zengo.sol @@ -132,6 +132,7 @@ contract ZengoDAO is Constants, ZengoStorage, GStates, PermissionsEnumerable, Co newProposal.votingIterationCount = 0; newProposal.verificationState = Structs.VerificationState(0); newProposal.streetAddress = _streetAddress; + newProposal.createdAt = block.timestamp; newProposal.latitude = _latitude; newProposal.longitude = _longitude; proposalEvidence[GOVERNANCE_CYCLE][proposalCount] = newEvidence; diff --git a/apps/contracts/contracts/lib/Structs.sol b/apps/contracts/contracts/lib/Structs.sol index 7512eca..b2ef94d 100644 --- a/apps/contracts/contracts/lib/Structs.sol +++ b/apps/contracts/contracts/lib/Structs.sol @@ -6,6 +6,7 @@ library Structs { address proposer; uint8 votingIterationCount; uint256 proposalId; + uint256 createdAt; int256 latitude; int256 longitude; string title; diff --git a/apps/contracts/contracts/storage/ZengoStorage.sol b/apps/contracts/contracts/storage/ZengoStorage.sol index ec29847..1c7e9bb 100644 --- a/apps/contracts/contracts/storage/ZengoStorage.sol +++ b/apps/contracts/contracts/storage/ZengoStorage.sol @@ -23,24 +23,17 @@ contract ZengoStorage { mapping(address => Structs.Moderator) public moderatorStruct; mapping(uint256 => mapping(address => uint256)) public votingPoints; - mapping(uint256 => mapping(uint256 => Structs.Vote[])) - public voteIterations; - - mapping(uint256 => mapping(uint256 => Structs.Evidence)) - public proposalEvidence; - mapping(uint256 => mapping(uint256 => mapping(uint8 => Structs.Evidence[]))) - public votingIterationEvidence; - - mapping(uint256 => mapping(uint256 => mapping(uint8 => mapping(address => Structs.VerificationState)))) - public vote; - mapping(uint256 => mapping(uint256 => mapping(uint8 => mapping(address => bool)))) - public hasVoted; - mapping(uint256 => mapping(uint256 => mapping(uint8 => mapping(Structs.VerificationState => uint256)))) - public voteCount; - - function getModeratorInfo( - address _moderator - ) public view returns (Structs.Moderator memory) { + mapping(uint256 => mapping(uint256 => Structs.Vote[])) public voteIterations; + + mapping(uint256 => mapping(uint256 => Structs.Evidence)) public proposalEvidence; + mapping(uint256 => mapping(uint256 => mapping(uint8 => Structs.Evidence[]))) public votingIterationEvidence; + + mapping(uint256 => mapping(uint256 => mapping(uint8 => mapping(address => Structs.VerificationState)))) public vote; + mapping(uint256 => mapping(uint256 => mapping(uint8 => mapping(address => bool)))) public hasVoted; + mapping(uint256 => mapping(uint256 => mapping(uint8 => mapping(Structs.VerificationState => uint256)))) public + voteCount; + + function getModeratorInfo(address _moderator) public view returns (Structs.Moderator memory) { require(moderators[_moderator], "Given address is not a Moderator"); return moderatorStruct[_moderator]; } @@ -50,20 +43,13 @@ contract ZengoStorage { } function getModerators() public view returns (Structs.Moderator[] memory) { - Structs.Moderator[] - memory moderatorsStructArray = new Structs.Moderator[]( + Structs.Moderator[] memory moderatorsStructArray = new Structs.Moderator[]( moderatorList.length ); for (uint256 i = 0; i < moderatorList.length; i++) { - moderatorsStructArray[i].moderatorType = moderatorStruct[ - moderatorList[i] - ].moderatorType; - moderatorsStructArray[i].position = moderatorStruct[ - moderatorList[i] - ].position; - moderatorsStructArray[i].organization = moderatorStruct[ - moderatorList[i] - ].organization; + moderatorsStructArray[i].moderatorType = moderatorStruct[moderatorList[i]].moderatorType; + moderatorsStructArray[i].position = moderatorStruct[moderatorList[i]].position; + moderatorsStructArray[i].organization = moderatorStruct[moderatorList[i]].organization; } return moderatorsStructArray; } @@ -71,11 +57,7 @@ contract ZengoStorage { function getAllProposals() public view - returns ( - Structs.Proposal[] memory, - Structs.Vote[] memory, - Structs.Evidence[] memory - ) + returns (Structs.Proposal[] memory, Structs.Vote[] memory, Structs.Evidence[] memory) { Structs.Proposal[] memory proposalsArray = new Structs.Proposal[]( proposalCount + 1 @@ -90,70 +72,33 @@ contract ZengoStorage { uint256 eCount = 0; for (uint256 i = 0; i < proposalCount + 1; i++) { - proposalsArray[i].votingIterationCount = proposals[ - GOVERNANCE_CYCLE - ][i].votingIterationCount; - proposalsArray[i].proposalId = proposals[GOVERNANCE_CYCLE][i] - .proposalId; + proposalsArray[i].votingIterationCount = proposals[GOVERNANCE_CYCLE][i].votingIterationCount; + proposalsArray[i].proposalId = proposals[GOVERNANCE_CYCLE][i].proposalId; proposalsArray[i].title = proposals[GOVERNANCE_CYCLE][i].title; - proposalsArray[i].proposalDescription = proposals[GOVERNANCE_CYCLE][ - i - ].proposalDescription; - proposalsArray[i].proposalType = proposals[GOVERNANCE_CYCLE][i] - .proposalType; - proposalsArray[i].proposer = proposals[GOVERNANCE_CYCLE][i] - .proposer; - proposalsArray[i].isEligibleForFunding = proposals[ - GOVERNANCE_CYCLE - ][i].isEligibleForFunding; - proposalsArray[i].isVerified = proposals[GOVERNANCE_CYCLE][i] - .isVerified; - proposalsArray[i].verificationState = proposals[GOVERNANCE_CYCLE][i] - .verificationState; - proposalsArray[i].streetAddress = proposals[GOVERNANCE_CYCLE][i] - .streetAddress; - proposalsArray[i].latitude = proposals[GOVERNANCE_CYCLE][i] - .latitude; - proposalsArray[i].longitude = proposals[GOVERNANCE_CYCLE][i] - .longitude; - for ( - uint256 j = 0; - j < proposals[GOVERNANCE_CYCLE][i].votingIterationCount; - j++ - ) { - voteIterationsArray[count].votingIteration = voteIterations[ - GOVERNANCE_CYCLE - ][i][j].votingIteration; - voteIterationsArray[count].proposalId = voteIterations[ - GOVERNANCE_CYCLE - ][i][j].proposalId; - voteIterationsArray[count].totalVotes = voteIterations[ - GOVERNANCE_CYCLE - ][i][j].totalVotes; - voteIterationsArray[count].inProgress = voteIterations[ - GOVERNANCE_CYCLE - ][i][j].inProgress; - voteIterationsArray[count].resultState = voteIterations[ - GOVERNANCE_CYCLE - ][i][j].resultState; + proposalsArray[i].proposalDescription = proposals[GOVERNANCE_CYCLE][i].proposalDescription; + proposalsArray[i].proposalType = proposals[GOVERNANCE_CYCLE][i].proposalType; + proposalsArray[i].proposer = proposals[GOVERNANCE_CYCLE][i].proposer; + proposalsArray[i].isEligibleForFunding = proposals[GOVERNANCE_CYCLE][i].isEligibleForFunding; + proposalsArray[i].isVerified = proposals[GOVERNANCE_CYCLE][i].isVerified; + proposalsArray[i].verificationState = proposals[GOVERNANCE_CYCLE][i].verificationState; + proposalsArray[i].streetAddress = proposals[GOVERNANCE_CYCLE][i].streetAddress; + proposalsArray[i].latitude = proposals[GOVERNANCE_CYCLE][i].latitude; + proposalsArray[i].longitude = proposals[GOVERNANCE_CYCLE][i].longitude; + proposalsArray[i].createdAt = proposals[GOVERNANCE_CYCLE][i].createdAt; + for (uint256 j = 0; j < proposals[GOVERNANCE_CYCLE][i].votingIterationCount; j++) { + voteIterationsArray[count].votingIteration = voteIterations[GOVERNANCE_CYCLE][i][j].votingIteration; + voteIterationsArray[count].proposalId = voteIterations[GOVERNANCE_CYCLE][i][j].proposalId; + voteIterationsArray[count].totalVotes = voteIterations[GOVERNANCE_CYCLE][i][j].totalVotes; + voteIterationsArray[count].inProgress = voteIterations[GOVERNANCE_CYCLE][i][j].inProgress; + voteIterationsArray[count].resultState = voteIterations[GOVERNANCE_CYCLE][i][j].resultState; count++; - for ( - uint256 k = 0; - k < voteIterations[GOVERNANCE_CYCLE][i][j].evidenceCount; - k++ - ) { - evidencesArray[eCount] - .evidenceDescription = votingIterationEvidence[ - GOVERNANCE_CYCLE - ][i][uint8(j)][k].evidenceDescription; - evidencesArray[eCount] - .evidenceUri = votingIterationEvidence[ - GOVERNANCE_CYCLE - ][i][uint8(j)][k].evidenceUri; - evidencesArray[eCount] - .evidenceTimestamp = votingIterationEvidence[ - GOVERNANCE_CYCLE - ][i][uint8(j)][k].evidenceTimestamp; + for (uint256 k = 0; k < voteIterations[GOVERNANCE_CYCLE][i][j].evidenceCount; k++) { + evidencesArray[eCount].evidenceDescription = + votingIterationEvidence[GOVERNANCE_CYCLE][i][uint8(j)][k].evidenceDescription; + evidencesArray[eCount].evidenceUri = + votingIterationEvidence[GOVERNANCE_CYCLE][i][uint8(j)][k].evidenceUri; + evidencesArray[eCount].evidenceTimestamp = + votingIterationEvidence[GOVERNANCE_CYCLE][i][uint8(j)][k].evidenceTimestamp; eCount++; } }