跳到主要内容

Action C API

Defines API for querying action and sending action. More...

Attributes

Name
uint32_tlen
size_tsize

Detailed Description

Defines API for querying action and sending action.

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

Attributes Documentation

variable len

uint32_t len;

variable size

size_t size;

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