Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add withdrawl permission api calls #676

Merged
merged 1 commit into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// Blinded balances
vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;

// Withdrawals
vector<withdraw_permission_object> get_withdraw_permissions_by_giver(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const;
vector<withdraw_permission_object> get_withdraw_permissions_by_recipient(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const;

//private:
static string price_to_string( const price& _price, const asset_object& _base, const asset_object& _quote );
Expand Down Expand Up @@ -2051,6 +2054,54 @@ vector<blinded_balance_object> database_api_impl::get_blinded_balances( const fl
return result;
}

//////////////////////////////////////////////////////////////////////
// //
// Withdrawals //
// //
//////////////////////////////////////////////////////////////////////

vector<withdraw_permission_object> database_api::get_withdraw_permissions_by_giver(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const
{
return my->get_withdraw_permissions_by_giver( account, start, limit );
}

vector<withdraw_permission_object> database_api_impl::get_withdraw_permissions_by_giver(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const
{
FC_ASSERT( limit <= 101 );
vector<withdraw_permission_object> result;

const auto& withdraw_idx = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>();
auto withdraw_index_end = withdraw_idx.end();
auto withdraw_itr = withdraw_idx.lower_bound(boost::make_tuple(account, start));
while(withdraw_itr != withdraw_index_end && withdraw_itr->withdraw_from_account == account && result.size() < limit)
{
result.push_back(*withdraw_itr);
++withdraw_itr;
}
return result;
}

vector<withdraw_permission_object> database_api::get_withdraw_permissions_by_recipient(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const
{
return my->get_withdraw_permissions_by_recipient( account, start, limit );
}

vector<withdraw_permission_object> database_api_impl::get_withdraw_permissions_by_recipient(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const
{
FC_ASSERT( limit <= 101 );
vector<withdraw_permission_object> result;

const auto& withdraw_idx = _db.get_index_type<withdraw_permission_index>().indices().get<by_authorized>();
auto withdraw_index_end = withdraw_idx.end();
auto withdraw_itr = withdraw_idx.lower_bound(boost::make_tuple(account, start));
while(withdraw_itr != withdraw_index_end && withdraw_itr->authorized_account == account && result.size() < limit)
{
result.push_back(*withdraw_itr);
++withdraw_itr;
}
return result;
}

//////////////////////////////////////////////////////////////////////
// //
// Private methods //
Expand Down
27 changes: 27 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,28 @@ class database_api
*/
vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;

/////////////////
// Withdrawals //
/////////////////

/**
* @brief Get non expired withdraw permission objects for a giver(ex:recurring customer)
* @param account Account to get objects from
* @param start Withdraw permission objects(1.12.X) before this ID will be skipped in results. Pagination purposes.
* @param limit Maximum number of objects to retrieve
* @return Withdraw permission objects for the account
*/
vector<withdraw_permission_object> get_withdraw_permissions_by_giver(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const;

/**
* @brief Get non expired withdraw permission objects for a recipient(ex:service provider)
* @param account Account to get objects from
* @param start Withdraw permission objects(1.12.X) before this ID will be skipped in results. Pagination purposes.
* @param limit Maximum number of objects to retrieve
* @return Withdraw permission objects for the account
*/
vector<withdraw_permission_object> get_withdraw_permissions_by_recipient(account_id_type account, withdraw_permission_id_type start, uint32_t limit)const;

private:
std::shared_ptr< database_api_impl > my;
};
Expand Down Expand Up @@ -731,4 +753,9 @@ FC_API(graphene::app::database_api,

// Blinded balances
(get_blinded_balances)

// Withdrawals
(get_withdraw_permissions_by_giver)
(get_withdraw_permissions_by_recipient)

)