Scorum
shared_authority.cpp
Go to the documentation of this file.
2 
3 namespace scorum {
4 namespace chain {
5 
6 shared_authority::operator authority() const
7 {
9 
10  result.account_auths.reserve(account_auths.size());
11  for (const auto& item : account_auths)
12  result.account_auths.insert(item);
13 
14  result.key_auths.reserve(key_auths.size());
15  for (const auto& item : key_auths)
16  result.key_auths.insert(item);
17 
18  result.weight_threshold = weight_threshold;
19 
20  return result;
21 }
22 
24 {
25  clear();
26 
27  for (const auto& item : a.account_auths)
28  account_auths.insert(item);
29 
30  for (const auto& item : a.key_auths)
31  key_auths.insert(item);
32 
34 
35  return *this;
36 }
37 
39 {
40  key_auths[k] = w;
41 }
42 
44 {
45  account_auths[k] = w;
46 }
47 
48 std::vector<public_key_type> shared_authority::get_keys() const
49 {
50  std::vector<public_key_type> result;
51  result.reserve(key_auths.size());
52  for (const auto& k : key_auths)
53  result.push_back(k.first);
54  return result;
55 }
56 
58 {
59  uint64_t auth_weights = 0;
60  for (const auto& item : account_auths)
61  auth_weights += item.second;
62  for (const auto& item : key_auths)
63  auth_weights += item.second;
64  return auth_weights < weight_threshold;
65 }
66 
68 {
69  return account_auths.size() + key_auths.size();
70 }
71 
73 {
74  account_auths.clear();
75  key_auths.clear();
76 }
77 
79 {
80  for (const auto& item : account_auths)
81  {
82  FC_ASSERT(protocol::is_valid_account_name(item.first));
83  }
84 }
85 
87 {
89  && (a.key_auths == b.key_auths);
90 }
91 
92 bool operator==(const authority& a, const shared_authority& b)
93 {
94  return a == authority(b);
95 }
96 
97 bool operator==(const shared_authority& a, const authority& b)
98 {
99  return authority(a) == b;
100 }
101 }
102 } // scorum::chain
bool operator==(const shared_authority &a, const shared_authority &b)
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
bool is_valid_account_name(const std::string &name)
Definition: authority.cpp:58
uint16_t authority_weight_type
Definition: types.hpp:68
Definition: asset.cpp:15
shared_authority & operator=(const authority &a)
void add_authority(const public_key_type &k, authority_weight_type w)
std::vector< public_key_type > get_keys() const
account_authority_map account_auths
account_authority_map account_auths
Definition: authority.hpp:55
key_authority_map key_auths
Definition: authority.hpp:56