Skip to content

Commit

Permalink
Merge commit '447018b319668deddf4d55baac168c1afc0a5e21' into muse
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Feb 19, 2016
2 parents e1f6be0 + 447018b commit a13c1fb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const


// Add the account's balances
auto balance_range = _db.get_index_type<account_balance_index>().indices().get<by_account>().equal_range(account->id);
auto balance_range = _db.get_index_type<account_balance_index>().indices().get<by_account_asset>().equal_range(boost::make_tuple(account->id));
//vector<account_balance_object> balances;
std::for_each(balance_range.first, balance_range.second,
[&acnt](const account_balance_object& balance) {
Expand Down Expand Up @@ -711,7 +711,7 @@ vector<asset> database_api_impl::get_account_balances(account_id_type acnt, cons
{
// if the caller passes in an empty list of assets, return balances for all assets the account owns
const account_balance_index& balance_index = _db.get_index_type<account_balance_index>();
auto range = balance_index.indices().get<by_account>().equal_range(acnt);
auto range = balance_index.indices().get<by_account_asset>().equal_range(boost::make_tuple(acnt));
for (const account_balance_object& balance : boost::make_iterator_range(range.first, range.second))
result.push_back(asset(balance.get_balance()));
}
Expand Down
7 changes: 4 additions & 3 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

add_custom_target( build_hardfork_hpp
COMMAND cat-parts hardfork.d include/graphene/chain/hardfork.hpp )
COMMAND cat-parts hardfork.d "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" )
set_source_files_properties( "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" PROPERTIES GENERATED TRUE )

add_dependencies( build_hardfork_hpp cat-parts )

Expand Down Expand Up @@ -84,13 +85,13 @@ add_library( graphene_chain
block_database.cpp

${HEADERS}
include/graphene/chain/hardfork.hpp
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
)

add_dependencies( graphene_chain build_hardfork_hpp )
target_link_libraries( graphene_chain fc graphene_db )
target_include_directories( graphene_chain
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )

if(MSVC)
set_source_files_properties( db_init.cpp db_block.cpp database.cpp block_database.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/db_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace graphene { namespace chain {

asset database::get_balance(account_id_type owner, asset_id_type asset_id) const
{
auto& index = get_index_type<account_balance_index>().indices().get<by_balance>();
auto& index = get_index_type<account_balance_index>().indices().get<by_account_asset>();
auto itr = index.find(boost::make_tuple(owner, asset_id));
if( itr == index.end() )
return asset(0, asset_id);
Expand All @@ -55,7 +55,7 @@ void database::adjust_balance(account_id_type account, asset delta )
if( delta.amount == 0 )
return;

auto& index = get_index_type<account_balance_index>().indices().get<by_balance>();
auto& index = get_index_type<account_balance_index>().indices().get<by_account_asset>();
auto itr = index.find(boost::make_tuple(account, delta.asset_id));
if(itr == index.end())
{
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx
ptrx.operation_results = std::move(eval_state.operation_results);

//Make sure the temp account has no non-zero balances
const auto& index = get_index_type<account_balance_index>().indices().get<by_account>();
auto range = index.equal_range(GRAPHENE_TEMP_ACCOUNT);
const auto& index = get_index_type<account_balance_index>().indices().get<by_account_asset>();
auto range = index.equal_range( boost::make_tuple( GRAPHENE_TEMP_ACCOUNT ) );
std::for_each(range.first, range.second, [](const account_balance_object& b) { FC_ASSERT(b.balance == 0); });

return ptrx;
Expand Down
30 changes: 21 additions & 9 deletions libraries/chain/include/graphene/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,35 @@ namespace graphene { namespace chain {
map< account_id_type, set<account_id_type> > referred_by;
};

struct by_asset;
struct by_account;
struct by_balance;
struct by_account_asset;
struct by_asset_balance;
/**
* @ingroup object_index
*/
typedef multi_index_container<
account_balance_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_balance>, composite_key<
account_balance_object,
member<account_balance_object, account_id_type, &account_balance_object::owner>,
member<account_balance_object, asset_id_type, &account_balance_object::asset_type> >
ordered_unique< tag<by_account_asset>,
composite_key<
account_balance_object,
member<account_balance_object, account_id_type, &account_balance_object::owner>,
member<account_balance_object, asset_id_type, &account_balance_object::asset_type>
>
>,
ordered_non_unique< tag<by_account>, member<account_balance_object, account_id_type, &account_balance_object::owner> >,
ordered_non_unique< tag<by_asset>, member<account_balance_object, asset_id_type, &account_balance_object::asset_type> >
ordered_unique< tag<by_asset_balance>,
composite_key<
account_balance_object,
member<account_balance_object, asset_id_type, &account_balance_object::asset_type>,
member<account_balance_object, share_type, &account_balance_object::balance>,
member<account_balance_object, account_id_type, &account_balance_object::owner>
>,
composite_key_compare<
std::less< asset_id_type >,
std::greater< share_type >,
std::less< account_id_type >
>
>
>
> account_balance_object_multi_index_type;

Expand Down

0 comments on commit a13c1fb

Please sign in to comment.