Created
August 16, 2021 21:17
-
-
Save nexto123/9e5f63a188270f1750292d89892894c0 to your computer and use it in GitHub Desktop.
Ether bank mini project..
This file contains hidden or 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
pragma solidity 0.8.1; | |
contract Bank { | |
mapping(address => uint) balance; | |
function addBalance(uint _toAdd) public returns (uint) { | |
balance[msg.sender] += _toAdd; | |
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, "Don't tranfer money to yourself!"); | |
_transfer(msg.sender, recipient, amount); | |
assert(balance[msg.sender] == previousSenderBalance - amount); | |
//event logs and further checks. | |
// balance[msg.sender] -= amount; | |
// balance[recpient] += amount; | |
} | |
function _transfer(address from, address to, uint amount) private { | |
balance[from] -= amount; | |
balance[to] += amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment