Skip to content

Proposal_contract

weidong edited this page Apr 9, 2020 · 2 revisions

Add proposal and voting instructions

torage structure

  • The proposal structure
struct Proposals {
    address createPeople;	 Founder address
    bytes   proposalName;	 The name of the proposed
    uint    proposalId;	 	 Proposal ID
    uint    createTime;	 	 Proposal creation time
    uint    agreeTicket;     	 Number of votes in favour of the proposal 
    uint    opposeTicket;    	 Number of negative votes on proposals 
    bool    isPass;		 Whether the proposal passes or not
}
  • Total number of proposals, number of authorized persons, contract owners
uint public proposalId;         
uint public voterNum;
address public owner;          
  • mapping relation
mapping (uint => Proposals) public proposalInfo;		   	Proposal id => proposal information (available from outside)
mapping (bytes => bool) isProposalExist;				Whether the proposal exists
mapping (address => mapping(uint => bool)) isVote; 		   	Whether or not an address votes on a proposal
mapping (address => bool) isVoteAuthority;				Whether an address has voting and proposal authority

function realization

  • (1)Authorizes a addressa to vote and propose
giveAuthorityToVote(address voter) 
  • (2)Remove voting and proposal rights from an address
cancelAuthorToVote(address cancelAddr)
  • (3)Add a new proposal and return the proposal id
addProposal(bytes newproposal)
  • (4)Vote by proposal id,true means yes, false means no
voteThoughId(uint id, bool isOk) 
  • (5)To obtain whether a proposal is passed, yes is greater than no, and more than half of the 51 nodes vote yes (i.e., yes is greater than or equal to 26).
isProposalPassed(uint id)
  • (6)ets the creation time of a proposal
getProposalCreateTime(uint id)
  • (7)To find out if an address has proposal and voting rights
getAddrIsAuthority(address addr)

Clone this wiki locally