-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsign_state.cpp
85 lines (74 loc) · 2.11 KB
/
sign_state.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
#include <steemit/protocol/sign_state.hpp>
namespace steemit { namespace protocol {
bool sign_state::signed_by( const public_key_type& k )
{
auto itr = provided_signatures.find(k);
if( itr == provided_signatures.end() )
{
auto pk = available_keys.find(k);
if( pk != available_keys.end() )
return provided_signatures[k] = true;
return false;
}
return itr->second = true;
}
bool sign_state::check_authority( string id )
{
if( approved_by.find(id) != approved_by.end() ) return true;
return check_authority( get_active(id) );
}
bool sign_state::check_authority( const authority& auth, uint32_t depth )
{
uint32_t total_weight = 0;
for( const auto& k : auth.key_auths )
{
if( signed_by( k.first ) )
{
total_weight += k.second;
if( total_weight >= auth.weight_threshold )
return true;
}
}
for( const auto& a : auth.account_auths )
{
if( approved_by.find(a.first) == approved_by.end() )
{
if( depth == max_recursion )
continue;
if( check_authority( get_active( a.first ), depth+1 ) )
{
approved_by.insert( a.first );
total_weight += a.second;
if( total_weight >= auth.weight_threshold )
return true;
}
}
else
{
total_weight += a.second;
if( total_weight >= auth.weight_threshold )
return true;
}
}
return total_weight >= auth.weight_threshold;
}
bool sign_state::remove_unused_signatures()
{
vector<public_key_type> remove_sigs;
for( const auto& sig : provided_signatures )
if( !sig.second ) remove_sigs.push_back( sig.first );
for( auto& sig : remove_sigs )
provided_signatures.erase(sig);
return remove_sigs.size() != 0;
}
sign_state::sign_state(
const flat_set<public_key_type>& sigs,
const authority_getter& a,
const flat_set<public_key_type>& keys
) : get_active(a), available_keys(keys)
{
for( const auto& key : sigs )
provided_signatures[ key ] = false;
approved_by.insert( "temp" );
}
} } // steemit::protocol