-
Notifications
You must be signed in to change notification settings - Fork 649
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 htlc api calls #1729
add htlc api calls #1729
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,11 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl> | |
vector<withdraw_permission_object> get_withdraw_permissions_by_giver(const std::string account_id_or_name, withdraw_permission_id_type start, uint32_t limit)const; | ||
vector<withdraw_permission_object> get_withdraw_permissions_by_recipient(const std::string account_id_or_name, withdraw_permission_id_type start, uint32_t limit)const; | ||
|
||
// HTCL | ||
optional<htlc_object> get_htlc(htlc_id_type id) const; | ||
vector<htlc_object> get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; | ||
vector<htlc_object> get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; | ||
|
||
//private: | ||
static string price_to_string( const price& _price, const asset_object& _base, const asset_object& _quote ); | ||
|
||
|
@@ -969,6 +974,12 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const | |
acnt.withdraws.emplace_back(withdraw); | ||
}); | ||
|
||
// get htlcs | ||
auto htlc_range = _db.get_index_type<htlc_index>().indices().get<by_from_id>().equal_range(account->id); | ||
std::for_each(htlc_range.first, htlc_range.second, | ||
[&acnt] (const htlc_object& htlc) { | ||
acnt.htlcs.emplace_back(htlc); | ||
}); | ||
|
||
results[account_name_or_id] = acnt; | ||
} | ||
|
@@ -2382,6 +2393,74 @@ vector<withdraw_permission_object> database_api_impl::get_withdraw_permissions_b | |
return result; | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// // | ||
// HTLC // | ||
// // | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
optional<htlc_object> database_api::get_htlc(htlc_id_type id)const | ||
{ | ||
return my->get_htlc(id); | ||
} | ||
|
||
fc::optional<htlc_object> database_api_impl::get_htlc(htlc_id_type id) const | ||
{ | ||
auto obj = get_objects( { id }).front(); | ||
if ( !obj.is_null() ) | ||
{ | ||
return fc::optional<htlc_object>(obj.template as<htlc_object>(GRAPHENE_MAX_NESTED_OBJECTS)); | ||
} | ||
return fc::optional<htlc_object>(); | ||
} | ||
|
||
vector<htlc_object> database_api::get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const | ||
{ | ||
return my->get_htlc_by_from(account_id_or_name, start, limit); | ||
} | ||
|
||
vector<htlc_object> database_api_impl::get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const | ||
{ | ||
FC_ASSERT( limit <= 101 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When adding new API calls with limits, please make the limit configurable as in #1513 |
||
vector<htlc_object> result; | ||
|
||
const auto& htlc_idx = _db.get_index_type< htlc_index >().indices().get< by_from_id >(); | ||
auto htlc_index_end = htlc_idx.end(); | ||
const account_id_type account = get_account_from_string(account_id_or_name)->id; | ||
auto htlc_itr = htlc_idx.lower_bound(boost::make_tuple(account, start)); | ||
|
||
while(htlc_itr != htlc_index_end && htlc_itr->transfer.from == account && result.size() < limit) | ||
{ | ||
result.push_back(*htlc_itr); | ||
++htlc_itr; | ||
} | ||
return result; | ||
} | ||
|
||
vector<htlc_object> database_api::get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const | ||
{ | ||
return my->get_htlc_by_to(account_id_or_name, start, limit); | ||
} | ||
|
||
vector<htlc_object> database_api_impl::get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const | ||
{ | ||
|
||
FC_ASSERT( limit <= 101 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When adding new API calls with limits, please make the limit configurable as in #1513 |
||
vector<htlc_object> result; | ||
|
||
const auto& htlc_idx = _db.get_index_type< htlc_index >().indices().get< by_to_id >(); | ||
auto htlc_index_end = htlc_idx.end(); | ||
const account_id_type account = get_account_from_string(account_id_or_name)->id; | ||
auto htlc_itr = htlc_idx.lower_bound(boost::make_tuple(account, start)); | ||
|
||
while(htlc_itr != htlc_index_end && htlc_itr->transfer.to == account && result.size() < limit) | ||
{ | ||
result.push_back(*htlc_itr); | ||
++htlc_itr; | ||
} | ||
return result; | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// // | ||
// Private methods // | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
#include <graphene/chain/proposal_object.hpp> | ||
#include <graphene/chain/worker_object.hpp> | ||
#include <graphene/chain/witness_object.hpp> | ||
#include <graphene/chain/htlc_object.hpp> | ||
|
||
#include <graphene/market_history/market_history_plugin.hpp> | ||
|
||
|
@@ -743,7 +744,36 @@ class database_api | |
*/ | ||
vector<withdraw_permission_object> get_withdraw_permissions_by_recipient(const std::string account_id_or_name, withdraw_permission_id_type start, uint32_t limit)const; | ||
|
||
private: | ||
////////// | ||
// HTLC // | ||
////////// | ||
|
||
/** | ||
* @brief Get HTLC object | ||
* @param id HTLC contarct id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: contarct |
||
* @return HTLC object for the id | ||
*/ | ||
optional<htlc_object> get_htlc(htlc_id_type id) const; | ||
|
||
/** | ||
* @brief Get non expired HTLC objects using the sender account | ||
* @param account Account ID or name to get objects from | ||
* @param start Withdraw permission objects(1.16.X) before this ID will be skipped in results. Pagination purposes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C&P error |
||
* @param limit Maximum number of objects to retrieve | ||
* @return HTLC objects for the account | ||
*/ | ||
vector<htlc_object> get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; | ||
|
||
/** | ||
* @brief Get non expired HTLC objects using the receiver account | ||
* @param account Account ID or name to get objects from | ||
* @param start Withdraw permission objects(1.16.X) before this ID will be skipped in results. Pagination purposes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C&P error |
||
* @param limit Maximum number of objects to retrieve | ||
* @return HTLC objects for the account | ||
*/ | ||
vector<htlc_object> get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; | ||
|
||
private: | ||
std::shared_ptr< database_api_impl > my; | ||
}; | ||
|
||
|
@@ -865,4 +895,8 @@ FC_API(graphene::app::database_api, | |
(get_withdraw_permissions_by_giver) | ||
(get_withdraw_permissions_by_recipient) | ||
|
||
// HTLC | ||
(get_htlc) | ||
(get_htlc_by_from) | ||
(get_htlc_by_to) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also list htlcs for which the account is the recipient?