Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
abi_data_handler.cpp
Go to the documentation of this file.
3
4namespace sysio::trace_api {
5
7 // currently abis are operator provided so no need to protect against abuse
8 abi_serializer_by_account.emplace(name,
9 std::make_shared<chain::abi_serializer>(abi, chain::abi_serializer::create_yield_function(fc::microseconds::maximum())));
10 }
11
12 std::tuple<fc::variant, std::optional<fc::variant>> abi_data_handler::serialize_to_variant(const std::variant<action_trace_v0, action_trace_v1> & action, const yield_function& yield ) {
13 auto account = std::visit([](auto &&action) -> auto { return action.account; }, action);
14
15 if (abi_serializer_by_account.count(account) > 0) {
16 const auto &serializer_p = abi_serializer_by_account.at(account);
17 auto action_name = std::visit([](auto &&action) -> auto { return action.action; }, action);
18 auto type_name = serializer_p->get_action_type(action_name);
19
20 if (!type_name.empty()) {
21 try {
22 // abi_serializer expects a yield function that takes a recursion depth
23 auto abi_yield = [yield](size_t recursion_depth) {
24 yield();
25 SYS_ASSERT( recursion_depth < chain::abi_serializer::max_recursion_depth, chain::abi_recursion_depth_exception,
26 "exceeded max_recursion_depth ${r} ", ("r", chain::abi_serializer::max_recursion_depth) );
27 };
28 return std::visit([&](auto &&action) -> std::tuple<fc::variant, std::optional<fc::variant>> {
29 using T = std::decay_t<decltype(action)>;
30 std::optional<fc::variant> ret_data;
31 auto params = serializer_p->binary_to_variant(type_name, action.data, abi_yield);
32 if constexpr (std::is_same_v<T, action_trace_v1>) {
33 if(action.return_value.size() > 0) {
34 ret_data = serializer_p->binary_to_variant(type_name, action.return_value, abi_yield);
35 }
36 }
37 return {params, ret_data};
38 }, action);
39 } catch (...) {
40 except_handler(MAKE_EXCEPTION_WITH_CONTEXT(std::current_exception()));
41 }
42 }
43 }
44
45 return {};
46 }
47}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
static constexpr microseconds maximum()
Definition time.hpp:14
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void add_abi(const chain::name &name, const chain::abi_def &abi)
std::tuple< fc::variant, std::optional< fc::variant > > serialize_to_variant(const std::variant< action_trace_v0, action_trace_v1 > &action, const yield_function &yield)
sysio::chain_apis::account_query_db::get_accounts_by_authorizers_params params
string type_name
Definition abi_def.hpp:7
sysio::chain::action_name action_name
#define MAKE_EXCEPTION_WITH_CONTEXT(eptr)
Definition common.hpp:56
#define T(meth, val, expected)
static constexpr size_t max_recursion_depth
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
Immutable except for fc::from_variant.
Definition name.hpp:43