Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
whitelisted_intrinsics.cpp
Go to the documentation of this file.
3
4namespace sysio { namespace chain {
5
6 template<typename Iterator>
7 bool find_intrinsic_helper( uint64_t h, std::string_view name, Iterator& itr, const Iterator& end ) {
8 for( ; itr != end && itr->first == h; ++itr ) {
9 if( itr->second.compare( 0, itr->second.size(), name.data(), name.size() ) == 0 ) {
10 return true;
11 }
12 }
13
14 return false;
15 }
16
17 whitelisted_intrinsics_type::iterator
18 find_intrinsic( whitelisted_intrinsics_type& whitelisted_intrinsics, uint64_t h, std::string_view name )
19 {
20 auto itr = whitelisted_intrinsics.lower_bound( h );
21 const auto end = whitelisted_intrinsics.end();
22
23 if( !find_intrinsic_helper( h, name, itr, end ) )
24 return end;
25
26 return itr;
27 }
28
29 whitelisted_intrinsics_type::const_iterator
30 find_intrinsic( const whitelisted_intrinsics_type& whitelisted_intrinsics, uint64_t h, std::string_view name )
31 {
32 auto itr = whitelisted_intrinsics.lower_bound( h );
33 const auto end = whitelisted_intrinsics.end();
34
35 if( !find_intrinsic_helper( h, name, itr, end ) )
36 return end;
37
38 return itr;
39 }
40
41 bool is_intrinsic_whitelisted( const whitelisted_intrinsics_type& whitelisted_intrinsics, std::string_view name )
42 {
43 uint64_t h = static_cast<uint64_t>( std::hash<std::string_view>{}( name ) );
44 auto itr = whitelisted_intrinsics.lower_bound( h );
45 const auto end = whitelisted_intrinsics.end();
46
47 return find_intrinsic_helper( h, name, itr, end );
48 }
49
50
51 void add_intrinsic_to_whitelist( whitelisted_intrinsics_type& whitelisted_intrinsics, std::string_view name )
52 {
53 uint64_t h = static_cast<uint64_t>( std::hash<std::string_view>{}( name ) );
54 auto itr = find_intrinsic( whitelisted_intrinsics, h, name );
55 SYS_ASSERT( itr == whitelisted_intrinsics.end(), database_exception,
56 "cannot add intrinsic '${name}' since it already exists in the whitelist",
57 ("name", std::string(name))
58 );
59
60 whitelisted_intrinsics.emplace( std::piecewise_construct,
61 std::forward_as_tuple( h ),
62 std::forward_as_tuple( name.data(), name.size(),
63 whitelisted_intrinsics.get_allocator() )
64 );
65 }
66
67 void remove_intrinsic_from_whitelist( whitelisted_intrinsics_type& whitelisted_intrinsics, std::string_view name )
68 {
69 uint64_t h = static_cast<uint64_t>( std::hash<std::string_view>{}( name ) );
70 auto itr = find_intrinsic( whitelisted_intrinsics, h, name );
71 SYS_ASSERT( itr != whitelisted_intrinsics.end(), database_exception,
72 "cannot remove intrinsic '${name}' since it does not exist in the whitelist",
73 ("name", std::string(name))
74 );
75
76 whitelisted_intrinsics.erase( itr );
77 }
78
80 const std::set<std::string>& s )
81 {
82 whitelisted_intrinsics.clear();
83
84 for( const auto& name : s ) {
85 uint64_t h = static_cast<uint64_t>( std::hash<std::string_view>{}( name ) );
86 whitelisted_intrinsics.emplace( std::piecewise_construct,
87 std::forward_as_tuple( h ),
88 std::forward_as_tuple( name.data(), name.size(),
89 whitelisted_intrinsics.get_allocator() )
90 );
91 }
92 }
93
94 std::set<std::string> convert_intrinsic_whitelist_to_set( const whitelisted_intrinsics_type& whitelisted_intrinsics ) {
95 std::set<std::string> s;
96
97 for( const auto& p : whitelisted_intrinsics ) {
98 s.emplace( p.second.data(), p.second.size() );
99 }
100
101 return s;
102 }
103
104} }
const mie::Vuint & p
Definition bn.cpp:27
std::string name
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
void add_intrinsic_to_whitelist(whitelisted_intrinsics_type &whitelisted_intrinsics, std::string_view name)
key Invalid authority Invalid transaction Invalid block ID Invalid packed transaction Invalid chain ID Invalid symbol Signature type is not a currently activated type Block can not be found Unlinkable block Block does not guarantee concurrent execution without conflicts Block exhausted allowed resources Block is from the future Block is not signed by expected producer Block includes an ill formed protocol feature activation extension Block includes an ill formed additional block signature extension Error decompressing transaction Transaction should have at least one required authority Expired Transaction Invalid Reference Block Duplicate deferred transaction The transaction can not be found Transaction is too big Invalid transaction extension Transaction includes disallowed Transaction exceeded transient resource limit Account name already exists sysio_assert_message assertion failure Action can not be found Attempt to use unaccessible API Inline Action exceeds maximum size limit sysio_assert_code assertion failure uses restricted error code value action return value size too big database_exception
whitelisted_intrinsics_type::iterator find_intrinsic(whitelisted_intrinsics_type &whitelisted_intrinsics, uint64_t h, std::string_view name)
void reset_intrinsic_whitelist(whitelisted_intrinsics_type &whitelisted_intrinsics, const std::set< std::string > &s)
bool find_intrinsic_helper(uint64_t h, std::string_view name, Iterator &itr, const Iterator &end)
void remove_intrinsic_from_whitelist(whitelisted_intrinsics_type &whitelisted_intrinsics, std::string_view name)
bool is_intrinsic_whitelisted(const whitelisted_intrinsics_type &whitelisted_intrinsics, std::string_view name)
std::set< std::string > convert_intrinsic_whitelist_to_set(const whitelisted_intrinsics_type &whitelisted_intrinsics)
shared_flat_multimap< uint64_t, shared_string > whitelisted_intrinsics_type
unsigned __int64 uint64_t
Definition stdint.h:136
size_t size() const
Definition zm.h:519
Immutable except for fc::from_variant.
Definition name.hpp:43
char * s