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
52 changes: 52 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_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 +2055,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_withdrawals_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_withdrawals_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,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 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 +754,8 @@ FC_API(graphene::app::database_api,

// Blinded balances
(get_blinded_balances)

// Withdrawals
(get_withdraw_permissions_by_giver)
(get_withdraw_permissions_by_recipient)
)
2 changes: 0 additions & 2 deletions libraries/chain/include/graphene/chain/protocol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ namespace graphene { namespace chain {
friend bool operator == ( const public_key_type& p1, const fc::ecc::public_key& p2);
friend bool operator == ( const public_key_type& p1, const public_key_type& p2);
friend bool operator != ( const public_key_type& p1, const public_key_type& p2);
// TODO: This is temporary for testing
bool is_valid_v1( const std::string& base58str );
};

struct extended_public_key_type
Expand Down
25 changes: 0 additions & 25 deletions libraries/chain/protocol/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ namespace graphene { namespace chain {
// TODO: Refactor syntactic checks into static is_valid()
// to make public_key_type API more similar to address API
std::string prefix( GRAPHENE_ADDRESS_PREFIX );

// TODO: This is temporary for testing
try
{
if( is_valid_v1( base58str ) )
prefix = std::string( "BTS" );
}
catch( ... )
{
}

const size_t prefix_len = prefix.size();
FC_ASSERT( base58str.size() > prefix_len );
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
Expand All @@ -64,20 +53,6 @@ namespace graphene { namespace chain {
FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check );
};

// TODO: This is temporary for testing
bool public_key_type::is_valid_v1( const std::string& base58str )
{
std::string prefix( "BTS" );
const size_t prefix_len = prefix.size();
FC_ASSERT( base58str.size() > prefix_len );
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
auto bin_key = fc::raw::unpack<binary_key>(bin);
fc::ecc::public_key_data key_data = bin_key.data;
FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check );
return true;
}

public_key_type::operator fc::ecc::public_key_data() const
{
return key_data;
Expand Down