-
Notifications
You must be signed in to change notification settings - Fork 648
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
Conversation
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.
I'd recommend that change type of start
to object_id_type
or withdraw_permission_object_id_type
.
Having CLI commands for WP is good but not a priority. Businesses will build GUI's with the API's. |
changed start type. change in the loop was needed to make it work with the object id. |
libraries/app/database_api.cpp
Outdated
}); | ||
|
||
auto withdraw_itr = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>().lower_bound(boost::make_tuple(account, start)); | ||
while( withdraw_itr->withdraw_from_account == account && result.size() < limit) |
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.
Need to check for end()
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.
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.
libraries/app/database_api.cpp
Outdated
result.emplace_back(withdraw); | ||
}); | ||
|
||
auto withdraw_itr = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>().lower_bound(boost::make_tuple(account, start)); |
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.
Perhaps use upper_bound
for pagination, otherwise we will have effectively 99 rows per page, which will impact performance somehow.
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.
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.
libraries/app/database_api.cpp
Outdated
|
||
auto withdraw_index_end = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>().end(); | ||
auto withdraw_itr = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>().lower_bound(boost::make_tuple(account, start)); | ||
while( withdraw_itr->withdraw_from_account == account && result.size() < limit && withdraw_itr != withdraw_index_end) |
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.
end
check should be before dereferencing (withdraw_itr->
)
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.
sorry, changed.
libraries/app/database_api.cpp
Outdated
@@ -2071,8 +2071,9 @@ vector<withdraw_permission_object> database_api_impl::get_withdrawals_giver(acco | |||
FC_ASSERT( limit <= 100 ); | |||
vector<withdraw_permission_object> result; | |||
|
|||
auto withdraw_index_end = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>().end(); |
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.
Two lines of _db.get_index_type<withdraw_permission_index>().indices().get<by_from>()
is ugly.
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.
yea, found the issue. testing now and will upload with all the last suggestions.
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.
was just needing const auto&
to make it work.
libraries/app/database_api.cpp
Outdated
while( withdraw_itr->withdraw_from_account == account && result.size() < limit && withdraw_itr != withdraw_index_end) | ||
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.upper_bound(boost::make_tuple(account, start)); |
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.
After changed start
to withdraw_permission_id_type
and using upper_bound
at same time, it would be unable to return the object whose id is 1.12.0
(although in production it's been removed long before).
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.
yes but i added an extra block for it 2 calls in the. do yo think we should remove it ?
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.
But it's ambiguous when start
is 1.12.0
(want it to be returned or not). IMHO we can just change start
to object_id_type
so users can pass in 0.0.0
for example.
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.
And make the in-code document about start
clearer.
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.
extended start
doc line.
Another option would be: keep |
Used this option. |
The code looks OK now. Other concerns:
@TheTaconator @ryanRfox please advise. |
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.
The API names are ambiguous, they may refer to query for histories, may refer to query by the opposites. Please change the names to get_withdraw_permissions_by_giver
and get_withdraw_permissions_by_recipient
.
i am sending a new pull request for this as i sent unwanted commits when changed the names here. will reference to this pull. |
#611
pull request exposes 2 new api calls to get withdraw objects from accounts:
get_withdrawals_giver
andget_withdrawals_recipient
they can only can get non expired objects as they will be removed from the index when they expire at https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/db_update.cpp#L485
i think history will be needed eventually but we don't want to add it to core so we probably can add this objects here: #500
also, if merged, the calls will need to be added to
cli_wallet
so i can create some documentation on how a business can use this feature as it is now fully from the cli.