Hello Dear EOSIO Community,
I have following transaction on mainnet that I want to unpack. I get its data using curl:
curl https://api.tokenika.io/v1/history/get_transaction -d'{"id": "474157059f407274020d9c498c3a02b07bce36a3229838677de8947efe153ed0"}'
[...]
"packed_trx":"4936395b23cae0baad75000000000100a6823403ea3055000000572d3ccdcd0180a92206baa920cd00000000a8ed32322b80a92206baa920cdc0d52406baa920cd102700000000000004454f53000000000a756e7061636b206d652100"
[...]
"trx":{
"expiration":"2018-07-01T20:15:05",
"ref_block_num":51747,
"ref_block_prefix":1974319840,
"max_net_usage_words":0,
"max_cpu_usage_ms":0,
"delay_sec":0,
"context_free_actions":[],
"actions":[
{
"account":"eosio.token",
"name":"transfer",
"authorization":[{
"actor":"tokenika4eos",
"permission":"active"
}],
[...]
I try to unpack packed_trx
using struct defined in transaction.hpp
time_point_sec expiration; ///< the time at which a transaction expires
uint16_t ref_block_num = 0U; ///< specifies a block num in the last 2^16 blocks.
uint32_t ref_block_prefix = 0UL; ///< specifies the lower 32 bits of the blockid at get_ref_blocknum
fc::unsigned_int max_net_usage_words = 0UL; /// upper limit on total network bandwidth (in 8 byte words) billed for this transaction
uint8_t max_cpu_usage_ms = 0; /// upper limit on the total CPU time billed for this transaction
fc::unsigned_int delay_sec = 0UL;
After few source code checks, I've found that both time_point_sec
and fc::unsigned_int
should be uint32
.
So I try to read first field of that struct, expiration
. I read first 8 characters from packed_trx
string (32 input bits/8 bits per byte = 4 bytes, *2 hex numbers per byte = 8 hex numbers)
that's 4936395b
and cast that to integer using little-endian format getting 1530476105
at the end, which is Unix timestamp date 07/01/2018 @ 8:15pm (UTC)
which is cool because it matches my expiration date from transaction.
When I repeat whole process to rest of the data, I get:
expiration = 1530476105
ref_block_num = 51747
ref_block_prefix = 1974319840
max_net_usage_words = 0
max_cpu_usage_ms = 1
delay_sec = 880977408
This would be really nice, but it isn't true since this transaction is defined to have all three values max_net_usage_words
, max_cpu_usage_ms
, delay_sec
set to 0
.
Is there anything obvious that I'm doing wrong? How to correctly unpack "packed_trx" from transaction?