Skip to content

Commit

Permalink
Merge pull request cryptonomex#676 from oxarbitrage/issue611_2
Browse files Browse the repository at this point in the history
add withdrawl permission api calls
  • Loading branch information
oxarbitrage authored Feb 19, 2018
2 parents 86276a5 + 65f64db commit 4d5071b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
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)

)

0 comments on commit 4d5071b

Please sign in to comment.