39 lines
916 B
Solidity
39 lines
916 B
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity >=0.4.22 <0.9.0;
|
|
|
|
import "./BaseContract.sol";
|
|
|
|
contract Bank is BaseContract{
|
|
address[] public atms;
|
|
event NoMoney(address from, uint amount, uint balance);
|
|
event Withdraw(address from, uint amount, uint balance);
|
|
event AddATM(address atm);
|
|
constructor() {}
|
|
|
|
modifier onlyATM() {
|
|
bool found = false;
|
|
for(uint i=0; i<atms.length; i++) {
|
|
if(msg.sender == atms[i]){
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
require(found, "You're not our ATM.");
|
|
_;
|
|
}
|
|
|
|
function addATM(address atm) public onlyOwner {
|
|
atms.push(atm);
|
|
emit AddATM(atm);
|
|
}
|
|
|
|
function withdraw(uint amount) public onlyATM {
|
|
if(amount<=address(this).balance){
|
|
emit NoMoney(msg.sender, amount, address(this).balance);
|
|
revert("Bank doesn't have enough money to withdraw");
|
|
}
|
|
payable(msg.sender).transfer(amount);
|
|
emit Withdraw(msg.sender, amount, address(this).balance);
|
|
}
|
|
}
|