Skip to content

Commit

Permalink
AbieFund#28 Upgrade the contract to Solidity 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
iamonuwa committed Apr 12, 2019
1 parent bb439b1 commit 2825fa5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
46 changes: 23 additions & 23 deletions contracts/Abie.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Part of this contract is from the solidity documentation
pragma solidity ^0.4.8;
pragma solidity ^0.5.7;

/** Prepare for deployments:
*
Expand All @@ -18,11 +18,11 @@ contract Abie {
uint public nbMembers;
uint public nbProposalsFund;
uint public nbMembershipReq;
uint public registrationTime = 1 years;
uint public registrationTime = 365;
uint[2] public voteLength = [5 minutes, 5 minutes];
uint MAX_DELEGATION_DEPTH=10;
address NOT_COUNTED=0;
address COUNTED=1;
address payable NOT_COUNTED= address(0);
address payable COUNTED= address(1);

event Donated(address donor, uint amount);

Expand Down Expand Up @@ -81,7 +81,7 @@ contract Abie {
}

/// @param initialMembers First members of the organization.
function Abie(bytes32 _name, bytes32 _statement, address[] initialMembers) public{
constructor(bytes32 _name, bytes32 _statement, address[] memory initialMembers) public{
name=_name;
statement=_statement;
for (uint i;i<initialMembers.length;++i){
Expand Down Expand Up @@ -121,14 +121,14 @@ contract Abie {
}

/// Receive funds.
function () payable public{
function () payable external{
// require(msg.value+address(this).balance >= 1000000000000000000000000);
Donated(msg.sender, msg.value);
emit Donated(msg.sender, msg.value);
}

/// Ask for membership.
function askMembership () payable public costs(fee) {
Donated(msg.sender,msg.value); // Register the donation.
emit Donated(msg.sender,msg.value); // Register the donation.

// Create a proposal to add the member.
proposals.push(Proposal({
Expand All @@ -140,7 +140,7 @@ contract Abie {
data: 0x0,
proposalType: ProposalType.AddMember,
endDate: now + 5 minutes,
lastMemberCounted: 0,
lastMemberCounted: address(0),
executed: false
}));

Expand All @@ -149,7 +149,7 @@ contract Abie {

/// Add Proposal.
function addProposal (bytes32 _name, uint _value, bytes32 _data) payable public costs(fee) { //require(msg.value+address(this).balance >= address(this).balance);
Donated(msg.sender,msg.value); // Register the donation.
emit Donated(msg.sender,msg.value); // Register the donation.
// Create a proposal to add the member.
proposals.push(Proposal({
name: _name,
Expand All @@ -160,7 +160,7 @@ contract Abie {
data: _data,
proposalType: ProposalType.FundProject,
endDate: now + 5 minutes,
lastMemberCounted: 0,
lastMemberCounted: address(0),
executed: false
}));

Expand Down Expand Up @@ -196,12 +196,12 @@ contract Abie {
Proposal storage proposal = proposals[proposalID];
address current;
require (proposal.endDate <= now); // You can't count while the vote is not over.
require (proposal.lastMemberCounted != COUNTED); // The count is already over
require (address(proposal.lastMemberCounted) != COUNTED); // The count is already over

if (proposal.lastMemberCounted == NOT_COUNTED)
if (address(proposal.lastMemberCounted) == NOT_COUNTED)
current = memberList.first;
else
current = proposal.lastMemberCounted;
current = address(proposal.lastMemberCounted);

while (max-- != 0) {
Member storage member = members[current];
Expand All @@ -215,7 +215,7 @@ contract Abie {
depth+=1;
delegate=members[delegate].delegate[uint(proposal.proposalType)]; // Find the delegate.
if (delegate==current // The delegation chain forms a circle.
|| delegate==0 // Has not set a delegate.
|| delegate==address(0) // Has not set a delegate.
|| depth>MAX_DELEGATION_DEPTH) { // Too much depth, we must limit it in order to avoid some circle of delegation made to consume too much gaz.
break;
}
Expand All @@ -233,8 +233,8 @@ contract Abie {
}

current=member.succ; // In next iteration start from the next node.
if (current==0) { // We reached the last member.
proposal.lastMemberCounted=COUNTED;
if (current==address(0)) { // We reached the last member.
proposal.lastMemberCounted=address(0);
break;
}
}
Expand All @@ -259,7 +259,7 @@ contract Abie {
require(proposal.executed == false); // rejected if executed already
require (beneficiary == msg.sender); // rejected if caller is not the beneficiary
proposal.executed = true; // The proposal was executed.
beneficiary.transfer(check); // The beneficiary gets the requested amount.
address(uint160(beneficiary)).transfer(check); // The beneficiary gets the requested amount.
}

/// CONSTANTS ///
Expand All @@ -268,14 +268,14 @@ contract Abie {
* @param member member to get the delegate from.
* @param proposalType 0 for AddMember, 1 for FundProject.
*/
function getDelegate(address member, uint8 proposalType) public constant returns (address){
function getDelegate(address member, uint8 proposalType) public view returns (address){
return members[member].delegate[proposalType];
}

/** Return true if the proposal is validated, false otherwise.
* @param proposalID ID of the proposal to count votes from.
*/
function isExecutable(uint proposalID) public constant returns (bool) {
function isExecutable(uint proposalID) public view returns (bool) {
Proposal storage proposal = proposals[proposalID];

if (proposal.lastMemberCounted != COUNTED) // Not counted yet.
Expand All @@ -288,19 +288,19 @@ contract Abie {
return (proposal.voteYes>proposal.voteNo);
}

function isValidMember(address m) public constant returns(bool) {
function isValidMember(address m) public view returns(bool) {
if (members[m].registration==0) // Not a member.
return false;
if (members[m].registration+registrationTime<now) // Has expired.
return false;
return true;
}

function contractBalance() public constant returns(uint256) {
function contractBalance() public view returns(uint256) {
return address(this).balance;
}

function timeLeft(uint proposalID) public constant returns(uint256) {
function timeLeft(uint proposalID) public view returns(uint256) {
Proposal storage proposal = proposals[proposalID];
return proposal.endDate - now;
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
pragma solidity ^0.4.4;
pragma solidity ^0.5.7;

contract Migrations {
address public owner;
uint public last_completed_migration;

modifier restricted() {
if (msg.sender != owner) throw;
if (msg.sender != owner) revert();
_;
}

function Migrations() {
constructor() public {
owner = msg.sender;
}

function setCompleted(uint completed) restricted {
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) restricted {
function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
Expand Down

0 comments on commit 2825fa5

Please sign in to comment.