In this final part of the tutorial, you will be finalizing your Proposal Contract.
Let's start with a function to terminate a proposal.
function teminateProposal() external onlyOwner active {
proposal_history[counter].is_active = false;
}
This function terminates the current proposal. It can only be called by the owner of the contract and the current proposal should be active to run this function which is indicated by active modifier.
Now, you will implement 3 query functions to retrieve data from the blockchain. Remember, the person/contract that call a query function does not pay gas fees.
function isVoted(address _address) public view returns (bool) {
for (uint i = 0; i < voted_addresses.length; i++) {
if (voted_addresses[i] == _address) {
return true;
}
}
return false;
}
function getCurrentProposal() external view returns(Proposal memory) {
return proposal_history[counter];
}
Memory refers to a temporary location where data can be stored. It's erased between (external) function calls and is cheaper to use than storage. You may think it as the RAM of the EVM.
function getProposal(uint256 number) external view returns(Proposal memory) {
return proposal_history[number];
}
Congrulations, now you can look through the window thinking how did you became a smart contract developer!
On the next page, you can find the full contract ✌️
Swap insights and ask questions about “Learn everything about Solidity”.
Ask a question or share your thoughts about this lesson.