-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwipeout.cpp
186 lines (140 loc) · 4.65 KB
/
wipeout.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
/*
Copyright 2019 cc32d9@gmail.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <eosio/eosio.hpp>
#include <eosio/multi_index.hpp>
using namespace eosio;
using std::string;
CONTRACT wipeout : public eosio::contract {
public:
wipeout( name self, name code, datastream<const char*> ds ):
contract(self, code, ds)
{}
ACTION wipeaux(uint32_t count)
{
require_auth(_self);
uint32_t orig_count = count;
{
apitypes _apitypes(_self, _self.value);
auto itr = _apitypes.begin();
while(itr != _apitypes.end() && count > 0) {
itr = _apitypes.erase(itr);
--count;
}
}
{
providers _providers(_self, _self.value);
auto itr = _providers.begin();
while(itr != _providers.end() && count > 0) {
itr = _providers.erase(itr);
--count;
}
}
{
props _props(_self, _self.value);
auto itr = _props.begin();
while(itr != _props.end() && count > 0) {
itr = _props.erase(itr);
--count;
}
}
check(orig_count > count, "Nothing to wipe");
}
ACTION wipeentries(uint32_t count)
{
require_auth(_self);
uint32_t orig_count = count;
networks _networks(_self, _self.value);
auto netitr = _networks.begin();
while(netitr != _networks.end() && count > 0) {
records _records(_self, netitr->netname.value);
auto recitr = _records.begin();
while( recitr != _records.end() && count > 0) {
recitr = _records.erase(recitr);
--count;
}
if( recitr == _records.end() ) {
netitr = _networks.erase(netitr);
}
}
check(orig_count > count, "Nothing to wipe");
}
private:
struct [[eosio::table("networks")]] network {
name netname;
checksum256 chainid;
string description;
string url;
auto primary_key()const { return netname.value; }
};
typedef eosio::multi_index<name("networks"), network> networks;
struct [[eosio::table("apitypes")]] apitype {
name type;
string description;
string url;
auto primary_key()const { return type.value; }
};
typedef eosio::multi_index<name("apitypes"), apitype> apitypes;
struct [[eosio::table("providers")]] provider {
name provider;
bool approved;
string url;
string email;
string im;
auto primary_key()const { return provider.value; }
};
typedef eosio::multi_index<name("providers"), provider> providers;
struct [[eosio::table("auditors")]] auditor {
name auditor;
string contact_name;
string pgp_key_fingerprint;
string pgp_key_server;
string email;
string im;
auto primary_key()const { return auditor.value; }
};
typedef eosio::multi_index<name("auditors"), auditor> auditors;
inline static uint128_t recidx(name type, name provider) {
return (((uint128_t)type.value)<<64) | provider.value;
}
// network name is the scope
struct [[eosio::table("records")]] record {
uint64_t id;
name type;
name provider;
name srvname;
string url;
string continent;
string country;
uint32_t flags;
uint32_t revision;
time_point_sec updated_on;
name audited_by;
time_point_sec audited_on;
string audit_ipfs_file;
auto primary_key()const { return id; }
uint64_t get_type() const { return type.value; }
uint128_t get_recidx() const { return recidx(type, provider); }
};
typedef eosio::multi_index<name("records"), record,
indexed_by<name("type"), const_mem_fun<record, uint64_t, &record::get_type>>,
indexed_by<name("recidx"), const_mem_fun<record, uint128_t, &record::get_recidx>>
> records;
struct [[eosio::table("props")]] prop {
name property;
uint64_t val_uint;
string val_str;
name val_name;
auto primary_key()const { return property.value; }
};
typedef eosio::multi_index<name("props"), prop> props;
};