-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.mjs
39 lines (36 loc) · 1.44 KB
/
actions.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import serialize_name from "./name.mjs";
import serialize_permission from "./permission.mjs";
import serialize_varuint32 from "./varuint32.mjs";
/**
* Serializes EOSIO actions to a WASM hex string for mutating the state of a smart contract.
* @name actions
* @kind function
* @param {Objext} arg Argument.
* @param {string} arg.account The account name of the smart contract.
* @param {string} arg.action The name of the action on the contract to interact with.
* @param {Array<Authorization>} arg.authorization List of authorizations.
* @param {string} arg.hex_data The hex string data to push to the contract.
* @returns {sting} A hex string of the actions to
* @ignore
*/
export function serialize_action({ account, action, authorization, hex_data }) {
let hex_str = serialize_name(account) + serialize_name(action);
if (authorization) {
hex_str += serialize_varuint32(authorization.length);
for (const perm of authorization) hex_str += serialize_permission(perm);
}
hex_str += serialize_varuint32(hex_data.length / 2) + hex_data;
return hex_str;
}
/**
* Serializes a list of EOSIO actions.
* @kind function
* @name serialize_actions
* @param {actions} action_list List of actions to serialize.
* @returns {string} Serialized actions.
*/
export function serialize_actions(action_list) {
let hex_str = serialize_varuint32(action_list.length);
for (const action of action_list) hex_str += serialize_action(action);
return hex_str;
}