Skip to main content

libraries/eosiolib/contracts/eosio/transaction.hpp

More...

Namespaces

Name
eosio
eosio::internal_use_do_not_use

Classes

Name
classeosio::transaction_header
Contains details about the transaction.
classeosio::transaction
structeosio::onerror

Detailed Description

Copyright: defined in eos/LICENSE

Source code


#pragma once
#include "action.hpp"
#include "system.hpp"
#include "../../core/eosio/time.hpp"
#include "../../core/eosio/serialize.hpp"

#include <vector>

namespace eosio {
namespace internal_use_do_not_use {
extern "C" {
__attribute__((eosio_wasm_import))
void send_deferred(const uint128_t&, uint64_t, const char*, size_t, uint32_t);

__attribute__((eosio_wasm_import))
int cancel_deferred(const uint128_t&);

__attribute__((eosio_wasm_import))
size_t read_transaction(char*, size_t);

__attribute__((eosio_wasm_import))
size_t transaction_size();

__attribute__((eosio_wasm_import))
int tapos_block_num();

__attribute__((eosio_wasm_import))
int tapos_block_prefix();

__attribute__((eosio_wasm_import))
uint32_t expiration();

__attribute__((eosio_wasm_import))
int get_action( uint32_t, uint32_t, char*, size_t);

__attribute__((eosio_wasm_import))
int get_context_free_data( uint32_t, char*, size_t);
}
}

typedef std::tuple<uint16_t, std::vector<char>> extension;

typedef std::vector<extension> extensions_type;

class transaction_header {
public:

transaction_header( time_point_sec exp = time_point_sec(current_time_point()) + 60)
:expiration(exp)
{}

time_point_sec expiration;
uint16_t ref_block_num;
uint32_t ref_block_prefix;
unsigned_int max_net_usage_words = 0UL;
uint8_t max_cpu_usage_ms = 0UL;
unsigned_int delay_sec = 0UL;

EOSLIB_SERIALIZE( transaction_header, (expiration)(ref_block_num)(ref_block_prefix)(max_net_usage_words)(max_cpu_usage_ms)(delay_sec) )
};

class transaction : public transaction_header {
public:

transaction(time_point_sec exp = time_point_sec(current_time_point()) + 60) : transaction_header( exp ) {}

void send(const uint128_t& sender_id, name payer, bool replace_existing = false) const {
auto serialize = pack(*this);
internal_use_do_not_use::send_deferred(sender_id, payer.value, serialize.data(), serialize.size(), replace_existing);
}

std::vector<action> context_free_actions;
std::vector<action> actions;
extensions_type transaction_extensions;

EOSLIB_SERIALIZE_DERIVED( transaction, transaction_header, (context_free_actions)(actions)(transaction_extensions) )
};

struct onerror {
uint128_t sender_id;
std::vector<char> sent_trx;

static onerror from_current_action() {
return unpack_action_data<onerror>();
}

transaction unpack_sent_trx() const {
return unpack<transaction>(sent_trx);
}

EOSLIB_SERIALIZE( onerror, (sender_id)(sent_trx) )
};

inline void send_deferred(const uint128_t& sender_id, name payer, const char* serialized_transaction, size_t size, bool replace = false) {
internal_use_do_not_use::send_deferred(sender_id, payer.value, serialized_transaction, size, replace);
}
inline action get_action( uint32_t type, uint32_t index ) {
constexpr size_t max_stack_buffer_size = 512;
int s = internal_use_do_not_use::get_action( type, index, nullptr, 0 );
eosio::check( s > 0, "get_action size failed" );
size_t size = static_cast<size_t>(s);
char* buffer = (char*)( max_stack_buffer_size < size ? malloc(size) : alloca(size) );
auto size2 = internal_use_do_not_use::get_action( type, index, buffer, size );
eosio::check( size == static_cast<size_t>(size2), "get_action failed" );
return eosio::unpack<eosio::action>( buffer, size );
}

inline size_t read_transaction(char* ptr, size_t sz) {
return internal_use_do_not_use::read_transaction( ptr, sz );
}

inline int cancel_deferred(const uint128_t& sender_id) {
return internal_use_do_not_use::cancel_deferred(sender_id);
}

inline size_t transaction_size() {
return internal_use_do_not_use::transaction_size();
}

inline int tapos_block_num() {
return internal_use_do_not_use::tapos_block_num();
}

inline int tapos_block_prefix() {
return internal_use_do_not_use::tapos_block_prefix();
}

inline uint32_t expiration() {
return internal_use_do_not_use::expiration();
}

inline int get_context_free_data( uint32_t index, char* buff, size_t size ) {
return internal_use_do_not_use::get_context_free_data(index, buff, size);
}
}

Updated on 2022-12-05 at 15:38:08 +0000