Scorum
sign_state.cpp
Go to the documentation of this file.
1 
3 
4 namespace scorum {
5 namespace protocol {
6 
8 {
9  auto itr = provided_signatures.find(k);
10  if (itr == provided_signatures.end())
11  {
12  auto pk = available_keys.find(k);
13  if (pk != available_keys.end())
14  return provided_signatures[k] = true;
15  return false;
16  }
17  return itr->second = true;
18 }
19 
20 bool sign_state::check_authority(const std::string& id)
21 {
22  if (approved_by.find(id) != approved_by.end())
23  return true;
24  return check_authority(get_active(id));
25 }
26 
27 bool sign_state::check_authority(const authority& auth, uint32_t depth)
28 {
29  uint32_t total_weight = 0;
30  for (const auto& k : auth.key_auths)
31  {
32  if (signed_by(k.first))
33  {
34  total_weight += k.second;
35  if (total_weight >= auth.weight_threshold)
36  return true;
37  }
38  }
39 
40  for (const auto& a : auth.account_auths)
41  {
42  if (approved_by.find(a.first) == approved_by.end())
43  {
44  if (depth == max_recursion)
45  continue;
46  if (check_authority(get_active(a.first), depth + 1))
47  {
48  approved_by.insert(a.first);
49  total_weight += a.second;
50  if (total_weight >= auth.weight_threshold)
51  return true;
52  }
53  }
54  else
55  {
56  total_weight += a.second;
57  if (total_weight >= auth.weight_threshold)
58  return true;
59  }
60  }
61  return total_weight >= auth.weight_threshold;
62 }
63 
65 {
66  std::vector<public_key_type> remove_sigs;
67  for (const auto& sig : provided_signatures)
68  if (!sig.second)
69  remove_sigs.push_back(sig.first);
70 
71  for (auto& sig : remove_sigs)
72  provided_signatures.erase(sig);
73 
74  return remove_sigs.size() != 0;
75 }
76 
77 sign_state::sign_state(const flat_set<public_key_type>& sigs,
78  const authority_getter& a,
79  const flat_set<public_key_type>& keys)
80  : get_active(a)
81  , available_keys(keys)
82 {
83  for (const auto& key : sigs)
84  provided_signatures[key] = false;
85  approved_by.insert("temp");
86 }
87 }
88 } // scorum::protocol
std::function< authority(const std::string &)> authority_getter
Definition: sign_state.hpp:9
Definition: asset.cpp:15
account_authority_map account_auths
Definition: authority.hpp:55
key_authority_map key_auths
Definition: authority.hpp:56
bool check_authority(const std::string &id)
Definition: sign_state.cpp:20
flat_set< std::string > approved_by
Definition: sign_state.hpp:33
const authority_getter & get_active
Definition: sign_state.hpp:29
sign_state(const flat_set< public_key_type > &sigs, const authority_getter &a, const flat_set< public_key_type > &keys)
Definition: sign_state.cpp:77
const flat_set< public_key_type > & available_keys
Definition: sign_state.hpp:30
flat_map< public_key_type, bool > provided_signatures
Definition: sign_state.hpp:32
bool signed_by(const public_key_type &k)
Definition: sign_state.cpp:7