Disclaimer: I'm a noob when it comes to programming altogether let alone smart contracts.
I refactored this code that was written like three years ago so it could work with solidity 0.5.0. I deployed it on Remix's Javascript VM but the addPayee function is not working: transact to Donation.addPayee errored: VM error: revert. Please help thanks :(
Also, I'm not sure that the contract is assigning me (the deployer) as the owner.
contract Donation {
address public owner;
struct Payee {
bool status;
uint weight;
uint balance;
}
e.
mapping(address => Payee) public payees;
mapping (int8 => address) public payeesIndex;
int8 public payeesIndexSize;
function Donations() private {
// Set the address of the contract deployer to be owner.
owner = msg.sender;
payees[owner].status = true;
payees[owner].weight = 10;
payeesIndex[0] = owner;
payeesIndexSize = 1;
}
// Check if current account calling methods is the owner.
modifier isOwner() {
require (msg.sender == owner);
_;
}
// Aggregate all payee weights.
function getTotalWeight() public view returns (uint) {
int8 i;
uint totalWeight = 0;
for (i=0;i<payeesIndexSize;i++) {
if (payees[payeesIndex[i]].status == true) {
totalWeight += payees[payeesIndex[i]].weight;
}
}
return totalWeight;
}
// Add a new payee to the contract.
function addPayee(address _payee, uint _weight) isOwner public returns (bool) {
payees[_payee].weight = _weight;
payees[_payee].status = true;
payeesIndex[payeesIndexSize] = _payee;
payeesIndexSize++;
}
function getStatus(address _address) public view returns(bool) {
return payees[_address].status;
}