-
Notifications
You must be signed in to change notification settings - Fork 3.7k
add cleos convert pack_transaction and unpack_transaction #5018
add cleos convert pack_transaction and unpack_transaction #5018
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be useful. Thanks. Can you rebase to develop branch and use the new variant_to_bin there to also support passing in unpacked action data with your transaction and also support unpacking of action data. Seems like that should be optional so that if someone wants to avoid interacting with an active nodeos they can as long as they pack that action data like in your examples.
thanks, I will do that! |
206a0eb
to
ef60b93
Compare
…nly unpacked action when parsing a trx
ef60b93
to
4e9965d
Compare
std::tie( it, std::ignore ) = abi_cache.emplace( account, result["abi"].as_blob().data ); | ||
//we also received result["wasm"], but we don't use it | ||
} | ||
const std::vector<char>& abi_v = it->second; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above should be moved to its own function to avoid duplication and to use same abi_cache for variant_to_bin and bin_to_variant
@@ -1725,6 +1752,86 @@ int main( int argc, char** argv ) { | |||
// create account | |||
auto createAccount = create_account_subcommand( create, true /*simple*/ ); | |||
|
|||
// convert subcommand | |||
auto convert = app.add_subcommand("convert", localized("Pack and unpack transactions"), false); // TODO also add converting action args based on abi from here ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To address your TODO, I do think having the ability to specify an abi file to use would be nice. In that case it should NOT connect to nodeos or need to.
std::vector<char> trx_blob(trx_hex.size()/2); | ||
fc::from_hex(trx_hex, trx_blob.data(), trx_blob.size()); | ||
transaction unpacked_trx = fc::raw::unpack<transaction>(trx_blob); | ||
// TODO would it be nice to put the unpacked_trx actions into the trx actions in a separate unpacked_data field or somesuch ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove TODO, that would require api changes.
std::cout << fc::json::to_pretty_string(unpacked_action_data) << std::endl; | ||
} | ||
} else { | ||
// TODO should the "sigantures" and "context_free_data" fields be copied from trx_var into the action field(s) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, signatures and context_free_data should be added to the signed transaction if available.
bool unpack_action_data_flag = false; | ||
auto unpack_transaction = convert->add_subcommand("unpack_transaction", localized("From packed to plain signed json form")); | ||
unpack_transaction->add_option("transaction", packed_transaction_json, localized("The packed transaction json (string containing packed_trx and optionally compression fields)"))->required(); | ||
unpack_transaction->add_flag("--unpack-action-data", unpack_action_data_flag, localized("Upack all action datas within transaction and only return those, needs interaction with nodeos")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why anyone would use --unpack-action-data
. What is the use case? I think it is fine, just not sure anyone would use it.
Replaced by #5225 |
I needed a way to pack and unpack transactions from shell scripts and found this easiest to do.
Would something like this be accepted ? Or are any changes required ?
Thanks, Leon
--
for example pack:
and unpack: