Skip to content

Commit

Permalink
Add automatic handling of action.data if action.hex_data is available…
Browse files Browse the repository at this point in the history
…. Added better error messages for common mistakes.
  • Loading branch information
heifner committed Feb 25, 2019
1 parent fb5bce9 commit 0f7709f
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
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>();
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))
});
Expand Down

0 comments on commit 0f7709f

Please sign in to comment.