Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
limit_auth_changes.cpp
Go to the documentation of this file.
3
4namespace sysiosystem {
5
6 void system_contract::limitauthchg(const name& account, const std::vector<name>& allow_perms,
7 const std::vector<name>& disallow_perms) {
8 limit_auth_change_table table(get_self(), get_self().value);
9 require_auth(account);
10 sysio::check(allow_perms.empty() || disallow_perms.empty(), "either allow_perms or disallow_perms must be empty");
11 sysio::check(allow_perms.empty() ||
12 std::find(allow_perms.begin(), allow_perms.end(), "owner"_n) != allow_perms.end(),
13 "allow_perms does not contain owner");
14 sysio::check(disallow_perms.empty() ||
15 std::find(disallow_perms.begin(), disallow_perms.end(), "owner"_n) == disallow_perms.end(),
16 "disallow_perms contains owner");
17 auto it = table.find(account.value);
18 if(!allow_perms.empty() || !disallow_perms.empty()) {
19 if(it == table.end()) {
20 table.emplace(account, [&](auto& row){
21 row.account = account;
22 row.allow_perms = allow_perms;
23 row.disallow_perms = disallow_perms;
24 });
25 } else {
26 table.modify(it, account, [&](auto& row){
27 row.allow_perms = allow_perms;
28 row.disallow_perms = disallow_perms;
29 });
30 }
31 } else {
32 if(it != table.end())
33 table.erase(it);
34 }
35 }
36
37 void check_auth_change(name contract, name account, const binary_extension<name>& authorized_by) {
38 name by(authorized_by.has_value() ? authorized_by.value().value : 0);
39 if(by.value)
40 sysio::require_auth({account, by});
41 limit_auth_change_table table(contract, contract.value);
42 auto it = table.find(account.value);
43 if(it == table.end())
44 return;
45 sysio::check(by.value, "authorized_by is required for this account");
46 if(!it->allow_perms.empty())
47 sysio::check(
48 std::find(it->allow_perms.begin(), it->allow_perms.end(), by) != it->allow_perms.end(),
49 "authorized_by does not appear in allow_perms");
50 else
51 sysio::check(
52 std::find(it->disallow_perms.begin(), it->disallow_perms.end(), by) == it->disallow_perms.end(),
53 "authorized_by appears in disallow_perms");
54 }
55
56} // namespace sysiosystem
void limitauthchg(const name &account, const std::vector< name > &allow_perms, const std::vector< name > &disallow_perms)
void check_auth_change(name contract, name account, const binary_extension< name > &authorized_by)
sysio::multi_index<"limitauthchg"_n, limit_auth_change > limit_auth_change_table
#define value
Definition pkcs11.h:157
Immutable except for fc::from_variant.
Definition name.hpp:43