|
|
@ -6,7 +6,6 @@ const storage = `pragma solidity >=0.4.22 <0.7.0; |
|
|
|
* @title Storage |
|
|
|
* @title Storage |
|
|
|
* @dev Store & retreive value in a variable |
|
|
|
* @dev Store & retreive value in a variable |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
contract Storage { |
|
|
|
contract Storage { |
|
|
|
|
|
|
|
|
|
|
|
uint256 number; |
|
|
|
uint256 number; |
|
|
@ -15,7 +14,6 @@ contract Storage { |
|
|
|
* @dev Store value in variable |
|
|
|
* @dev Store value in variable |
|
|
|
* @param num value to store |
|
|
|
* @param num value to store |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function store(uint256 num) public { |
|
|
|
function store(uint256 num) public { |
|
|
|
number = num; |
|
|
|
number = num; |
|
|
|
} |
|
|
|
} |
|
|
@ -24,7 +22,6 @@ contract Storage { |
|
|
|
* @dev Return value
|
|
|
|
* @dev Return value
|
|
|
|
* @return value of 'number' |
|
|
|
* @return value of 'number' |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function retreive() public view returns (uint256){ |
|
|
|
function retreive() public view returns (uint256){ |
|
|
|
return number; |
|
|
|
return number; |
|
|
|
} |
|
|
|
} |
|
|
@ -36,7 +33,6 @@ const owner = `pragma solidity >=0.4.22 <0.7.0; |
|
|
|
* @title Owner |
|
|
|
* @title Owner |
|
|
|
* @dev Set & change owner |
|
|
|
* @dev Set & change owner |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
contract Owner { |
|
|
|
contract Owner { |
|
|
|
|
|
|
|
|
|
|
|
address private owner; |
|
|
|
address private owner; |
|
|
@ -58,7 +54,6 @@ contract Owner { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @dev Set contract deployer as owner |
|
|
|
* @dev Set contract deployer as owner |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
constructor() public { |
|
|
|
constructor() public { |
|
|
|
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
|
|
|
|
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
|
|
|
|
emit OwnerSet(address(0), owner); |
|
|
|
emit OwnerSet(address(0), owner); |
|
|
@ -68,7 +63,6 @@ contract Owner { |
|
|
|
* @dev Change owner |
|
|
|
* @dev Change owner |
|
|
|
* @param newOwner address of new owner |
|
|
|
* @param newOwner address of new owner |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function changeOwner(address newOwner) public isOwner { |
|
|
|
function changeOwner(address newOwner) public isOwner { |
|
|
|
emit OwnerSet(owner, newOwner); |
|
|
|
emit OwnerSet(owner, newOwner); |
|
|
|
owner = newOwner; |
|
|
|
owner = newOwner; |
|
|
@ -78,7 +72,6 @@ contract Owner { |
|
|
|
* @dev Return owner address
|
|
|
|
* @dev Return owner address
|
|
|
|
* @return address of owner |
|
|
|
* @return address of owner |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function getOwner() external view returns (address) { |
|
|
|
function getOwner() external view returns (address) { |
|
|
|
return owner; |
|
|
|
return owner; |
|
|
|
} |
|
|
|
} |
|
|
@ -90,7 +83,6 @@ const ballot = `pragma solidity >=0.4.22 <0.7.0; |
|
|
|
* @title Ballot |
|
|
|
* @title Ballot |
|
|
|
* @dev Implements voting process along with vote delegation |
|
|
|
* @dev Implements voting process along with vote delegation |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
contract Ballot { |
|
|
|
contract Ballot { |
|
|
|
|
|
|
|
|
|
|
|
struct Voter { |
|
|
|
struct Voter { |
|
|
@ -117,7 +109,6 @@ contract Ballot { |
|
|
|
* @dev Create a new ballot to choose one of 'proposalNames'. |
|
|
|
* @dev Create a new ballot to choose one of 'proposalNames'. |
|
|
|
* @param proposalNames names of proposals |
|
|
|
* @param proposalNames names of proposals |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
constructor(bytes32[] memory proposalNames) public { |
|
|
|
constructor(bytes32[] memory proposalNames) public { |
|
|
|
chairperson = msg.sender; |
|
|
|
chairperson = msg.sender; |
|
|
|
voters[chairperson].weight = 1; |
|
|
|
voters[chairperson].weight = 1; |
|
|
@ -137,7 +128,6 @@ contract Ballot { |
|
|
|
* @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. |
|
|
|
* @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. |
|
|
|
* @param voter address of voter |
|
|
|
* @param voter address of voter |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function giveRightToVote(address voter) public { |
|
|
|
function giveRightToVote(address voter) public { |
|
|
|
require( |
|
|
|
require( |
|
|
|
msg.sender == chairperson, |
|
|
|
msg.sender == chairperson, |
|
|
@ -155,7 +145,6 @@ contract Ballot { |
|
|
|
* @dev Delegate your vote to the voter 'to'. |
|
|
|
* @dev Delegate your vote to the voter 'to'. |
|
|
|
* @param to address to which vote is delegated |
|
|
|
* @param to address to which vote is delegated |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function delegate(address to) public { |
|
|
|
function delegate(address to) public { |
|
|
|
Voter storage sender = voters[msg.sender]; |
|
|
|
Voter storage sender = voters[msg.sender]; |
|
|
|
require(!sender.voted, "You already voted."); |
|
|
|
require(!sender.voted, "You already voted."); |
|
|
@ -185,7 +174,6 @@ contract Ballot { |
|
|
|
* @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. |
|
|
|
* @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. |
|
|
|
* @param proposal index of proposal in the proposals array |
|
|
|
* @param proposal index of proposal in the proposals array |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function vote(uint proposal) public { |
|
|
|
function vote(uint proposal) public { |
|
|
|
Voter storage sender = voters[msg.sender]; |
|
|
|
Voter storage sender = voters[msg.sender]; |
|
|
|
require(sender.weight != 0, "Has no right to vote"); |
|
|
|
require(sender.weight != 0, "Has no right to vote"); |
|
|
@ -203,7 +191,6 @@ contract Ballot { |
|
|
|
* @dev Computes the winning proposal taking all previous votes into account. |
|
|
|
* @dev Computes the winning proposal taking all previous votes into account. |
|
|
|
* @return winningProposal_ index of winning proposal in the proposals array |
|
|
|
* @return winningProposal_ index of winning proposal in the proposals array |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function winningProposal() public view |
|
|
|
function winningProposal() public view |
|
|
|
returns (uint winningProposal_) |
|
|
|
returns (uint winningProposal_) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -220,7 +207,6 @@ contract Ballot { |
|
|
|
* @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then |
|
|
|
* @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then |
|
|
|
* @return winnerName_ the name of the winner |
|
|
|
* @return winnerName_ the name of the winner |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function winnerName() public view |
|
|
|
function winnerName() public view |
|
|
|
returns (bytes32 winnerName_) |
|
|
|
returns (bytes32 winnerName_) |
|
|
|
{ |
|
|
|
{ |
|
|
|