Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::trace_api::abi_data_handler Class Reference

#include <abi_data_handler.hpp>

Classes

class  shared_provider
 

Public Member Functions

 abi_data_handler (exception_handler except_handler)
 
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)
 

Detailed Description

Data Handler that uses sysio::chain::abi_serializer to decode data with a known set of ABI's Can be used directly as a Data_handler_provider OR shared between request_handlers using the ::shared_provider abstraction.

Definition at line 19 of file abi_data_handler.hpp.

Constructor & Destructor Documentation

◆ abi_data_handler()

sysio::trace_api::abi_data_handler::abi_data_handler ( exception_handler except_handler)
inlineexplicit

Definition at line 21 of file abi_data_handler.hpp.

22 :except_handler( std::move( except_handler ) )
23 {
24 }

Member Function Documentation

◆ add_abi()

void sysio::trace_api::abi_data_handler::add_abi ( const chain::name & name,
const chain::abi_def & abi )

Add an ABI definition to this data handler

Parameters
name- the name of the account/contract that this ABI belongs to
abi- the ABI definition of that ABI

Definition at line 6 of file abi_data_handler.cpp.

6 {
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 }
std::string name
static constexpr microseconds maximum()
Definition time.hpp:14
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ serialize_to_variant()

std::tuple< fc::variant, std::optional< fc::variant > > sysio::trace_api::abi_data_handler::serialize_to_variant ( const std::variant< action_trace_v0, action_trace_v1 > & action,
const yield_function & yield )

Given an action trace, produce a tuple representing the data and return_value fields in the trace

Parameters
action- trace of the action including metadata necessary for finding the ABI
yield- a yield function to allow cooperation during long running tasks
Returns
tuple where the first element is a variant representing the data field of the action interpreted by known ABIs OR an empty variant, and the second element represents the return_value field of the trace.

Definition at line 12 of file abi_data_handler.cpp.

12 {
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 }
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
thread_local yield_t yield
Definition yield.hpp:52
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)
action(action_type t, connection_hdl h)
static constexpr size_t max_recursion_depth
account_query_db::get_accounts_by_authorizers_params params
Here is the call graph for this function:

The documentation for this class was generated from the following files: