-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankDB.sol
37 lines (31 loc) · 1.03 KB
/
BankDB.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pragma solidity ^0.4.9;
import "./DougEnabled.sol";
import "./ContractProvider.sol";
contract BankDB is DougEnabled {
mapping (address => uint) public balances;
function deposit(address addr) public payable returns (bool) {
if (doug != 0x0) {
address bank = ContractProvider(doug).contracts("bank");
if (msg.sender == bank) {
balances[addr] += msg.value;
return true;
}
msg.sender.transfer(msg.value);
return false;
}
}
function withdraw(address addr, uint amount) public returns (bool) {
if (doug != 0x0) {
address bank = ContractProvider(doug).contracts("bank");
if (msg.sender == bank) {
uint oldBalance = balances[addr];
if (oldBalance >= amount) {
msg.sender.transfer(amount);
balances[addr] = oldBalance - amount;
return true;
}
}
}
return false;
}
}