contract Bank{
mapping (address => uint) balance;
address owner;
event balanceAdded(uint amount, address depositedTo);
event transferAmount(uint amount, address transferredFrom, address transfferedTo);
modifier onlyOwner {
require(msg.sender == owner);
_;
}
constructor(){
owner = msg.sender;
}
function addBalance (uint _toAdd) public onlyOwner returns(uint) {
balance [msg.sender] += _toAdd;
emit balanceAdded(_toAdd, msg.sender);
return balance[msg.sender];
}
function getBalance() public view returns(uint) {
return balance [msg.sender];
}
function transfer(address recepient, uint amount) public {
require(balance[msg.sender]>=amount);
require(msg.sender != recepient);
uint previousSenderBalance = balance[msg.sender];
_transfer(msg.sender,recepient, amount);
assert(balance[msg.sender] == previousSenderBalance - amount);
emit transferAmount(amount, msg.sender, recepient);
}
function _transfer(address from, address to, uint amount) private {
balance[from] -= amount;
balance[to] += amount;
}
}