Skip to content

Instantly share code, notes, and snippets.

@msusur
Last active May 9, 2022 00:16
Show Gist options
  • Save msusur/d861764a92825770bc5f392d2cfb5aa1 to your computer and use it in GitHub Desktop.
Save msusur/d861764a92825770bc5f392d2cfb5aa1 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.18;
contract SharedAccount {
// Owner takes all the money.
// Owner can close account and share the balance with all accounts.
// Owner can change owner.
struct AccountBalance {
address addr;
uint balance;
bool isActive;
}
mapping(address => AccountBalance) accounts;
uint maxAccountCount;
uint public numberOfAccounts;
function SharedAccount(uint _maxAccountCount) public {
if(_maxAccountCount != 0) {
maxAccountCount = _maxAccountCount;
} else {
maxAccountCount = 128;
}
}
function openAccount() payable public {
require(!isAccountExists(msg.sender)); // modifier ile yapilir mi?
require(numberOfAccounts < maxAccountCount); // modifier ile yapilir mi?
accounts[msg.sender] = AccountBalance(msg.sender, msg.value, true);
numberOfAccounts++;
}
function withdrawMoney(uint amount) public {
require(isAccountExists(msg.sender)); // modifier ile yapilir mi?
require(accounts[msg.sender].balance >= amount); // modifier ile yapilir mi?
msg.sender.transfer(amount);
accounts[msg.sender].balance -= amount;
}
function depositMoney() payable public {
require(isAccountExists(msg.sender)); // modifier ile yapilir mi?
accounts[msg.sender].balance += msg.value;
}
function isAccountExists(address accountOwner) private returns (bool) {
return accounts[accountOwner].addr != address(0) && accounts[accountOwner].isActive;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment