Created
April 8, 2021 17:26
-
-
Save harnen/05f2fa58a3ffeb663acc5bd21d9b7182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.16; | |
contract MultiObject { | |
uint256 money; | |
uint256 counter; | |
mapping(uint => address payable) public users; | |
constructor() public { | |
money = 0; | |
users[0] = 0x5c6B0f7Bf3E7ce046039Bd8FABdfD3f9F5021678; | |
users[1] = 0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7; | |
users[2] = 0x1aE0EA34a72D944a8C7603FfB3eC30a6669E454C; | |
counter = 3; | |
} | |
function sendMoney() public payable { | |
money += msg.value; | |
} | |
function addUser(address payable user) public{ | |
users[counter] = user; | |
counter++; | |
} | |
function payAll() payable public{ | |
uint amount = money/counter; | |
for(uint i = 0; i < counter; i++){ | |
users[i].transfer(amount); | |
} | |
money = 0; | |
} | |
function paySomeone(address payable addr) public{ | |
addr.transfer(money); | |
money = 0; | |
} | |
function showMoney() public view returns (uint){ | |
return money; | |
} | |
function showUser(uint index) public view returns (address payable){ | |
return users[index]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment