From e44c6c4006893f7d1a9f80ab7902f6dc33cebcc6 Mon Sep 17 00:00:00 2001 From: Allen Han Date: Wed, 19 Feb 2020 20:27:18 -0500 Subject: [PATCH 1/4] Use get_raw_abi for both get cleos command and cleos transactions --- programs/cleos/main.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 0ac37cfef1..5dcc56579f 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -471,13 +471,12 @@ auto abi_serializer_resolver = [](const name& account) -> std::optional > abi_cache; auto it = abi_cache.find( account ); if ( it == abi_cache.end() ) { - auto result = call(get_abi_func, fc::mutable_variant_object("account_name", account)); - auto abi_results = result.as(); - - std::optional abis; - if( abi_results.abi.has_value() ) { - abis.emplace( *abi_results.abi, abi_serializer::create_yield_function( abi_serializer_max_time ) ); - } else { + fc::optional abis; + auto raw_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", account)); + if (!raw_result["abi"].is_null()) { + auto abi_result = fc::raw::unpack(raw_result["abi"].as_blob().data); + abis.emplace(abi_result, abi_serializer_max_time); + } else { std::cerr << "ABI for contract " << account.to_string() << " not found. Action data will be shown in hex only." << std::endl; } abi_cache.emplace( account, abis ); @@ -2780,10 +2779,11 @@ int main( int argc, char** argv ) { auto getAbi = get->add_subcommand("abi", localized("Retrieve the ABI for an account")); getAbi->add_option("name", accountName, localized("The name of the account whose abi should be retrieved"))->required(); getAbi->add_option("-f,--file",filename, localized("The name of the file to save the contract .abi to instead of writing to console") ); - getAbi->callback([&] { - auto result = call(get_abi_func, fc::mutable_variant_object("account_name", accountName)); + getAbi->set_callback([&] { + auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", accountName)); + auto abi_result = fc::raw::unpack(raw_abi_result["abi"].as_blob().data); - auto abi = fc::json::to_pretty_string( result["abi"] ); + auto abi = fc::json::to_pretty_string( abi_result ); if( filename.size() ) { std::cerr << localized("saving abi to ${filename}", ("filename", filename)) << std::endl; std::ofstream abiout( filename.c_str() ); From ca86373fdf84c3f59264f04e5e1cbcb2e6cb6787 Mon Sep 17 00:00:00 2001 From: Allen Han Date: Thu, 20 Feb 2020 08:43:07 -0500 Subject: [PATCH 2/4] Improve the error handling --- programs/cleos/main.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 5dcc56579f..82959f64df 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -472,9 +472,10 @@ auto abi_serializer_resolver = [](const name& account) -> std::optional abis; - auto raw_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", account)); - if (!raw_result["abi"].is_null()) { - auto abi_result = fc::raw::unpack(raw_result["abi"].as_blob().data); + auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", account)); + auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; + if (raw_abi_blob.size() != 0) { + auto abi_result = fc::raw::unpack(raw_abi_blob); abis.emplace(abi_result, abi_serializer_max_time); } else { std::cerr << "ABI for contract " << account.to_string() << " not found. Action data will be shown in hex only." << std::endl; @@ -2781,15 +2782,21 @@ int main( int argc, char** argv ) { getAbi->add_option("-f,--file",filename, localized("The name of the file to save the contract .abi to instead of writing to console") ); getAbi->set_callback([&] { auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", accountName)); - auto abi_result = fc::raw::unpack(raw_abi_result["abi"].as_blob().data); - - auto abi = fc::json::to_pretty_string( abi_result ); - if( filename.size() ) { - std::cerr << localized("saving abi to ${filename}", ("filename", filename)) << std::endl; - std::ofstream abiout( filename.c_str() ); - abiout << abi; - } else { - std::cout << abi << "\n"; + auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; + if (raw_abi_blob.size() != 0) { + auto abi_result = fc::raw::unpack(raw_abi_result["abi"].as_blob().data); + std::cout << "789\n"; + auto abi = fc::json::to_pretty_string(abi_result); + if (filename.size()) { + std::cerr << localized("saving abi to ${filename}", ("filename", filename)) << std::endl; + std::ofstream abiout(filename.c_str()); + abiout << abi; + } else { + std::cout << abi << "\n"; + } + } else + { + FC_THROW_EXCEPTION(key_not_found_exception, "Key ${key}", ("key", "abi")); } }); From b61d06c812631e28fa5e3f51758c3736c922977d Mon Sep 17 00:00:00 2001 From: Allen Han Date: Thu, 20 Feb 2020 11:10:36 -0500 Subject: [PATCH 3/4] fix pr comments and add const --- programs/cleos/main.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 82959f64df..5f82727424 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -471,13 +471,13 @@ auto abi_serializer_resolver = [](const name& account) -> std::optional > abi_cache; auto it = abi_cache.find( account ); if ( it == abi_cache.end() ) { - fc::optional abis; - auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", account)); - auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; - if (raw_abi_blob.size() != 0) { - auto abi_result = fc::raw::unpack(raw_abi_blob); - abis.emplace(abi_result, abi_serializer_max_time); - } else { + const auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", account)); + const auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; + + fc::optional abis; + if (raw_abi_blob.size() != 0) { + abis.emplace(fc::raw::unpack(raw_abi_blob), abi_serializer_max_time); + } else { std::cerr << "ABI for contract " << account.to_string() << " not found. Action data will be shown in hex only." << std::endl; } abi_cache.emplace( account, abis ); @@ -2781,12 +2781,10 @@ int main( int argc, char** argv ) { getAbi->add_option("name", accountName, localized("The name of the account whose abi should be retrieved"))->required(); getAbi->add_option("-f,--file",filename, localized("The name of the file to save the contract .abi to instead of writing to console") ); getAbi->set_callback([&] { - auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", accountName)); - auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; + const auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", accountName)); + const auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; if (raw_abi_blob.size() != 0) { - auto abi_result = fc::raw::unpack(raw_abi_result["abi"].as_blob().data); - std::cout << "789\n"; - auto abi = fc::json::to_pretty_string(abi_result); + const auto abi = fc::json::to_pretty_string(fc::raw::unpack(raw_abi_blob)); if (filename.size()) { std::cerr << localized("saving abi to ${filename}", ("filename", filename)) << std::endl; std::ofstream abiout(filename.c_str()); @@ -2794,8 +2792,7 @@ int main( int argc, char** argv ) { } else { std::cout << abi << "\n"; } - } else - { + } else { FC_THROW_EXCEPTION(key_not_found_exception, "Key ${key}", ("key", "abi")); } }); From acf2bb63bcc9a91d3100927f5dc2e537a21a23fa Mon Sep 17 00:00:00 2001 From: Clayton Calabrese Date: Tue, 21 Jun 2022 17:28:44 -0500 Subject: [PATCH 4/4] fix errors preventing building due to removed fc::optional and convert get_callback to callback. --- programs/cleos/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 5f82727424..e1f882871c 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -474,7 +474,7 @@ auto abi_serializer_resolver = [](const name& account) -> std::optional abis; + std::optional abis; if (raw_abi_blob.size() != 0) { abis.emplace(fc::raw::unpack(raw_abi_blob), abi_serializer_max_time); } else { @@ -2780,7 +2780,7 @@ int main( int argc, char** argv ) { auto getAbi = get->add_subcommand("abi", localized("Retrieve the ABI for an account")); getAbi->add_option("name", accountName, localized("The name of the account whose abi should be retrieved"))->required(); getAbi->add_option("-f,--file",filename, localized("The name of the file to save the contract .abi to instead of writing to console") ); - getAbi->set_callback([&] { + getAbi->callback([&] { const auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", accountName)); const auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; if (raw_abi_blob.size() != 0) {