How to make use of context_free_actions to store the static data into the block?
I want to store data into block directly through context_free_actions. Just like exetra_data in ETH. I tried:
eos.transaction({
context_free_actions: ["heyheyhey"],
actions: [{
account: "eosiotesta1",
name: 'hi',
authorization: [{
actor: "eosiotesta1",
permission: 'active'
}],
data: {
"user": "xxx"
}
}]
}, config.optLocal).then(ret => {
console.log(ret);
})
but it just ignored the context_free_actions data:
{ transaction_id:
'00936e44c568f79758ff17769afc6178b860c2ff60f1247bcf5761a747636d1a',
broadcast: false,
transaction:
{ compression: 'none',
transaction:
{ expiration: '2018-08-10T08:20:30',
ref_block_num: 10347,
ref_block_prefix: 158023551,
net_usage_words: 0,
max_cpu_usage_ms: 0,
delay_sec: 0,
context_free_actions: [],
actions: [Array],
transaction_extensions: [] },
signatures:
[ 'SIG_K1_KkkhvCasWeKQ3uXLmQyTmtgqzXL5iKJCtegvnUNQBwEBbcpKWnvDurYtgD9gFYNzefybXL5P4i59urdmFwXD1JsEtKhpfG' ] } }
And then I tried to add the data after signature:
eos.transaction({
actions: [{
account: "eosiotesta1",
name: 'hi',
authorization: [{
actor: "eosiotesta1",
permission: 'active'
}],
data: {
"user": "yeah"
}
}]
}, config.optLocal).then(ret => {
let actionFreeArray = [];
actionFreeArray.push("heyheyhey");
actionFreeArray.push("yeahyeahyeah");
ret.transaction.transaction.context_free_actions = actionFreeArray;
eos.pushTransaction(ret).then(aa => {
console.log(aa)
})
})
It failed. "Invalid packed transaction"
So, how to make use of context_free_actions to store the static data into the block?
Context_free_actions is an action[] so it will have to be formatted just like all other actions (hi in your example).
An example from the back-end uses the null account and the nonce operation:
("context_free_actions", fc::variants({
fc::mutable_variant_object()
("account", name(config::null_account_name))
("name", "nonce")
("data", fc::raw::pack(v))
})
);
If the signature does not pass or you get another error please let me know. This is untested.
There is some support for nonce here: https://github.com/EOSIO/eosjs/issues/193#issuecomment-397355862 .. A context_free_action can't have any authorizations though.
I tried as you said.
eos.transaction({
context_free_actions: [{
account: "eosio.null",
name: 'nonce',
data: "test data"
}],
actions: [{
account: "eosiotesta1",
name: 'hi',
authorization: [{
actor: "eosiotesta1",
permission: 'active'
}],
data: {
"user": "yeah"
}
}]
}, config.optBCST).then(ret => {
console.log(ret)
})
the result is:
{ broadcast: true,
transaction:
{ compression: 'none',
transaction:
{ expiration: '2018-08-13T03:02:04',
ref_block_num: 34216,
ref_block_prefix: 3335960694,
net_usage_words: 0,
max_cpu_usage_ms: 0,
delay_sec: 0,
context_free_actions: [],
actions: [Array],
transaction_extensions: [] },
signatures:
[ 'SIG_K1_Jx329gyq3JhYsDTrLgr8Ft1rjj8j2vq2zyNDFs5PmCFHAVBaHN5Ge61pzX955L8veZUdpe9afrFTnSXQLxv8e9aJrufi3A' ] },
transaction_id:
'b13113aa5974cc8e41de5e90c5bd8b63cfdad9316eaef4f3e402c82aa4e137d6',
processed:
{ id:
'b13113aa5974cc8e41de5e90c5bd8b63cfdad9316eaef4f3e402c82aa4e137d6',
receipt:
{ status: 'executed', cpu_usage_us: 277, net_usage_words: 13 },
elapsed: 277,
net_usage: 104,
scheduled: false,
action_traces: [ [Object] ],
except: null } }
the field context_free_actions is till empty.
Instead of data: "test data" use data: {value: "test data"} ..
I'm planning a patch release today, you'll need to get the commit above.
There is a back-end issue that appears only if you set forceActionDataHex: false .. It is true by default so you'll probably be ok.
The get_transaction API does return the context free data.
This is my test transaction on Junglenet: eos.getTransaction('48daee59ef01835244db2e336f23eb33401bd86c63aec5047358acb9b8a9810e')
Released [email protected]
Good! The transaction data on block post as below:
"transactions": [{
"status": "executed",
"cpu_usage_us": 290,
"net_usage_words": 16,
"trx": {
"id": "d74843749d1e255f13572b7a3b95af9ddd6df23d1d0ad19d88e1496091d4be2b",
"signatures": [
"SIG_K1_KVzwg3QRH6ZmempNsvAxpPQa42hF4tDpV5cqwqo7EY4oSU7NMrEFwG7gdSDCnUHHhmH1EwtVAmV1z9bqtTvvQNSXiSgaWG"
],
"compression": "none",
"packed_context_free_data": "",
"context_free_data": [],
"packed_trx": "8497725bb601973ea96f0000000100408c7a02ea3055000000000085269d000706686168616861010082c95865ea3055000000000000806b010082c95865ea305500000000a8ed3232080000000000d08cf200",
"transaction": {
"expiration": "2018-08-14T08:49:08",
"ref_block_num": 438,
"ref_block_prefix": 1873362583,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [{
"account": "eosio.null",
"name": "nonce",
"authorization": [],
"data": "06686168616861"
}
],
"actions": [{
"account": "eosiotesta1",
"name": "hi",
"authorization": [{
"actor": "eosiotesta1",
"permission": "active"
}
],
"data": {
"user": "yeah"
},
"hex_data": "0000000000d08cf2"
}
],
"transaction_extensions": []
}
}
}
]
The context_free_actions have data now without authorization.
You can close this issue. @jcalfee