My idea for college was to make contract where the total amount from contract is shared equally between 2 partners on testnet I am using Mist and have two wallets (accounts) one is called the MainAcc and other partner1. I can push my contract online, there's no errors in compiler I can push it on the blockchain, but when I go to my contract and call function withdraw
and choose an user it starts processing, everything looks fine and transaction is mined, but no ether have been moved from contract to partner or MainAcc.
If i compile it Remix it works i can send money beetween Accounts but have warning --- Gas requirement of function PayCheck.withdraw() high: infinite. If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage) --- maybe thats reason why it wont work on TestNet
I am really desperate, have made whole seminar about smart contracts (history, idea, crypto currency, blockchain, benefits etc) and Ethereum as biggest platform and only need this simple contract to finish it with cool example :(
Thanks in advance!
pragma solidity ^0.4.18;
contract PayCheck {
address[] employees = [0xE83fad0b5EdF2999c29a00199Ca9B773A4627239, 0x118531D9C6C9114c8B999Ac1197778d1669Fc6c6];
mapping (address => uint) withdrawnAmounts;
constructor() payable public{
}
function () payable public{
}
modifier canWithdraw() {
bool contains = false;
for(uint i = 0; i < employees.length; i++) {
if(employees[i] == msg.sender) {
contains = true;
}
}
require(contains);
_;
}
function withdraw() canWithdraw public{
uint amountAllocated = address(this).balance/employees.length;
uint amountWithdrawn = withdrawnAmounts[msg.sender];
uint amount = amountAllocated - amountWithdrawn;
withdrawnAmounts[msg.sender] = amountWithdrawn + amount;
if (amount > 0) {
msg.sender.transfer(amount);
}
}
}