github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata/cashier.sol (about) 1 pragma solidity ^0.4.24; 2 3 import "./Ownable.sol"; 4 5 contract Cashier is Ownable { 6 address public safe; 7 uint256 public depositFee; 8 uint256 public minAmount; 9 uint256 public maxAmount; 10 uint256 public gasLimit; 11 address[] public customers; 12 uint256[] public amounts; 13 bool paused; 14 15 event Receipt(address indexed customer, uint256 amount, uint256 fee); 16 17 function Cashier(address _safe, uint256 _fee, uint256 _minAmount, uint256 _maxAmount) public { 18 require(_safe != address(0)); 19 require(_minAmount > 0); 20 require(_maxAmount >= _minAmount); 21 safe = _safe; 22 depositFee = _fee; 23 minAmount = _minAmount; 24 maxAmount = _maxAmount; 25 gasLimit = 4000000; 26 } 27 28 function () external payable { 29 deposit(); 30 } 31 32 function deposit() public payable { 33 require(!paused); 34 require(msg.value >= minAmount + depositFee); 35 uint256 amount = msg.value - depositFee; 36 require(amount <= maxAmount); 37 38 if (safe.call.value(amount).gas(gasLimit)()) { 39 customers.push(msg.sender); 40 amounts.push(amount); 41 42 emit Receipt(msg.sender, amount, depositFee); 43 } 44 } 45 46 function withdraw(uint256 amount) external onlyOwner { 47 require(address(this).balance >= amount); 48 msg.sender.transfer(amount); 49 } 50 51 function setSafe(address _safe) external onlyOwner { 52 require(_safe != address(0)); 53 safe = _safe; 54 } 55 56 function setMinAmount(uint256 _minAmount) external onlyOwner { 57 require(maxAmount >= _minAmount); 58 minAmount = _minAmount; 59 } 60 61 function setMaxAmount(uint256 _maxAmount) external onlyOwner { 62 require(_maxAmount >= minAmount); 63 maxAmount = _maxAmount; 64 } 65 66 function setDepositFee(uint256 _fee) external onlyOwner { 67 depositFee = _fee; 68 } 69 70 function setGasLimit(uint256 _gasLimit) external onlyOwner { 71 gasLimit = _gasLimit; 72 } 73 74 function pause() external onlyOwner { 75 require(!paused); 76 paused = true; 77 } 78 79 function resume() external onlyOwner { 80 require(paused); 81 paused = false; 82 } 83 84 }