Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] Using get raw abi in cleos #491

Merged
merged 4 commits into from
Jun 22, 2022
Merged
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
28 changes: 16 additions & 12 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,12 @@ auto abi_serializer_resolver = [](const name& account) -> std::optional<abi_seri
static unordered_map<account_name, std::optional<abi_serializer> > 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<eosio::chain_apis::read_only::get_abi_results>();
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;

std::optional<abi_serializer> abis;
if( abi_results.abi.has_value() ) {
abis.emplace( *abi_results.abi, abi_serializer::create_yield_function( abi_serializer_max_time ) );
if (raw_abi_blob.size() != 0) {
abis.emplace(fc::raw::unpack<abi_def>(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;
}
Expand Down Expand Up @@ -2781,15 +2781,19 @@ 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->callback([&] {
auto result = call(get_abi_func, fc::mutable_variant_object("account_name", accountName));

auto abi = fc::json::to_pretty_string( result["abi"] );
if( filename.size() ) {
std::cerr << localized("saving abi to ${filename}", ("filename", filename)) << std::endl;
std::ofstream abiout( filename.c_str() );
abiout << abi;
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) {
const auto abi = fc::json::to_pretty_string(fc::raw::unpack<abi_def>(raw_abi_blob));
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 {
std::cout << abi << "\n";
FC_THROW_EXCEPTION(key_not_found_exception, "Key ${key}", ("key", "abi"));
}
});

Expand Down