Merge pull request #225 from peerplays-network/feature/GRPH-152

[GRPH-152] Allow APIs to be called by account/asset name and id
This commit is contained in:
Alfredo Garcia 2019-11-28 15:29:12 -03:00 committed by GitHub
commit 6f0ce36292
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 409 additions and 258 deletions

View file

@ -103,7 +103,7 @@ namespace graphene { namespace app {
} }
else if( api_name == "asset_api" ) 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" ) else if( api_name == "debug_api" )
{ {
@ -526,10 +526,12 @@ namespace graphene { namespace app {
} // end get_relevant_accounts( obj ) } // end get_relevant_accounts( obj )
#endif #endif
vector<order_history_object> history_api::get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const vector<order_history_object> history_api::get_fill_order_history( std::string asset_a, std::string asset_b, uint32_t limit )const
{ {
FC_ASSERT(_app.chain_database()); FC_ASSERT(_app.chain_database());
const auto& db = *_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); if( a > b ) std::swap(a,b);
const auto& history_idx = db.get_index_type<graphene::market_history::history_index>().indices().get<by_key>(); const auto& history_idx = db.get_index_type<graphene::market_history::history_index>().indices().get<by_key>();
history_key hkey; history_key hkey;
@ -551,7 +553,7 @@ namespace graphene { namespace app {
return result; return result;
} }
vector<operation_history_object> history_api::get_account_history( account_id_type account, vector<operation_history_object> history_api::get_account_history( const std::string account_id_or_name,
operation_history_id_type stop, operation_history_id_type stop,
unsigned limit, unsigned limit,
operation_history_id_type start ) const operation_history_id_type start ) const
@ -560,7 +562,9 @@ namespace graphene { namespace app {
const auto& db = *_app.chain_database(); const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 ); FC_ASSERT( limit <= 100 );
vector<operation_history_object> result; vector<operation_history_object> result;
account_id_type account;
try { 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); 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) if(start == operation_history_id_type() || start.instance.value > node.operation_id.instance.value)
start = node.operation_id; start = node.operation_id;
@ -584,7 +588,7 @@ namespace graphene { namespace app {
return result; return result;
} }
vector<operation_history_object> history_api::get_account_history_operations( account_id_type account, vector<operation_history_object> history_api::get_account_history_operations( const std::string account_id_or_name,
int operation_id, int operation_id,
operation_history_id_type start, operation_history_id_type start,
operation_history_id_type stop, operation_history_id_type stop,
@ -594,6 +598,11 @@ namespace graphene { namespace app {
const auto& db = *_app.chain_database(); const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 ); FC_ASSERT( limit <= 100 );
vector<operation_history_object> result; vector<operation_history_object> 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); const auto& stats = account(db).statistics(db);
if( stats.most_recent_op == account_transaction_history_id_type() ) return result; if( stats.most_recent_op == account_transaction_history_id_type() ) return result;
const account_transaction_history_object* node = &stats.most_recent_op(db); const account_transaction_history_object* node = &stats.most_recent_op(db);
@ -620,7 +629,7 @@ namespace graphene { namespace app {
} }
vector<operation_history_object> history_api::get_relative_account_history( account_id_type account, vector<operation_history_object> history_api::get_relative_account_history( const std::string account_id_or_name,
uint32_t stop, uint32_t stop,
unsigned limit, unsigned limit,
uint32_t start) const uint32_t start) const
@ -629,6 +638,10 @@ namespace graphene { namespace app {
const auto& db = *_app.chain_database(); const auto& db = *_app.chain_database();
FC_ASSERT(limit <= 100); FC_ASSERT(limit <= 100);
vector<operation_history_object> result; vector<operation_history_object> 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); const auto& stats = account(db).statistics(db);
if( start == 0 ) if( start == 0 )
start = stats.total_ops; start = stats.total_ops;
@ -668,11 +681,13 @@ namespace graphene { namespace app {
return hist->tracked_buckets(); return hist->tracked_buckets();
} }
vector<bucket_object> history_api::get_market_history( asset_id_type a, asset_id_type b, vector<bucket_object> 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 uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const
{ try { { try {
FC_ASSERT(_app.chain_database()); FC_ASSERT(_app.chain_database());
const auto& db = *_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<bucket_object> result; vector<bucket_object> result;
result.reserve(200); result.reserve(200);
@ -692,7 +707,7 @@ namespace graphene { namespace app {
++itr; ++itr;
} }
return result; 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(){}; crypto_api::crypto_api(){};
@ -751,12 +766,16 @@ namespace graphene { namespace app {
} }
// asset_api // 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() { } asset_api::~asset_api() { }
vector<account_asset_balance> asset_api::get_asset_holders( asset_id_type asset_id, uint32_t start, uint32_t limit ) const { vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const {
FC_ASSERT(limit <= 100); 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 >(); 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 ) ); auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
@ -787,11 +806,11 @@ namespace graphene { namespace app {
return result; return result;
} }
// get number of asset holders. // 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 >(); 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 ) ); auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
int count = boost::distance(range) - 1; int count = boost::distance(range) - 1;
return count; return count;

View file

@ -81,23 +81,26 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
bool is_public_key_registered(string public_key) const; bool is_public_key_registered(string public_key) const;
// Accounts // Accounts
vector<optional<account_object>> get_accounts(const vector<account_id_type>& account_ids)const; account_id_type get_account_id_from_string(const std::string& name_or_id)const;
vector<optional<account_object>> get_accounts(const vector<std::string>& account_names_or_ids)const;
std::map<string,full_account> get_full_accounts( const vector<string>& names_or_ids, bool subscribe ); std::map<string,full_account> get_full_accounts( const vector<string>& names_or_ids, bool subscribe );
optional<account_object> get_account_by_name( string name )const; optional<account_object> get_account_by_name( string name )const;
vector<account_id_type> get_account_references( account_id_type account_id )const; vector<account_id_type> get_account_references( const std::string account_id_or_name )const;
vector<optional<account_object>> lookup_account_names(const vector<string>& account_names)const; vector<optional<account_object>> lookup_account_names(const vector<string>& account_names)const;
map<string,account_id_type> lookup_accounts(const string& lower_bound_name, uint32_t limit)const; map<string,account_id_type> lookup_accounts(const string& lower_bound_name, uint32_t limit)const;
uint64_t get_account_count()const; uint64_t get_account_count()const;
// Balances // Balances
vector<asset> get_account_balances(account_id_type id, const flat_set<asset_id_type>& assets)const; vector<asset> get_account_balances(const std::string& account_name_or_id, const flat_set<asset_id_type>& assets)const;
vector<asset> get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets)const;
vector<balance_object> get_balance_objects( const vector<address>& addrs )const; vector<balance_object> get_balance_objects( const vector<address>& addrs )const;
vector<asset> get_vested_balances( const vector<balance_id_type>& objs )const; vector<asset> get_vested_balances( const vector<balance_id_type>& objs )const;
vector<vesting_balance_object> get_vesting_balances( account_id_type account_id )const; vector<vesting_balance_object> get_vesting_balances( const std::string account_id_or_name )const;
// Assets // Assets
vector<optional<asset_object>> get_assets(const vector<asset_id_type>& asset_ids)const; asset_id_type get_asset_id_from_string(const std::string& symbol_or_id)const;
vector<optional<asset_object>> get_assets(const vector<std::string>& asset_symbols_or_ids)const;
// helper function
vector<optional<asset_object>> get_assets( const vector<asset_id_type>& asset_ids )const;
vector<asset_object> list_assets(const string& lower_bound_symbol, uint32_t limit)const; vector<asset_object> list_assets(const string& lower_bound_symbol, uint32_t limit)const;
vector<optional<asset_object>> lookup_asset_symbols(const vector<string>& symbols_or_ids)const; vector<optional<asset_object>> lookup_asset_symbols(const vector<string>& symbols_or_ids)const;
uint64_t get_asset_count()const; uint64_t get_asset_count()const;
@ -124,12 +127,13 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
asset get_sweeps_vesting_balance_available_for_claim( account_id_type account )const; asset get_sweeps_vesting_balance_available_for_claim( account_id_type account )const;
// Markets / feeds // Markets / feeds
vector<limit_order_object> get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const; vector<limit_order_object> get_limit_orders( const asset_id_type a, const asset_id_type b, const uint32_t limit )const;
vector<call_order_object> get_call_orders(asset_id_type a, uint32_t limit)const; vector<limit_order_object> get_limit_orders( const std::string& a, const std::string& b, const uint32_t limit)const;
vector<force_settlement_object> get_settle_orders(asset_id_type a, uint32_t limit)const; vector<call_order_object> get_call_orders(const std::string& a, uint32_t limit)const;
vector<call_order_object> get_margin_positions( const account_id_type& id )const; vector<force_settlement_object> get_settle_orders(const std::string& a, uint32_t limit)const;
void subscribe_to_market(std::function<void(const variant&)> callback, asset_id_type a, asset_id_type b); vector<call_order_object> get_margin_positions( const std::string account_id_or_name )const;
void unsubscribe_from_market(asset_id_type a, asset_id_type b); void subscribe_to_market(std::function<void(const variant&)> 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_ticker get_ticker( const string& base, const string& quote )const;
market_volume get_24_volume( 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; 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<database_api_impl>
// Witnesses // Witnesses
vector<optional<witness_object>> get_witnesses(const vector<witness_id_type>& witness_ids)const; vector<optional<witness_object>> get_witnesses(const vector<witness_id_type>& witness_ids)const;
fc::optional<witness_object> get_witness_by_account(account_id_type account)const; fc::optional<witness_object> get_witness_by_account(const std::string account_id_or_name)const;
map<string, witness_id_type> lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const; map<string, witness_id_type> lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const;
uint64_t get_witness_count()const; uint64_t get_witness_count()const;
// Committee members // Committee members
vector<optional<committee_member_object>> get_committee_members(const vector<committee_member_id_type>& committee_member_ids)const; vector<optional<committee_member_object>> get_committee_members(const vector<committee_member_id_type>& committee_member_ids)const;
fc::optional<committee_member_object> get_committee_member_by_account(account_id_type account)const; fc::optional<committee_member_object> get_committee_member_by_account(const std::string account_id_or_name)const;
map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const; map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const;
// Votes // Votes
@ -157,10 +161,10 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
bool verify_authority( const signed_transaction& trx )const; bool verify_authority( const signed_transaction& trx )const;
bool verify_account_authority( const string& name_or_id, const flat_set<public_key_type>& signers )const; bool verify_account_authority( const string& name_or_id, const flat_set<public_key_type>& signers )const;
processed_transaction validate_transaction( const signed_transaction& trx )const; processed_transaction validate_transaction( const signed_transaction& trx )const;
vector< fc::variant > get_required_fees( const vector<operation>& ops, asset_id_type id )const; vector< fc::variant > get_required_fees( const vector<operation>& ops, const std::string& asset_id_or_symbol )const;
// Proposed transactions // Proposed transactions
vector<proposal_object> get_proposed_transactions( account_id_type id )const; vector<proposal_object> get_proposed_transactions( const std::string account_id_or_name )const;
// Blinded balances // Blinded balances
vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const; vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;
@ -175,6 +179,10 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
gpos_info get_gpos_info(const account_id_type account) const; gpos_info get_gpos_info(const account_id_type account) const;
//private: //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<typename T> template<typename T>
void subscribe_to_item( const T& i )const 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<optional<account_object>> database_api::get_accounts(const vector<account_id_type>& 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<optional<account_object>> database_api_impl::get_accounts(const vector<account_id_type>& account_ids)const vector<optional<account_object>> database_api::get_accounts(const vector<std::string>& account_names_or_ids)const
{ {
vector<optional<account_object>> result; result.reserve(account_ids.size()); return my->get_accounts( account_names_or_ids );
std::transform(account_ids.begin(), account_ids.end(), std::back_inserter(result), }
[this](account_id_type id) -> optional<account_object> {
if(auto o = _db.find(id)) vector<optional<account_object>> database_api_impl::get_accounts(const vector<std::string>& account_names_or_ids)const
{ {
subscribe_to_item( id ); vector<optional<account_object>> result; result.reserve(account_names_or_ids.size());
return *o; std::transform(account_names_or_ids.begin(), account_names_or_ids.end(), std::back_inserter(result),
} [this](std::string id_or_name) -> optional<account_object> {
return {}; 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; return result;
} }
@ -758,16 +771,17 @@ optional<account_object> database_api_impl::get_account_by_name( string name )co
return optional<account_object>(); return optional<account_object>();
} }
vector<account_id_type> database_api::get_account_references( account_id_type account_id )const vector<account_id_type> 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<account_id_type> database_api_impl::get_account_references( account_id_type account_id )const vector<account_id_type> database_api_impl::get_account_references( const std::string account_id_or_name )const
{ {
const auto& idx = _db.get_index_type<account_index>(); const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const base_primary_index&>(idx); const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>(); const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_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); auto itr = refs.account_to_account_memberships.find(account_id);
vector<account_id_type> result; vector<account_id_type> result;
@ -836,13 +850,16 @@ uint64_t database_api_impl::get_account_count()const
// // // //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
vector<asset> database_api::get_account_balances(account_id_type id, const flat_set<asset_id_type>& assets)const vector<asset> database_api::get_account_balances(const std::string& account_name_or_id, const flat_set<asset_id_type>& assets)const
{ {
return my->get_account_balances( id, assets ); return my->get_account_balances( account_name_or_id, assets );
} }
vector<asset> database_api_impl::get_account_balances(account_id_type acnt, const flat_set<asset_id_type>& assets)const vector<asset> database_api_impl::get_account_balances( const std::string& account_name_or_id,
const flat_set<asset_id_type>& assets)const
{ {
const account_object* account = get_account_from_string(account_name_or_id);
account_id_type acnt = account->id;
vector<asset> result; vector<asset> result;
if (assets.empty()) if (assets.empty())
{ {
@ -865,15 +882,7 @@ vector<asset> database_api_impl::get_account_balances(account_id_type acnt, cons
vector<asset> database_api::get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets)const vector<asset> database_api::get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets)const
{ {
return my->get_named_account_balances( name, assets ); return my->get_account_balances( name, assets );
}
vector<asset> database_api_impl::get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets) const
{
const auto& accounts_by_name = _db.get_index_type<account_index>().indices().get<by_name>();
auto itr = accounts_by_name.find(name);
FC_ASSERT( itr != accounts_by_name.end() );
return get_account_balances(itr->get_id(), assets);
} }
vector<balance_object> database_api::get_balance_objects( const vector<address>& addrs )const vector<balance_object> database_api::get_balance_objects( const vector<address>& addrs )const
@ -923,15 +932,16 @@ vector<asset> database_api_impl::get_vested_balances( const vector<balance_id_ty
} FC_CAPTURE_AND_RETHROW( (objs) ) } FC_CAPTURE_AND_RETHROW( (objs) )
} }
vector<vesting_balance_object> database_api::get_vesting_balances( account_id_type account_id )const vector<vesting_balance_object> 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<vesting_balance_object> database_api_impl::get_vesting_balances( account_id_type account_id )const vector<vesting_balance_object> database_api_impl::get_vesting_balances( const std::string account_id_or_name )const
{ {
try try
{ {
const account_id_type account_id = get_account_from_string(account_id_or_name)->id;
vector<vesting_balance_object> result; vector<vesting_balance_object> result;
auto vesting_range = _db.get_index_type<vesting_balance_index>().indices().get<by_account>().equal_range(account_id); auto vesting_range = _db.get_index_type<vesting_balance_index>().indices().get<by_account>().equal_range(account_id);
std::for_each(vesting_range.first, vesting_range.second, std::for_each(vesting_range.first, vesting_range.second,
@ -941,7 +951,7 @@ vector<vesting_balance_object> database_api_impl::get_vesting_balances( account_
}); });
return result; return result;
} }
FC_CAPTURE_AND_RETHROW( (account_id) ); FC_CAPTURE_AND_RETHROW( (account_id_or_name) );
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -950,9 +960,48 @@ vector<vesting_balance_object> database_api_impl::get_vesting_balances( account_
// // // //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
vector<optional<asset_object>> database_api::get_assets(const vector<asset_id_type>& 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<asset_id_type>(1));
else
{
const auto& idx = _db.get_index_type<asset_index>().indices().get<by_symbol>();
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<optional<asset_object>> database_api::get_assets(const vector<std::string>& asset_symbols_or_ids)const
{
return my->get_assets( asset_symbols_or_ids );
}
vector<optional<asset_object>> database_api_impl::get_assets(const vector<std::string>& asset_symbols_or_ids)const
{
vector<optional<asset_object>> 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<asset_object> {
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<optional<asset_object>> database_api_impl::get_assets(const vector<asset_id_type>& asset_ids)const vector<optional<asset_object>> database_api_impl::get_assets(const vector<asset_id_type>& asset_ids)const
@ -1208,7 +1257,7 @@ vector<bet_object> database_api_impl::get_all_unmatched_bets_for_bettor(account_
// // // //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
vector<limit_order_object> database_api::get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const vector<limit_order_object> 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 ); return my->get_limit_orders( a, b, limit );
} }
@ -1216,12 +1265,22 @@ vector<limit_order_object> 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. * @return the limit orders for both sides of the book for the two assets specified up to limit number on each side.
*/ */
vector<limit_order_object> database_api_impl::get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const vector<limit_order_object> 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<limit_order_object> 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<limit_order_index>(); const auto& limit_order_idx = _db.get_index_type<limit_order_index>();
const auto& limit_price_idx = limit_order_idx.indices().get<by_price>(); const auto& limit_price_idx = limit_order_idx.indices().get<by_price>();
vector<limit_order_object> result; vector<limit_order_object> result;
result.reserve(limit*2);
uint32_t count = 0; uint32_t count = 0;
auto limit_itr = limit_price_idx.lower_bound(price::max(a,b)); auto limit_itr = limit_price_idx.lower_bound(price::max(a,b));
@ -1245,45 +1304,46 @@ vector<limit_order_object> database_api_impl::get_limit_orders(asset_id_type a,
return result; return result;
} }
vector<call_order_object> database_api::get_call_orders(asset_id_type a, uint32_t limit)const vector<call_order_object> database_api::get_call_orders(const std::string& a, uint32_t limit)const
{ {
return my->get_call_orders( a, limit ); return my->get_call_orders( a, limit );
} }
vector<call_order_object> database_api_impl::get_call_orders(asset_id_type a, uint32_t limit)const vector<call_order_object> database_api_impl::get_call_orders(const std::string& a, uint32_t limit)const
{ {
const auto& call_index = _db.get_index_type<call_order_index>().indices().get<by_price>(); const auto& call_index = _db.get_index_type<call_order_index>().indices().get<by_price>();
const asset_object& mia = _db.get(a); 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()); price index_price = price::min(mia->bitasset_data(_db).options.short_backing_asset, mia->get_id());
return vector<call_order_object>(call_index.lower_bound(index_price.min()), return vector<call_order_object>(call_index.lower_bound(index_price.min()),
call_index.lower_bound(index_price.max())); call_index.lower_bound(index_price.max()));
} }
vector<force_settlement_object> database_api::get_settle_orders(asset_id_type a, uint32_t limit)const vector<force_settlement_object> database_api::get_settle_orders(const std::string& a, uint32_t limit)const
{ {
return my->get_settle_orders( a, limit ); return my->get_settle_orders( a, limit );
} }
vector<force_settlement_object> database_api_impl::get_settle_orders(asset_id_type a, uint32_t limit)const vector<force_settlement_object> database_api_impl::get_settle_orders(const std::string& a, uint32_t limit)const
{ {
const auto& settle_index = _db.get_index_type<force_settlement_index>().indices().get<by_expiration>(); const auto& settle_index = _db.get_index_type<force_settlement_index>().indices().get<by_expiration>();
const asset_object& mia = _db.get(a); const asset_object* mia = get_asset_from_string(a);
return vector<force_settlement_object>(settle_index.lower_bound(mia.get_id()), return vector<force_settlement_object>(settle_index.lower_bound(mia->get_id()),
settle_index.upper_bound(mia.get_id())); settle_index.upper_bound(mia->get_id()));
} }
vector<call_order_object> database_api::get_margin_positions( const account_id_type& id )const vector<call_order_object> 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<call_order_object> database_api_impl::get_margin_positions( const account_id_type& id )const vector<call_order_object> database_api_impl::get_margin_positions( const std::string account_id_or_name )const
{ {
try try
{ {
const auto& idx = _db.get_index_type<call_order_index>(); const auto& idx = _db.get_index_type<call_order_index>();
const auto& aidx = idx.indices().get<by_account>(); const auto& aidx = idx.indices().get<by_account>();
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 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) ) ); auto end = aidx.lower_bound( boost::make_tuple( id+1, asset_id_type(0) ) );
vector<call_order_object> result; vector<call_order_object> result;
@ -1293,31 +1353,37 @@ vector<call_order_object> database_api_impl::get_margin_positions( const account
++start; ++start;
} }
return result; return result;
} FC_CAPTURE_AND_RETHROW( (id) ) } FC_CAPTURE_AND_RETHROW( (account_id_or_name) )
} }
void database_api::subscribe_to_market(std::function<void(const variant&)> callback, asset_id_type a, asset_id_type b) void database_api::subscribe_to_market(std::function<void(const variant&)> callback, const std::string& a, const std::string& b)
{ {
my->subscribe_to_market( callback, a, b ); my->subscribe_to_market( callback, a, b );
} }
void database_api_impl::subscribe_to_market(std::function<void(const variant&)> callback, asset_id_type a, asset_id_type b) void database_api_impl::subscribe_to_market(std::function<void(const variant&)> callback, const std::string& a, const std::string& b)
{ {
if(a > b) std::swap(a,b); auto asset_a_id = get_asset_from_string(a)->id;
FC_ASSERT(a != b); auto asset_b_id = get_asset_from_string(b)->id;
_market_subscriptions[ std::make_pair(a,b) ] = callback;
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 ); 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); auto asset_a_id = get_asset_from_string(a)->id;
FC_ASSERT(a != b); auto asset_b_id = get_asset_from_string(b)->id;
_market_subscriptions.erase(std::make_pair(a,b));
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 market_ticker database_api::get_ticker( const string& base, const string& quote )const
@ -1540,9 +1606,10 @@ vector<optional<witness_object>> database_api::get_witnesses(const vector<witnes
return my->get_witnesses( witness_ids ); return my->get_witnesses( witness_ids );
} }
vector<worker_object> database_api::get_workers_by_account(account_id_type account)const vector<worker_object> database_api::get_workers_by_account(const std::string account_id_or_name)const
{ {
const auto& idx = my->_db.get_index_type<worker_index>().indices().get<by_account>(); const auto& idx = my->_db.get_index_type<worker_index>().indices().get<by_account>();
const account_id_type account = my->get_account_from_string(account_id_or_name)->id;
auto itr = idx.find(account); auto itr = idx.find(account);
vector<worker_object> result; vector<worker_object> result;
@ -1568,14 +1635,15 @@ vector<optional<witness_object>> database_api_impl::get_witnesses(const vector<w
return result; return result;
} }
fc::optional<witness_object> database_api::get_witness_by_account(account_id_type account)const fc::optional<witness_object> 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<witness_object> database_api_impl::get_witness_by_account(account_id_type account) const fc::optional<witness_object> database_api_impl::get_witness_by_account(const std::string account_id_or_name) const
{ {
const auto& idx = _db.get_index_type<witness_index>().indices().get<by_account>(); const auto& idx = _db.get_index_type<witness_index>().indices().get<by_account>();
const account_id_type account = get_account_from_string(account_id_or_name)->id;
auto itr = idx.find(account); auto itr = idx.find(account);
if( itr != idx.end() ) if( itr != idx.end() )
return *itr; return *itr;
@ -1643,14 +1711,15 @@ vector<optional<committee_member_object>> database_api_impl::get_committee_membe
return result; return result;
} }
fc::optional<committee_member_object> database_api::get_committee_member_by_account(account_id_type account)const fc::optional<committee_member_object> 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<committee_member_object> database_api_impl::get_committee_member_by_account(account_id_type account) const fc::optional<committee_member_object> database_api_impl::get_committee_member_by_account(const std::string account_id_or_name) const
{ {
const auto& idx = _db.get_index_type<committee_member_index>().indices().get<by_account>(); const auto& idx = _db.get_index_type<committee_member_index>().indices().get<by_account>();
const account_id_type account = get_account_from_string(account_id_or_name)->id;
auto itr = idx.find(account); auto itr = idx.find(account);
if( itr != idx.end() ) if( itr != idx.end() )
return *itr; return *itr;
@ -1903,9 +1972,9 @@ processed_transaction database_api_impl::validate_transaction( const signed_tran
return _db.validate_transaction(trx); return _db.validate_transaction(trx);
} }
vector< fc::variant > database_api::get_required_fees( const vector<operation>& ops, asset_id_type id )const vector< fc::variant > database_api::get_required_fees( const vector<operation>& 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; uint32_t current_recursion = 0;
}; };
vector< fc::variant > database_api_impl::get_required_fees( const vector<operation>& ops, asset_id_type id )const vector< fc::variant > database_api_impl::get_required_fees( const vector<operation>& ops, const std::string& asset_id_or_symbol )const
{ {
vector< operation > _ops = ops; vector< operation > _ops = ops;
// //
@ -1974,7 +2043,7 @@ vector< fc::variant > database_api_impl::get_required_fees( const vector<operati
vector< fc::variant > result; vector< fc::variant > result;
result.reserve(ops.size()); 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( get_required_fees_helper helper(
_db.current_fee_schedule(), _db.current_fee_schedule(),
a.options.core_exchange_rate, a.options.core_exchange_rate,
@ -1992,16 +2061,17 @@ vector< fc::variant > database_api_impl::get_required_fees( const vector<operati
// // // //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
vector<proposal_object> database_api::get_proposed_transactions( account_id_type id )const vector<proposal_object> 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 */ /** TODO: add secondary index that will accelerate this process */
vector<proposal_object> database_api_impl::get_proposed_transactions( account_id_type id )const vector<proposal_object> database_api_impl::get_proposed_transactions( const std::string account_id_or_name )const
{ {
const auto& idx = _db.get_index_type<proposal_index>(); const auto& idx = _db.get_index_type<proposal_index>();
vector<proposal_object> result; vector<proposal_object> result;
const account_id_type id = get_account_from_string(account_id_or_name)->id;
idx.inspect_all_objects( [&](const object& obj){ idx.inspect_all_objects( [&](const object& obj){
const proposal_object& p = static_cast<const proposal_object&>(obj); const proposal_object& p = static_cast<const proposal_object&>(obj);
@ -2116,6 +2186,26 @@ vector<tournament_object> database_api_impl::get_tournaments_by_state(tournament
return result; 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<account_id_type>(1));
else
{
const auto& idx = _db.get_index_type<account_index>().indices().get<by_name>();
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<tournament_id_type> database_api::get_registered_tournaments(account_id_type account_filter, uint32_t limit) const vector<tournament_id_type> database_api::get_registered_tournaments(account_id_type account_filter, uint32_t limit) const
{ {
return my->get_registered_tournaments(account_filter, limit); return my->get_registered_tournaments(account_filter, limit);

View file

@ -95,31 +95,32 @@ namespace graphene { namespace app {
class history_api class history_api
{ {
public: 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 * @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 stop ID of the earliest operation to retrieve
* @param limit Maximum number of operations to retrieve (must not exceed 100) * @param limit Maximum number of operations to retrieve (must not exceed 100)
* @param start ID of the most recent operation to retrieve * @param start ID of the most recent operation to retrieve
* @return A list of operations performed by account, ordered from most recent to oldest. * @return A list of operations performed by account, ordered from most recent to oldest.
*/ */
vector<operation_history_object> get_account_history(account_id_type account, vector<operation_history_object> get_account_history(const std::string account_id_or_name,
operation_history_id_type stop = operation_history_id_type(), operation_history_id_type stop = operation_history_id_type(),
unsigned limit = 100, unsigned limit = 100,
operation_history_id_type start = operation_history_id_type())const; operation_history_id_type start = operation_history_id_type())const;
/** /**
* @brief Get only asked operations relevant to the specified account * @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 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 stop ID of the earliest operation to retrieve
* @param limit Maximum number of operations to retrieve (must not exceed 100) * @param limit Maximum number of operations to retrieve (must not exceed 100)
* @param start ID of the most recent operation to retrieve * @param start ID of the most recent operation to retrieve
* @return A list of operations performed by account, ordered from most recent to oldest. * @return A list of operations performed by account, ordered from most recent to oldest.
*/ */
vector<operation_history_object> get_account_history_operations(account_id_type account, vector<operation_history_object> get_account_history_operations(const std::string account_id_or_name,
int operation_id, int operation_id,
operation_history_id_type start = operation_history_id_type(), operation_history_id_type start = operation_history_id_type(),
operation_history_id_type stop = 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 * @breif Get operations relevant to the specified account referenced
* by an event numbering specific to the account. The current number of operations * 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). * 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 * @param stop Sequence number of earliest operation. 0 is default and will
* query 'limit' number of operations. * query 'limit' number of operations.
* @param limit Maximum number of operations to retrieve (must not exceed 100) * @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. * 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. * @return A list of operations performed by account, ordered from most recent to oldest.
*/ */
vector<operation_history_object> get_relative_account_history( account_id_type account, vector<operation_history_object> get_relative_account_history( const std::string account_id_or_name,
uint32_t stop = 0, uint32_t stop = 0,
unsigned limit = 100, unsigned limit = 100,
uint32_t start = 0) const; uint32_t start = 0) const;
vector<order_history_object> get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const; vector<order_history_object> get_fill_order_history( std::string asset_a, std::string asset_b, uint32_t limit )const;
vector<bucket_object> get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, vector<bucket_object> 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; fc::time_point_sec start, fc::time_point_sec end )const;
vector<account_balance_object> list_core_accounts()const; vector<account_balance_object> list_core_accounts()const;
flat_set<uint32_t> get_market_history_buckets()const; flat_set<uint32_t> get_market_history_buckets()const;
private: private:
application& _app; application& _app;
graphene::app::database_api database_api;
}; };
/** /**
@ -325,15 +327,35 @@ namespace graphene { namespace app {
class asset_api class asset_api
{ {
public: public:
asset_api(graphene::chain::database& db); asset_api(graphene::app::application& app);
~asset_api(); ~asset_api();
vector<account_asset_balance> 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<account_asset_balance> 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<asset_holders> get_all_asset_holders() const; vector<asset_holders> get_all_asset_holders() const;
private: private:
graphene::app::application& _app;
graphene::chain::database& _db; graphene::chain::database& _db;
graphene::app::database_api database_api;
}; };
/** /**

View file

@ -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 * @param account_ids IDs of the accounts to retrieve
* @return The accounts corresponding to the provided IDs * @return The accounts corresponding to the provided IDs
* *
* This function has semantics identical to @ref get_objects * This function has semantics identical to @ref get_objects
*/ */
vector<optional<account_object>> get_accounts(const vector<account_id_type>& account_ids)const; vector<optional<account_object>> get_accounts(const vector<std::string>& account_names_or_ids)const;
/** /**
* @brief Fetch all objects relevant to the specified accounts and subscribe to updates * @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. * @return all accounts that referr to the key or account id in their owner or active authorities.
*/ */
vector<account_id_type> get_account_references( account_id_type account_id )const; vector<account_id_type> get_account_references( const std::string account_name_or_id )const;
/** /**
* @brief Get a list of accounts by name * @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 * @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 * @return Balances of the account
*/ */
vector<asset> get_account_balances(account_id_type id, const flat_set<asset_id_type>& assets)const; vector<asset> get_account_balances( const std::string& account_name_or_id,
const flat_set<asset_id_type>& assets )const;
/// Semantically equivalent to @ref get_account_balances, but takes a name instead of an ID. /// Semantically equivalent to @ref get_account_balances, but takes a name instead of an ID.
vector<asset> get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets)const; vector<asset> get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets)const;
@ -314,7 +323,7 @@ class database_api
vector<asset> get_vested_balances( const vector<balance_id_type>& objs )const; vector<asset> get_vested_balances( const vector<balance_id_type>& objs )const;
vector<vesting_balance_object> get_vesting_balances( account_id_type account_id )const; vector<vesting_balance_object> get_vesting_balances( const std::string account_id_or_name )const;
/** /**
* @brief Get the total number of accounts registered with the blockchain * @brief Get the total number of accounts registered with the blockchain
@ -325,14 +334,21 @@ class database_api
// Assets // // 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 * @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 * @return The assets corresponding to the provided IDs
* *
* This function has semantics identical to @ref get_objects * This function has semantics identical to @ref get_objects
*/ */
vector<optional<asset_object>> get_assets(const vector<asset_id_type>& asset_ids)const; vector<optional<asset_object>> get_assets(const vector<std::string>& asset_symbols_or_ids)const;
/** /**
* @brief Get assets alphabetically by symbol name * @brief Get assets alphabetically by symbol name
@ -434,47 +450,47 @@ class database_api
* @param limit Maximum number of orders to retrieve * @param limit Maximum number of orders to retrieve
* @return The limit orders, ordered from least price to greatest * @return The limit orders, ordered from least price to greatest
*/ */
vector<limit_order_object> get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const; vector<limit_order_object> get_limit_orders(const std::string& a, const std::string& b, uint32_t limit)const;
/** /**
* @brief Get call orders in a given asset * @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 * @param limit Maximum number of orders to retrieve
* @return The call orders, ordered from earliest to be called to latest * @return The call orders, ordered from earliest to be called to latest
*/ */
vector<call_order_object> get_call_orders(asset_id_type a, uint32_t limit)const; vector<call_order_object> get_call_orders(const std::string& a, uint32_t limit)const;
/** /**
* @brief Get forced settlement orders in a given asset * @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 * @param limit Maximum number of orders to retrieve
* @return The settle orders, ordered from earliest settlement date to latest * @return The settle orders, ordered from earliest settlement date to latest
*/ */
vector<force_settlement_object> get_settle_orders(asset_id_type a, uint32_t limit)const; vector<force_settlement_object> get_settle_orders(const std::string& a, uint32_t limit)const;
/** /**
* @return all open margin positions for a given account id. * @return all open margin positions for a given account id.
*/ */
vector<call_order_object> get_margin_positions( const account_id_type& id )const; vector<call_order_object> 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 * @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 callback Callback method which is called when the market changes
* @param a First asset ID * @param a First asset ID or name
* @param b Second asset ID * @param b Second asset ID or name
* *
* Callback will be passed a variant containing a vector<pair<operation, operation_result>>. The vector will * Callback will be passed a variant containing a vector<pair<operation, operation_result>>. The vector will
* contain, in order, the operations which changed the market, and their results. * contain, in order, the operations which changed the market, and their results.
*/ */
void subscribe_to_market(std::function<void(const variant&)> callback, void subscribe_to_market(std::function<void(const variant&)> 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 * @brief Unsubscribe from updates to a given market
* @param a First asset ID * @param a First asset ID or name
* @param b Second asset ID * @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 * @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 * @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 * @return The witness object, or null if the account does not have a witness
*/ */
fc::optional<witness_object> get_witness_by_account(account_id_type account)const; fc::optional<witness_object> get_witness_by_account(const std::string account_name_or_id)const;
/** /**
* @brief Get names and IDs for registered witnesses * @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 * @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 * @return The committee_member object, or null if the account does not have a committee_member
*/ */
fc::optional<committee_member_object> get_committee_member_by_account(account_id_type account)const; fc::optional<committee_member_object> get_committee_member_by_account(const std::string account_id_or_name)const;
/** /**
* @brief Get names and IDs for registered committee_members * @brief Get names and IDs for registered committee_members
@ -580,9 +596,11 @@ class database_api
/// WORKERS /// 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<worker_object> get_workers_by_account(account_id_type account)const; vector<worker_object> 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 * For each operation calculate the required fee in the specified asset type. If the asset type does
* not have a valid core_exchange_rate * not have a valid core_exchange_rate
*/ */
vector< fc::variant > get_required_fees( const vector<operation>& ops, asset_id_type id )const; vector< fc::variant > get_required_fees( const vector<operation>& ops, const std::string& asset_id_or_symbol )const;
/////////////////////////// ///////////////////////////
// Proposed transactions // // Proposed transactions //
@ -648,7 +666,7 @@ class database_api
/** /**
* @return the set of proposed transactions relevant to the specified account id. * @return the set of proposed transactions relevant to the specified account id.
*/ */
vector<proposal_object> get_proposed_transactions( account_id_type id )const; vector<proposal_object> get_proposed_transactions( const std::string account_id_or_name )const;
////////////////////// //////////////////////
// Blinded balances // // Blinded balances //
@ -734,6 +752,7 @@ FC_API(graphene::app::database_api,
(is_public_key_registered) (is_public_key_registered)
// Accounts // Accounts
(get_account_id_from_string)
(get_accounts) (get_accounts)
(get_full_accounts) (get_full_accounts)
(get_account_by_name) (get_account_by_name)
@ -754,6 +773,7 @@ FC_API(graphene::app::database_api,
(list_assets) (list_assets)
(lookup_asset_symbols) (lookup_asset_symbols)
(get_asset_count) (get_asset_count)
(get_asset_id_from_string)
// Peerplays // Peerplays
(list_sports) (list_sports)

View file

@ -355,7 +355,8 @@ private:
for( const fc::optional<graphene::chain::account_object>& optional_account : owner_account_objects ) for( const fc::optional<graphene::chain::account_object>& optional_account : owner_account_objects )
if (optional_account) if (optional_account)
{ {
fc::optional<witness_object> 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_object> witness_obj = _remote_db->get_witness_by_account(account_id);
if (witness_obj) if (witness_obj)
claim_registered_witness(optional_account->name); claim_registered_witness(optional_account->name);
} }
@ -729,9 +730,17 @@ public:
{ {
return _remote_db->get_dynamic_global_properties(); 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 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); FC_ASSERT(rec);
return *rec; return *rec;
} }
@ -753,9 +762,16 @@ public:
{ {
return get_account(account_name_or_id).get_id(); 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<asset_object> find_asset(asset_id_type id)const optional<asset_object> 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 ) if( rec )
_asset_cache[id] = *rec; _asset_cache[id] = *rec;
return rec; return rec;
@ -1018,7 +1034,7 @@ public:
("chain_id", _chain_id) ); ("chain_id", _chain_id) );
size_t account_pagination = 100; 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(); size_t n = _wallet.my_accounts.size();
account_ids_to_send.reserve( std::min( account_pagination, n ) ); account_ids_to_send.reserve( std::min( account_pagination, n ) );
auto it = _wallet.my_accounts.begin(); auto it = _wallet.my_accounts.begin();
@ -1033,7 +1049,8 @@ public:
{ {
assert( it != _wallet.my_accounts.end() ); assert( it != _wallet.my_accounts.end() );
old_accounts.push_back( *it ); 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; ++it;
} }
std::vector< optional< account_object > > accounts = _remote_db->get_accounts(account_ids_to_send); 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_operation committee_member_create_op;
committee_member_create_op.committee_member_account = get_account_id(owner_account); committee_member_create_op.committee_member_account = get_account_id(owner_account);
committee_member_create_op.url = url; 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)); FC_THROW("Account ${owner_account} is already a committee_member", ("owner_account", owner_account));
signed_transaction tx; signed_transaction tx;
@ -1763,7 +1780,7 @@ public:
// then maybe it's the owner account // then maybe it's the owner account
try 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_object> witness = _remote_db->get_witness_by_account(owner_account_id); fc::optional<witness_object> witness = _remote_db->get_witness_by_account(owner_account_id);
if (witness) if (witness)
return *witness; return *witness;
@ -1799,7 +1816,7 @@ public:
// then maybe it's the owner account // then maybe it's the owner account
try 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_object> witness = _remote_db->get_witness_by_account(owner_account_id); fc::optional<witness_object> witness = _remote_db->get_witness_by_account(owner_account_id);
if (witness) if (witness)
return true; return true;
@ -1834,8 +1851,7 @@ public:
// then maybe it's the owner account // then maybe it's the owner account
try try
{ {
account_id_type owner_account_id = get_account_id(owner_account); fc::optional<committee_member_object> committee_member = _remote_db->get_committee_member_by_account(owner_account);
fc::optional<committee_member_object> committee_member = _remote_db->get_committee_member_by_account(owner_account_id);
if (committee_member) if (committee_member)
return *committee_member; return *committee_member;
else else
@ -1871,7 +1887,7 @@ public:
witness_create_op.initial_secret = enc.result(); 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)); FC_THROW("Account ${owner_account} is already a witness", ("owner_account", owner_account));
signed_transaction tx; signed_transaction tx;
@ -2037,12 +2053,7 @@ public:
return result; return result;
} }
// try casting to avoid a round-trip if we were given an account ID vector< vesting_balance_object > vbos = _remote_db->get_vesting_balances( account_name );
fc::optional<account_id_type> acct_id = maybe_id<account_id_type>( account_name );
if( !acct_id )
acct_id = get_account( account_name ).id;
vector< vesting_balance_object > vbos = _remote_db->get_vesting_balances( *acct_id );
if( vbos.size() == 0 ) if( vbos.size() == 0 )
return result; return result;
@ -2110,12 +2121,7 @@ public:
fc::optional<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(account_name); fc::optional<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(account_name);
if( !vbid ) if( !vbid )
{ {
//Changes done to retrive user account/witness account based on account name vbos = _remote_db->get_vesting_balances( account_name );
fc::optional<account_id_type> acct_id = maybe_id<account_id_type>( account_name );
if( !acct_id )
acct_id = get_account( account_name ).id;
vbos = _remote_db->get_vesting_balances( *acct_id );
if( vbos.size() == 0 ) if( vbos.size() == 0 )
FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); 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_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_object> committee_member_obj = _remote_db->get_committee_member_by_account(committee_member);
fc::optional<committee_member_object> committee_member_obj = _remote_db->get_committee_member_by_account(committee_member_owner_account_id);
if (!committee_member_obj) if (!committee_member_obj)
FC_THROW("Account ${committee_member} is not registered as a committee_member", ("committee_member", committee_member)); 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_object voting_account_object = get_account(voting_account);
account_id_type witness_owner_account_id = get_account_id(witness);
fc::optional<witness_object> witness_obj = _remote_db->get_witness_by_account(witness_owner_account_id); fc::optional<witness_object> witness_obj = _remote_db->get_witness_by_account(witness);
if (!witness_obj) if (!witness_obj)
FC_THROW("Account ${witness} is not registered as a witness", ("witness", witness)); 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); account_object voting_account_object = get_account(voting_account);
for (const std::string& witness : witnesses_to_approve) for (const std::string& witness : witnesses_to_approve)
{ {
account_id_type witness_owner_account_id = get_account_id(witness); fc::optional<witness_object> witness_obj = _remote_db->get_witness_by_account(witness);
fc::optional<witness_object> witness_obj = _remote_db->get_witness_by_account(witness_owner_account_id);
if (!witness_obj) if (!witness_obj)
FC_THROW("Account ${witness} is not registered as a witness", ("witness", witness)); 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); 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) for (const std::string& witness : witnesses_to_reject)
{ {
account_id_type witness_owner_account_id = get_account_id(witness); fc::optional<witness_object> witness_obj = _remote_db->get_witness_by_account(witness);
fc::optional<witness_object> witness_obj = _remote_db->get_witness_by_account(witness_owner_account_id);
if (!witness_obj) if (!witness_obj)
FC_THROW("Account ${witness} is not registered as a witness", ("witness", witness)); 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); unsigned votes_removed = voting_account_object.options.votes.erase(witness_obj->vote_id);
@ -3706,8 +3708,8 @@ map<string,account_id_type> wallet_api::list_accounts(const string& lowerbound,
vector<asset> wallet_api::list_account_balances(const string& id) vector<asset> wallet_api::list_account_balances(const string& id)
{ {
if( auto real_id = detail::maybe_id<account_id_type>(id) ) if( auto real_id = detail::maybe_id<account_id_type>(id) )
return my->_remote_db->get_account_balances(*real_id, flat_set<asset_id_type>()); return my->_remote_db->get_account_balances(id, flat_set<asset_id_type>());
return my->_remote_db->get_account_balances(get_account(id).id, flat_set<asset_id_type>()); return my->_remote_db->get_account_balances(id, flat_set<asset_id_type>());
} }
vector<asset_object> wallet_api::list_assets(const string& lowerbound, uint32_t limit)const vector<asset_object> wallet_api::list_assets(const string& lowerbound, uint32_t limit)const
@ -3743,7 +3745,6 @@ asset wallet_api::get_lottery_balance( asset_id_type lottery_id )const
vector<operation_detail> wallet_api::get_account_history(string name, int limit) const vector<operation_detail> wallet_api::get_account_history(string name, int limit) const
{ {
vector<operation_detail> result; vector<operation_detail> result;
auto account_id = get_account(name).get_id();
while (limit > 0) while (limit > 0)
{ {
@ -3764,7 +3765,7 @@ vector<operation_detail> wallet_api::get_account_history(string name, int limit)
int page_limit = skip_first_row ? std::min(100, limit + 1) : std::min(100, limit); int page_limit = skip_first_row ? std::min(100, limit + 1) : std::min(100, limit);
vector<operation_history_object> current = my->_remote_hist->get_account_history(account_id, operation_history_id_type(), vector<operation_history_object> current = my->_remote_hist->get_account_history(name, operation_history_id_type(),
page_limit, start); page_limit, start);
bool first_row = true; bool first_row = true;
for (auto &o : current) for (auto &o : current)
@ -3799,11 +3800,10 @@ vector<operation_detail> wallet_api::get_relative_account_history(string name, u
FC_ASSERT( start > 0 || limit <= 100 ); FC_ASSERT( start > 0 || limit <= 100 );
vector<operation_detail> result; vector<operation_detail> result;
auto account_id = get_account(name).get_id();
while( limit > 0 ) while( limit > 0 )
{ {
vector <operation_history_object> current = my->_remote_hist->get_relative_account_history(account_id, stop, std::min<uint32_t>(100, limit), start); vector <operation_history_object> current = my->_remote_hist->get_relative_account_history(name, stop, std::min<uint32_t>(100, limit), start);
for (auto &o : current) { for (auto &o : current) {
std::stringstream ss; std::stringstream ss;
auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result));
@ -3824,22 +3824,22 @@ vector<account_balance_object> wallet_api::list_core_accounts()const
vector<bucket_object> wallet_api::get_market_history( string symbol1, string symbol2, uint32_t bucket , fc::time_point_sec start, fc::time_point_sec end )const vector<bucket_object> 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<limit_order_object> wallet_api::get_limit_orders(string a, string b, uint32_t limit)const vector<limit_order_object> 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<call_order_object> wallet_api::get_call_orders(string a, uint32_t limit)const vector<call_order_object> 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<force_settlement_object> wallet_api::get_settle_orders(string a, uint32_t limit)const vector<force_settlement_object> 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 brain_key_info wallet_api::suggest_brain_key()const

View file

@ -55,25 +55,25 @@ BOOST_AUTO_TEST_CASE(get_account_history) {
int account_create_op_id = operation::tag<account_create_operation>::value; int account_create_op_id = operation::tag<account_create_operation>::value;
//account_id_type() did 3 ops and includes id0 //account_id_type() did 3 ops and includes id0
vector<operation_history_object> histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(), 100, operation_history_id_type()); vector<operation_history_object> 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u);
BOOST_CHECK_EQUAL(histories[2].op.which(), asset_create_op_id); BOOST_CHECK_EQUAL(histories[2].op.which(), asset_create_op_id);
// 1 account_create op larger than id1 // 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_EQUAL(histories.size(), 1u);
BOOST_CHECK(histories[0].id.instance() != 0); BOOST_CHECK(histories[0].id.instance() != 0);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);
// Limit 2 returns 2 result // 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_EQUAL(histories.size(), 2u);
BOOST_CHECK(histories[1].id.instance() != 0); BOOST_CHECK(histories[1].id.instance() != 0);
BOOST_CHECK_EQUAL(histories[1].op.which(), account_create_op_id); BOOST_CHECK_EQUAL(histories[1].op.which(), account_create_op_id);
// bob has 1 op // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(zero_id_object) {
graphene::app::history_api hist_api(app); graphene::app::history_api hist_api(app);
// no history at all in the chain // no history at all in the chain
vector<operation_history_object> histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 4, operation_history_id_type(0)); vector<operation_history_object> 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
create_bitasset("USD", account_id_type()); // create op 0 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)); fc::usleep(fc::milliseconds(2000));
// what if the account only has one history entry and it is 0? // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u);
} FC_LOG_AND_RETHROW() } 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 // 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 // no history at all in the chain
vector<operation_history_object> histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 4, operation_history_id_type(0)); vector<operation_history_object> 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
create_bitasset("USD", account_id_type()); // create op 0 create_bitasset("USD", account_id_type()); // create op 0
generate_block(); generate_block();
// what if the account only has one history entry and it is 0? // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u);
@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) {
generate_block(); generate_block();
// f(A, 0, 4, 9) = { 5, 3, 1, 0 } // 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u);
// f(A, 0, 4, 6) = { 5, 3, 1, 0 } // 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u);
// f(A, 0, 4, 5) = { 5, 3, 1, 0 } // 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u);
// f(A, 0, 4, 4) = { 3, 1, 0 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u);
// f(A, 0, 4, 3) = { 3, 1, 0 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u);
// f(A, 0, 4, 2) = { 1, 0 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u);
// f(A, 0, 4, 1) = { 1, 0 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u);
// f(A, 0, 4, 0) = { 5, 3, 1, 0 } // 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u);
// f(A, 1, 5, 9) = { 5, 3 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
// f(A, 1, 5, 6) = { 5, 3 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
// f(A, 1, 5, 5) = { 5, 3 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
// f(A, 1, 5, 4) = { 3 } // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
// f(A, 1, 5, 3) = { 3 } // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
// f(A, 1, 5, 2) = { } // 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// f(A, 1, 5, 1) = { } // 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// f(A, 1, 5, 0) = { 5, 3 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
// f(A, 0, 3, 9) = { 5, 3, 1 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u);
// f(A, 0, 3, 6) = { 5, 3, 1 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u);
// f(A, 0, 3, 5) = { 5, 3, 1 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u);
// f(A, 0, 3, 4) = { 3, 1, 0 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u);
// f(A, 0, 3, 3) = { 3, 1, 0 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u);
// f(A, 0, 3, 2) = { 1, 0 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u);
// f(A, 0, 3, 1) = { 1, 0 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u);
// f(A, 0, 3, 0) = { 5, 3, 1 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u);
// f(B, 0, 4, 9) = { 6, 4, 2, 1 } // 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 1u);
// f(B, 0, 4, 6) = { 6, 4, 2, 1 } // 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 1u);
// f(B, 0, 4, 5) = { 4, 2, 1 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u);
// f(B, 0, 4, 4) = { 4, 2, 1 } // 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u);
BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u);
// f(B, 0, 4, 3) = { 2, 1 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u);
// f(B, 0, 4, 2) = { 2, 1 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u);
// f(B, 0, 4, 1) = { 1 } // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u);
// f(B, 0, 4, 0) = { 6, 4, 2, 1 } // 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 1u);
// f(B, 2, 4, 9) = { 6, 4 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u);
// f(B, 2, 4, 6) = { 6, 4 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u);
// f(B, 2, 4, 5) = { 4 } // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u);
// f(B, 2, 4, 4) = { 4 } // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u);
// f(B, 2, 4, 3) = { } // 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// f(B, 2, 4, 2) = { } // 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// f(B, 2, 4, 1) = { } // 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// f(B, 2, 4, 0) = { 6, 4 } // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u);
// 0 limits // 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); 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// create a new account C = alice { 7 } // create a new account C = alice { 7 }
@ -388,16 +388,16 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) {
generate_block(); generate_block();
// f(C, 0, 4, 10) = { 7 } // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u);
// f(C, 8, 4, 10) = { } // 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// f(A, 0, 10, 0) = { 7, 5, 3, 1, 0 } // 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.size(), 5u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 5u); 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 {} // anything against account_id_type() should be {}
vector<operation_history_object> histories = vector<operation_history_object> 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); 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); 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// anything against alice should be {} // 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); 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); 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// dan should have history // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(track_account) {
generate_block( ~database::skip_fork_db ); 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u);
@ -473,7 +473,7 @@ BOOST_AUTO_TEST_CASE(track_account) {
generate_block(); 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.size(), 3u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u);
@ -508,7 +508,7 @@ BOOST_AUTO_TEST_CASE(track_account2) {
generate_block(); generate_block();
// all account_id_type() should have 4 ops {4,2,1,0} // all account_id_type() should have 4 ops {4,2,1,0}
vector<operation_history_object> histories = hist_api.get_account_history(account_id_type(), operation_history_id_type(0), 10, operation_history_id_type(0)); vector<operation_history_object> 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.size(), 4u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); 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); BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u);
// all alice account should have 2 ops {3, 0} // 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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u);
// alice first op should be {0} // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u);
// alice second op should be {3} // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u);
// anything against dan should be {} // 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); 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); 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
} catch (fc::exception &e) { } catch (fc::exception &e) {
@ -553,7 +553,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_operations) {
int account_create_op_id = operation::tag<account_create_operation>::value; int account_create_op_id = operation::tag<account_create_operation>::value;
// no asset_create operation on account_id_type() should not throw any exception // no asset_create operation on account_id_type() should not throw any exception
vector<operation_history_object> histories = hist_api.get_account_history_operations(account_id_type(), asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); vector<operation_history_object> 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
//account_id_type() do 3 ops //account_id_type() do 3 ops
@ -565,27 +565,27 @@ BOOST_AUTO_TEST_CASE(get_account_history_operations) {
fc::usleep(fc::milliseconds(2000)); fc::usleep(fc::milliseconds(2000));
//account_id_type() did 1 asset_create op //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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u);
BOOST_CHECK_EQUAL(histories[0].op.which(), asset_create_op_id); BOOST_CHECK_EQUAL(histories[0].op.which(), asset_create_op_id);
//account_id_type() did 2 account_create ops //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.size(), 2u);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);
// No asset_create op larger than id1 // 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); BOOST_CHECK_EQUAL(histories.size(), 0u);
// Limit 1 returns 1 result // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);
// alice has 1 op // 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.size(), 1u);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);

View file

@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(track_votes_witnesses_enabled)
INVOKE(put_my_witnesses); INVOKE(put_my_witnesses);
const account_id_type witness1_id= get_account("witness1").id; 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); BOOST_CHECK_EQUAL(witness1_object->total_votes, 111);
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(track_votes_witnesses_disabled)
INVOKE(put_my_witnesses); INVOKE(put_my_witnesses);
const account_id_type witness1_id= get_account("witness1").id; 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); BOOST_CHECK_EQUAL(witness1_object->total_votes, 0);
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE(track_votes_committee_enabled)
INVOKE(put_my_committee_members); INVOKE(put_my_committee_members);
const account_id_type committee1_id= get_account("committee1").id; 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); BOOST_CHECK_EQUAL(committee1_object->total_votes, 111);
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
@ -513,7 +513,7 @@ BOOST_AUTO_TEST_CASE(track_votes_committee_disabled)
INVOKE(put_my_committee_members); INVOKE(put_my_committee_members);
const account_id_type committee1_id= get_account("committee1").id; 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); BOOST_CHECK_EQUAL(committee1_object->total_votes, 0);
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()