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

Conversation

oxarbitrage
Copy link
Member

#611

pull request exposes 2 new api calls to get withdraw objects from accounts: get_withdrawals_giver and get_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.

Copy link
Member

@abitmore abitmore left a 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.

@abitmore
Copy link
Member

abitmore commented Feb 9, 2018

Having CLI commands for WP is good but not a priority. Businesses will build GUI's with the API's.

@abitmore abitmore added this to the Next Non-Consensus-Changing Release milestone Feb 9, 2018
@abitmore abitmore added the api label Feb 9, 2018
@oxarbitrage
Copy link
Member Author

changed start type. change in the loop was needed to make it work with the object id.

});

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)
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.emplace_back(withdraw);
});

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.


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)
Copy link
Member

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->)

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, changed.

@@ -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();
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

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));
Copy link
Member

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).

Copy link
Member Author

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 ?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

extended start doc line.

@abitmore
Copy link
Member

Another option would be: keep lower_bound and withdraw_permission_id_type, but increase the maximum value of limit to 101, so clients can get 100 new rows per page.

@oxarbitrage
Copy link
Member Author

oxarbitrage commented Feb 11, 2018

Another option would be: keep lower_bound and withdraw_permission_id_type, but increase the maximum value of limit to 101, so clients can get 100 new rows per page.

Used this option.

@abitmore
Copy link
Member

The code looks OK now. Other concerns:

  • the API names are not beautiful enough
  • the API may be enough for payers, but we may need more powerful API's for recipients which are usually service providers therefore may generate large quantities of objects and need to query with complex filters. To serve them better, need to implement plugins or even external data processing tools (E.G. ElasticSearch), although this discussion does not belong to this ticket.

@TheTaconator @ryanRfox please advise.

Copy link
Member

@abitmore abitmore left a 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.

@oxarbitrage
Copy link
Member Author

i am sending a new pull request for this as i sent unwanted commits when changed the names here. will reference to this pull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants