10namespace sysio {
namespace chain {
19 struct abi_from_variant;
20 struct abi_to_variant;
22 struct abi_traverse_context;
23 struct abi_traverse_context_with_path;
24 struct binary_to_variant_context;
25 struct variant_to_binary_context;
39 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
42 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
46 std::string_view
resolve_type(
const std::string_view& t)
const;
47 bool is_array(
const std::string_view& type)
const;
48 bool is_optional(
const std::string_view& type)
const;
50 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
53 bool is_integer(
const std::string_view& type)
const;
55 bool is_struct(
const std::string_view& type)
const;
69 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
72 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
75 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
78 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
82 template<
typename T,
typename Resolver>
84 template<
typename T,
typename Resolver>
85 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
88 template<
typename T,
typename Resolver>
91 template<
typename T,
typename Resolver>
93 template<
typename T,
typename Resolver>
94 [[deprecated(
"use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]]
97 template<
typename Vec>
100 return abi_vec.size() <= 4;
103 template<
typename Vec>
128 deadline += max_serialization_time;
130 return [max_serialization_time, deadline](
size_t recursion_depth) {
135 "serialization time limit ${t}us exceeded", (
"t", max_serialization_time) );
141 map<type_name, type_name, std::less<>> typedefs;
142 map<type_name, struct_def, std::less<>> structs;
143 map<name,type_name> actions;
144 map<name,type_name> tables;
145 map<uint64_t, string> error_messages;
146 map<type_name, variant_def, std::less<>>
variants;
147 map<name,type_name> action_results;
149 map<type_name, pair<unpack_function, pack_function>, std::less<>> built_in_types;
150 void configure_built_in_types();
158 void _variant_to_binary(
const std::string_view& type,
const fc::variant& var,
161 static std::string_view _remove_bin_extension(
const std::string_view& type);
172 const static size_t hex_log_max_size = 64;
206 using path_root = std::variant<empty_path_root, array_type_path_root, struct_type_path_root, variant_type_path_root>;
225 using path_item = std::variant<empty_path_item, array_index_path_item, field_path_item, variant_path_item>;
277 string limit_size(
const std::string_view& str );
285 return std::is_base_of<transaction, T>::value ||
286 std::is_same<T, packed_transaction>::value ||
287 std::is_same<T, transaction_trace>::value ||
288 std::is_same<T, transaction_receipt>::value ||
289 std::is_same<T, action_trace>::value ||
290 std::is_same<T, signed_transaction>::value ||
291 std::is_same<T, signed_block>::value ||
292 std::is_same<T, action>::value;
310 template<
template<
typename ...>
class Container,
typename T,
typename ...Args >
336 template<
typename M,
typename Resolver, not_require_abi_t<M> = 1>
347 template<
typename M,
typename Resolver, require_abi_t<M> = 1>
354 template<
typename M,
typename Resolver, require_abi_t<M> = 1>
359 array.reserve(v.size());
361 for (
const auto& iter: v) {
363 add(elem_mvo,
"_", iter, resolver, ctx);
364 array.emplace_back(std::move(elem_mvo[
"_"]));
373 template<
typename M,
typename Resolver, require_abi_t<M> = 1>
379 add(obj_mvo,
"_", *v, resolver, ctx);
380 mvo(
name, std::move(obj_mvo[
"_"]));
383 template<
typename Resolver>
400 template<
typename Resolver,
typename... Args>
406 std::visit(adder, v);
407 mvo(
name, std::move(obj_mvo[
"_"]));
410 template<
typename Resolver>
416 if( act.
account == config::system_account_name && act.
name ==
"setcode"_n ) {
418 if( setcode_act.code.size() > 0 ) {
420 mvo(
"code_hash", code_hash);
439 template<
typename Resolver>
446 mvo(
"name", act.
name);
450 out(
name, std::move(mvo));
459 sub_obj(
"size", data.size() );
460 if( data.size() > impl::hex_log_max_size ) {
461 sub_obj(
"trimmed_hex", std::vector<char>(&data[0], &data[0] + impl::hex_log_max_size) );
463 sub_obj(
"hex", data );
465 mvo(
name, std::move(sub_obj));
470 auto abi = resolver(act.
account);
472 auto type = abi->get_action_type(act.
name);
477 mvo(
"data", abi->_binary_to_variant( type, act.
data, _ctx ));
478 set_hex_data(mvo,
"hex_data", act.
data);
481 set_hex_data(mvo,
"data", act.
data);
484 set_hex_data(mvo,
"data", act.
data);
487 set_hex_data(mvo,
"data", act.
data);
490 set_hex_data(mvo,
"data", act.
data);
492 out(
name, std::move(mvo));
504 template<
typename Resolver>
514 mvo(
"receipt", act_trace.
receipt);
515 mvo(
"receiver", act_trace.
receiver);
516 add(mvo,
"act", act_trace.
act, resolver, ctx);
518 mvo(
"elapsed", act_trace.
elapsed);
519 mvo(
"console", act_trace.
console);
520 mvo(
"trx_id", act_trace.
trx_id);
525 mvo(
"except", act_trace.
except);
529 auto act = act_trace.
act;
531 auto abi = resolver(act.account);
533 auto type = abi->get_action_result_type(act.name);
537 mvo(
"return_value_data", abi->_binary_to_variant( type, act_trace.
return_value, _ctx ));
541 out(
name, std::move(mvo));
553 template<
typename Resolver>
567 add(mvo,
"transaction", trx, resolver, ctx);
569 out(
name, std::move(mvo));
577 template<
typename Resolver>
590 add(mvo,
"actions", trx.
actions, resolver, ctx);
596 mvo(
"deferred_transaction_generation", deferred_transaction_generation);
599 out(
name, std::move(mvo));
608 template<
typename Resolver>
614 mvo(
"timestamp", block.timestamp);
615 mvo(
"producer", block.producer);
616 mvo(
"confirmed", block.confirmed);
617 mvo(
"previous", block.previous);
618 mvo(
"transaction_mroot", block.transaction_mroot);
619 mvo(
"action_mroot", block.action_mroot);
620 mvo(
"schedule_version", block.schedule_version);
621 mvo(
"new_producers", block.new_producers);
624 flat_multimap<uint16_t, block_header_extension> header_exts = block.validate_and_extract_header_extensions();
626 const auto& new_protocol_features =
629 pf_array.reserve(new_protocol_features.size());
630 for (
auto feature : new_protocol_features) {
632 add(feature_mvo,
"feature_digest", feature, resolver, ctx);
633 pf_array.push_back(feature_mvo);
635 mvo(
"new_protocol_features", pf_array);
638 const auto& new_producer_schedule =
640 mvo(
"new_producer_schedule", new_producer_schedule);
643 mvo(
"producer_signature", block.producer_signature);
644 add(mvo,
"transactions", block.transactions, resolver, ctx);
647 auto block_exts = block.validate_and_extract_extensions();
649 const auto& additional_signatures =
651 mvo(
"additional_signatures", additional_signatures);
654 out(
name, std::move(mvo));
665 template<
typename T,
typename Resolver>
672 ,_resolver(_resolver)
683 template<
typename Member,
class Class, Member (Class::*member) >
701 template<
typename M,
typename Resolver, not_require_abi_t<M> = 1>
712 template<
typename M,
typename Resolver, require_abi_t<M> = 1>
719 template<
typename M,
typename Resolver, require_abi_t<M> = 1>
728 extract(*itr, o_iter, resolver, ctx);
729 o.emplace_back(std::move(o_iter));
737 template<
typename M,
typename Resolver, require_abi_t<M> = 1>
743 extract(vo, obj, resolver, ctx);
744 o = std::make_shared<M>(obj);
752 template<
typename Resolver>
757 SYS_ASSERT(vo.
contains(
"account"), packed_transaction_type_exception,
"Missing account");
766 bool valid_empty_data =
false;
768 const auto& data = vo[
"data"];
769 if( data.is_string() ) {
771 valid_empty_data = act.
data.empty();
772 }
else if ( data.is_object() ) {
773 auto abi = resolver(act.
account);
775 auto type = abi->get_action_type(act.
name);
779 act.
data = std::move( abi->_variant_to_binary( type, data, _ctx ));
780 valid_empty_data = act.
data.empty();
786 if( !valid_empty_data && act.
data.empty() ) {
788 const auto& data = vo[
"hex_data"];
789 if( data.is_string() ) {
795 SYS_ASSERT(valid_empty_data || !act.
data.empty(), packed_transaction_type_exception,
796 "Failed to deserialize data for ${account}:${name}", (
"account", act.
account)(
"name", act.
name));
799 template<
typename Resolver>
804 SYS_ASSERT(vo.
contains(
"signatures"), packed_transaction_type_exception,
"Missing signatures");
805 SYS_ASSERT(vo.
contains(
"compression"), packed_transaction_type_exception,
"Missing compression");
806 std::vector<signature_type> signatures;
812 std::vector<bytes> cfd;
813 bool use_packed_cfd =
false;
814 if( vo.
contains(
"packed_context_free_data") && vo[
"packed_context_free_data"].is_string() && !vo[
"packed_context_free_data"].as_string().empty() ) {
815 from_variant(vo[
"packed_context_free_data"], packed_cfd );
816 use_packed_cfd =
true;
817 }
else if( vo.
contains(
"context_free_data") ) {
821 if( vo.
contains(
"packed_trx") && vo[
"packed_trx"].is_string() && !vo[
"packed_trx"].as_string().empty() ) {
824 if( use_packed_cfd ) {
825 ptrx =
packed_transaction( std::move( packed_trx ), std::move( signatures ), std::move( packed_cfd ), compression );
827 ptrx =
packed_transaction( std::move( packed_trx ), std::move( signatures ), std::move( cfd ), compression );
830 SYS_ASSERT(vo.
contains(
"transaction"), packed_transaction_type_exception,
"Missing transaction");
831 if( use_packed_cfd ) {
833 extract( vo[
"transaction"], trx, resolver, ctx );
834 ptrx =
packed_transaction( std::move(trx), std::move(signatures), std::move(packed_cfd), compression );
837 extract( vo[
"transaction"], trx, resolver, ctx );
853 template<
typename T,
typename Resolver>
860 ,_resolver(_resolver)
871 template<
typename Member,
class Class, Member (Class::*member)>
875 if( itr != _vo.
end() )
885 template<
typename M,
typename Resolver, require_abi_t<M>>
891 mvo(
name, std::move(member_mvo));
894 template<
typename M,
typename Resolver, require_abi_t<M>>
897 auto h = ctx.enter_scope();
903template<
typename T,
typename Resolver>
908 vo = std::move(mvo[
"_"]);
913 to_variant( o, vo, resolver, create_yield_function(max_serialization_time) );
916template<
typename T,
typename Resolver>
922 vo = std::move(mvo[
"_"]);
932template<
typename T,
typename Resolver>
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
static constexpr microseconds maximum()
An order-preserving dictionary of variants.
static sha256 hash(const char *d, uint32_t dlen)
static constexpr time_point maximum()
An order-preserving dictionary of variants.
iterator find(const string &key) const
bool contains(const char *key) const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
variant_object & get_object()
abi_from_variant_visitor(const variant_object &_vo, T &v, Resolver _resolver, abi_traverse_context &_ctx)
void operator()(const char *name) const
void operator()(const char *name) const
abi_to_variant_visitor(mutable_variant_object &_mvo, const T &_val, Resolver _resolver, abi_traverse_context &_ctx)
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
void unpack(Stream &s, std::deque< T > &value)
std::vector< fc::variant > variants
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
std::variant< empty_path_root, array_type_path_root, struct_type_path_root, variant_type_path_root > path_root
constexpr bool type_requires_abi_v()
std::enable_if_t<!type_requires_abi_v< T >(), int > not_require_abi_t
std::enable_if_t< type_requires_abi_v< T >(), int > require_abi_t
string limit_size(const std::string_view &str)
limits the string size to default max_length of output_name
std::variant< empty_path_item, array_index_path_item, field_path_item, variant_path_item > path_item
constexpr bool single_type_requires_abi_v()
#define T(meth, val, expected)
unsigned __int64 uint64_t
defines visit functions for T Unless this is specialized, visit() will not be defined for T.
static constexpr size_t max_recursion_depth
type_name get_action_result_type(name action_result) const
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
void set_abi(const abi_def &abi, const yield_function_t &yield)
type_name get_table_type(name action) const
static void to_log_variant(const T &o, fc::variant &vo, Resolver resolver, const yield_function_t &yield)
const struct_def & get_struct(const std::string_view &type) const
static bool to_abi(const Vec &abi_vec, abi_def &abi)
int get_integer_size(const std::string_view &type) const
bytes variant_to_binary(const std::string_view &type, const fc::variant &var, const fc::microseconds &max_serialization_time, bool short_path=false) const
std::string_view fundamental_type(const std::string_view &type) const
type_name get_action_type(name action) const
static void to_variant(const T &o, fc::variant &vo, Resolver resolver, const yield_function_t &yield)
namespace sysio::chain::impl
std::optional< string > get_error_message(uint64_t error_code) const
bool is_integer(const std::string_view &type) const
static bool is_empty_abi(const Vec &abi_vec)
std::function< void(const fc::variant &, fc::datastream< char * > &, bool, bool, const abi_serializer::yield_function_t &)> pack_function
void add_specialized_unpack_pack(const string &name, std::pair< abi_serializer::unpack_function, abi_serializer::pack_function > unpack_pack)
std::function< fc::variant(fc::datastream< const char * > &, bool, bool, const abi_serializer::yield_function_t &)> unpack_function
fc::variant binary_to_variant(const std::string_view &type, const bytes &binary, const yield_function_t &yield, bool short_path=false) const
bool is_optional(const std::string_view &type) const
bool is_struct(const std::string_view &type) const
bool is_builtin_type(const std::string_view &type) const
bool is_type(const std::string_view &type, const yield_function_t &yield) const
std::string_view resolve_type(const std::string_view &t) const
static void from_variant(const fc::variant &v, T &o, Resolver resolver, const yield_function_t &yield)
bool is_array(const std::string_view &type) const
vector< permission_level > authorization
std::optional< block_id_type > producer_block_id
block_timestamp_type block_time
fc::unsigned_int creator_action_ordinal
std::optional< fc::exception > except
fc::unsigned_int closest_unnotified_ancestor_action_ordinal
flat_set< account_delta > account_ram_deltas
fc::unsigned_int action_ordinal
transaction_id_type trx_id
the transaction that generated this action
std::vector< char > return_value
std::optional< action_receipt > receipt
std::optional< uint64_t > error_code
static constexpr uint16_t extension_id()
static constexpr uint16_t extension_id()
static void extract(const fc::variant &v, vector< M > &o, Resolver resolver, abi_traverse_context &ctx)
static void extract(const fc::variant &v, packed_transaction &ptrx, Resolver resolver, abi_traverse_context &ctx)
static void extract(const fc::variant &v, M &o, Resolver, abi_traverse_context &ctx)
static void extract(const fc::variant &v, std::shared_ptr< M > &o, Resolver resolver, abi_traverse_context &ctx)
static void extract(const fc::variant &v, M &o, Resolver resolver, abi_traverse_context &ctx)
static void extract(const fc::variant &v, action &act, Resolver resolver, abi_traverse_context &ctx)
void operator()(T &v) const
mutable_variant_object & obj_mvo
abi_traverse_context & ctx
add_static_variant(mutable_variant_object &o, Resolver &r, abi_traverse_context &ctx)
static void add(mutable_variant_object &out, const char *name, const packed_transaction &ptrx, Resolver resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &mvo, const char *name, const M &v, Resolver resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &mvo, const char *name, const std::shared_ptr< M > &v, Resolver resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &out, const char *name, const action_trace &act_trace, Resolver resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &out, const char *name, const transaction &trx, Resolver resolver, abi_traverse_context &ctx)
static bool add_special_logging(mutable_variant_object &mvo, const char *name, const action &act, Resolver &resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &mvo, const char *name, const std::variant< Args... > &v, Resolver resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &mvo, const char *name, const vector< M > &v, Resolver resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &mvo, const char *name, const M &v, Resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &out, const char *name, const signed_block &block, Resolver resolver, abi_traverse_context &ctx)
static void add(mutable_variant_object &out, const char *name, const action &act, Resolver resolver, abi_traverse_context &ctx)
void set_array_index_of_path_back(uint32_t i)
abi_traverse_context_with_path(const abi_serializer &abis, abi_serializer::yield_function_t yield, const std::string_view &type)
fc::scoped_exit< std::function< void()> > push_to_path(const path_item &item)
string get_path_string() const
const abi_serializer & abis
void hint_array_type_if_in_array()
void set_path_root(const std::string_view &type)
void hint_variant_type_if_in_array(const map< type_name, variant_def >::const_iterator &itr)
string maybe_shorten(const std::string_view &str)
void hint_struct_type_if_in_array(const map< type_name, struct_def >::const_iterator &itr)
abi_traverse_context_with_path(const abi_serializer &abis, const abi_traverse_context &ctx, const std::string_view &type)
abi_traverse_context(abi_serializer::yield_function_t yield)
abi_serializer::yield_function_t yield
void check_deadline() const
abi_serializer::yield_function_t get_yield_function()
fc::scoped_exit< std::function< void()> > enter_scope()
map< type_name, struct_def >::const_iterator parent_struct_itr
map< type_name, struct_def >::const_iterator struct_itr
static constexpr bool value()
static constexpr bool value()
map< type_name, variant_def >::const_iterator variant_itr
fc::scoped_exit< std::function< void()> > disallow_extensions_unless(bool condition)
bool extensions_allowed() const
map< type_name, variant_def >::const_iterator variant_itr
Immutable except for fc::from_variant.
const bytes & get_packed_context_free_data() const
const vector< signature_type > & get_signatures() const
const fc::enum_type< uint8_t, compression_type > & get_compression() const
const vector< bytes > & get_context_free_data() const
const transaction & get_transaction() const
const bytes & get_packed_transaction() const
static constexpr uint16_t extension_id()
static constexpr uint16_t extension_id()
vector< bytes > context_free_data
for each context-free action, there is an entry here
vector< signature_type > signatures
vector< action > context_free_actions
flat_multimap< uint16_t, transaction_extension > validate_and_extract_extensions() const
yubihsm_pkcs11_object_template template