Skip to main content

Dispatcher

Module: Contracts API

Defines C++ functions to dispatch action to proper action handler inside a contract.

Functions

Name
template <typename Contract ,typename FirstAction ,typename SecondAction ,typename... Actions>
bool
dispatch(uint64_t code, uint64_t act)
template <typename T ,typename... Args>
bool
execute_action(name self, name code, void(T::*)(Args...) func)

Defines

Name
EOSIO_DISPATCH(TYPE, MEMBERS)

Functions Documentation

function dispatch

template <typename Contract ,
typename FirstAction ,
typename SecondAction ,
typename... Actions>
bool dispatch(
uint64_t code,
uint64_t act
)

This method will dynamically dispatch an incoming set of actions to

static Contract::on( ActionType )

For this to work the Actions must be derived from eosio::contract

function execute_action

template <typename T ,
typename... Args>
bool execute_action(
name self,
name code,
void(T::*)(Args...) func
)

Parameters:

  • obj - The contract object that has the correponding action handler
  • func - The action handler

Template Parameters:

  • T - The contract class that has the correponding action handler, this contract should be derived from eosio::contract
  • Q - The namespace of the action handler function
  • Args - The arguments that the action handler accepts, i.e. members of the action

Return: true

Unpack the received action and execute the correponding action handler

Macros Documentation

define EOSIO_DISPATCH

#define EOSIO_DISPATCH(
TYPE,
MEMBERS
)
extern "C" { \
[[eosio::wasm_entry]] \
void apply( uint64_t receiver, uint64_t code, uint64_t action ) { \
if( code == receiver ) { \
switch( action ) { \
EOSIO_DISPATCH_HELPER( TYPE, MEMBERS ) \
} \
/* does not allow destructor of thiscontract to run: eosio_exit(0); */ \
} \
} \
} \

Parameters:

  • TYPE - The class name of the contract
  • MEMBERS - The sequence of available actions supported by this contract

Note: To be able to use this macro, the contract needs to be derived from eosio::contract

Convenient macro to create contract apply handler

Example:

EOSIO_DISPATCH( eosio::bios, (setpriv)(setalimits)(setglimits)(setprods)(reqauth) )

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