-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDonation.sol
45 lines (41 loc) · 1.3 KB
/
Donation.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
44
45
pragma solidity >=0.7.0 <0.8.0;
contract Donation{
struct Appealers{
address payable adr;
uint time;
bool reg;
uint asked;
bool grant;
}
mapping (uint=>Appealers) public appealers;
event Appeal (address by,uint id);
constructor() public{
}
function registeration(uint id) private
{
require(!(appealers[id].reg),"user registered");
appealers[id].reg=true;
}
function appeal(uint id) public
{
if(appealers[id].reg==false)
registeration(id);
require(block.timestamp>appealers[id].time+20 seconds,"can appeal once in 20 seconds");
appealers[id].asked++;
uint t=block.timestamp;
appealers[id].grant=false;
appealers[id].adr=msg.sender;
appealers[id].time=t;
assert(appealers[id].time==t);
emit Appeal(msg.sender,id);
}
function pay(uint id) payable public
{
require(msg.sender!=appealers[id].adr,"cannot donate to yourself");
require(appealers[id].reg==true,"user has not appealed");
require(appealers[id].grant==false,"already granted");
appealers[id].adr.transfer(msg.value);
appealers[id].grant=true;
assert(appealers[id].grant==true);
}
}