pragma solidity 0.7.5;
contract Bank {
mapping(address => uint) balance;
address owner;
event balanceAdded(uint indexed amount, address indexed depositedTo);
event balanceTransfer(address sender, address recipient, uint indexed amount);
modifier onlyOwner {
require(msg.sender == owner);
_; //run the function
}
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 recipient, uint amount) public {
require(balance[msg.sender] >= amount, "Balance not sufficient");
require(msg.sender != recipient, "Dont transfer money to yourself");
uint previousSenderBalance = balance[msg.sender];
transfer(msg.sender, recipient, amount);
assert(balance[msg.sender] == previousSenderBalance - amount);
emit balanceTransfer(msg.sender, recipient, amount);
}
function transfer(address from, address to, uint amount) private {
balance[from] -= amount;
balance[to] += amount;
}
}