diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 5ab286cf86a..bfceb4b40cc 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -1309,13 +1309,49 @@ 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_id_type id = trx.id(); - if( id == transaction().id() ) { - std::cerr << "file/string does not represent a transaction" << 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_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::cout << string( id ) << std::endl; + 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)) });