-
Notifications
You must be signed in to change notification settings - Fork 5
/
RSVP.sol
56 lines (43 loc) · 1.47 KB
/
RSVP.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
46
47
48
49
50
51
52
53
54
55
56
pragma solidity 0.4.25;
contract RSVP{
mapping (address => bool) public bookings;
address public owner;
uint N=3;
bytes32 [] unlockCodesHashes = new bytes32[](N);
uint RESERVATION = 0;
uint UNLOCKING = 1;
uint state=RESERVATION;
constructor() public{
owner = msg.sender;
unlockCodesHashes[0] = 0xA2242EAD55C94C3DEB7CF2340BFEF9D5BCACA22DFE66E646745EE4371C633FC8;//pippo
unlockCodesHashes[1] = 0xC48B4DF565B0C96F84FEDF18F26596ED40AA9F46F11021AF7125D34D1D3ACFFE;//pluto
unlockCodesHashes[2] = 0xF106E246ECDAB88CB2262780F60079651AEAA6A3C8F5B1E75FC2AB0582CD3F67;//paperino
}
function reserveSeat() payable public{
require(state == RESERVATION);
require(msg.value == 0.03 ether);
require(bookings[msg.sender] == false);
bookings[msg.sender] = true;
}
function () payable public{
reserveSeat();
}
function unlockStake(string code) public {
require(state == UNLOCKING);
require(bookings[msg.sender] == true);
for(uint i=0;i<N;i++){
if(sha256(code) == unlockCodesHashes[i]) {
unlockCodesHashes[i]=0;
msg.sender.transfer(0.03 ether);
}
}
}
function stopRSVP(){
require(msg.sender == owner);
state = UNLOCKING;
}
function close() public{
require(msg.sender == owner);
selfdestruct(owner);
}
}