forked from eosdac/eosio.lost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eosio.lost.cpp
190 lines (137 loc) · 5.67 KB
/
eosio.lost.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "eosio.lost.hpp"
void lostcontract::add(name account, string eth_address, asset value) {
require_auth(_self);
whitelist_table whitelist(_self, _self.value);
eosio_assert(is_account(account), "Account does not exist");
auto existing = whitelist.find(account.value);
eosio_assert(existing == whitelist.end(), "Address is already on the whitelist");
whitelist.emplace(_self, [&](whitelist_info &w){
w.account = account;
w.eth_address = eth_address;
w.value = value;
});
}
void lostcontract::propose(name claimer) {
verifications_table verifications(_self, _self.value);
producers_table producers("eosio"_n, "eosio"_n.value);
auto verification = verifications.find(claimer.value);
eosio_assert(verification != verifications.end(), "Account not verified");
time_point_sec deadline{now() - WAITING_PERIOD};
eosio_assert(verification->added < deadline, "Thirty day waiting period has not passed");
eosio_assert(verification->proposed == 0, "Already proposed this lost key");
// Create transaction to be proposed
time_point_sec expire{now() + PROPOSAL_EXPIRY};
transaction trx;
trx.expiration = expire;
trx.ref_block_num = 0;
trx.ref_block_prefix = 0;
vector<eosiosystem::key_weight> keys;
eosiosystem::key_weight kw {
.key = verification->new_key,
.weight = (uint16_t) 1,
};
keys.push_back(kw);
eosiosystem::authority new_authority{
.threshold = (uint32_t) 1,
.keys = keys,
.accounts = {},
.waits = {}
};
action act_active = action(permission_level{verification->claimer, "owner"_n},
"eosio"_n, "updateauth"_n,
std::make_tuple(
verification->claimer,
"active"_n,
"owner"_n,
new_authority
));
action act_owner = action(permission_level{verification->claimer, "owner"_n},
"eosio"_n, "updateauth"_n,
std::make_tuple(
verification->claimer,
"owner"_n,
name{0},
new_authority
));
trx.actions.push_back(act_active);
trx.actions.push_back(act_owner);
// create a wrap transaction
transaction wrap;
wrap.expiration = expire;
wrap.ref_block_num = 0;
wrap.ref_block_prefix = 0;
vector<permission_level> perms;
perms.push_back(permission_level{"eosio"_n, "active"_n});
perms.push_back(permission_level{"eosio.wrap"_n, "active"_n});
wrap.actions.push_back(action(perms,
"eosio.wrap"_n, "exec"_n,
std::make_tuple(
"eosio"_n,
trx
)));
// Create the msig inline from here
// Get the top 30 bps for the requested list
vector<permission_level> requested;
auto by_votes = producers.get_index<"prototalvote"_n>();
auto prod_itr = by_votes.begin();
// requested.push_back(permission_level{_self, "active"_n});
if (prod_itr == by_votes.end()){
// testing purposes for unactivated chains
requested.push_back(permission_level{"eosio"_n, "active"_n});
}
else {
for (uint8_t i = 0;i<30;i++){
requested.push_back(permission_level{prod_itr->owner, "active"_n});
prod_itr++;
}
}
action(permission_level{_self, "active"_n},
"eosio.msig"_n, "propose"_n,
std::make_tuple(
_self, // proposer
verification->claimer, // proposal name
requested, // requested permissions
wrap // transaction
)).send();
// Mark this verification as proposed
verifications.modify(verification, same_payer, [&](verify_info &v){
v.proposed = 1;
});
}
void lostcontract::verify(std::vector<char> sig, name account, public_key newpubkey, name rampayer) {
require_auth(rampayer);
verifications_table verifications(_self, _self.value);
whitelist_table whitelist(_self, _self.value);
eosio_assert(is_account(account), "Account does not exist");
// Disable for testing
// auto whitelisted = whitelist.find(account.value);
// eosio_assert(whitelisted != whitelist.end(), "Account is not whitelisted");
auto verification = verifications.find(account.value);
eosio_assert(verification == verifications.end(), "Account already verified");
verifications.emplace(rampayer, [&](verify_info &v){
v.claimer = account;
v.added = time_point_sec(now());
v.new_key = newpubkey;
v.proposed = 0;
});
}
void lostcontract::reset(name claimer){
require_auth(_self);
verifications_table verifications(_self, _self.value);
auto verification = verifications.find(claimer.value);
eosio_assert(verification != verifications.end(), "Account not verified");
verifications.modify(verification, same_payer, [&](verify_info &v){
v.proposed = 0;
});
}
void lostcontract::clear(){
require_auth(_self);
verifications_table verifications(_self, _self.value);
auto itr = verifications.begin();
while (itr != verifications.end()){
itr = verifications.erase(itr);
}
}
EOSIO_DISPATCH( lostcontract,
(add)(propose)(verify)(reset)(clear)
)