Skip to content

Commit

Permalink
Added max_depth to all uses of variant
Browse files Browse the repository at this point in the history
  • Loading branch information
pmconrad committed Mar 19, 2018
1 parent 097537e commit af118f6
Show file tree
Hide file tree
Showing 43 changed files with 232 additions and 250 deletions.
2 changes: 1 addition & 1 deletion libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace graphene { namespace app {
{
auto block_num = b.block_num();
auto& callback = _callbacks.find(id)->second;
fc::async( [capture_this,this,id,block_num,trx_num,trx,callback](){ callback( fc::variant(transaction_confirmation{ id, block_num, trx_num, trx}) ); } );
fc::async( [capture_this,this,id,block_num,trx_num,trx,callback](){ callback( fc::variant(transaction_confirmation{ id, block_num, trx_num, trx}, 5) ); } );
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace detail {
if( _options->count("seed-nodes") )
{
auto seeds_str = _options->at("seed-nodes").as<string>();
auto seeds = fc::json::from_string(seeds_str).as<vector<string>>();
auto seeds = fc::json::from_string(seeds_str).as<vector<string>>(2);
for( const string& endpoint_string : seeds )
{
try {
Expand Down Expand Up @@ -241,7 +241,7 @@ namespace detail {

void new_connection( const fc::http::websocket_connection_ptr& c )
{
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(*c);
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(*c, GRAPHENE_NET_MAX_NESTED_OBJECTS);
auto login = std::make_shared<graphene::app::login_api>( std::ref(*_self) );
login->enable_api("database_api");

Expand Down Expand Up @@ -304,7 +304,7 @@ namespace detail {
_websocket_tls_server->start_accept();
} FC_CAPTURE_AND_RETHROW() }

application_impl(application* self)
explicit application_impl(application* self)
: _self(self),
_chain_db(std::make_shared<chain::database>())
{
Expand All @@ -320,20 +320,19 @@ namespace detail {
public_key_type init_pubkey( init_key );
for( uint64_t i=0; i<genesis.initial_active_witnesses; i++ )
genesis.initial_witness_candidates[i].block_signing_key = init_pubkey;
return;
}

void startup()
{ try {
fc::create_directories(_data_dir / "blockchain");

auto initial_state = [&] {
auto initial_state = [this] {
ilog("Initializing database...");
if( _options->count("genesis-json") )
{
std::string genesis_str;
fc::read_file_contents( _options->at("genesis-json").as<boost::filesystem::path>(), genesis_str );
genesis_state_type genesis = fc::json::from_string( genesis_str ).as<genesis_state_type>();
genesis_state_type genesis = fc::json::from_string( genesis_str ).as<genesis_state_type>( 20 );
bool modified_genesis = false;
if( _options->count("genesis-timestamp") )
{
Expand Down Expand Up @@ -370,7 +369,7 @@ namespace detail {
graphene::egenesis::compute_egenesis_json( egenesis_json );
FC_ASSERT( egenesis_json != "" );
FC_ASSERT( graphene::egenesis::get_egenesis_json_hash() == fc::sha256::hash( egenesis_json ) );
auto genesis = fc::json::from_string( egenesis_json ).as<genesis_state_type>();
auto genesis = fc::json::from_string( egenesis_json ).as<genesis_state_type>( 20 );
genesis.initial_chain_id = fc::sha256::hash( egenesis_json );
return genesis;
}
Expand All @@ -386,7 +385,7 @@ namespace detail {
loaded_checkpoints.reserve( cps.size() );
for( auto cp : cps )
{
auto item = fc::json::from_string(cp).as<std::pair<uint32_t,block_id_type> >();
auto item = fc::json::from_string(cp).as<std::pair<uint32_t,block_id_type> >( 2 );
loaded_checkpoints[item.first] = item.second;
}
}
Expand Down Expand Up @@ -421,7 +420,7 @@ namespace detail {

if(fc::exists(_options->at("api-access").as<boost::filesystem::path>()))
{
_apiaccess = fc::json::from_file( _options->at("api-access").as<boost::filesystem::path>() ).as<api_access>();
_apiaccess = fc::json::from_file( _options->at("api-access").as<boost::filesystem::path>() ).as<api_access>( 20 );
ilog( "Using api access file from ${path}",
("path", _options->at("api-access").as<boost::filesystem::path>().string()) );
}
Expand Down Expand Up @@ -987,7 +986,7 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
if( fc::exists(genesis_out) )
{
try {
genesis_state = fc::json::from_file(genesis_out).as<genesis_state_type>();
genesis_state = fc::json::from_file(genesis_out).as<genesis_state_type>( 20 );
} catch(const fc::exception& e) {
std::cerr << "Unable to parse existing genesis file:\n" << e.to_string()
<< "\nWould you like to replace it? [y/N] ";
Expand Down
49 changes: 20 additions & 29 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ typedef std::map< std::pair<graphene::chain::asset_id_type, graphene::chain::ass

namespace graphene { namespace app {

class database_api_impl;


class database_api_impl : public std::enable_shared_from_this<database_api_impl>
{
public:
database_api_impl( graphene::chain::database& db, const application_options* app_options );
explicit database_api_impl( graphene::chain::database& db, const application_options* app_options );
~database_api_impl();


Expand Down Expand Up @@ -170,7 +167,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
return;

if( !is_subscribed_to_item(i) )
_subscribe_filter.insert( vec.data(), vec.size() );//(vecconst char*)&i, sizeof(i) );
_subscribe_filter.insert( vec.data(), vec.size() );
}

template<typename T>
Expand Down Expand Up @@ -202,7 +199,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>

auto sub = _market_subscriptions.find( market );
if( sub != _market_subscriptions.end() ) {
queue[market].emplace_back( full_object ? obj->to_variant() : fc::variant(obj->id) );
queue[market].emplace_back( full_object ? obj->to_variant() : fc::variant(obj->id, 1) );
}
}

Expand Down Expand Up @@ -260,7 +257,7 @@ database_api_impl::database_api_impl( graphene::chain::database& db, const appli
_applied_block_connection = _db.applied_block.connect([this](const signed_block&){ on_applied_block(); });

_pending_trx_connection = _db.on_pending_transaction.connect([this](const signed_transaction& trx ){
if( _pending_trx_callback ) _pending_trx_callback( fc::variant(trx) );
if( _pending_trx_callback ) _pending_trx_callback( fc::variant(trx, GRAPHENE_MAX_NESTED_OBJECTS) );
});
}

Expand Down Expand Up @@ -624,7 +621,7 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
{
const account_object* account = nullptr;
if (std::isdigit(account_name_or_id[0]))

This comment has been minimized.

Copy link
@abitmore

abitmore Apr 5, 2018

Member

We got good luck since [0] here will return '\0' when the string is empty. IMHO it's still dangerous to call [] without checking length.

account = _db.find(fc::variant(account_name_or_id).as<account_id_type>());
account = _db.find(fc::variant(account_name_or_id, 1).as<account_id_type>(1));
else
{
const auto& idx = _db.get_index_type<account_index>().indices().get<by_name>();
Expand All @@ -643,7 +640,6 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
}
}

// fc::mutable_variant_object full_account;
full_account acnt;
acnt.account = *account;
acnt.statistics = account->statistics(_db);
Expand All @@ -652,12 +648,6 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
acnt.lifetime_referrer_name = account->lifetime_referrer(_db).name;
acnt.votes = lookup_vote_ids( vector<vote_id_type>(account->options.votes.begin(),account->options.votes.end()) );

// Add the account itself, its statistics object, cashback balance, and referral account names
/*
full_account("account", *account)("statistics", account->statistics(_db))
("registrar_name", account->registrar(_db).name)("referrer_name", account->referrer(_db).name)
("lifetime_referrer_name", account->lifetime_referrer(_db).name);
*/
if (account->cashback_vb)
{
acnt.cashback_balance = account->cashback_balance(_db);
Expand All @@ -677,7 +667,6 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const

// Add the account's balances
auto balance_range = _db.get_index_type<account_balance_index>().indices().get<by_account_asset>().equal_range(boost::make_tuple(account->id));
//vector<account_balance_object> balances;
std::for_each(balance_range.first, balance_range.second,
[&acnt](const account_balance_object& balance) {
acnt.balances.emplace_back(balance);
Expand Down Expand Up @@ -989,7 +978,7 @@ vector<optional<asset_object>> database_api_impl::lookup_asset_symbols(const vec
[this, &assets_by_symbol](const string& symbol_or_id) -> optional<asset_object> {
if( !symbol_or_id.empty() && std::isdigit(symbol_or_id[0]) )
{
auto ptr = _db.find(variant(symbol_or_id).as<asset_id_type>());
auto ptr = _db.find(variant(symbol_or_id, 1).as<asset_id_type>(1));
return ptr == nullptr? optional<asset_object>() : *ptr;
}
auto itr = assets_by_symbol.find(symbol_or_id);
Expand Down Expand Up @@ -1763,7 +1752,7 @@ vector<variant> database_api_impl::lookup_vote_ids( const vector<vote_id_type>&
{
auto itr = committee_idx.find( id );
if( itr != committee_idx.end() )
result.emplace_back( variant( *itr ) );
result.emplace_back( variant( *itr, 1 ) );
else
result.emplace_back( variant() );
break;
Expand All @@ -1772,7 +1761,7 @@ vector<variant> database_api_impl::lookup_vote_ids( const vector<vote_id_type>&
{
auto itr = witness_idx.find( id );
if( itr != witness_idx.end() )
result.emplace_back( variant( *itr ) );
result.emplace_back( variant( *itr, 1 ) );
else
result.emplace_back( variant() );
break;
Expand All @@ -1781,12 +1770,12 @@ vector<variant> database_api_impl::lookup_vote_ids( const vector<vote_id_type>&
{
auto itr = for_worker_idx.find( id );
if( itr != for_worker_idx.end() ) {
result.emplace_back( variant( *itr ) );
result.emplace_back( variant( *itr, 1 ) );
}
else {
auto itr = against_worker_idx.find( id );
if( itr != against_worker_idx.end() ) {
result.emplace_back( variant( *itr ) );
result.emplace_back( variant( *itr, 1 ) );
}
else {
result.emplace_back( variant() );
Expand All @@ -1795,6 +1784,8 @@ vector<variant> database_api_impl::lookup_vote_ids( const vector<vote_id_type>&
break;
}
case vote_id_type::VOTE_TYPE_COUNT: break; // supress unused enum value warnings
default:
FC_CAPTURE_AND_THROW( fc::out_of_range_exception, (id) );
}
}
return result;
Expand Down Expand Up @@ -1908,8 +1899,8 @@ bool database_api::verify_authority( const signed_transaction& trx )const
bool database_api_impl::verify_authority( const signed_transaction& trx )const
{
trx.verify_authority( _db.get_chain_id(),
[&]( account_id_type id ){ return &id(_db).active; },
[&]( account_id_type id ){ return &id(_db).owner; },
[this]( account_id_type id ){ return &id(_db).active; },
[this]( account_id_type id ){ return &id(_db).owner; },
_db.get_global_properties().parameters.max_authority_depth );
return true;
}
Expand All @@ -1924,7 +1915,7 @@ bool database_api_impl::verify_account_authority( const string& name_or_id, cons
FC_ASSERT( name_or_id.size() > 0);
const account_object* account = nullptr;
if (std::isdigit(name_or_id[0]))
account = _db.find(fc::variant(name_or_id).as<account_id_type>());
account = _db.find(fc::variant(name_or_id, 1).as<account_id_type>(1));
else
{
const auto& idx = _db.get_index_type<account_index>().indices().get<by_name>();
Expand Down Expand Up @@ -1985,7 +1976,7 @@ struct get_required_fees_helper
{
asset fee = current_fee_schedule.set_fee( op, core_exchange_rate );
fc::variant result;
fc::to_variant( fee, result );
fc::to_variant( fee, result, GRAPHENE_NET_MAX_NESTED_OBJECTS );
return result;
}
}
Expand All @@ -2005,7 +1996,7 @@ struct get_required_fees_helper
// two mutually recursive functions instead of a visitor
result.first = current_fee_schedule.set_fee( proposal_create_op, core_exchange_rate );
fc::variant vresult;
fc::to_variant( result, vresult );
fc::to_variant( result, vresult, GRAPHENE_NET_MAX_NESTED_OBJECTS );
return vresult;
}

Expand Down Expand Up @@ -2222,7 +2213,7 @@ void database_api_impl::handle_object_changed(bool force_notify, bool full_objec
}
else
{
updates.emplace_back( id );
updates.emplace_back( fc::variant( id, 1 ) );
}
}
}
Expand Down Expand Up @@ -2262,7 +2253,7 @@ void database_api_impl::on_applied_block()
auto capture_this = shared_from_this();
block_id_type block_id = _db.head_block_id();
fc::async([this,capture_this,block_id](){
_block_applied_callback(fc::variant(block_id));
_block_applied_callback(fc::variant(block_id, 1));
});
}

Expand Down Expand Up @@ -2303,7 +2294,7 @@ void database_api_impl::on_applied_block()
{
auto itr = _market_subscriptions.find(item.first);
if(itr != _market_subscriptions.end())
itr->second(fc::variant(item.second));
itr->second(fc::variant(item.second, GRAPHENE_NET_MAX_NESTED_OBJECTS));
}
});
}
Expand Down
14 changes: 11 additions & 3 deletions libraries/app/include/graphene/app/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,24 @@ class plugin : public abstract_plugin
/// @group Some useful tools for boost::program_options arguments using vectors of JSON strings
/// @{
template<typename T>
T dejsonify(const string& s)
T dejsonify(const string& s, uint32_t max_depth)
{
return fc::json::from_string(s).as<T>();
return fc::json::from_string(s).as<T>(max_depth);
}

namespace impl {
template<typename T>
T dejsonify( const string& s )
{
return graphene::app::dejsonify<T>( s, GRAPHENE_MAX_NESTED_OBJECTS );
}
}

#define DEFAULT_VALUE_VECTOR(value) default_value({fc::json::to_string(value)}, fc::json::to_string(value))
#define LOAD_VALUE_SET(options, name, container, type) \
if( options.count(name) ) { \
const std::vector<std::string>& ops = options[name].as<std::vector<std::string>>(); \
std::transform(ops.begin(), ops.end(), std::inserter(container, container.end()), &graphene::app::dejsonify<type>); \
std::transform(ops.begin(), ops.end(), std::inserter(container, container.end()), &graphene::app::impl::dejsonify<type>); \
}
/// @}

Expand Down
10 changes: 2 additions & 8 deletions libraries/chain/db_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,19 @@ void debug_apply_update( database& db, const fc::variant_object& vo )
switch( action )
{
case db_action_create:
/*
idx.create( [&]( object& obj )
{
idx.object_from_variant( vo, obj );
} );
*/
FC_ASSERT( false );
break;
case db_action_write:
db.modify( db.get_object( oid ), [&]( object& obj )
{
idx.object_default( obj );
idx.object_from_variant( vo, obj );
idx.object_from_variant( vo, obj, GRAPHENE_MAX_NESTED_OBJECTS );
} );
break;
case db_action_update:
db.modify( db.get_object( oid ), [&]( object& obj )
{
idx.object_from_variant( vo, obj );
idx.object_from_variant( vo, obj, GRAPHENE_MAX_NESTED_OBJECTS );
} );
break;
case db_action_delete:
Expand Down
10 changes: 5 additions & 5 deletions libraries/chain/get_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ fc::variant_object get_config()
result[ "GRAPHENE_DEFAULT_WITNESS_PAY_VESTING_SECONDS" ] = GRAPHENE_DEFAULT_WITNESS_PAY_VESTING_SECONDS;
result[ "GRAPHENE_DEFAULT_WORKER_BUDGET_PER_DAY" ] = GRAPHENE_DEFAULT_WORKER_BUDGET_PER_DAY;
result[ "GRAPHENE_MAX_INTEREST_APR" ] = GRAPHENE_MAX_INTEREST_APR;
result[ "GRAPHENE_COMMITTEE_ACCOUNT" ] = GRAPHENE_COMMITTEE_ACCOUNT;
result[ "GRAPHENE_WITNESS_ACCOUNT" ] = GRAPHENE_WITNESS_ACCOUNT;
result[ "GRAPHENE_RELAXED_COMMITTEE_ACCOUNT" ] = GRAPHENE_RELAXED_COMMITTEE_ACCOUNT;
result[ "GRAPHENE_NULL_ACCOUNT" ] = GRAPHENE_NULL_ACCOUNT;
result[ "GRAPHENE_TEMP_ACCOUNT" ] = GRAPHENE_TEMP_ACCOUNT;
result[ "GRAPHENE_COMMITTEE_ACCOUNT" ] = fc::variant(GRAPHENE_COMMITTEE_ACCOUNT, GRAPHENE_MAX_NESTED_OBJECTS);
result[ "GRAPHENE_WITNESS_ACCOUNT" ] = fc::variant(GRAPHENE_WITNESS_ACCOUNT, GRAPHENE_MAX_NESTED_OBJECTS);
result[ "GRAPHENE_RELAXED_COMMITTEE_ACCOUNT" ] = fc::variant(GRAPHENE_RELAXED_COMMITTEE_ACCOUNT, GRAPHENE_MAX_NESTED_OBJECTS);
result[ "GRAPHENE_NULL_ACCOUNT" ] = fc::variant(GRAPHENE_NULL_ACCOUNT, GRAPHENE_MAX_NESTED_OBJECTS);
result[ "GRAPHENE_TEMP_ACCOUNT" ] = fc::variant(GRAPHENE_TEMP_ACCOUNT, GRAPHENE_MAX_NESTED_OBJECTS);

return result;
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/graphene/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@
///@}

#define GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET (asset_id_type(743))

#define GRAPHENE_MAX_NESTED_OBJECTS (200)
4 changes: 2 additions & 2 deletions libraries/chain/include/graphene/chain/protocol/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ namespace graphene { namespace chain {

namespace fc
{
void to_variant( const graphene::chain::address& var, fc::variant& vo );
void from_variant( const fc::variant& var, graphene::chain::address& vo );
void to_variant( const graphene::chain::address& var, fc::variant& vo, uint32_t max_depth = 1 );
void from_variant( const fc::variant& var, graphene::chain::address& vo, uint32_t max_depth = 1 );
}

namespace std
Expand Down
Loading

0 comments on commit af118f6

Please sign in to comment.