//SPDX-License-Identifier: Unlicensed
pragma solidity 0.7.5;
contract Bank{
mapping (address => uint) balance; //This mapping defines address as key and Ether Balance Value
/*@dev An event "accountData" has been created to log changes on balances it is
emitted under the deposit and withdrawal function to log changes */
event accountData(address reciever, uint amountChange);
address owner; //state variable that define owner
modifier onlyOwner {
require(msg.sender == owner,"Only Owner can execute transaction"); //Only owner execution
_; //excutes the function on function body
}
constructor(address _owner) {
owner = _owner; //Called before contract execution to define owner constructor
}
function deposit() public payable returns(uint) {
balance[msg.sender] += msg.value; //Adds amount
uint amount = msg.value;
emit accountData(msg.sender, amount);
return balance[msg.sender]; //Returns balance
}
function withdrawFunds(uint amount) public payable returns(uint) {
require(balance[msg.sender] >= amount,"Insufficient Balance, please check that you have enough funds");
uint previousBalanceNumber = balance[msg.sender];
balance[msg.sender] -= amount; //Decreasing the balance
msg.sender.transfer(amount); //This function will allow the withdrawal to happen
assert(balance[msg.sender] == previousBalanceNumber - amount); //Just a Random check
emit accountData(msg.sender,amount); //Will emit a log from the event parameters
return balance[msg.sender];
}
function transferFunds(address recipient, uint amount) public {
require(balance[msg.sender] >= amount,"Not enough funds to excute transactions");
require(msg.sender != recipient, "One cannot transfer funds to their own address");
_transferFunds(msg.sender,recipient,amount);
}
function _transferFunds(address from, address to, uint amount) private {
balance[from] -= amount; //This function will decrease balance from sender
balance[to] += amount; //This function will increase the ether balance to reciever
}
function getBalance() public view returns(uint){
uint amount = balance[msg.sender];
return amount; //returns user balance
}
}
Here is my solution to the assignment, however I am confused as to how to implement
msg.sender.transfer(amount) on the withdrawal function on the 0.8.7 complier; it returns:
TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".
--> payable functions/Transfer_Assignment.sol:42:5:
|