-
Notifications
You must be signed in to change notification settings - Fork 18
/
proxyinfo_migrate.cpp
78 lines (67 loc) · 2.45 KB
/
proxyinfo_migrate.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
#include <eosiolib/eosio.hpp>
/**
* This is a hack to assist with migrating table data to a new schema. The sequence goes like this:
* 1) update proxyinfo and proxyinfo_migrate contracts with proper structs for migration
* 2) set proxyinfo_migrate contract
* 3) push action migratetotmp (moving ram usage from proxies to regproxyinfo account)
* 4) verify data in proxiestmp table
* 5) push action eraseorig
* 6) set proxyinfo contract
* 7) push action migratetmp
* 8) verify data in proxies table
* 9) push action erasetmp
*
*/
class proxyinfo_contract : public eosio::contract {
public:
proxyinfo_contract(account_name self)
:eosio::contract(self),
proxies(_self, _self),
proxiestmp(_self, _self)
{}
void migratetotmp() {
require_auth(_self);
for (const auto & row : proxies) {
eosio::print("Migrating owner=", row.owner, ", name=", row.name, ", website=", row.website, "\n");
proxiestmp.emplace(_self, [&](auto & i) {
i.owner = row.owner;
i.name = row.name;
i.website = row.website;
});
}
}
void erasetmp() {
require_auth(_self);
for(auto itr = proxiestmp.begin(); itr != proxiestmp.end();) {
itr = proxiestmp.erase(itr);
}
}
void eraseorig() {
require_auth(_self);
for(auto itr = proxies.begin(); itr != proxies.end();) {
itr = proxies.erase(itr);
}
}
private:
// @abi table proxies i64
struct proxy {
account_name owner;
std::string name;
std::string website;
auto primary_key()const { return owner; }
EOSLIB_SERIALIZE(proxy, (owner)(name)(website))
};
typedef eosio::multi_index<N(proxies), proxy> proxy_table;
proxy_table proxies;
// @abi table proxiestmp i64
struct proxytmp {
account_name owner;
std::string name;
std::string website;
auto primary_key()const { return owner; }
EOSLIB_SERIALIZE(proxytmp, (owner)(name)(website))
};
typedef eosio::multi_index<N(proxiestmp), proxytmp> proxytmp_table;
proxytmp_table proxiestmp;
};
EOSIO_ABI(proxyinfo_contract, (migratetotmp)(erasetmp)(eraseorig))