@@ -539,6 +539,7 @@ dynamic_global_property_object database_api_impl::get_dynamic_global_properties(
539
539
540
540
vector<vector<account_id_type>> database_api::get_key_references ( vector<public_key_type> key )const
541
541
{
542
+ FC_ASSERT (key.size () <= 100 , " Number of keys must be 100 or less" );
542
543
return my->get_key_references ( key );
543
544
}
544
545
@@ -547,6 +548,10 @@ vector<vector<account_id_type>> database_api::get_key_references( vector<public_
547
548
*/
548
549
vector<vector<account_id_type>> database_api_impl::get_key_references ( vector<public_key_type> keys )const
549
550
{
551
+ const auto & idx = _db.get_index_type <account_index>();
552
+ const auto & aidx = dynamic_cast <const base_primary_index&>(idx);
553
+ const auto & refs = aidx.get_secondary_index <graphene::chain::account_member_index>();
554
+
550
555
vector< vector<account_id_type> > final_result;
551
556
final_result.reserve (keys.size ());
552
557
@@ -566,36 +571,30 @@ vector<vector<account_id_type>> database_api_impl::get_key_references( vector<pu
566
571
subscribe_to_item ( a4 );
567
572
subscribe_to_item ( a5 );
568
573
569
- const auto & idx = _db.get_index_type <account_index>();
570
- const auto & aidx = dynamic_cast <const primary_index<account_index>&>(idx);
571
- const auto & refs = aidx.get_secondary_index <graphene::chain::account_member_index>();
572
- auto itr = refs.account_to_key_memberships .find (key);
573
574
vector<account_id_type> result;
574
575
575
576
for ( auto & a : {a1,a2,a3,a4,a5} )
576
577
{
577
578
auto itr = refs.account_to_address_memberships .find (a);
578
579
if ( itr != refs.account_to_address_memberships .end () )
579
580
{
580
- result.reserve ( itr->second .size () );
581
+ result.reserve ( result. size () + itr->second .size () );
581
582
for ( auto item : itr->second )
582
583
{
583
584
result.push_back (item);
584
585
}
585
586
}
586
587
}
587
588
589
+ auto itr = refs.account_to_key_memberships .find (key);
588
590
if ( itr != refs.account_to_key_memberships .end () )
589
591
{
590
- result.reserve ( itr->second .size () );
592
+ result.reserve ( result. size () + itr->second .size () );
591
593
for ( auto item : itr->second ) result.push_back (item);
592
594
}
593
595
final_result.emplace_back ( std::move (result) );
594
596
}
595
597
596
- for ( auto i : final_result )
597
- subscribe_to_item (i);
598
-
599
598
return final_result;
600
599
}
601
600
@@ -620,7 +619,7 @@ bool database_api_impl::is_public_key_registered(string public_key) const
620
619
return false ;
621
620
}
622
621
const auto & idx = _db.get_index_type <account_index>();
623
- const auto & aidx = dynamic_cast <const primary_index<account_index> &>(idx);
622
+ const auto & aidx = dynamic_cast <const base_primary_index &>(idx);
624
623
const auto & refs = aidx.get_secondary_index <graphene::chain::account_member_index>();
625
624
auto itr = refs.account_to_key_memberships .find (key);
626
625
bool is_known = itr != refs.account_to_key_memberships .end ();
@@ -755,6 +754,10 @@ std::map<string,full_account> database_api::get_full_accounts( const vector<stri
755
754
756
755
std::map<std::string, full_account> database_api_impl::get_full_accounts ( const vector<std::string>& names_or_ids, bool subscribe)
757
756
{
757
+ const auto & proposal_idx = _db.get_index_type <proposal_index>();
758
+ const auto & pidx = dynamic_cast <const base_primary_index&>(proposal_idx);
759
+ const auto & proposals_by_account = pidx.get_secondary_index <graphene::chain::required_approval_index>();
760
+
758
761
std::map<std::string, full_account> results;
759
762
760
763
for (const std::string& account_name_or_id : names_or_ids)
@@ -784,9 +787,6 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
784
787
acnt.cashback_balance = account->cashback_balance (_db);
785
788
}
786
789
// Add the account's proposals
787
- const auto & proposal_idx = _db.get_index_type <proposal_index>();
788
- const auto & pidx = dynamic_cast <const primary_index<proposal_index>&>(proposal_idx);
789
- const auto & proposals_by_account = pidx.get_secondary_index <graphene::chain::required_approval_index>();
790
790
auto required_approvals_itr = proposals_by_account._account_to_proposals .find ( account->id );
791
791
if ( required_approvals_itr != proposals_by_account._account_to_proposals .end () )
792
792
{
@@ -797,11 +797,9 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
797
797
798
798
799
799
// Add the account's balances
800
- auto balance_range = _db.get_index_type <account_balance_index>().indices ().get <by_account_asset>().equal_range (boost::make_tuple (account->id ));
801
- std::for_each (balance_range.first , balance_range.second ,
802
- [&acnt](const account_balance_object& balance) {
803
- acnt.balances .emplace_back (balance);
804
- });
800
+ const auto & balances = _db.get_index_type < primary_index< account_balance_index > >().get_secondary_index < balances_by_account_index >().get_account_balances ( account->id );
801
+ for ( const auto balance : balances )
802
+ acnt.balances .emplace_back ( *balance.second );
805
803
806
804
// Add the account's vesting balances
807
805
auto vesting_range = _db.get_index_type <vesting_balance_index>().indices ().get <by_account>().equal_range (account->id );
@@ -869,7 +867,7 @@ vector<account_id_type> database_api::get_account_references( const std::string
869
867
vector<account_id_type> database_api_impl::get_account_references ( const std::string account_id_or_name )const
870
868
{
871
869
const auto & idx = _db.get_index_type <account_index>();
872
- const auto & aidx = dynamic_cast <const primary_index<account_index> &>(idx);
870
+ const auto & aidx = dynamic_cast <const base_primary_index &>(idx);
873
871
const auto & refs = aidx.get_secondary_index <graphene::chain::account_member_index>();
874
872
const account_id_type account_id = get_account_from_string (account_id_or_name)->id ;
875
873
auto itr = refs.account_to_account_memberships .find (account_id);
@@ -953,10 +951,10 @@ vector<asset> database_api_impl::get_account_balances(const std::string& account
953
951
if (assets.empty ())
954
952
{
955
953
// if the caller passes in an empty list of assets, return balances for all assets the account owns
956
- const account_balance_index & balance_index = _db.get_index_type <account_balance_index>();
957
- auto range = balance_index.indices (). get <by_account_asset >().equal_range ( boost::make_tuple ( acnt) );
958
- for ( const account_balance_object& balance : boost::make_iterator_range (range. first , range. second ) )
959
- result.push_back (asset ( balance.get_balance ()) );
954
+ const auto & balance_index = _db.get_index_type < primary_index< account_balance_index > >();
955
+ const auto & balances = balance_index.get_secondary_index < balances_by_account_index >().get_account_balances ( acnt );
956
+ for ( const auto balance : balances )
957
+ result.push_back ( balance.second -> get_balance () );
960
958
}
961
959
else
962
960
{
0 commit comments