This repository has been archived by the owner on Nov 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
EmailVerification.sol
74 lines (57 loc) · 2.17 KB
/
EmailVerification.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! E-mail verification contract
//! By Gav Wood, 2016.
pragma solidity ^0.4.0;
contract Owned {
modifier only_owner { if (msg.sender != owner) return; _; }
event NewOwner(address indexed old, address indexed current);
function setOwner(address _new) only_owner { NewOwner(owner, _new); owner = _new; }
address public owner = msg.sender;
}
contract Certifier {
event Confirmed(address indexed who);
event Revoked(address indexed who);
function certified(address _who) constant returns (bool);
function get(address _who, string _field) constant returns (bytes32) {}
function getAddress(address _who, string _field) constant returns (address) {}
function getUint(address _who, string _field) constant returns (uint) {}
}
contract ProofOfEmail is Owned, Certifier {
modifier when_fee_paid { if (msg.value < fee) return; _; }
event Requested(address indexed who, bytes32 emailHash);
event Puzzled(address indexed who, bytes32 indexed emailHash, bytes32 puzzle);
function request(bytes32 _emailHash) payable when_fee_paid {
Requested(msg.sender, _emailHash);
}
function puzzle(address _who, bytes32 _puzzle, bytes32 _emailHash) only_owner {
puzzles[_puzzle] = _emailHash;
Puzzled(_who, _emailHash, _puzzle);
}
function confirm(bytes32 _code) returns (bool) {
var emailHash = puzzles[sha3(_code)];
if (emailHash == 0)
return;
delete puzzles[sha3(_code)];
if (reverse[emailHash] != 0)
return;
entries[msg.sender] = emailHash;
reverse[emailHash] = msg.sender;
Confirmed(msg.sender);
}
function setFee(uint _new) only_owner {
fee = _new;
}
function drain() only_owner {
if (!msg.sender.send(this.balance))
throw;
}
function certified(address _who) constant returns (bool) {
return entries[_who] != 0;
}
function get(address _who, string _field) constant returns (bytes32) {
entries[_who];
}
mapping (address => bytes32) entries;
mapping (bytes32 => address) public reverse;
mapping (bytes32 => bytes32) puzzles;
uint public fee = 0 finney;
}