Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request DasCoin/dascoin-blockchain!179
  • Loading branch information
Branislav Zelenak committed Aug 31, 2018
2 parents 816ab93 + f972b6a commit 416c1ae
Show file tree
Hide file tree
Showing 49 changed files with 2,574 additions and 652 deletions.
105 changes: 103 additions & 2 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
vector<balance_object> get_balance_objects( const vector<address>& addrs )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;
tethered_accounts_balances_collection get_tethered_accounts_balances( account_id_type id, asset_id_type asset )const;
vector<tethered_accounts_balances_collection> get_tethered_accounts_balances( account_id_type account, const flat_set<asset_id_type>& assets )const;

// Assets
asset_id_type get_web_asset_id() const;
Expand Down Expand Up @@ -202,7 +204,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
vector<das33_pledge_holder_object> get_das33_pledges_by_account(account_id_type account) const;
vector<das33_pledge_holder_object> get_das33_pledges_by_project(das33_project_id_type project, das33_pledge_holder_id_type from, uint32_t limit) const;
vector<das33_project_object> get_das33_projects(const string& lower_bound_name, uint32_t limit) const;

vector<asset> get_amount_of_assets_pledged_to_project(das33_project_id_type project) const;

template<typename T>
void subscribe_to_item( const T& i )const
Expand Down Expand Up @@ -1060,6 +1062,73 @@ vector<vesting_balance_object> database_api_impl::get_vesting_balances( account_
FC_CAPTURE_AND_RETHROW( (account_id) );
}

vector<tethered_accounts_balances_collection> database_api::get_tethered_accounts_balances( account_id_type id, const flat_set<asset_id_type>& assets )const
{
return my->get_tethered_accounts_balances( id, assets );
}

vector<tethered_accounts_balances_collection> database_api_impl::get_tethered_accounts_balances( account_id_type account, const flat_set<asset_id_type>& assets )const
{
vector<asset_id_type> tmp;
if (assets.empty()) {
// if the caller passes in an empty list of assets, get 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_asset>().equal_range(boost::make_tuple(account));
for (const account_balance_object &balance : boost::make_iterator_range(range.first, range.second))
tmp.emplace_back(balance.asset_type);
} else {
tmp.reserve(assets.size());
std::copy(assets.begin(), assets.end(), std::back_inserter(tmp));
}
vector<tethered_accounts_balances_collection> result;
std::transform(tmp.begin(), tmp.end(), std::back_inserter(result), [this, account](asset_id_type id) {
return get_tethered_accounts_balances(account, id);
});
return result;
}

tethered_accounts_balances_collection database_api_impl::get_tethered_accounts_balances( account_id_type id, asset_id_type asset )const
{
tethered_accounts_balances_collection ret;
ret.total = 0;
ret.asset_id = asset;
const auto& idx = _db.get_index_type<account_index>().indices().get<by_id>();
const auto it = idx.find(id);
flat_set<tuple<account_id_type, string, account_kind>> accounts;
if (it != idx.end())
{
const auto& account = *it;
if (account.kind == account_kind::wallet)
{
accounts.insert(make_tuple(id, account.name, account.kind));
std::transform(account.vault.begin(), account.vault.end(), std::inserter(accounts, accounts.begin()), [&](account_id_type vault)
{
const auto& vault_acc = vault(_db);
return make_tuple(vault, vault_acc.name, account_kind::vault);
});
}
else if (account.kind == account_kind::custodian || account.kind == account_kind::special)
{
accounts.insert(make_tuple(id, account.name, account.kind));
}
else if (account.kind == account_kind::vault)
{
if (account.parents.empty())
accounts.insert(make_tuple(id, account.name, account.kind));
else
return get_tethered_accounts_balances(*(account.parents.begin()), asset);
}
}

for (const auto& i : accounts)
{
const auto& balance_obj = _db.get_balance_object(get<0>(i), asset);
ret.total += balance_obj.balance + balance_obj.reserved;
ret.details.emplace_back(tethered_accounts_balance{get<0>(i), get<1>(i), get<2>(i), balance_obj.balance, balance_obj.reserved});
}
return ret;
}

//////////////////////////////////////////////////////////////////////
// //
// Assets //
Expand Down Expand Up @@ -2710,7 +2779,7 @@ vector<dasc_holder> database_api_impl::get_top_dasc_holders() const
{
holder.vaults = account.vault.size();
const auto& balance_obj = _db.get_balance_object(account.id, dasc_id);
holder.amount = balance_obj.balance;
holder.amount = balance_obj.balance + balance_obj.reserved;
std::for_each(account.vault.begin(), account.vault.end(), [this, &holder, &dasc_id](const account_id_type& vault_id) {
const auto& balance_obj = _db.get_balance_object(vault_id, dasc_id);
holder.amount += balance_obj.balance;
Expand Down Expand Up @@ -2878,6 +2947,38 @@ vector<das33_project_object> database_api_impl::get_das33_projects(const string&
return result;
}

vector<asset> database_api::get_amount_of_assets_pledged_to_project(das33_project_id_type project) const
{
return my->get_amount_of_assets_pledged_to_project(project);
}

vector<asset> database_api_impl::get_amount_of_assets_pledged_to_project(das33_project_id_type project) const
{
vector<asset> result;
map<asset_id_type, int> index_map;

auto default_pledge_id = das33_pledge_holder_id_type();

const auto& pledges = _db.get_index_type<das33_pledge_holder_index>().indices().get<by_project>();
for( auto itr = pledges.lower_bound(project); itr != pledges.upper_bound(project); ++itr )
{
if (itr->id != default_pledge_id)
{
if (index_map.find(itr->pledged.asset_id) != index_map.end())
{
result[index_map[itr->pledged.asset_id]] += itr->pledged;
}
else
{
index_map[itr->pledged.asset_id] = result.size();
result.emplace_back(itr->pledged);
}
}
}

return result;
}


//////////////////////////////////////////////////////////////////////
// //
Expand Down
86 changes: 61 additions & 25 deletions libraries/app/impacted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,31 +515,67 @@ struct get_impacted_account_visitor
_impacted.insert( op.account );
}

void operator() ( const das33_pledge_asset_operation& op )
{
_impacted.insert( op.account_id );
}

void operator() ( const das33_project_create_operation& op )
{
_impacted.insert( op.authority );
_impacted.insert( op.owner );
}

void operator() ( const das33_project_update_operation& op )
{
_impacted.insert( op.authority );
}

void operator() ( const das33_project_delete_operation& op )
{
_impacted.insert( op.authority );
}

void operator() ( const update_global_parameters_operation& op )
{
_impacted.insert(op.authority);
}
void operator() ( const das33_pledge_asset_operation& op )
{
_impacted.insert( op.account_id );
}

void operator() ( const das33_distribute_project_pledges_operation& op )
{
_impacted.insert(op.authority);
}

void operator() ( const das33_project_reject_operation& op )
{
_impacted.insert(op.authority);
}

void operator() ( const das33_distribute_pledge_operation& op )
{
_impacted.insert(op.authority);
}

void operator() ( const das33_pledge_reject_operation& op )
{
_impacted.insert(op.authority);
}

void operator() ( const das33_set_use_external_btc_price_operation& op)
{
_impacted.insert(op.authority);
}

void operator() ( const das33_pledge_result_operation& op )
{
_impacted.insert(op.funders_account);
_impacted.insert(op.account_to_fund);
}

void operator() ( const das33_project_create_operation& op )
{
_impacted.insert( op.authority );
_impacted.insert( op.owner );
}

void operator() ( const das33_project_update_operation& op )
{
_impacted.insert( op.authority );
}

void operator() ( const das33_project_delete_operation& op )
{
_impacted.insert( op.authority );
}

void operator() ( const update_global_parameters_operation& op )
{
_impacted.insert(op.authority);
}

void operator()( const update_external_btc_price_operation& op )
{
_impacted.insert( op.issuer );
}
};

void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
Expand Down
36 changes: 35 additions & 1 deletion libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ struct daspay_authority
optional<string> memo;
};

struct tethered_accounts_balance
{
account_id_type account;
string name;
account_kind kind;
share_type balance;
share_type reserved;
};

struct tethered_accounts_balances_collection
{
share_type total;
asset_id_type asset_id;
vector<tethered_accounts_balance> details;
};

/**
* @brief The database_api class implements the RPC API for the chain database.
Expand Down Expand Up @@ -376,6 +391,14 @@ class database_api

vector<vesting_balance_object> get_vesting_balances( account_id_type account_id )const;

/**
* @brief Get a tethered accounts' balances in various assets
* @param id ID of the account to get balances for
* @param assets IDs of the assets to get balances of; if empty, get all assets account has a balance in
* @return Balances of the tethered accounts
*/
vector<tethered_accounts_balances_collection> get_tethered_accounts_balances(account_id_type id, const flat_set<asset_id_type>& assets)const;

/**
* @brief Get the total number of accounts registered with the blockchain
*/
Expand Down Expand Up @@ -959,7 +982,14 @@ class database_api
* @params limit number of projects to return, max 100
* @return vector of das33 project objects
*/
vector<das33_project_object> get_das33_projects(const string& lower_bound_name, uint32_t limit)const;
vector<das33_project_object> get_das33_projects(const string& lower_bound_name, uint32_t limit) const;

/**
* @brief Gets a sum of all pledges made to project
* @params project id of a project
* @return vector of assets, each with total sum of that asset pledged
*/
vector<asset> get_amount_of_assets_pledged_to_project(das33_project_id_type project) const;

private:
std::shared_ptr< database_api_impl > my;
Expand All @@ -979,6 +1009,8 @@ FC_REFLECT( graphene::app::limit_orders_collection_grouped_by_price, (buy)(sell)
FC_REFLECT( graphene::app::cycle_price, (cycle_amount)(asset_amount)(frequency) );
FC_REFLECT( graphene::app::dasc_holder, (holder)(vaults)(amount) );
FC_REFLECT( graphene::app::daspay_authority, (payment_provider)(daspay_public_key)(memo) );
FC_REFLECT( graphene::app::tethered_accounts_balance, (account)(name)(kind)(balance)(reserved) );
FC_REFLECT( graphene::app::tethered_accounts_balances_collection, (asset_id)(total)(details) );

FC_API( graphene::app::database_api,
// Objects
Expand Down Expand Up @@ -1024,6 +1056,7 @@ FC_API( graphene::app::database_api,
(get_balance_objects)
(get_vested_balances)
(get_vesting_balances)
(get_tethered_accounts_balances)

// Assets
(get_assets)
Expand Down Expand Up @@ -1131,4 +1164,5 @@ FC_API( graphene::app::database_api,
(get_das33_pledges_by_account)
(get_das33_pledges_by_project)
(get_das33_projects)
(get_amount_of_assets_pledged_to_project)
)
1 change: 0 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ add_library( graphene_chain
wire_out_with_fee_evaluator.cpp
cycle_evaluator.cpp
change_fee_evaluator.cpp
balance_checker.cpp

access_layer.cpp

Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ object_id_type change_public_keys_evaluator::do_apply(const change_public_keys_o
void_result set_roll_back_enabled_evaluator::do_evaluate(const set_roll_back_enabled_operation& op)
{
try {

FC_ASSERT( db().head_block_time() <= HARDFORK_BLC_200_TIME, "Remove (hard-fork) set_roll_back_enabled operation." );

return {};
} FC_CAPTURE_AND_RETHROW((op))
}
Expand All @@ -541,6 +544,9 @@ object_id_type set_roll_back_enabled_evaluator::do_apply(const set_roll_back_ena
void_result roll_back_public_keys_evaluator::do_evaluate(const roll_back_public_keys_operation& op)
{
try {

FC_ASSERT( db().head_block_time() <= HARDFORK_BLC_200_TIME, "Remove (hard-fork) roll_back_public_keys operation." );

const auto op_authority_obj = op.authority(db());
db().perform_chain_authority_check("personal identity validation",
db().get_global_properties().authorities.pi_validator,
Expand Down
21 changes: 21 additions & 0 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,25 @@ void_result asset_deny_issue_request_evaluator::do_apply(const asset_deny_issue_

} FC_CAPTURE_AND_RETHROW((o)) }

void_result update_external_btc_price_evaluator::do_evaluate(const update_external_btc_price_operation& o)
{ try {

const auto& d = db();
FC_ASSERT( o.issuer == d.get_chain_authorities().webasset_issuer );

return{};

} FC_CAPTURE_AND_RETHROW((o)) }

void_result update_external_btc_price_evaluator::do_apply(const update_external_btc_price_operation& o)
{ try {

auto btc_price = o.eur_amount_per_btc;
db().modify(db().get_dynamic_global_properties(), [btc_price](dynamic_global_property_object& dgpo){
dgpo.external_btc_price = btc_price;
});
return {};

} FC_CAPTURE_AND_RETHROW((o)) }

} } // graphene::chain
32 changes: 0 additions & 32 deletions libraries/chain/balance_checker.cpp

This file was deleted.

Loading

0 comments on commit 416c1ae

Please sign in to comment.