Implement a smart contract for a managing the renovation fund of a shared flat.
Alice is the representative of a shared flat. She adds Bob, Claire, and Dan as residents.
After a while, Alice creates a proposal for repairing the roof. For this, she creates a pdf with all the details, which she uploads to the cloud. Then she submits the proposal to the smart contract, including a link to the pdf, the hash of the pdf for validation, the needed amount of ether, and a deadline.
Sometime before the deadline, Bob and Dan decide to vote "yes" for this proposal. This way, 2/3 of the residents agree with the proposal, so it is accepted. After the deadline, Alice can redeem the proposed amount to implement the proposal.
Later, Alice can submit new proposals, and the residents can vote for them just like before.
constructor: function RenovationFund()
msg.sender
) is the representative of the house.add resident: function addResident(address resident)
resident
as a resident of the house.resident
is already registered, this transaction fails.remove resident: function removeResident(address resident)
resident
from the house.resident
was not registered, this transaction fails.resident
has voted, their vote must be invalidated.submit proposal: function submitProposal(uint256 amount, string link, string hash, uint256 deadline)
amount
wei. A document with all the details must be available under link
. hash
is the hash value of the document (so that residents can validate that that it has not been changed). deadline
is a timestamp that represents the deadline for voting.1
, the second will be 2
, etc.msg.sender
) is the representative of the house and there is no ongoing proposal (i.e. either this is the first proposal, or the previous one has already been executed).vote: function vote(uint16 proposalId, bool voteYes)
voteYes
(i.e. yes or no) for the current proposal.proposalId
must match the id of the current proposal, i.e. when voting for the first proposal, proposalId
must be 1
.execute proposal: function executeProposal()
pay: function () payable
pragma solidity ^0.4.21;
contract RenovationFund {
// <contract_variables>
// </contract_variables>
function RenovationFund() public {
// TODO
}
function addResident(address resident) public {
// TODO
}
function removeResident(address resident) public {
// TODO
}
function submitProposal(uint256 amount, string link, string hash, uint256 deadline) public {
// TODO
}
function vote(uint16 proposalId, bool voteYes) public {
// TODO
}
function executeProposal() public {
// TODO
}
function () public payable {
// TODO
}
}