Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

cleos get transaction_id enhancements #6829

Merged
merged 3 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion programs/cleos/help_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const char* error_advice_authority_type_exception = R"=====(Ensure that your aut
)=====";
const char* error_advice_action_type_exception = R"=====(Ensure that your action JSON follows the contract's abi!)=====";
const char* error_advice_transaction_type_exception = R"=====(Ensure that your transaction JSON follows the right transaction format!
You can refer to contracts/eosiolib/transaction.hpp for reference)=====";
You can refer to eosio.cdt/libraries/eosiolib/transaction.hpp for reference)=====";
const char* error_advice_abi_type_exception = R"=====(Ensure that your abi JSON follows the following format!
{
"types" : [{ "new_type_name":"type_name", "type":"type_name" }],
Expand Down
47 changes: 44 additions & 3 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,9 +1309,50 @@ struct get_transaction_id_subcommand {

get_transaction_id->set_callback([&] {
try {
auto trx_var = json_from_file_or_string(trx_to_check);
auto trx = trx_var.as<transaction>();
std::cout << string(trx.id()) << std::endl;
fc::variant trx_var = json_from_file_or_string(trx_to_check);
if( trx_var.is_object() ) {
fc::variant_object& vo = trx_var.get_object();
// if actions.data & actions.hex_data provided, use the hex_data since only currently support unexploded data
if( vo.contains("actions") ) {
if( vo["actions"].is_array() ) {
fc::mutable_variant_object mvo = vo;
fc::variants& action_variants = mvo["actions"].get_array();
for( auto& action_v : action_variants ) {
if( !action_v.is_object() ) {
std::cerr << "Empty 'action' in transaction" << endl;
return;
}
fc::variant_object& action_vo = action_v.get_object();
if( action_vo.contains( "data" ) && action_vo.contains( "hex_data" ) ) {
fc::mutable_variant_object maction_vo = action_vo;
maction_vo["data"] = maction_vo["hex_data"];
action_vo = maction_vo;
vo = mvo;
} else if( action_vo.contains( "data" ) ) {
if( !action_vo["data"].is_string() ) {
std::cerr << "get transaction_id only supports un-exploded 'data' (hex form)" << std::endl;
return;
}
}
}
} else {
std::cerr << "transaction json 'actions' is not an array" << std::endl;
return;
}
} else {
std::cerr << "transaction json does not include 'actions'" << std::endl;
return;
}
auto trx = trx_var.as<transaction>();
transaction_id_type id = trx.id();
if( id == transaction().id() ) {
std::cerr << "file/string does not represent a transaction" << std::endl;
} else {
std::cout << string( id ) << std::endl;
}
} else {
std::cerr << "file/string does not represent a transaction" << std::endl;
}
} EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Fail to parse transaction JSON '${data}'", ("data",trx_to_check))
});
}
Expand Down