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 api calls to get non expired withdrawls #657

Closed
wants to merge 9 commits into from
48 changes: 48 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ 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_withdrawals_giver(account_id_type account, object_id_type start, uint32_t limit)const;
vector<withdraw_permission_object> get_withdrawals_recipient(account_id_type account, object_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 +2055,50 @@ vector<blinded_balance_object> database_api_impl::get_blinded_balances( const fl
return result;
}

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

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

vector<withdraw_permission_object> database_api_impl::get_withdrawals_giver(account_id_type account, object_id_type start, uint32_t limit)const
{
FC_ASSERT( limit <= 100 );
vector<withdraw_permission_object> result;

auto withdraw_itr = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>().lower_bound(boost::make_tuple(account, start));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use upper_bound for pagination, otherwise we will have effectively 99 rows per page, which will impact performance somehow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense change to upper_bound but i had to add a special case to be able to retrieve first object. this will not make too much sense in the live change as 1.12.0 is already gone but as i am in a private testnet i think the right thing is to consider it.

while( withdraw_itr->withdraw_from_account == account && result.size() < limit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check for end()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added end of index check at 845eb37

for some reason i cant do _db.get_index_type<withdraw_permission_index>().indices().get<by_from>() alone. when i do it i get a compiler error as:

...
sion_object> >; TagList = boost::mpl::v_item<graphene::chain::by_from, boost::mpl::vector0<mpl_::na>, 0>; Category = boost::multi_index::detail::ordered_unique_tag]’ is protected
   ~ordered_index()
   ^
/home/alfredo/CLionProjects/issue611/libraries/app/database_api.cpp:2074:95: error: within this context
    auto withdraw_idx = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>();
...

so i had to code that twice, as far as i remember i never saw the issue in other indexes.

{
result.push_back(*withdraw_itr);
++withdraw_itr;
}
return result;
}

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

vector<withdraw_permission_object> database_api_impl::get_withdrawals_recipient(account_id_type account, object_id_type start, uint32_t limit)const
{
FC_ASSERT( limit <= 100 );
vector<withdraw_permission_object> result;

auto withdraw_itr = _db.get_index_type<withdraw_permission_index>().indices().get<by_authorized>().lower_bound(boost::make_tuple(account, start));
while( 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,29 @@ 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 Used for pagination purposes
* @param limit Maximum number of objects to retrieve
* @return Withdraw permission objects for the account
*/
vector<withdraw_permission_object> get_withdrawals_giver(account_id_type account, object_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 Used for pagination purposes
* @param limit Maximum number of objects to retrieve
* @return Withdraw permission objects for the account
*/
vector<withdraw_permission_object> get_withdrawals_recipient(account_id_type account, object_id_type start, uint32_t limit)const;


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

// Blinded balances
(get_blinded_balances)

// Withdrawals
(get_withdrawals_giver)
(get_withdrawals_recipient)
)