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 43a23802b7a..11b019ef2d3 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; @@ -273,28 +281,7 @@ class read_only { read_only::get_table_rows_result result; const auto& d = db.db(); - uint64_t scope = 0; - try { - name s(p.scope); - scope = s.value; - } catch( ... ) { - try { - auto trimmed_scope_str = p.scope; - boost::trim(trimmed_scope_str); - scope = boost::lexical_cast(trimmed_scope_str.c_str(), trimmed_scope_str.size()); - } catch( ... ) { - try { - auto symb = eosio::chain::symbol::from_string(p.scope); - scope = symb.value(); - } catch( ... ) { - try { - scope = ( eosio::chain::string_to_symbol( 0, p.scope.c_str() ) >> 8 ); - } catch( ... ) { - FC_ASSERT( false, "could not convert scope string to any of the following: uint64_t, valid name, or valid symbol (with or without the precision)" ); - } - } - } - } + uint64_t scope = convert_to_type(p.scope, "scope"); abi_serializer abis; abis.set_abi(abi); @@ -306,12 +293,12 @@ class read_only { auto upper = idx.lower_bound(boost::make_tuple(next_tid)); if (p.lower_bound.size()) { - lower = idx.lower_bound(boost::make_tuple(t_id->id, fc::variant( - p.lower_bound).as())); + auto lv = convert_to_type(p.lower_bound, "lower_bound"); + lower = idx.lower_bound(boost::make_tuple(t_id->id, lv)); } if (p.upper_bound.size()) { - upper = idx.lower_bound(boost::make_tuple(t_id->id, fc::variant( - p.upper_bound).as())); + auto uv = convert_to_type(p.upper_bound, "upper_bound"); + upper = idx.lower_bound(boost::make_tuple(t_id->id, uv)); } vector data; diff --git a/programs/cleos/httpc.cpp b/programs/cleos/httpc.cpp index f893afc080f..ab612fa82ae 100644 --- a/programs/cleos/httpc.cpp +++ b/programs/cleos/httpc.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include