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"}'

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?


An unsigned_int is stored locally as uint32_t, but it is serialized as varuint32.

See for example: https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/varint.hpp and there's something similar in https://github.com/EOSIO/fc/blob/9a0ed1f85e38adc6ace8c944b5f5f725f4829ba2/include/fc/io/varint.hpp which is the packing lib.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.