From d2ac2503f4e42af990fdbf8971ee91a66f332af9 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 8 Jun 2018 15:09:35 -0500 Subject: [PATCH] Peer review fix. Only attempt conversion to name/symbol for uint64_t --- plugins/chain_plugin/chain_plugin.cpp | 31 ++++++++++++++ .../eosio/chain_plugin/chain_plugin.hpp | 41 +++++-------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 5f137445112..0a07bb4c58e 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include @@ -600,6 +602,35 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params }; } +template<> +uint64_t convert_to_type(const string& str, const string& desc) { + uint64_t value = 0; + try { + name s(str); + value = s.value; + } catch( ... ) { + try { + auto trimmed_str = str; + boost::trim(trimmed_str); + value = boost::lexical_cast(trimmed_str.c_str(), trimmed_str.size()); + } catch( ... ) { + try { + auto symb = eosio::chain::symbol::from_string(str); + value = symb.value(); + } catch( ... ) { + try { + value = ( eosio::chain::string_to_symbol( 0, str.c_str() ) >> 8 ); + } catch( ... ) { + FC_ASSERT( false, "Could not convert ${desc} string '${str}' to any of the following: " + "uint64_t, valid name, or valid symbol (with or without the precision)", + ("desc", desc)("str", str)); + } + } + } + } + return value; +} + abi_def get_abi( const controller& db, const name& account ) { const auto &d = db.db(); const account_object *code_accnt = d.find(account); diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index cdb9f068f74..70aaced5326 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -16,8 +16,6 @@ #include #include -#include -#include #include @@ -50,6 +48,16 @@ struct permission { template struct resolver_factory; +template +Type convert_to_type(const string& str, const string& desc) { + try { + return fc::variant(str).as(); + } FC_RETHROW_EXCEPTIONS(warn, "Could not convert {desc} string '${str}' to key type.", ("desc", desc)("str",str) ) +} + +template<> +uint64_t convert_to_type(const string& str, const string& desc); + class read_only { const controller& db; @@ -268,35 +276,6 @@ class read_only { } } - template - static Type convert_to_type(const string& str, const string& desc) { - Type value = 0; - try { - name s(str); - value = s.value; - } catch( ... ) { - try { - auto trimmed_str = str; - boost::trim(trimmed_str); - value = boost::lexical_cast(trimmed_str.c_str(), trimmed_str.size()); - } catch( ... ) { - try { - auto symb = eosio::chain::symbol::from_string(str); - value = symb.value(); - } catch( ... ) { - try { - value = ( eosio::chain::string_to_symbol( 0, str.c_str() ) >> 8 ); - } catch( ... ) { - FC_ASSERT( false, "Could not convert " + desc + - " string '" + str + - "' to any of the following: key_type, valid name, or valid symbol (with or without the precision)" ); - } - } - } - } - return value; - } - template read_only::get_table_rows_result get_table_rows_ex( const read_only::get_table_rows_params& p, const abi_def& abi )const { read_only::get_table_rows_result result;