Created
February 4, 2016 15:20
-
-
Save agatsoh/d21976f12b0da2fe4c7c 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
contract Bank { | |
address owner; | |
mapping (address => uint) balances; | |
function init() returns(bool){ | |
owner = tx.origin; | |
return true; | |
} | |
// This will take the value of the transaction and add to the senders account. | |
function deposit(address customer,uint value) returns (bool res) { | |
// If the amount they send is 0, return false. | |
balances[customer] += value; | |
return true; | |
} | |
// Attempt to withdraw the given 'amount' of Ether from the account. | |
function withdraw(address customer, uint amount) returns (bool res) { | |
// Skip if someone tries to withdraw 0 or if they don't have | |
// enough Ether to make the withdrawal. | |
if (balances[customer] < amount || amount == 0){ | |
return false; | |
} | |
balances[customer] -= amount; | |
return true; | |
} | |
function getBalanceOf(address customer) constant returns(uint){ | |
return balances[customer]; | |
} | |
} | |
import "./Bank.sol" as Bank; | |
contract FundManager { | |
address owner; | |
Bank public bank; | |
function init(address bank) returns (bool){ | |
owner = tx.origin; | |
bank = Bank(bank); | |
return true; | |
} | |
function deposit(uint value) returns (bool res) { | |
bool success = bank.deposit(tx.origin,value); | |
return success; | |
} | |
function withdraw(uint amount) returns (bool res) { | |
bool success = bank.withdraw(tx.origin, amount); | |
return success; | |
} | |
function getBankaddress() constant returns (address){ | |
return address(bank); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment