forked from eosnetworkfoundation/eos-system-contracts
/
eosio.bios.hpp
282 lines (250 loc) · 13.7 KB
/
eosio.bios.hpp
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#pragma once
#include <eosio/action.hpp>
#include <eosio/crypto.hpp>
#include <eosio/eosio.hpp>
#include <eosio/fixed_bytes.hpp>
#include <eosio/privileged.hpp>
#include <eosio/producer_schedule.hpp>
namespace eosiobios {
using eosio::action_wrapper;
using eosio::check;
using eosio::checksum256;
using eosio::ignore;
using eosio::name;
using eosio::permission_level;
using eosio::public_key;
struct permission_level_weight {
permission_level permission;
uint16_t weight;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE( permission_level_weight, (permission)(weight) )
};
struct key_weight {
eosio::public_key key;
uint16_t weight;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE( key_weight, (key)(weight) )
};
struct wait_weight {
uint32_t wait_sec;
uint16_t weight;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE( wait_weight, (wait_sec)(weight) )
};
struct authority {
uint32_t threshold = 0;
std::vector<key_weight> keys;
std::vector<permission_level_weight> accounts;
std::vector<wait_weight> waits;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE( authority, (threshold)(keys)(accounts)(waits) )
};
struct block_header {
uint32_t timestamp;
name producer;
uint16_t confirmed = 0;
checksum256 previous;
checksum256 transaction_mroot;
checksum256 action_mroot;
uint32_t schedule_version = 0;
std::optional<eosio::producer_schedule> new_producers;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(block_header, (timestamp)(producer)(confirmed)(previous)(transaction_mroot)(action_mroot)
(schedule_version)(new_producers))
};
/**
* The `eosio.bios` is the first sample of system contract provided by `block.one` through the EOSIO platform. It is a minimalist system contract because it only supplies the actions that are absolutely critical to bootstrap a chain and nothing more. This allows for a chain agnostic approach to bootstrapping a chain.
*
* Just like in the `eosio.system` sample contract implementation, there are a few actions which are not implemented at the contract level (`newaccount`, `updateauth`, `deleteauth`, `linkauth`, `unlinkauth`, `canceldelay`, `onerror`, `setabi`, `setcode`), they are just declared in the contract so they will show in the contract's ABI and users will be able to push those actions to the chain via the account holding the `eosio.system` contract, but the implementation is at the EOSIO core level. They are referred to as EOSIO native actions.
*/
class [[eosio::contract("eosio.bios")]] bios : public eosio::contract {
public:
using contract::contract;
/**
* New account action, called after a new account is created. This code enforces resource-limits rules
* for new accounts as well as new account naming conventions.
*
* 1. accounts cannot contain '.' symbols which forces all acccounts to be 12
* characters long without '.' until a future account auction process is implemented
* which prevents name squatting.
*
* 2. new accounts must stake a minimal number of tokens (as set in system parameters)
* therefore, this method will execute an inline buyram from receiver for newacnt in
* an amount equal to the current new account creation fee.
*/
[[eosio::action]]
void newaccount( name creator,
name name,
ignore<authority> owner,
ignore<authority> active){}
/**
* Update authorization action updates pemission for an account.
*
* @param account - the account for which the permission is updated,
* @param pemission - the permission name which is updated,
* @param parem - the parent of the permission which is updated,
* @param aut - the json describing the permission authorization.
*/
[[eosio::action]]
void updateauth( ignore<name> account,
ignore<name> permission,
ignore<name> parent,
ignore<authority> auth ) {}
/**
* Delete authorization action deletes the authorization for an account's permission.
*
* @param account - the account for which the permission authorization is deleted,
* @param permission - the permission name been deleted.
*/
[[eosio::action]]
void deleteauth( ignore<name> account,
ignore<name> permission ) {}
/**
* Link authorization action assigns a specific action from a contract to a permission you have created. Five system
* actions can not be linked `updateauth`, `deleteauth`, `linkauth`, `unlinkauth`, and `canceldelay`.
* This is useful because when doing authorization checks, the EOSIO based blockchain starts with the
* action needed to be authorized (and the contract belonging to), and looks up which permission
* is needed to pass authorization validation. If a link is set, that permission is used for authoraization
* validation otherwise then active is the default, with the exception of `eosio.any`.
* `eosio.any` is an implicit permission which exists on every account; you can link actions to `eosio.any`
* and that will make it so linked actions are accessible to any permissions defined for the account.
*
* @param account - the permission's owner to be linked and the payer of the RAM needed to store this link,
* @param code - the owner of the action to be linked,
* @param type - the action to be linked,
* @param requirement - the permission to be linked.
*/
[[eosio::action]]
void linkauth( ignore<name> account,
ignore<name> code,
ignore<name> type,
ignore<name> requirement ) {}
/**
* Unlink authorization action it's doing the reverse of linkauth action, by unlinking the given action.
*
* @param account - the owner of the permission to be unlinked and the receiver of the freed RAM,
* @param code - the owner of the action to be unlinked,
* @param type - the action to be unlinked.
*/
[[eosio::action]]
void unlinkauth( ignore<name> account,
ignore<name> code,
ignore<name> type ) {}
/**
* Cancel delay action cancels a deferred transaction.
*
* @param canceling_auth - the permission that authorizes this action,
* @param trx_id - the deferred transaction id to be cancelled.
*/
[[eosio::action]]
void canceldelay( ignore<permission_level> canceling_auth, ignore<checksum256> trx_id ) {}
/**
* Set code action sets the contract code for an account.
*
* @param account - the account for which to set the contract code.
* @param vmtype - reserved, set it to zero.
* @param vmversion - reserved, set it to zero.
* @param code - the code content to be set, in the form of a blob binary..
*/
[[eosio::action]]
void setcode( name account, uint8_t vmtype, uint8_t vmversion, const std::vector<char>& code ) {}
/**
* Set abi action sets the abi for contract identified by `account` name. Creates an entry in the abi_hash_table
* index, with `account` name as key, if it is not already present and sets its value with the abi hash.
* Otherwise it is updating the current abi hash value for the existing `account` key.
*
* @param account - the name of the account to set the abi for
* @param abi - the abi hash represented as a vector of characters
*/
[[eosio::action]]
void setabi( name account, const std::vector<char>& abi );
/**
* On error action, notification of this action is delivered to the sender of a deferred transaction
* when an objective error occurs while executing the deferred transaction.
* This action is not meant to be called directly.
*
* @param sender_id - the id for the deferred transaction chosen by the sender,
* @param sent_trx - the deferred transaction that failed.
*/
[[eosio::action]]
void onerror( ignore<uint128_t> sender_id, ignore<std::vector<char>> sent_trx );
/**
* Set privilege action allows to set privilege status for an account (turn it on/off).
* @param account - the account to set the privileged status for.
* @param is_priv - 0 for false, > 0 for true.
*/
[[eosio::action]]
void setpriv( name account, uint8_t is_priv );
/**
* Sets the resource limits of an account
*
* @param account - name of the account whose resource limit to be set
* @param ram_bytes - ram limit in absolute bytes
* @param net_weight - fractionally proportionate net limit of available resources based on (weight / total_weight_of_all_accounts)
* @param cpu_weight - fractionally proportionate cpu limit of available resources based on (weight / total_weight_of_all_accounts)
*/
[[eosio::action]]
void setalimits( name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight );
/**
* Set producers action, sets a new list of active producers, by proposing a schedule change, once the block that
* contains the proposal becomes irreversible, the schedule is promoted to "pending"
* automatically. Once the block that promotes the schedule is irreversible, the schedule will
* become "active".
*
* @param schedule - New list of active producers to set
*/
[[eosio::action]]
void setprods( const std::vector<eosio::producer_authority>& schedule );
/**
* Set params action, sets the blockchain parameters. By tuning these parameters, various degrees of customization can be achieved.
*
* @param params - New blockchain parameters to set
*/
[[eosio::action]]
void setparams( const eosio::blockchain_parameters& params );
/**
* Require authorization action, checks if the account name `from` passed in as param has authorization to access
* current action, that is, if it is listed in the action’s allowed permissions vector.
*
* @param from - the account name to authorize
*/
[[eosio::action]]
void reqauth( name from );
/**
* Activate action, activates a protocol feature
*
* @param feature_digest - hash of the protocol feature to activate.
*/
[[eosio::action]]
void activate( const eosio::checksum256& feature_digest );
/**
* Require activated action, asserts that a protocol feature has been activated
*
* @param feature_digest - hash of the protocol feature to check for activation.
*/
[[eosio::action]]
void reqactivated( const eosio::checksum256& feature_digest );
struct [[eosio::table]] abi_hash {
name owner;
checksum256 hash;
uint64_t primary_key()const { return owner.value; }
EOSLIB_SERIALIZE( abi_hash, (owner)(hash) )
};
typedef eosio::multi_index< "abihash"_n, abi_hash > abi_hash_table;
using newaccount_action = action_wrapper<"newaccount"_n, &bios::newaccount>;
using updateauth_action = action_wrapper<"updateauth"_n, &bios::updateauth>;
using deleteauth_action = action_wrapper<"deleteauth"_n, &bios::deleteauth>;
using linkauth_action = action_wrapper<"linkauth"_n, &bios::linkauth>;
using unlinkauth_action = action_wrapper<"unlinkauth"_n, &bios::unlinkauth>;
using canceldelay_action = action_wrapper<"canceldelay"_n, &bios::canceldelay>;
using setcode_action = action_wrapper<"setcode"_n, &bios::setcode>;
using setabi_action = action_wrapper<"setabi"_n, &bios::setabi>;
using setpriv_action = action_wrapper<"setpriv"_n, &bios::setpriv>;
using setalimits_action = action_wrapper<"setalimits"_n, &bios::setalimits>;
using setprods_action = action_wrapper<"setprods"_n, &bios::setprods>;
using setparams_action = action_wrapper<"setparams"_n, &bios::setparams>;
using reqauth_action = action_wrapper<"reqauth"_n, &bios::reqauth>;
using activate_action = action_wrapper<"activate"_n, &bios::activate>;
using reqactivated_action = action_wrapper<"reqactivated"_n, &bios::reqactivated>;
};
}