Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Peer review fix. Only attempt conversion to name/symbol for uint64_t
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jun 8, 2018
1 parent 9560c47 commit d2ac250
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
31 changes: 31 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <eosio/chain/wast_to_wasm.hpp>

#include <boost/signals2/connection.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>

#include <fc/io/json.hpp>
#include <fc/variant.hpp>
Expand Down Expand Up @@ -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<uint64_t>(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_object, by_name>(account);
Expand Down
41 changes: 10 additions & 31 deletions plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <eosio/chain/plugin_interface.hpp>

#include <boost/container/flat_set.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>

#include <fc/static_variant.hpp>

Expand Down Expand Up @@ -50,6 +48,16 @@ struct permission {
template<typename>
struct resolver_factory;

template<typename Type>
Type convert_to_type(const string& str, const string& desc) {
try {
return fc::variant(str).as<Type>();
} 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;

Expand Down Expand Up @@ -268,35 +276,6 @@ class read_only {
}
}

template<typename Type>
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<Type>(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 <typename IndexType, typename Scope>
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;
Expand Down

0 comments on commit d2ac250

Please sign in to comment.