contract SafeBank {
    uint public constant minDeposit = 300 finney; //minimum deposit is 0.3 Ether (not worth it to deposit much less because of network fees)

    mapping (address => uint) public balances; //balance of each user
    Log transferLog; //logs each deposit and each withdraw for auditing
    
    constructor(address _log) public payable {
        transferLog = Log(_log);
    }
    
    //deposits Eth in the contract:
    function deposit() public payable {
        require(msg.value >= minDeposit, "Minimum deposit not met."); //requires at least minDeposit

        balances[msg.sender] += msg.value; //adds Eth to the balance of whoever called this function
        transferLog.register(msg.sender, msg.value, "Deposit"); //logs the deposit
    }
    
    //withdraws Eth from the contract:
    function withdraw(uint amount) public {
        require(amount <= balances[msg.sender], "Insufficient funds"); //requires the user has enough balance

        (bool success,) = msg.sender.call.value(amount)(""); //tries to send Eth to the user using the new Solidity ^0.6.0 way
        if(success) { //if the transfer fails, the whole transaction is reverted
            balances[msg.sender] -= amount; //reduce the user's balance
            transferLog.register(msg.sender, amount, "Withdraw"); //logs the withdrawal
        }
    }
    
    //the new fallback function:
    receive() external payable {
        
    }
}
//Safely stores user's Ether and allows withdrawals using the new Solidity ^0.6.0 way:
function deposit() public payable {
    require(msg.value >= minDeposit, "Minimum deposit not met."); //requires at least minDeposit

    balances[msg.sender] += msg.value; //adds Eth to the balance of whoever called this function
    transferLog.register(msg.sender, msg.value, "Deposit"); //logs the deposit
}

//deposits Eth in the contract: