Menu

Transaction

Type-safe C++ wrappers for transaction C API. More...

Classes

Type Name
class eosio::transaction_header
Contains details about the transaction.
class eosio::transaction
Contains the actions, context_free_actions and extensions type for a transaction.
struct eosio::onerror
Contains and sender id and packed transaction.

Typedefs

Variables

Functions

Detailed Description

An inline message allows one contract to send another contract a message which is processed immediately after the current message's processing ends such that the success or failure of the parent transaction is dependent on the success of the message. If an inline message fails in processing then the whole tree of transactions and actions rooted in the block will me marked as failing and none of effects on the database will persist. Inline actions and Deferred transactions must adhere to the permissions available to the parent transaction or, in the future, delegated to the contract account for future use.

Note:

There are some methods from the transactioncapi that can be used directly from C++

Typedefs Documentation

typedef extension

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

typedef extensions_type

typedef std::vector< extension > eosio::extensions_type;

Variables Documentation

variable expiration

time_point_sec eosio::transaction_header::expiration;

variable ref_block_num

uint16_t eosio::transaction_header::ref_block_num;

variable ref_block_prefix

uint32_t eosio::transaction_header::ref_block_prefix;

variable max_net_usage_words

unsigned_int eosio::transaction_header::max_net_usage_words;

variable max_cpu_usage_ms

uint8_t eosio::transaction_header::max_cpu_usage_ms;

number of 8 byte words this transaction can serialize into after compressions

variable delay_sec

unsigned_int eosio::transaction_header::delay_sec;

number of CPU usage units to bill transaction for

variable context_free_actions

std::vector< action > eosio::transaction::context_free_actions;

variable actions

std::vector< action > eosio::transaction::actions;

variable transaction_extensions

extensions_type eosio::transaction::transaction_extensions;

variable sender_id

uint128_t eosio::onerror::sender_id;

variable sent_trx

std::vector< char > eosio::onerror::sent_trx;

Functions Documentation

function from_current_action

static static onerror eosio::onerror::from_current_action()

from_current_action unpacks and returns a onerror struct

function send_deferred

void eosio::send_deferred(
    const uint128_t & sender_id,
    name payer,
    const char * serialized_transaction,
    size_t size,
    bool replace = false
)

Send a deferred transaction

Parameters:

  • sender_id - Account name of the sender of this deferred transaction
  • payer - Account name responsible for paying the RAM for this deferred transaction
  • serialized_transaction - The packed transaction to be deferred
  • size - The size of the packed transaction, required for persistence.
  • replace - If true, will replace an existing transaction.

function get_action

action eosio::get_action(
    uint32_t type,
    uint32_t index
)

Retrieve the indicated action from the active transaction.

Parameters:

  • type - 0 for context free action, 1 for action
  • index - the index of the requested action

Returns:

the indicated action

function read_transaction

size_t eosio::read_transaction(
    char * ptr,
    size_t sz
)

Access a copy of the currently executing transaction.

Returns:

the currently executing transaction

function cancel_deferred

int eosio::cancel_deferred(
    const uint128_t & sender_id
)

Cancels a deferred transaction.

Parameters:

  • sender_id - The id of the sender

Precondition:

The deferred transaction ID exists.

Precondition:

The deferred transaction ID has not yet been published.

Post

Deferred transaction canceled.

Returns:

1 if transaction was canceled, 0 if transaction was not found

Example:

id = 0xffffffffffffffff
cancel_deferred( id );

function transaction_size

size_t eosio::transaction_size()

Gets the size of the currently executing transaction.

Returns:

size of the currently executing transaction

function tapos_block_num

int eosio::tapos_block_num()

Gets the block number used for TAPOS on the currently executing transaction.

Returns:

block number used for TAPOS on the currently executing transaction Example:

int tbn = tapos_block_num();

function tapos_block_prefix

int eosio::tapos_block_prefix()

Gets the block prefix used for TAPOS on the currently executing transaction.

Returns:

block prefix used for TAPOS on the currently executing transaction Example:

int tbp = tapos_block_prefix();

function expiration

uint32_t eosio::expiration()

Gets the expiration of the currently executing transaction.

Gets the expiration of the currently executing transaction.

Returns:

expiration of the currently executing transaction in seconds since Unix epoch

function get_context_free_data

int eosio::get_context_free_data(
    uint32_t index,
    char * buff,
    size_t size
)

Retrieve the signed_transaction.context_free_data[index].

Parameters:

  • index - the index of the context_free_data entry to retrieve
  • buff - output buff of the context_free_data entry
  • size - amount of context_free_data[index] to retrieve into buff, 0 to report required size

Returns:

size copied, or context_free_data[index].size() if 0 passed for size, or -1 if index not valid

function transaction_header

eosio::transaction_header::transaction_header(
    time_point_sec exp = time_point_sec(now()+60)
)

Construct a new transaction_header object initialising the transaction header expiration to now + 60 seconds.

Construct a new transaction_header with an expiration of now + 60 seconds.

function transaction

eosio::transaction::transaction(
    time_point_sec exp = time_point_sec(now()+60)
)

Construct a new transaction object initialising the transaction header expiration to now + 60 seconds.

Construct a new transaction with an expiration of now + 60 seconds.

function send

void eosio::transaction::send(
    const uint128_t & sender_id,
    name payer,
    bool replace_existing = false
) const

Writes the symbol_code as a string to the provided char buffer.

Sends this transaction, packs the transaction then sends it as a deferred transaction

Parameters:

  • sender_id - ID of sender
  • payer - Account paying for RAM
  • replace_existing - Defaults to false, if this is 0/false then if the provided sender_id is already in use by an in-flight transaction from this contract, which will be a failing assert. If 1 then transaction will atomically cancel/replace the inflight transaction

function unpack_sent_trx

transaction eosio::onerror::unpack_sent_trx() const

Unpacks and returns a transaction.

unpack_sent_trx unpacks and returns a transaction