Action C API
Defines API for querying action and sending action. More...
Functions
Detailed Description
A EOS.IO action has the following abstract structure:
struct action {
capi_name account_name; // the contract defining the primary code to execute for code/type
capi_name action_name; // the action to be taken
permission_level authorization; // the accounts and permission levels provided
bytes data; // opaque data processed by code
};
This API enables your contract to inspect the fields on the current action and act accordingly. Example:
// Assume this action is used for the following examples:
// {
// "code": "eos",
// "type": "transfer",
// "authorization": [{ "account": "inita", "permission": "active" }],
// "data": {
// "from": "inita",
// "to": "initb",
// "amount": 1000
// }
// }
char buffer[128];
uint32_t total = read_action(buffer, 5); // buffer contains the content of the action up to 5 bytes
print(total); // Output: 5
uint32_t msgsize = action_size();
print(msgsize); // Output: size of the above action's data field
require_recipient("initc"_n); // initc account will be notified for this action
require_auth("inita"_n); // Do nothing since inita exists in the auth list
require_auth("initb"_n); // Throws an exception
print(current_time()); // Output: timestamp (in microseconds since 1970) of current block
Functions Documentation
function read_action_data
uint32_t read_action_data(
void * msg,
uint32_t len
)
Copy current action data to the specified location.
Copy up to length bytes of current action data to the specified location
Parameters:
- msg - a pointer where up to length bytes of the current action data will be copied
- len - len of the current action data to be copied, 0 to report required size
Returns:
the number of bytes copied to msg, or number of bytes that can be copied if len==0 passed
Precondition:
msg
is a valid pointer to a range of memory at least len
bytes long
Post
msg
is filled with packed action data
function action_data_size
uint32_t action_data_size(
void
)
Get the length of current action's data field.
Get the length of the current action's data field. This method is useful for dynamically sized actions
Returns:
the length of the current action's data field
function require_recipient
void require_recipient(
capi_name name
)
Add the specified account to set of accounts to be notified.
Add the specified account to set of accounts to be notified
Parameters:
- name - name of the account to be verified
function require_auth
void require_auth(
capi_name name
)
Verify specified account exists in the set of provided auths.
Verifies that name exists in the set of provided auths on a action. Throws if not found.
Parameters:
- name - name of the account to be verified
function has_auth
bool has_auth(
capi_name name
)
Verifies that name has auth.
Verifies that name has auth.
Parameters:
- name - name of the account to be verified
function require_auth2
void require_auth2(
capi_name name,
capi_name permission
)
Verify specified account exists in the set of provided auths.
Verifies that name exists in the set of provided auths on a action. Throws if not found.
Parameters:
- name - name of the account to be verified
- permission - permission level to be verified
function is_account
bool is_account(
capi_name name
)
Verifies that Name is an existing account.
Verifies that Name is an existing account.
Parameters:
- name - name of the account to check
function send_inline
void send_inline(
char * serialized_action,
size_t size
)
Send an inline action in the context of this action's parent transaction
Parameters:
- serialized_action - serialized action
- size - size of serialized action in bytes
Precondition:
serialized_action
is a valid pointer to an array at least size
bytes long
function send_context_free_inline
void send_context_free_inline(
char * serialized_action,
size_t size
)
/function Send an inline context free action in the context of this action's parent transaction
Parameters:
- serialized_action - serialized action
- size - size of serialized action in bytes
Precondition:
serialized_action
is a valid pointer to an array at least size
bytes long
function publication_time
uint64_t publication_time(
void
)
Get the publication time.
Returns the time in microseconds from 1970 of the publication_time
Returns:
the time in microseconds from 1970 of the publication_time
function current_receiver
capi_name current_receiver(
void
)
Get the current receiver of the action.
Get the current receiver of the action
Returns:
the account which specifies the current receiver of the action
function set_action_return_value
void set_action_return_value(
void * return_value,
size_t size
)
Set the action return value.
Set the action return value which will be included in the action_receipt
Parameters:
- return_value - serialized return value
- size - size of serialized return value in bytes
Precondition:
return_value
is a valid pointer to an array at least size
bytes long