Skip to content

Commit

Permalink
Merge pull request #491 from eosnetworkfoundation/cleos_get_raw_abi
Browse files Browse the repository at this point in the history
Using get raw abi in cleos
  • Loading branch information
ClaytonCalabrese authored Jun 22, 2022
2 parents 23fd8a8 + acf2bb6 commit befc500
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,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 @@ -2780,15 +2780,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

0 comments on commit befc500

Please sign in to comment.