diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 73861eb8..29a4edf9 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -103,7 +103,7 @@ namespace graphene { namespace app { } else if( api_name == "asset_api" ) { - _asset_api = std::make_shared< asset_api >( std::ref( *_app.chain_database() ) ); + _asset_api = std::make_shared< asset_api >( _app ); } else if( api_name == "debug_api" ) { @@ -526,10 +526,12 @@ namespace graphene { namespace app { } // end get_relevant_accounts( obj ) #endif - vector history_api::get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const + vector history_api::get_fill_order_history( std::string asset_a, std::string asset_b, uint32_t limit )const { FC_ASSERT(_app.chain_database()); const auto& db = *_app.chain_database(); + asset_id_type a = database_api.get_asset_id_from_string( asset_a ); + asset_id_type b = database_api.get_asset_id_from_string( asset_b ); if( a > b ) std::swap(a,b); const auto& history_idx = db.get_index_type().indices().get(); history_key hkey; @@ -551,7 +553,7 @@ namespace graphene { namespace app { return result; } - vector history_api::get_account_history( account_id_type account, + vector history_api::get_account_history( const std::string account_id_or_name, operation_history_id_type stop, unsigned limit, operation_history_id_type start ) const @@ -560,7 +562,9 @@ namespace graphene { namespace app { const auto& db = *_app.chain_database(); FC_ASSERT( limit <= 100 ); vector result; + account_id_type account; try { + account = database_api.get_account_id_from_string(account_id_or_name); const account_transaction_history_object& node = account(db).statistics(db).most_recent_op(db); if(start == operation_history_id_type() || start.instance.value > node.operation_id.instance.value) start = node.operation_id; @@ -584,7 +588,7 @@ namespace graphene { namespace app { return result; } - vector history_api::get_account_history_operations( account_id_type account, + vector history_api::get_account_history_operations( const std::string account_id_or_name, int operation_id, operation_history_id_type start, operation_history_id_type stop, @@ -594,6 +598,11 @@ namespace graphene { namespace app { const auto& db = *_app.chain_database(); FC_ASSERT( limit <= 100 ); vector result; + account_id_type account; + try { + account = database_api.get_account_id_from_string(account_id_or_name); + } catch (...) { return result; } + const auto& stats = account(db).statistics(db); if( stats.most_recent_op == account_transaction_history_id_type() ) return result; const account_transaction_history_object* node = &stats.most_recent_op(db); @@ -620,7 +629,7 @@ namespace graphene { namespace app { } - vector history_api::get_relative_account_history( account_id_type account, + vector history_api::get_relative_account_history( const std::string account_id_or_name, uint32_t stop, unsigned limit, uint32_t start) const @@ -629,6 +638,10 @@ namespace graphene { namespace app { const auto& db = *_app.chain_database(); FC_ASSERT(limit <= 100); vector result; + account_id_type account; + try { + account = database_api.get_account_id_from_string(account_id_or_name); + } catch(...) { return result; } const auto& stats = account(db).statistics(db); if( start == 0 ) start = stats.total_ops; @@ -668,11 +681,13 @@ namespace graphene { namespace app { return hist->tracked_buckets(); } - vector history_api::get_market_history( asset_id_type a, asset_id_type b, + vector history_api::get_market_history( std::string asset_a, std::string asset_b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const { try { FC_ASSERT(_app.chain_database()); const auto& db = *_app.chain_database(); + asset_id_type a = database_api.get_asset_id_from_string( asset_a ); + asset_id_type b = database_api.get_asset_id_from_string( asset_b ); vector result; result.reserve(200); @@ -692,7 +707,7 @@ namespace graphene { namespace app { ++itr; } return result; - } FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) } + } FC_CAPTURE_AND_RETHROW( (asset_a)(asset_b)(bucket_seconds)(start)(end) ) } crypto_api::crypto_api(){}; @@ -751,12 +766,16 @@ namespace graphene { namespace app { } // asset_api - asset_api::asset_api(graphene::chain::database& db) : _db(db) { } + asset_api::asset_api(graphene::app::application& app) : + _app(app), + _db( *app.chain_database()), + database_api( std::ref(*app.chain_database())) { } asset_api::~asset_api() { } - vector asset_api::get_asset_holders( asset_id_type asset_id, uint32_t start, uint32_t limit ) const { + vector asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const { FC_ASSERT(limit <= 100); + asset_id_type asset_id = database_api.get_asset_id_from_string( asset ); const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >(); auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) ); @@ -787,11 +806,11 @@ namespace graphene { namespace app { return result; } // get number of asset holders. - int asset_api::get_asset_holders_count( asset_id_type asset_id ) const { + int asset_api::get_asset_holders_count( std::string asset ) const { const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >(); + asset_id_type asset_id = database_api.get_asset_id_from_string( asset ); auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) ); - int count = boost::distance(range) - 1; return count; diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index a9d32764..c7d63ad5 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -81,23 +81,26 @@ class database_api_impl : public std::enable_shared_from_this bool is_public_key_registered(string public_key) const; // Accounts - vector> get_accounts(const vector& account_ids)const; + account_id_type get_account_id_from_string(const std::string& name_or_id)const; + vector> get_accounts(const vector& account_names_or_ids)const; std::map get_full_accounts( const vector& names_or_ids, bool subscribe ); optional get_account_by_name( string name )const; - vector get_account_references( account_id_type account_id )const; + vector get_account_references( const std::string account_id_or_name )const; vector> lookup_account_names(const vector& account_names)const; map lookup_accounts(const string& lower_bound_name, uint32_t limit)const; uint64_t get_account_count()const; // Balances - vector get_account_balances(account_id_type id, const flat_set& assets)const; - vector get_named_account_balances(const std::string& name, const flat_set& assets)const; + vector get_account_balances(const std::string& account_name_or_id, const flat_set& assets)const; vector get_balance_objects( const vector
& addrs )const; vector get_vested_balances( const vector& objs )const; - vector get_vesting_balances( account_id_type account_id )const; + vector get_vesting_balances( const std::string account_id_or_name )const; // Assets - vector> get_assets(const vector& asset_ids)const; + asset_id_type get_asset_id_from_string(const std::string& symbol_or_id)const; + vector> get_assets(const vector& asset_symbols_or_ids)const; + // helper function + vector> get_assets( const vector& asset_ids )const; vector list_assets(const string& lower_bound_symbol, uint32_t limit)const; vector> lookup_asset_symbols(const vector& symbols_or_ids)const; uint64_t get_asset_count()const; @@ -124,12 +127,13 @@ class database_api_impl : public std::enable_shared_from_this asset get_sweeps_vesting_balance_available_for_claim( account_id_type account )const; // Markets / feeds - vector get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const; - vector get_call_orders(asset_id_type a, uint32_t limit)const; - vector get_settle_orders(asset_id_type a, uint32_t limit)const; - vector get_margin_positions( const account_id_type& id )const; - void subscribe_to_market(std::function callback, asset_id_type a, asset_id_type b); - void unsubscribe_from_market(asset_id_type a, asset_id_type b); + vector get_limit_orders( const asset_id_type a, const asset_id_type b, const uint32_t limit )const; + vector get_limit_orders( const std::string& a, const std::string& b, const uint32_t limit)const; + vector get_call_orders(const std::string& a, uint32_t limit)const; + vector get_settle_orders(const std::string& a, uint32_t limit)const; + vector get_margin_positions( const std::string account_id_or_name )const; + void subscribe_to_market(std::function callback, const std::string& a, const std::string& b); + void unsubscribe_from_market(const std::string& a, const std::string& b); market_ticker get_ticker( const string& base, const string& quote )const; market_volume get_24_volume( const string& base, const string& quote )const; order_book get_order_book( const string& base, const string& quote, unsigned limit = 50 )const; @@ -137,13 +141,13 @@ class database_api_impl : public std::enable_shared_from_this // Witnesses vector> get_witnesses(const vector& witness_ids)const; - fc::optional get_witness_by_account(account_id_type account)const; + fc::optional get_witness_by_account(const std::string account_id_or_name)const; map lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const; uint64_t get_witness_count()const; // Committee members vector> get_committee_members(const vector& committee_member_ids)const; - fc::optional get_committee_member_by_account(account_id_type account)const; + fc::optional get_committee_member_by_account(const std::string account_id_or_name)const; map lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const; // Votes @@ -157,10 +161,10 @@ class database_api_impl : public std::enable_shared_from_this bool verify_authority( const signed_transaction& trx )const; bool verify_account_authority( const string& name_or_id, const flat_set& signers )const; processed_transaction validate_transaction( const signed_transaction& trx )const; - vector< fc::variant > get_required_fees( const vector& ops, asset_id_type id )const; + vector< fc::variant > get_required_fees( const vector& ops, const std::string& asset_id_or_symbol )const; // Proposed transactions - vector get_proposed_transactions( account_id_type id )const; + vector get_proposed_transactions( const std::string account_id_or_name )const; // Blinded balances vector get_blinded_balances( const flat_set& commitments )const; @@ -175,6 +179,10 @@ class database_api_impl : public std::enable_shared_from_this gpos_info get_gpos_info(const account_id_type account) const; //private: + const account_object* get_account_from_string( const std::string& name_or_id, + bool throw_if_not_found = true ) const; + const asset_object* get_asset_from_string( const std::string& symbol_or_id, + bool throw_if_not_found = true ) const; template void subscribe_to_item( const T& i )const { @@ -614,22 +622,27 @@ bool database_api_impl::is_public_key_registered(string public_key) const // // ////////////////////////////////////////////////////////////////////// -vector> database_api::get_accounts(const vector& account_ids)const +account_id_type database_api::get_account_id_from_string(const std::string& name_or_id)const { - return my->get_accounts( account_ids ); + return my->get_account_from_string( name_or_id )->id; } -vector> database_api_impl::get_accounts(const vector& account_ids)const +vector> database_api::get_accounts(const vector& account_names_or_ids)const { - vector> result; result.reserve(account_ids.size()); - std::transform(account_ids.begin(), account_ids.end(), std::back_inserter(result), - [this](account_id_type id) -> optional { - if(auto o = _db.find(id)) - { - subscribe_to_item( id ); - return *o; - } - return {}; + return my->get_accounts( account_names_or_ids ); +} + +vector> database_api_impl::get_accounts(const vector& account_names_or_ids)const +{ + vector> result; result.reserve(account_names_or_ids.size()); + std::transform(account_names_or_ids.begin(), account_names_or_ids.end(), std::back_inserter(result), + [this](std::string id_or_name) -> optional { + const account_object *account = get_account_from_string(id_or_name, false); + if(account == nullptr) + return {}; + + subscribe_to_item( account->id ); + return *account; }); return result; } @@ -758,16 +771,17 @@ optional database_api_impl::get_account_by_name( string name )co return optional(); } -vector database_api::get_account_references( account_id_type account_id )const +vector database_api::get_account_references( const std::string account_id_or_name )const { - return my->get_account_references( account_id ); + return my->get_account_references( account_id_or_name ); } -vector database_api_impl::get_account_references( account_id_type account_id )const +vector database_api_impl::get_account_references( const std::string account_id_or_name )const { const auto& idx = _db.get_index_type(); const auto& aidx = dynamic_cast(idx); const auto& refs = aidx.get_secondary_index(); + const account_id_type account_id = get_account_from_string(account_id_or_name)->id; auto itr = refs.account_to_account_memberships.find(account_id); vector result; @@ -836,13 +850,16 @@ uint64_t database_api_impl::get_account_count()const // // ////////////////////////////////////////////////////////////////////// -vector database_api::get_account_balances(account_id_type id, const flat_set& assets)const +vector database_api::get_account_balances(const std::string& account_name_or_id, const flat_set& assets)const { - return my->get_account_balances( id, assets ); + return my->get_account_balances( account_name_or_id, assets ); } -vector database_api_impl::get_account_balances(account_id_type acnt, const flat_set& assets)const +vector database_api_impl::get_account_balances( const std::string& account_name_or_id, + const flat_set& assets)const { + const account_object* account = get_account_from_string(account_name_or_id); + account_id_type acnt = account->id; vector result; if (assets.empty()) { @@ -865,15 +882,7 @@ vector database_api_impl::get_account_balances(account_id_type acnt, cons vector database_api::get_named_account_balances(const std::string& name, const flat_set& assets)const { - return my->get_named_account_balances( name, assets ); -} - -vector database_api_impl::get_named_account_balances(const std::string& name, const flat_set& assets) const -{ - const auto& accounts_by_name = _db.get_index_type().indices().get(); - auto itr = accounts_by_name.find(name); - FC_ASSERT( itr != accounts_by_name.end() ); - return get_account_balances(itr->get_id(), assets); + return my->get_account_balances( name, assets ); } vector database_api::get_balance_objects( const vector
& addrs )const @@ -923,15 +932,16 @@ vector database_api_impl::get_vested_balances( const vector database_api::get_vesting_balances( account_id_type account_id )const +vector database_api::get_vesting_balances( const std::string account_id_or_name )const { - return my->get_vesting_balances( account_id ); + return my->get_vesting_balances( account_id_or_name ); } -vector database_api_impl::get_vesting_balances( account_id_type account_id )const +vector database_api_impl::get_vesting_balances( const std::string account_id_or_name )const { try { + const account_id_type account_id = get_account_from_string(account_id_or_name)->id; vector result; auto vesting_range = _db.get_index_type().indices().get().equal_range(account_id); std::for_each(vesting_range.first, vesting_range.second, @@ -941,7 +951,7 @@ vector database_api_impl::get_vesting_balances( account_ }); return result; } - FC_CAPTURE_AND_RETHROW( (account_id) ); + FC_CAPTURE_AND_RETHROW( (account_id_or_name) ); } ////////////////////////////////////////////////////////////////////// @@ -950,9 +960,48 @@ vector database_api_impl::get_vesting_balances( account_ // // ////////////////////////////////////////////////////////////////////// -vector> database_api::get_assets(const vector& asset_ids)const +asset_id_type database_api::get_asset_id_from_string(const std::string& symbol_or_id)const { - return my->get_assets( asset_ids ); + return my->get_asset_from_string( symbol_or_id )->id; +} + +const asset_object* database_api_impl::get_asset_from_string( const std::string& symbol_or_id, + bool throw_if_not_found ) const +{ + // TODO cache the result to avoid repeatly fetching from db + FC_ASSERT( symbol_or_id.size() > 0); + const asset_object* asset = nullptr; + if (std::isdigit(symbol_or_id[0])) + asset = _db.find(fc::variant(symbol_or_id, 1).as(1)); + else + { + const auto& idx = _db.get_index_type().indices().get(); + auto itr = idx.find(symbol_or_id); + if (itr != idx.end()) + asset = &*itr; + } + if(throw_if_not_found) + FC_ASSERT( asset, "no such asset" ); + return asset; +} + +vector> database_api::get_assets(const vector& asset_symbols_or_ids)const +{ + return my->get_assets( asset_symbols_or_ids ); +} + +vector> database_api_impl::get_assets(const vector& asset_symbols_or_ids)const +{ + vector> result; result.reserve(asset_symbols_or_ids.size()); + std::transform(asset_symbols_or_ids.begin(), asset_symbols_or_ids.end(), std::back_inserter(result), + [this](std::string id_or_name) -> optional { + const asset_object* asset_obj = get_asset_from_string( id_or_name, false ); + if( asset_obj == nullptr ) + return {}; + subscribe_to_item(asset_obj->id ); + return asset_object( *asset_obj ); + }); + return result; } vector> database_api_impl::get_assets(const vector& asset_ids)const @@ -1208,7 +1257,7 @@ vector database_api_impl::get_all_unmatched_bets_for_bettor(account_ // // ////////////////////////////////////////////////////////////////////// -vector database_api::get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const +vector database_api::get_limit_orders(const std::string& a, const std::string& b, const uint32_t limit)const { return my->get_limit_orders( a, b, limit ); } @@ -1216,12 +1265,22 @@ vector database_api::get_limit_orders(asset_id_type a, asset /** * @return the limit orders for both sides of the book for the two assets specified up to limit number on each side. */ -vector database_api_impl::get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const +vector database_api_impl::get_limit_orders(const std::string& a, const std::string& b, const uint32_t limit)const +{ + const asset_id_type asset_a_id = get_asset_from_string(a)->id; + const asset_id_type asset_b_id = get_asset_from_string(b)->id; + + return get_limit_orders(asset_a_id, asset_b_id, limit); +} + +vector database_api_impl::get_limit_orders( const asset_id_type a, const asset_id_type b, + const uint32_t limit )const { const auto& limit_order_idx = _db.get_index_type(); const auto& limit_price_idx = limit_order_idx.indices().get(); vector result; + result.reserve(limit*2); uint32_t count = 0; auto limit_itr = limit_price_idx.lower_bound(price::max(a,b)); @@ -1245,45 +1304,46 @@ vector database_api_impl::get_limit_orders(asset_id_type a, return result; } -vector database_api::get_call_orders(asset_id_type a, uint32_t limit)const +vector database_api::get_call_orders(const std::string& a, uint32_t limit)const { return my->get_call_orders( a, limit ); } -vector database_api_impl::get_call_orders(asset_id_type a, uint32_t limit)const +vector database_api_impl::get_call_orders(const std::string& a, uint32_t limit)const { const auto& call_index = _db.get_index_type().indices().get(); - const asset_object& mia = _db.get(a); - price index_price = price::min(mia.bitasset_data(_db).options.short_backing_asset, mia.get_id()); + const asset_object* mia = get_asset_from_string(a); + price index_price = price::min(mia->bitasset_data(_db).options.short_backing_asset, mia->get_id()); return vector(call_index.lower_bound(index_price.min()), call_index.lower_bound(index_price.max())); } -vector database_api::get_settle_orders(asset_id_type a, uint32_t limit)const +vector database_api::get_settle_orders(const std::string& a, uint32_t limit)const { return my->get_settle_orders( a, limit ); } -vector database_api_impl::get_settle_orders(asset_id_type a, uint32_t limit)const +vector database_api_impl::get_settle_orders(const std::string& a, uint32_t limit)const { const auto& settle_index = _db.get_index_type().indices().get(); - const asset_object& mia = _db.get(a); - return vector(settle_index.lower_bound(mia.get_id()), - settle_index.upper_bound(mia.get_id())); + const asset_object* mia = get_asset_from_string(a); + return vector(settle_index.lower_bound(mia->get_id()), + settle_index.upper_bound(mia->get_id())); } -vector database_api::get_margin_positions( const account_id_type& id )const +vector database_api::get_margin_positions( const std::string account_id_or_name )const { - return my->get_margin_positions( id ); + return my->get_margin_positions( account_id_or_name ); } -vector database_api_impl::get_margin_positions( const account_id_type& id )const +vector database_api_impl::get_margin_positions( const std::string account_id_or_name )const { try { const auto& idx = _db.get_index_type(); const auto& aidx = idx.indices().get(); + const account_id_type id = get_account_from_string(account_id_or_name)->id; auto start = aidx.lower_bound( boost::make_tuple( id, asset_id_type(0) ) ); auto end = aidx.lower_bound( boost::make_tuple( id+1, asset_id_type(0) ) ); vector result; @@ -1293,31 +1353,37 @@ vector database_api_impl::get_margin_positions( const account ++start; } return result; - } FC_CAPTURE_AND_RETHROW( (id) ) + } FC_CAPTURE_AND_RETHROW( (account_id_or_name) ) } -void database_api::subscribe_to_market(std::function callback, asset_id_type a, asset_id_type b) +void database_api::subscribe_to_market(std::function callback, const std::string& a, const std::string& b) { my->subscribe_to_market( callback, a, b ); } -void database_api_impl::subscribe_to_market(std::function callback, asset_id_type a, asset_id_type b) +void database_api_impl::subscribe_to_market(std::function callback, const std::string& a, const std::string& b) { - if(a > b) std::swap(a,b); - FC_ASSERT(a != b); - _market_subscriptions[ std::make_pair(a,b) ] = callback; + auto asset_a_id = get_asset_from_string(a)->id; + auto asset_b_id = get_asset_from_string(b)->id; + + if(asset_a_id > asset_b_id) std::swap(asset_a_id,asset_b_id); + FC_ASSERT(asset_a_id != asset_b_id); + _market_subscriptions[ std::make_pair(asset_a_id,asset_b_id) ] = callback; } -void database_api::unsubscribe_from_market(asset_id_type a, asset_id_type b) +void database_api::unsubscribe_from_market(const std::string& a, const std::string& b) { my->unsubscribe_from_market( a, b ); } -void database_api_impl::unsubscribe_from_market(asset_id_type a, asset_id_type b) +void database_api_impl::unsubscribe_from_market(const std::string& a, const std::string& b) { - if(a > b) std::swap(a,b); - FC_ASSERT(a != b); - _market_subscriptions.erase(std::make_pair(a,b)); + auto asset_a_id = get_asset_from_string(a)->id; + auto asset_b_id = get_asset_from_string(b)->id; + + if(asset_a_id > asset_b_id) std::swap(asset_a_id,asset_b_id); + FC_ASSERT(asset_a_id != asset_b_id); + _market_subscriptions.erase(std::make_pair(asset_a_id,asset_b_id)); } market_ticker database_api::get_ticker( const string& base, const string& quote )const @@ -1540,9 +1606,10 @@ vector> database_api::get_witnesses(const vectorget_witnesses( witness_ids ); } -vector database_api::get_workers_by_account(account_id_type account)const +vector database_api::get_workers_by_account(const std::string account_id_or_name)const { const auto& idx = my->_db.get_index_type().indices().get(); + const account_id_type account = my->get_account_from_string(account_id_or_name)->id; auto itr = idx.find(account); vector result; @@ -1568,14 +1635,15 @@ vector> database_api_impl::get_witnesses(const vector database_api::get_witness_by_account(account_id_type account)const +fc::optional database_api::get_witness_by_account(const std::string account_id_or_name)const { - return my->get_witness_by_account( account ); + return my->get_witness_by_account( account_id_or_name ); } -fc::optional database_api_impl::get_witness_by_account(account_id_type account) const +fc::optional database_api_impl::get_witness_by_account(const std::string account_id_or_name) const { const auto& idx = _db.get_index_type().indices().get(); + const account_id_type account = get_account_from_string(account_id_or_name)->id; auto itr = idx.find(account); if( itr != idx.end() ) return *itr; @@ -1643,14 +1711,15 @@ vector> database_api_impl::get_committee_membe return result; } -fc::optional database_api::get_committee_member_by_account(account_id_type account)const +fc::optional database_api::get_committee_member_by_account(const std::string account_id_or_name)const { - return my->get_committee_member_by_account( account ); + return my->get_committee_member_by_account( account_id_or_name ); } -fc::optional database_api_impl::get_committee_member_by_account(account_id_type account) const +fc::optional database_api_impl::get_committee_member_by_account(const std::string account_id_or_name) const { const auto& idx = _db.get_index_type().indices().get(); + const account_id_type account = get_account_from_string(account_id_or_name)->id; auto itr = idx.find(account); if( itr != idx.end() ) return *itr; @@ -1903,9 +1972,9 @@ processed_transaction database_api_impl::validate_transaction( const signed_tran return _db.validate_transaction(trx); } -vector< fc::variant > database_api::get_required_fees( const vector& ops, asset_id_type id )const +vector< fc::variant > database_api::get_required_fees( const vector& ops, const std::string& asset_id_or_symbol )const { - return my->get_required_fees( ops, id ); + return my->get_required_fees( ops, asset_id_or_symbol ); } /** @@ -1964,7 +2033,7 @@ struct get_required_fees_helper uint32_t current_recursion = 0; }; -vector< fc::variant > database_api_impl::get_required_fees( const vector& ops, asset_id_type id )const +vector< fc::variant > database_api_impl::get_required_fees( const vector& ops, const std::string& asset_id_or_symbol )const { vector< operation > _ops = ops; // @@ -1974,7 +2043,7 @@ vector< fc::variant > database_api_impl::get_required_fees( const vector result; result.reserve(ops.size()); - const asset_object& a = id(_db); + const asset_object& a = *get_asset_from_string(asset_id_or_symbol); get_required_fees_helper helper( _db.current_fee_schedule(), a.options.core_exchange_rate, @@ -1992,16 +2061,17 @@ vector< fc::variant > database_api_impl::get_required_fees( const vector database_api::get_proposed_transactions( account_id_type id )const +vector database_api::get_proposed_transactions( const std::string account_id_or_name )const { - return my->get_proposed_transactions( id ); + return my->get_proposed_transactions( account_id_or_name ); } /** TODO: add secondary index that will accelerate this process */ -vector database_api_impl::get_proposed_transactions( account_id_type id )const +vector database_api_impl::get_proposed_transactions( const std::string account_id_or_name )const { const auto& idx = _db.get_index_type(); vector result; + const account_id_type id = get_account_from_string(account_id_or_name)->id; idx.inspect_all_objects( [&](const object& obj){ const proposal_object& p = static_cast(obj); @@ -2116,6 +2186,26 @@ vector database_api_impl::get_tournaments_by_state(tournament return result; } +const account_object* database_api_impl::get_account_from_string( const std::string& name_or_id, + bool throw_if_not_found ) const +{ + // TODO cache the result to avoid repeatly fetching from db + 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, 1).as(1)); + else + { + const auto& idx = _db.get_index_type().indices().get(); + auto itr = idx.find(name_or_id); + if (itr != idx.end()) + account = &*itr; + } + if(throw_if_not_found) + FC_ASSERT( account, "no such account" ); + return account; +} + vector database_api::get_registered_tournaments(account_id_type account_filter, uint32_t limit) const { return my->get_registered_tournaments(account_filter, limit); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index a263c4dd..d40dde6e 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -95,31 +95,32 @@ namespace graphene { namespace app { class history_api { public: - history_api(application& app):_app(app){} + history_api(application& app) + :_app(app), database_api( std::ref(*app.chain_database())) {} /** * @brief Get operations relevant to the specificed account - * @param account The account whose history should be queried + * @param account_id_or_name The account ID or name whose history should be queried * @param stop ID of the earliest operation to retrieve * @param limit Maximum number of operations to retrieve (must not exceed 100) * @param start ID of the most recent operation to retrieve * @return A list of operations performed by account, ordered from most recent to oldest. */ - vector get_account_history(account_id_type account, + vector get_account_history(const std::string account_id_or_name, operation_history_id_type stop = operation_history_id_type(), unsigned limit = 100, operation_history_id_type start = operation_history_id_type())const; /** * @brief Get only asked operations relevant to the specified account - * @param account The account whose history should be queried + * @param account_id_or_name The account ID or name whose history should be queried * @param operation_id The ID of the operation we want to get operations in the account( 0 = transfer , 1 = limit order create, ...) * @param stop ID of the earliest operation to retrieve * @param limit Maximum number of operations to retrieve (must not exceed 100) * @param start ID of the most recent operation to retrieve * @return A list of operations performed by account, ordered from most recent to oldest. */ - vector get_account_history_operations(account_id_type account, + vector get_account_history_operations(const std::string account_id_or_name, int operation_id, operation_history_id_type start = operation_history_id_type(), operation_history_id_type stop = operation_history_id_type(), @@ -129,7 +130,7 @@ namespace graphene { namespace app { * @breif Get operations relevant to the specified account referenced * by an event numbering specific to the account. The current number of operations * for the account can be found in the account statistics (or use 0 for start). - * @param account The account whose history should be queried + * @param account_id_or_name The account ID or name whose history should be queried * @param stop Sequence number of earliest operation. 0 is default and will * query 'limit' number of operations. * @param limit Maximum number of operations to retrieve (must not exceed 100) @@ -137,18 +138,19 @@ namespace graphene { namespace app { * 0 is default, which will start querying from the most recent operation. * @return A list of operations performed by account, ordered from most recent to oldest. */ - vector get_relative_account_history( account_id_type account, + vector get_relative_account_history( const std::string account_id_or_name, uint32_t stop = 0, unsigned limit = 100, uint32_t start = 0) const; - vector get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const; - vector get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, + vector get_fill_order_history( std::string asset_a, std::string asset_b, uint32_t limit )const; + vector get_market_history( std::string asset_a, std::string asset_b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const; vector list_core_accounts()const; flat_set get_market_history_buckets()const; private: application& _app; + graphene::app::database_api database_api; }; /** @@ -325,15 +327,35 @@ namespace graphene { namespace app { class asset_api { public: - asset_api(graphene::chain::database& db); + asset_api(graphene::app::application& app); ~asset_api(); - vector get_asset_holders( asset_id_type asset_id, uint32_t start, uint32_t limit )const; - int get_asset_holders_count( asset_id_type asset_id )const; + /** + * @brief Get asset holders for a specific asset + * @param asset The specific asset id or symbol + * @param start The start index + * @param limit Maximum limit must not exceed 100 + * @return A list of asset holders for the specified asset + */ + vector get_asset_holders( std::string asset, uint32_t start, uint32_t limit )const; + + /** + * @brief Get asset holders count for a specific asset + * @param asset The specific asset id or symbol + * @return Holders count for the specified asset + */ + int get_asset_holders_count( std::string asset )const; + + /** + * @brief Get all asset holders + * @return A list of all asset holders + */ vector get_all_asset_holders() const; private: + graphene::app::application& _app; graphene::chain::database& _db; + graphene::app::database_api database_api; }; /** diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index a45e617e..00f51a44 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -249,13 +249,21 @@ class database_api ////////////// /** - * @brief Get a list of accounts by ID + * @brief Get account object from a name or ID + * @param name_or_id name or ID of the account + * @return Account ID + * + */ + account_id_type get_account_id_from_string(const std::string& name_or_id)const; + + /** + * @brief Get a list of accounts by ID or Name * @param account_ids IDs of the accounts to retrieve * @return The accounts corresponding to the provided IDs * * This function has semantics identical to @ref get_objects */ - vector> get_accounts(const vector& account_ids)const; + vector> get_accounts(const vector& account_names_or_ids)const; /** * @brief Fetch all objects relevant to the specified accounts and subscribe to updates @@ -275,7 +283,7 @@ class database_api /** * @return all accounts that referr to the key or account id in their owner or active authorities. */ - vector get_account_references( account_id_type account_id )const; + vector get_account_references( const std::string account_name_or_id )const; /** * @brief Get a list of accounts by name @@ -304,7 +312,8 @@ class database_api * @param assets IDs of the assets to get balances of; if empty, get all assets account has a balance in * @return Balances of the account */ - vector get_account_balances(account_id_type id, const flat_set& assets)const; + vector get_account_balances( const std::string& account_name_or_id, + const flat_set& assets )const; /// Semantically equivalent to @ref get_account_balances, but takes a name instead of an ID. vector get_named_account_balances(const std::string& name, const flat_set& assets)const; @@ -314,7 +323,7 @@ class database_api vector get_vested_balances( const vector& objs )const; - vector get_vesting_balances( account_id_type account_id )const; + vector get_vesting_balances( const std::string account_id_or_name )const; /** * @brief Get the total number of accounts registered with the blockchain @@ -325,14 +334,21 @@ class database_api // Assets // //////////// + /** + * @brief Get asset ID from an asset symbol or ID + * @param symbol_or_id symbol name or ID of the asset + * @return asset ID + */ + asset_id_type get_asset_id_from_string(const std::string& symbol_or_id) const; + /** * @brief Get a list of assets by ID - * @param asset_ids IDs of the assets to retrieve + * @param asset_symbols_or_ids IDs or names of the assets to retrieve * @return The assets corresponding to the provided IDs * * This function has semantics identical to @ref get_objects */ - vector> get_assets(const vector& asset_ids)const; + vector> get_assets(const vector& asset_symbols_or_ids)const; /** * @brief Get assets alphabetically by symbol name @@ -434,47 +450,47 @@ class database_api * @param limit Maximum number of orders to retrieve * @return The limit orders, ordered from least price to greatest */ - vector get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const; + vector get_limit_orders(const std::string& a, const std::string& b, uint32_t limit)const; /** * @brief Get call orders in a given asset - * @param a ID of asset being called + * @param a ID or name of asset being called * @param limit Maximum number of orders to retrieve * @return The call orders, ordered from earliest to be called to latest */ - vector get_call_orders(asset_id_type a, uint32_t limit)const; + vector get_call_orders(const std::string& a, uint32_t limit)const; /** * @brief Get forced settlement orders in a given asset - * @param a ID of asset being settled + * @param a ID or name of asset being settled * @param limit Maximum number of orders to retrieve * @return The settle orders, ordered from earliest settlement date to latest */ - vector get_settle_orders(asset_id_type a, uint32_t limit)const; + vector get_settle_orders(const std::string& a, uint32_t limit)const; /** * @return all open margin positions for a given account id. */ - vector get_margin_positions( const account_id_type& id )const; + vector get_margin_positions( const std::string account_id_or_name )const; /** * @brief Request notification when the active orders in the market between two assets changes * @param callback Callback method which is called when the market changes - * @param a First asset ID - * @param b Second asset ID + * @param a First asset ID or name + * @param b Second asset ID or name * * Callback will be passed a variant containing a vector>. The vector will * contain, in order, the operations which changed the market, and their results. */ void subscribe_to_market(std::function callback, - asset_id_type a, asset_id_type b); + const std::string& a, const std::string& b); /** * @brief Unsubscribe from updates to a given market - * @param a First asset ID - * @param b Second asset ID + * @param a First asset ID or name + * @param b Second asset ID or name */ - void unsubscribe_from_market( asset_id_type a, asset_id_type b ); + void unsubscribe_from_market( const std::string& a, const std::string& b ); /** * @brief Returns the ticker for the market assetA:assetB @@ -533,7 +549,7 @@ class database_api * @param account The ID of the account whose witness should be retrieved * @return The witness object, or null if the account does not have a witness */ - fc::optional get_witness_by_account(account_id_type account)const; + fc::optional get_witness_by_account(const std::string account_name_or_id)const; /** * @brief Get names and IDs for registered witnesses @@ -563,10 +579,10 @@ class database_api /** * @brief Get the committee_member owned by a given account - * @param account The ID of the account whose committee_member should be retrieved + * @param account_id_or_name The ID or name of the account whose committee_member should be retrieved * @return The committee_member object, or null if the account does not have a committee_member */ - fc::optional get_committee_member_by_account(account_id_type account)const; + fc::optional get_committee_member_by_account(const std::string account_id_or_name)const; /** * @brief Get names and IDs for registered committee_members @@ -580,9 +596,11 @@ class database_api /// WORKERS /** - * Return the worker objects associated with this account. + * @brief Return the worker objects associated with this account. + * @param account_id_or_name The ID or name of the account whose worker should be retrieved + * @return The worker object or null if the account does not have a worker */ - vector get_workers_by_account(account_id_type account)const; + vector get_workers_by_account(const std::string account_id_or_name)const; /////////// @@ -639,7 +657,7 @@ class database_api * For each operation calculate the required fee in the specified asset type. If the asset type does * not have a valid core_exchange_rate */ - vector< fc::variant > get_required_fees( const vector& ops, asset_id_type id )const; + vector< fc::variant > get_required_fees( const vector& ops, const std::string& asset_id_or_symbol )const; /////////////////////////// // Proposed transactions // @@ -648,7 +666,7 @@ class database_api /** * @return the set of proposed transactions relevant to the specified account id. */ - vector get_proposed_transactions( account_id_type id )const; + vector get_proposed_transactions( const std::string account_id_or_name )const; ////////////////////// // Blinded balances // @@ -734,6 +752,7 @@ FC_API(graphene::app::database_api, (is_public_key_registered) // Accounts + (get_account_id_from_string) (get_accounts) (get_full_accounts) (get_account_by_name) @@ -754,6 +773,7 @@ FC_API(graphene::app::database_api, (list_assets) (lookup_asset_symbols) (get_asset_count) + (get_asset_id_from_string) // Peerplays (list_sports) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 78fcb82a..27eac237 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -355,7 +355,8 @@ private: for( const fc::optional& optional_account : owner_account_objects ) if (optional_account) { - fc::optional witness_obj = _remote_db->get_witness_by_account(optional_account->id); + std::string account_id = account_id_to_string(optional_account->id); + fc::optional witness_obj = _remote_db->get_witness_by_account(account_id); if (witness_obj) claim_registered_witness(optional_account->name); } @@ -729,9 +730,17 @@ public: { return _remote_db->get_dynamic_global_properties(); } + std::string account_id_to_string(account_id_type id) const + { + std::string account_id = fc::to_string(id.space_id) + + "." + fc::to_string(id.type_id) + + "." + fc::to_string(id.instance.value); + return account_id; + } account_object get_account(account_id_type id) const { - auto rec = _remote_db->get_accounts({id}).front(); + std::string account_id = account_id_to_string(id); + auto rec = _remote_db->get_accounts({account_id}).front(); FC_ASSERT(rec); return *rec; } @@ -753,9 +762,16 @@ public: { return get_account(account_name_or_id).get_id(); } + std::string asset_id_to_string(asset_id_type id) const + { + std::string asset_id = fc::to_string(id.space_id) + + "." + fc::to_string(id.type_id) + + "." + fc::to_string(id.instance.value); + return asset_id; + } optional find_asset(asset_id_type id)const { - auto rec = _remote_db->get_assets({id}).front(); + auto rec = _remote_db->get_assets({asset_id_to_string(id)}).front(); if( rec ) _asset_cache[id] = *rec; return rec; @@ -1018,7 +1034,7 @@ public: ("chain_id", _chain_id) ); size_t account_pagination = 100; - vector< account_id_type > account_ids_to_send; + vector< std::string > account_ids_to_send; size_t n = _wallet.my_accounts.size(); account_ids_to_send.reserve( std::min( account_pagination, n ) ); auto it = _wallet.my_accounts.begin(); @@ -1033,7 +1049,8 @@ public: { assert( it != _wallet.my_accounts.end() ); old_accounts.push_back( *it ); - account_ids_to_send.push_back( old_accounts.back().id ); + std::string account_id = account_id_to_string(old_accounts.back().id); + account_ids_to_send.push_back( account_id ); ++it; } std::vector< optional< account_object > > accounts = _remote_db->get_accounts(account_ids_to_send); @@ -1733,7 +1750,7 @@ public: committee_member_create_operation committee_member_create_op; committee_member_create_op.committee_member_account = get_account_id(owner_account); committee_member_create_op.url = url; - if (_remote_db->get_committee_member_by_account(committee_member_create_op.committee_member_account)) + if (_remote_db->get_committee_member_by_account(owner_account)) FC_THROW("Account ${owner_account} is already a committee_member", ("owner_account", owner_account)); signed_transaction tx; @@ -1763,7 +1780,7 @@ public: // then maybe it's the owner account try { - account_id_type owner_account_id = get_account_id(owner_account); + std::string owner_account_id = account_id_to_string(get_account_id(owner_account)); fc::optional witness = _remote_db->get_witness_by_account(owner_account_id); if (witness) return *witness; @@ -1799,7 +1816,7 @@ public: // then maybe it's the owner account try { - account_id_type owner_account_id = get_account_id(owner_account); + std::string owner_account_id = account_id_to_string(get_account_id(owner_account)); fc::optional witness = _remote_db->get_witness_by_account(owner_account_id); if (witness) return true; @@ -1834,8 +1851,7 @@ public: // then maybe it's the owner account try { - account_id_type owner_account_id = get_account_id(owner_account); - fc::optional committee_member = _remote_db->get_committee_member_by_account(owner_account_id); + fc::optional committee_member = _remote_db->get_committee_member_by_account(owner_account); if (committee_member) return *committee_member; else @@ -1871,7 +1887,7 @@ public: witness_create_op.initial_secret = enc.result(); - if (_remote_db->get_witness_by_account(witness_create_op.witness_account)) + if (_remote_db->get_witness_by_account(account_id_to_string(witness_create_op.witness_account))) FC_THROW("Account ${owner_account} is already a witness", ("owner_account", owner_account)); signed_transaction tx; @@ -2037,12 +2053,7 @@ public: return result; } - // try casting to avoid a round-trip if we were given an account ID - fc::optional acct_id = maybe_id( account_name ); - if( !acct_id ) - acct_id = get_account( account_name ).id; - - vector< vesting_balance_object > vbos = _remote_db->get_vesting_balances( *acct_id ); + vector< vesting_balance_object > vbos = _remote_db->get_vesting_balances( account_name ); if( vbos.size() == 0 ) return result; @@ -2110,12 +2121,7 @@ public: fc::optional vbid = maybe_id(account_name); if( !vbid ) { - //Changes done to retrive user account/witness account based on account name - fc::optional acct_id = maybe_id( account_name ); - if( !acct_id ) - acct_id = get_account( account_name ).id; - - vbos = _remote_db->get_vesting_balances( *acct_id ); + vbos = _remote_db->get_vesting_balances( account_name ); if( vbos.size() == 0 ) FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); } @@ -2188,8 +2194,7 @@ public: } account_object voting_account_object = get_account(voting_account); - account_id_type committee_member_owner_account_id = get_account_id(committee_member); - fc::optional committee_member_obj = _remote_db->get_committee_member_by_account(committee_member_owner_account_id); + fc::optional committee_member_obj = _remote_db->get_committee_member_by_account(committee_member); if (!committee_member_obj) FC_THROW("Account ${committee_member} is not registered as a committee_member", ("committee_member", committee_member)); @@ -2253,9 +2258,8 @@ public: } account_object voting_account_object = get_account(voting_account); - account_id_type witness_owner_account_id = get_account_id(witness); - fc::optional witness_obj = _remote_db->get_witness_by_account(witness_owner_account_id); + fc::optional witness_obj = _remote_db->get_witness_by_account(witness); if (!witness_obj) FC_THROW("Account ${witness} is not registered as a witness", ("witness", witness)); @@ -2311,8 +2315,7 @@ public: account_object voting_account_object = get_account(voting_account); for (const std::string& witness : witnesses_to_approve) { - account_id_type witness_owner_account_id = get_account_id(witness); - fc::optional witness_obj = _remote_db->get_witness_by_account(witness_owner_account_id); + fc::optional witness_obj = _remote_db->get_witness_by_account(witness); if (!witness_obj) FC_THROW("Account ${witness} is not registered as a witness", ("witness", witness)); auto insert_result = voting_account_object.options.votes.insert(witness_obj->vote_id); @@ -2321,8 +2324,7 @@ public: } for (const std::string& witness : witnesses_to_reject) { - account_id_type witness_owner_account_id = get_account_id(witness); - fc::optional witness_obj = _remote_db->get_witness_by_account(witness_owner_account_id); + fc::optional witness_obj = _remote_db->get_witness_by_account(witness); if (!witness_obj) FC_THROW("Account ${witness} is not registered as a witness", ("witness", witness)); unsigned votes_removed = voting_account_object.options.votes.erase(witness_obj->vote_id); @@ -3706,8 +3708,8 @@ map wallet_api::list_accounts(const string& lowerbound, vector wallet_api::list_account_balances(const string& id) { if( auto real_id = detail::maybe_id(id) ) - return my->_remote_db->get_account_balances(*real_id, flat_set()); - return my->_remote_db->get_account_balances(get_account(id).id, flat_set()); + return my->_remote_db->get_account_balances(id, flat_set()); + return my->_remote_db->get_account_balances(id, flat_set()); } vector wallet_api::list_assets(const string& lowerbound, uint32_t limit)const @@ -3743,8 +3745,7 @@ asset wallet_api::get_lottery_balance( asset_id_type lottery_id )const vector wallet_api::get_account_history(string name, int limit) const { vector result; - auto account_id = get_account(name).get_id(); - + while (limit > 0) { bool skip_first_row = false; @@ -3764,7 +3765,7 @@ vector wallet_api::get_account_history(string name, int limit) int page_limit = skip_first_row ? std::min(100, limit + 1) : std::min(100, limit); - vector current = my->_remote_hist->get_account_history(account_id, operation_history_id_type(), + vector current = my->_remote_hist->get_account_history(name, operation_history_id_type(), page_limit, start); bool first_row = true; for (auto &o : current) @@ -3799,11 +3800,10 @@ vector wallet_api::get_relative_account_history(string name, u FC_ASSERT( start > 0 || limit <= 100 ); vector result; - auto account_id = get_account(name).get_id(); while( limit > 0 ) { - vector current = my->_remote_hist->get_relative_account_history(account_id, stop, std::min(100, limit), start); + vector current = my->_remote_hist->get_relative_account_history(name, stop, std::min(100, limit), start); for (auto &o : current) { std::stringstream ss; auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); @@ -3824,22 +3824,22 @@ vector wallet_api::list_core_accounts()const vector wallet_api::get_market_history( string symbol1, string symbol2, uint32_t bucket , fc::time_point_sec start, fc::time_point_sec end )const { - return my->_remote_hist->get_market_history( get_asset_id(symbol1), get_asset_id(symbol2), bucket, start, end ); + return my->_remote_hist->get_market_history( symbol1, symbol2, bucket, start, end ); } vector wallet_api::get_limit_orders(string a, string b, uint32_t limit)const { - return my->_remote_db->get_limit_orders(get_asset(a).id, get_asset(b).id, limit); + return my->_remote_db->get_limit_orders(a, b, limit); } vector wallet_api::get_call_orders(string a, uint32_t limit)const { - return my->_remote_db->get_call_orders(get_asset(a).id, limit); + return my->_remote_db->get_call_orders(a, limit); } vector wallet_api::get_settle_orders(string a, uint32_t limit)const { - return my->_remote_db->get_settle_orders(get_asset(a).id, limit); + return my->_remote_db->get_settle_orders(a, limit); } brain_key_info wallet_api::suggest_brain_key()const diff --git a/tests/tests/history_api_tests.cpp b/tests/tests/history_api_tests.cpp index fcaeef5b..4edccce5 100644 --- a/tests/tests/history_api_tests.cpp +++ b/tests/tests/history_api_tests.cpp @@ -55,25 +55,25 @@ BOOST_AUTO_TEST_CASE(get_account_history) { int account_create_op_id = operation::tag::value; //account_id_type() did 3 ops and includes id0 - vector histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 100, operation_history_id_type()); + vector histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 100, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[2].op.which(), asset_create_op_id); // 1 account_create op larger than id1 - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 100, operation_history_id_type()); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 100, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK(histories[0].id.instance() != 0); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); // Limit 2 returns 2 result - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 2, operation_history_id_type()); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 2, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK(histories[1].id.instance() != 0); BOOST_CHECK_EQUAL(histories[1].op.which(), account_create_op_id); // bob has 1 op - histories = hist_api.get_account_history(bob_acc.get_id(), operation_history_id_type(), 100, operation_history_id_type()); + histories = hist_api.get_account_history("bob", operation_history_id_type(), 100, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); } FC_LOG_AND_RETHROW() @@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(zero_id_object) { graphene::app::history_api hist_api(app); // no history at all in the chain - vector histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 4, operation_history_id_type(0)); + vector histories = hist_api.get_account_history("committee-account", operation_history_id_type(0), 4, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); create_bitasset("USD", account_id_type()); // create op 0 @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(zero_id_object) { fc::usleep(fc::milliseconds(2000)); // what if the account only has one history entry and it is 0? - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type()); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); } FC_LOG_AND_RETHROW() @@ -107,13 +107,13 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { // account_id_type() and dan share operation id 1(account create) - share can be also in id 0 // no history at all in the chain - vector histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 4, operation_history_id_type(0)); + vector histories = hist_api.get_account_history("committee-account", operation_history_id_type(0), 4, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); create_bitasset("USD", account_id_type()); // create op 0 generate_block(); // what if the account only has one history entry and it is 0? - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type()); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { generate_block(); // f(A, 0, 4, 9) = { 5, 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type(9)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type(9)); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); // f(A, 0, 4, 6) = { 5, 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type(6)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type(6)); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); @@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); // f(A, 0, 4, 5) = { 5, 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type(5)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type(5)); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); @@ -152,33 +152,33 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); // f(A, 0, 4, 4) = { 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type(4)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type(4)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 4, 3) = { 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type(3)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type(3)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 4, 2) = { 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type(2)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 4, 1) = { 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type(1)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type(1)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 4, 0) = { 5, 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 4, operation_history_id_type()); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 4, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); @@ -186,103 +186,103 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); // f(A, 1, 5, 9) = { 5, 3 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(9)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(9)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 6) = { 5, 3 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(6)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(6)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 5) = { 5, 3 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(5)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(5)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 4) = { 3 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(4)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(4)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); // f(A, 1, 5, 3) = { 3 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(3)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(3)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); // f(A, 1, 5, 2) = { } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(2)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 0u); // f(A, 1, 5, 1) = { } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(1)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(1)); BOOST_CHECK_EQUAL(histories.size(), 0u); // f(A, 1, 5, 0) = { 5, 3 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 5, operation_history_id_type(0)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 5, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 0, 3, 9) = { 5, 3, 1 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type(9)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type(9)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 6) = { 5, 3, 1 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type(6)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type(6)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 5) = { 5, 3, 1 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type(5)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type(5)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 4) = { 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type(4)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type(4)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 3, 3) = { 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type(3)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type(3)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 3, 2) = { 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type(2)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 3, 1) = { 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type(1)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type(1)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 3, 0) = { 5, 3, 1 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 3, operation_history_id_type()); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(), 3, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 9) = { 6, 4, 2, 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type(9)); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(9)); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); @@ -290,7 +290,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 1u); // f(B, 0, 4, 6) = { 6, 4, 2, 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type(6)); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(6)); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); @@ -298,38 +298,38 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 1u); // f(B, 0, 4, 5) = { 4, 2, 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type(5)); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(5)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 4) = { 4, 2, 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type(4)); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(4)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 3) = { 2, 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type(3)); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(3)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); // f(B, 0, 4, 2) = { 2, 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type(2)); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); // f(B, 0, 4, 1) = { 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type(1)); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(1)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); // f(B, 0, 4, 0) = { 6, 4, 2, 1 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(), 4, operation_history_id_type()); + histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); @@ -337,49 +337,49 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 1u); // f(B, 2, 4, 9) = { 6, 4 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(9)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(9)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); // f(B, 2, 4, 6) = { 6, 4 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(6)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(6)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); // f(B, 2, 4, 5) = { 4 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(5)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(5)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); // f(B, 2, 4, 4) = { 4 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(4)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(4)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); // f(B, 2, 4, 3) = { } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(3)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(3)); BOOST_CHECK_EQUAL(histories.size(), 0u); // f(B, 2, 4, 2) = { } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(2)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 0u); // f(B, 2, 4, 1) = { } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(1)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(1)); BOOST_CHECK_EQUAL(histories.size(), 0u); // f(B, 2, 4, 0) = { 6, 4 } - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(2), 4, operation_history_id_type(0)); + histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); // 0 limits - histories = hist_api.get_account_history(dan.get_id(), operation_history_id_type(0), 0, operation_history_id_type(0)); + histories = hist_api.get_account_history("dan", operation_history_id_type(0), 0, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(3), 0, operation_history_id_type(9)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(3), 0, operation_history_id_type(9)); BOOST_CHECK_EQUAL(histories.size(), 0u); // create a new account C = alice { 7 } @@ -388,16 +388,16 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { generate_block(); // f(C, 0, 4, 10) = { 7 } - histories = hist_api.get_account_history(alice.get_id(), operation_history_id_type(0), 4, operation_history_id_type(10)); + histories = hist_api.get_account_history("alice", operation_history_id_type(0), 4, operation_history_id_type(10)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); // f(C, 8, 4, 10) = { } - histories = hist_api.get_account_history(alice.get_id(), operation_history_id_type(8), 4, operation_history_id_type(10)); + histories = hist_api.get_account_history("alice", operation_history_id_type(8), 4, operation_history_id_type(10)); BOOST_CHECK_EQUAL(histories.size(), 0u); // f(A, 0, 10, 0) = { 7, 5, 3, 1, 0 } - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 5u); @@ -432,23 +432,23 @@ BOOST_AUTO_TEST_CASE(track_account) { // anything against account_id_type() should be {} vector histories = - hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 10, operation_history_id_type(0)); + hist_api.get_account_history("committee-account", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(1), 1, operation_history_id_type(2)); + histories = hist_api.get_account_history("committee-account", operation_history_id_type(1), 1, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 0u); // anything against alice should be {} - histories = hist_api.get_account_history(alice_id, operation_history_id_type(0), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("alice", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - histories = hist_api.get_account_history(alice_id, operation_history_id_type(1), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("alice", operation_history_id_type(1), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - histories = hist_api.get_account_history(alice_id, operation_history_id_type(1), 1, operation_history_id_type(2)); + histories = hist_api.get_account_history("alice", operation_history_id_type(1), 1, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 0u); // dan should have history - histories = hist_api.get_account_history(dan_id, operation_history_id_type(0), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("dan", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); @@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(track_account) { generate_block( ~database::skip_fork_db ); - histories = hist_api.get_account_history(dan_id, operation_history_id_type(0), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("dan", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); @@ -473,7 +473,7 @@ BOOST_AUTO_TEST_CASE(track_account) { generate_block(); - histories = hist_api.get_account_history(dan_id, operation_history_id_type(0), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("dan", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); @@ -508,7 +508,7 @@ BOOST_AUTO_TEST_CASE(track_account2) { generate_block(); // all account_id_type() should have 4 ops {4,2,1,0} - vector histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 10, operation_history_id_type(0)); + vector histories = hist_api.get_account_history("committee-account", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); @@ -516,27 +516,27 @@ BOOST_AUTO_TEST_CASE(track_account2) { BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); // all alice account should have 2 ops {3, 0} - histories = hist_api.get_account_history(alice_id, operation_history_id_type(0), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("alice", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // alice first op should be {0} - histories = hist_api.get_account_history(alice_id, operation_history_id_type(0), 1, operation_history_id_type(1)); + histories = hist_api.get_account_history("alice", operation_history_id_type(0), 1, operation_history_id_type(1)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); // alice second op should be {3} - histories = hist_api.get_account_history(alice_id, operation_history_id_type(1), 1, operation_history_id_type(0)); + histories = hist_api.get_account_history("alice", operation_history_id_type(1), 1, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); // anything against dan should be {} - histories = hist_api.get_account_history(dan_id, operation_history_id_type(0), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("dan", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - histories = hist_api.get_account_history(dan_id, operation_history_id_type(1), 10, operation_history_id_type(0)); + histories = hist_api.get_account_history("dan", operation_history_id_type(1), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - histories = hist_api.get_account_history(dan_id, operation_history_id_type(1), 1, operation_history_id_type(2)); + histories = hist_api.get_account_history("dan", operation_history_id_type(1), 1, operation_history_id_type(2)); BOOST_CHECK_EQUAL(histories.size(), 0u); } catch (fc::exception &e) { @@ -553,7 +553,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_operations) { int account_create_op_id = operation::tag::value; // no asset_create operation on account_id_type() should not throw any exception - vector histories = hist_api.get_account_history_operations(account_id_type(), asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); + vector histories = hist_api.get_account_history_operations("committee-account", asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); BOOST_CHECK_EQUAL(histories.size(), 0u); //account_id_type() do 3 ops @@ -565,27 +565,27 @@ BOOST_AUTO_TEST_CASE(get_account_history_operations) { fc::usleep(fc::milliseconds(2000)); //account_id_type() did 1 asset_create op - histories = hist_api.get_account_history_operations(account_id_type(), asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); + histories = hist_api.get_account_history_operations("committee-account", asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[0].op.which(), asset_create_op_id); //account_id_type() did 2 account_create ops - histories = hist_api.get_account_history_operations(account_id_type(), account_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); + histories = hist_api.get_account_history_operations("committee-account", account_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); // No asset_create op larger than id1 - histories = hist_api.get_account_history_operations(account_id_type(), asset_create_op_id, operation_history_id_type(), operation_history_id_type(1), 100); + histories = hist_api.get_account_history_operations("committee-account", asset_create_op_id, operation_history_id_type(), operation_history_id_type(1), 100); BOOST_CHECK_EQUAL(histories.size(), 0u); // Limit 1 returns 1 result - histories = hist_api.get_account_history_operations(account_id_type(), account_create_op_id, operation_history_id_type(),operation_history_id_type(), 1); + histories = hist_api.get_account_history_operations("committee-account", account_create_op_id, operation_history_id_type(),operation_history_id_type(), 1); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); // alice has 1 op - histories = hist_api.get_account_history_operations(get_account("alice").id, account_create_op_id, operation_history_id_type(),operation_history_id_type(), 100); + histories = hist_api.get_account_history_operations("alice", account_create_op_id, operation_history_id_type(),operation_history_id_type(), 100); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); diff --git a/tests/tests/voting_tests.cpp b/tests/tests/voting_tests.cpp index 71c5e935..79f80e1f 100644 --- a/tests/tests/voting_tests.cpp +++ b/tests/tests/voting_tests.cpp @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(track_votes_witnesses_enabled) INVOKE(put_my_witnesses); const account_id_type witness1_id= get_account("witness1").id; - auto witness1_object = db_api1.get_witness_by_account(witness1_id); + auto witness1_object = db_api1.get_witness_by_account(witness1_id(db).name); BOOST_CHECK_EQUAL(witness1_object->total_votes, 111); } FC_LOG_AND_RETHROW() @@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(track_votes_witnesses_disabled) INVOKE(put_my_witnesses); const account_id_type witness1_id= get_account("witness1").id; - auto witness1_object = db_api1.get_witness_by_account(witness1_id); + auto witness1_object = db_api1.get_witness_by_account(witness1_id(db).name); BOOST_CHECK_EQUAL(witness1_object->total_votes, 0); } FC_LOG_AND_RETHROW() @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE(track_votes_committee_enabled) INVOKE(put_my_committee_members); const account_id_type committee1_id= get_account("committee1").id; - auto committee1_object = db_api1.get_committee_member_by_account(committee1_id); + auto committee1_object = db_api1.get_committee_member_by_account(committee1_id(db).name); BOOST_CHECK_EQUAL(committee1_object->total_votes, 111); } FC_LOG_AND_RETHROW() @@ -513,7 +513,7 @@ BOOST_AUTO_TEST_CASE(track_votes_committee_disabled) INVOKE(put_my_committee_members); const account_id_type committee1_id= get_account("committee1").id; - auto committee1_object = db_api1.get_committee_member_by_account(committee1_id); + auto committee1_object = db_api1.get_committee_member_by_account(committee1_id(db).name); BOOST_CHECK_EQUAL(committee1_object->total_votes, 0); } FC_LOG_AND_RETHROW()