-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFaucet.sol
43 lines (39 loc) · 1.11 KB
/
Faucet.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Version of Solidity compiler this program was written for
pragma solidity ^0.5.00;
contract owned {
address payable owner;
// Contract constructor: set owner
constructor() public {
owner = msg.sender;
}
// Access control modifier
modifier onlyOwner {
require(msg.sender == owner,
"Only the contract owner can call this function");
_;
}
}
contract mortal is owned {
// Contract destructor
function destroy() public onlyOwner {
selfdestruct(owner);
}
}
contract Faucet is mortal {
event Withdrawal(address indexed to, uint amount);
event Deposit(address indexed from, uint amount);
// Give out ether to anyone who asks
function withdraw(uint withdraw_amount) public {
// Limit withdrawal amount
require(withdraw_amount <= 0.1 ether);
require(address(this).balance >= withdraw_amount,
"Insufficient balance in faucet for withdrawal request");
// Send the amount to the address that requested it
msg.sender.transfer(withdraw_amount);
emit Withdrawal(msg.sender, withdraw_amount);
}
// Accept any incoming amount
function () external payable {
emit Deposit(msg.sender, msg.value);
}
}