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

cleos to display pushed actions' return values #9375

Merged
merged 13 commits into from
Aug 12, 2020
26 changes: 24 additions & 2 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,27 @@ fc::variant push_actions(std::vector<chain::action>&& actions, const std::vector
return push_transaction(trx, signing_keys);
}

void print_return_value( const fc::variant& at ) {
std::string return_value, return_value_prefix{"return value: "};
const auto & iter_value = at.get_object().find("return_value_data");
const auto & iter_hex = at.get_object().find("return_value_hex_data");
kimjh2005 marked this conversation as resolved.
Show resolved Hide resolved

if( iter_value != at.get_object().end() ) {
return_value = fc::json::to_string(iter_value->value(), fc::time_point::maximum());
}
else if( iter_hex != at.get_object().end() ) {
return_value = iter_hex->value().as_string();
return_value_prefix = "return value (hex): ";
}

if( !return_value.empty() ) {
if( return_value.size() > 100 ) {
return_value = return_value.substr(0, 100) + "...";
}
cout << "=>" << std::setw(46) << std::right << return_value_prefix << return_value << "\n";
}
}

void print_action( const fc::variant& at ) {
auto receiver = at["receiver"].as_string();
const auto& act = at["act"].get_object();
Expand All @@ -482,6 +503,7 @@ void print_action( const fc::variant& at ) {
*/
if( args.size() > 100 ) args = args.substr(0,100) + "...";
cout << "#" << std::setw(14) << right << receiver << " <= " << std::setw(28) << std::left << (code +"::" + func) << " " << args << "\n";
print_return_value(at);
if( console.size() ) {
std::stringstream ss(console);
string line;
Expand Down Expand Up @@ -1137,7 +1159,7 @@ struct create_account_subcommand {

if( active_key_str.empty() ) {
active = owner;
} else if ( active_key_str.find('{') != string::npos ) {
} else if ( active_key_str.find('{') != string::npos ) {
try{
active = parse_json_authority_or_key(active_key_str);
} EOS_RETHROW_EXCEPTIONS( explained_exception, "Invalid active authority: ${authority}", ("authority", owner_key_str) )
Expand Down Expand Up @@ -2622,7 +2644,7 @@ int main( int argc, char** argv ) {
});

// validate subcommand
auto validate = app.add_subcommand("validate", localized("Validate transactions"));
auto validate = app.add_subcommand("validate", localized("Validate transactions"));
validate->require_subcommand();

// validate signatures
Expand Down