Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain_apis::read_write Class Reference

#include <chain_plugin.hpp>

Classes

struct  push_transaction_results
 
struct  send_transaction2_params
 

Public Types

using push_block_params = chain::signed_block
 
using push_block_results = empty
 
using push_transaction_params = fc::variant_object
 
using push_transactions_params = vector<push_transaction_params>
 
using push_transactions_results = vector<push_transaction_results>
 
using send_transaction_params = push_transaction_params
 
using send_transaction_results = push_transaction_results
 

Public Member Functions

 read_write (controller &db, std::optional< trx_retry_db > &trx_retry, const fc::microseconds &abi_serializer_max_time, bool api_accept_transactions)
 
void validate () const
 
void push_block (push_block_params &&params, chain::plugin_interface::next_function< push_block_results > next)
 
void push_transaction (const push_transaction_params &params, chain::plugin_interface::next_function< push_transaction_results > next)
 
void push_transactions (const push_transactions_params &params, chain::plugin_interface::next_function< push_transactions_results > next)
 
void send_transaction (const send_transaction_params &params, chain::plugin_interface::next_function< send_transaction_results > next)
 
void send_transaction2 (const send_transaction2_params &params, chain::plugin_interface::next_function< send_transaction_results > next)
 

Detailed Description

Definition at line 653 of file chain_plugin.hpp.

Member Typedef Documentation

◆ push_block_params

◆ push_block_results

◆ push_transaction_params

◆ push_transactions_params

◆ push_transactions_results

◆ send_transaction_params

◆ send_transaction_results

Constructor & Destructor Documentation

◆ read_write()

sysio::chain_apis::read_write::read_write ( controller & db,
std::optional< trx_retry_db > & trx_retry,
const fc::microseconds & abi_serializer_max_time,
bool api_accept_transactions )

Definition at line 1312 of file chain_plugin.cpp.

1313: db(db)
1314, trx_retry(trx_retry)
1315, abi_serializer_max_time(abi_serializer_max_time)
1316, api_accept_transactions(api_accept_transactions)
1317{
1318}
const fc::microseconds abi_serializer_max_time
Definition main.cpp:173

Member Function Documentation

◆ push_block()

void sysio::chain_apis::read_write::push_block ( push_block_params && params,
chain::plugin_interface::next_function< push_block_results > next )

Definition at line 2129 of file chain_plugin.cpp.

2129 {
2130 try {
2131 app().get_method<incoming::methods::block_sync>()(std::make_shared<signed_block>( std::move(params) ), std::optional<block_id_type>{}, block_state_ptr{});
2132 } catch ( boost::interprocess::bad_alloc& ) {
2134 } catch ( const std::bad_alloc& ) {
2136 } FC_LOG_AND_DROP()
2138}
auto get_method() -> std::enable_if_t< is_method_decl< MethodDecl >::value, typename MethodDecl::method_type & >
static void handle_db_exhaustion()
static void handle_bad_alloc()
#define FC_LOG_AND_DROP(...)
application & app()
@ read_write
method_decl< chain_plugin_interface, bool(const signed_block_ptr &, const std::optional< block_id_type > &, const block_state_ptr &), first_provider_policy > block_sync
std::shared_ptr< block_state > block_state_ptr
account_query_db::get_accounts_by_authorizers_params params
Here is the call graph for this function:

◆ push_transaction()

void sysio::chain_apis::read_write::push_transaction ( const push_transaction_params & params,
chain::plugin_interface::next_function< push_transaction_results > next )

Definition at line 2140 of file chain_plugin.cpp.

2140 {
2141 try {
2142 auto pretty_input = std::make_shared<packed_transaction>();
2143 auto resolver = make_resolver(db, abi_serializer::create_yield_function( abi_serializer_max_time ));
2144 try {
2145 abi_serializer::from_variant(params, *pretty_input, std::move( resolver ), abi_serializer::create_yield_function( abi_serializer_max_time ));
2146 } SYS_RETHROW_EXCEPTIONS(chain::packed_transaction_type_exception, "Invalid packed transaction")
2147
2148 app().get_method<incoming::methods::transaction_async>()(pretty_input, true, false, false,
2149 [this, next](const std::variant<fc::exception_ptr, transaction_trace_ptr>& result) -> void {
2150 if (std::holds_alternative<fc::exception_ptr>(result)) {
2151 next(std::get<fc::exception_ptr>(result));
2152 } else {
2153 auto trx_trace_ptr = std::get<transaction_trace_ptr>(result);
2154
2155 try {
2156 fc::variant output;
2157 try {
2158 output = db.to_variant_with_abi( *trx_trace_ptr, abi_serializer::create_yield_function( abi_serializer_max_time ) );
2159
2160 // Create map of (closest_unnotified_ancestor_action_ordinal, global_sequence) with action trace
2161 std::map< std::pair<uint32_t, uint64_t>, fc::mutable_variant_object > act_traces_map;
2162 for( const auto& act_trace : output["action_traces"].get_array() ) {
2163 if (act_trace["receipt"].is_null() && act_trace["except"].is_null()) continue;
2164 auto closest_unnotified_ancestor_action_ordinal =
2165 act_trace["closest_unnotified_ancestor_action_ordinal"].as<fc::unsigned_int>().value;
2166 auto global_sequence = act_trace["receipt"].is_null() ?
2167 std::numeric_limits<uint64_t>::max() :
2168 act_trace["receipt"]["global_sequence"].as<uint64_t>();
2169 act_traces_map.emplace( std::make_pair( closest_unnotified_ancestor_action_ordinal,
2170 global_sequence ),
2171 act_trace.get_object() );
2172 }
2173
2174 std::function<vector<fc::variant>(uint32_t)> convert_act_trace_to_tree_struct =
2175 [&](uint32_t closest_unnotified_ancestor_action_ordinal) {
2176 vector<fc::variant> restructured_act_traces;
2177 auto it = act_traces_map.lower_bound(
2178 std::make_pair( closest_unnotified_ancestor_action_ordinal, 0)
2179 );
2180 for( ;
2181 it != act_traces_map.end() && it->first.first == closest_unnotified_ancestor_action_ordinal; ++it )
2182 {
2183 auto& act_trace_mvo = it->second;
2184
2185 auto action_ordinal = act_trace_mvo["action_ordinal"].as<fc::unsigned_int>().value;
2186 act_trace_mvo["inline_traces"] = convert_act_trace_to_tree_struct(action_ordinal);
2187 if (act_trace_mvo["receipt"].is_null()) {
2188 act_trace_mvo["receipt"] = fc::mutable_variant_object()
2189 ("abi_sequence", 0)
2190 ("act_digest", digest_type::hash(trx_trace_ptr->action_traces[action_ordinal-1].act))
2191 ("auth_sequence", flat_map<account_name,uint64_t>())
2192 ("code_sequence", 0)
2193 ("global_sequence", 0)
2194 ("receiver", act_trace_mvo["receiver"])
2195 ("recv_sequence", 0);
2196 }
2197 restructured_act_traces.push_back( std::move(act_trace_mvo) );
2198 }
2199 return restructured_act_traces;
2200 };
2201
2202 fc::mutable_variant_object output_mvo(output);
2203 output_mvo["action_traces"] = convert_act_trace_to_tree_struct(0);
2204
2205 output = output_mvo;
2206 } catch( chain::abi_exception& ) {
2207 output = *trx_trace_ptr;
2208 }
2209
2210 const chain::transaction_id_type& id = trx_trace_ptr->id;
2211 next(read_write::push_transaction_results{id, output});
2212 } CATCH_AND_CALL(next);
2213 }
2214 });
2215 } catch ( boost::interprocess::bad_alloc& ) {
2217 } catch ( const std::bad_alloc& ) {
2219 } CATCH_AND_CALL(next);
2220}
#define SYS_RETHROW_EXCEPTIONS(exception_type, FORMAT,...)
#define CATCH_AND_CALL(NEXT)
An order-preserving dictionary of variants.
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
fc::variant to_variant_with_abi(const T &obj, const abi_serializer::yield_function_t &yield) const
uint64_t id
Definition code_cache.cpp:0
Instance * as(ObjectInstance *object)
namespace sysio::chain
Definition authority.cpp:3
std::shared_ptr< exception > exception_ptr
Definition name.hpp:106
auto make_resolver(const controller &control, abi_serializer::yield_function_t yield)
std::shared_ptr< transaction_trace > transaction_trace_ptr
Definition trace.hpp:20
checksum_type transaction_id_type
Definition types.hpp:236
uint32_t next(octet_iterator &it, octet_iterator end)
Definition checked.h:137
#define value
Definition pkcs11.h:157
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
static void from_variant(const fc::variant &v, T &o, Resolver resolver, const yield_function_t &yield)
Here is the call graph for this function:

◆ push_transactions()

void sysio::chain_apis::read_write::push_transactions ( const push_transactions_params & params,
chain::plugin_interface::next_function< push_transactions_results > next )

Definition at line 2243 of file chain_plugin.cpp.

2243 {
2244 try {
2245 SYS_ASSERT( params.size() <= 1000, too_many_tx_at_once, "Attempt to push too many transactions at once" );
2246 auto params_copy = std::make_shared<read_write::push_transactions_params>(params.begin(), params.end());
2247 auto result = std::make_shared<read_write::push_transactions_results>();
2248 result->reserve(params.size());
2249
2250 push_recurse(this, 0, params_copy, result, next);
2251 } catch ( boost::interprocess::bad_alloc& ) {
2253 } catch ( const std::bad_alloc& ) {
2255 } CATCH_AND_CALL(next);
2256}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
Here is the call graph for this function:

◆ send_transaction()

void sysio::chain_apis::read_write::send_transaction ( const send_transaction_params & params,
chain::plugin_interface::next_function< send_transaction_results > next )

Definition at line 2258 of file chain_plugin.cpp.

2258 {
2259
2260 try {
2261 auto pretty_input = std::make_shared<packed_transaction>();
2262 auto resolver = make_resolver(db, abi_serializer::create_yield_function( abi_serializer_max_time ));
2263 try {
2264 abi_serializer::from_variant(params, *pretty_input, resolver, abi_serializer::create_yield_function( abi_serializer_max_time ));
2265 } SYS_RETHROW_EXCEPTIONS(chain::packed_transaction_type_exception, "Invalid packed transaction")
2266
2267 app().get_method<incoming::methods::transaction_async>()(pretty_input, true, false, false,
2268 [this, next](const std::variant<fc::exception_ptr, transaction_trace_ptr>& result) -> void {
2269 if (std::holds_alternative<fc::exception_ptr>(result)) {
2270 next(std::get<fc::exception_ptr>(result));
2271 } else {
2272 auto trx_trace_ptr = std::get<transaction_trace_ptr>(result);
2273
2274 try {
2275 fc::variant output;
2276 try {
2277 output = db.to_variant_with_abi( *trx_trace_ptr, abi_serializer::create_yield_function( abi_serializer_max_time ) );
2278 } catch( chain::abi_exception& ) {
2279 output = *trx_trace_ptr;
2280 }
2281
2282 const chain::transaction_id_type& id = trx_trace_ptr->id;
2284 } CATCH_AND_CALL(next);
2285 }
2286 });
2287 } catch ( boost::interprocess::bad_alloc& ) {
2289 } catch ( const std::bad_alloc& ) {
2291 } CATCH_AND_CALL(next);
2292}
push_transaction_results send_transaction_results
Here is the call graph for this function:

◆ send_transaction2()

void sysio::chain_apis::read_write::send_transaction2 ( const send_transaction2_params & params,
chain::plugin_interface::next_function< send_transaction_results > next )

Definition at line 2294 of file chain_plugin.cpp.

2294 {
2295 try {
2296 auto ptrx = std::make_shared<packed_transaction>();
2297 auto resolver = make_resolver(db, abi_serializer::create_yield_function( abi_serializer_max_time ));
2298 try {
2299 abi_serializer::from_variant(params.transaction, *ptrx, resolver, abi_serializer::create_yield_function( abi_serializer_max_time ));
2300 } SYS_RETHROW_EXCEPTIONS(chain::packed_transaction_type_exception, "Invalid packed transaction")
2301
2302 bool retry = params.retry_trx;
2303 std::optional<uint16_t> retry_num_blocks = params.retry_trx_num_blocks;
2304
2305 SYS_ASSERT( !retry || trx_retry.has_value(), unsupported_feature, "Transaction retry not enabled on node" );
2306 SYS_ASSERT( !retry || (ptrx->expiration() <= trx_retry->get_max_expiration_time()), tx_exp_too_far_exception,
2307 "retry transaction expiration ${e} larger than allowed ${m}",
2308 ("e", ptrx->expiration())("m", trx_retry->get_max_expiration_time()) );
2309
2310 app().get_method<incoming::methods::transaction_async>()(ptrx, true, false, static_cast<bool>(params.return_failure_trace),
2311 [this, ptrx, next, retry, retry_num_blocks](const std::variant<fc::exception_ptr, transaction_trace_ptr>& result) -> void {
2312 if( std::holds_alternative<fc::exception_ptr>( result ) ) {
2313 next( std::get<fc::exception_ptr>( result ) );
2314 } else {
2315 try {
2316 auto trx_trace_ptr = std::get<transaction_trace_ptr>( result );
2317 if( retry && trx_retry.has_value() && !trx_trace_ptr->except) {
2318 // will be ack'ed via next later
2319 trx_retry->track_transaction( ptrx, retry_num_blocks,
2320 [ptrx, next](const std::variant<fc::exception_ptr, std::unique_ptr<fc::variant>>& result ) {
2321 if( std::holds_alternative<fc::exception_ptr>( result ) ) {
2322 next( std::get<fc::exception_ptr>( result ) );
2323 } else {
2324 fc::variant& output = *std::get<std::unique_ptr<fc::variant>>( result );
2325 next( read_write::send_transaction_results{ptrx->id(), std::move( output )} );
2326 }
2327 } );
2328 } else {
2329 fc::variant output;
2330 try {
2331 output = db.to_variant_with_abi( *trx_trace_ptr, abi_serializer::create_yield_function( abi_serializer_max_time ) );
2332 } catch( chain::abi_exception& ) {
2333 output = *trx_trace_ptr;
2334 }
2335 const chain::transaction_id_type& id = trx_trace_ptr->id;
2336 next( read_write::send_transaction_results{id, std::move( output )} );
2337 }
2338 } CATCH_AND_CALL( next );
2339 }
2340 });
2341 } catch ( boost::interprocess::bad_alloc& ) {
2342 chain_plugin::handle_db_exhaustion();
2343 } catch ( const std::bad_alloc& ) {
2344 chain_plugin::handle_bad_alloc();
2345 } CATCH_AND_CALL(next);
2346}
unsigned short uint16_t
Definition stdint.h:125
Here is the call graph for this function:

◆ validate()

void sysio::chain_apis::read_write::validate ( ) const

Definition at line 1320 of file chain_plugin.cpp.

1320 {
1321 SYS_ASSERT( api_accept_transactions, missing_chain_api_plugin_exception,
1322 "Not allowed, node has api-accept-transactions = false" );
1323}

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