Action
用于查询和发送Action的API。
EOS.IO的action定义如下:
struct action {
scope_name scope; // the contract defining the primary code to execute for code/type
action_name name; // the action to be taken
permission_level[] authorization; // the accounts and permission levels provided
bytes data; // opaque data processed by code
};
使用Action系列API,让你可以在合约中查看当前Action的字段,以便正确响应。
示例代码:
// 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(N(initc)); // initc account will be notified for this action
require_auth(N(inita)); // Do nothing since inita exists in the auth list
require_auth(N(initb)); // Throws an exception
print(current_time()); // Output: timestamp (in microseconds since 1970) of current block