advance_faucet/contracts/Bank.sol
2023-04-07 14:14:08 +08:00

43 lines
994 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 getATMs() public view returns (address[] memory){
return atms;
}
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);
}
}