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

get_full_accounts API changes and new database APIs #1749

Merged
merged 25 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cfa8a73
add by_authorized withdraw objects to get_full_accounts results
oxarbitrage May 4, 2019
cab48ae
add api-limit-get-full-accounts to application, complete implementati…
oxarbitrage May 6, 2019
ee0df87
add configurable limits to get_full_account lists
oxarbitrage May 6, 2019
31f28a2
remove operator== overload from htlc and withdraw objects
oxarbitrage May 7, 2019
55098b8
add more_data struct to full_account
oxarbitrage May 7, 2019
d10f970
change for_eachs to for, populate more_data flags, remove find
oxarbitrage May 7, 2019
3aba3f7
have 2 limit options for get_full_accounts for vector accounts and li…
oxarbitrage May 8, 2019
2fd3db2
refactor get_proposed_transactions
oxarbitrage May 8, 2019
c20c325
separate htlc and withdraws in from and to
oxarbitrage May 8, 2019
445c6d4
move additional data computation outside loops
oxarbitrage May 8, 2019
413b9cf
add get_call_orders_by_account api call
oxarbitrage May 8, 2019
4eeb4d3
remove unsigned warnings
oxarbitrage May 8, 2019
bda09a0
move additional data logic back to inside loops as suggested by abit
oxarbitrage May 9, 2019
66c0f40
do proposal index in 1 line
oxarbitrage May 9, 2019
65d5180
change to withdraws_to for consistency, wrap long line
oxarbitrage May 9, 2019
38c3cef
add start argument to get_call_orders_by_account
oxarbitrage May 9, 2019
cd504f5
add get_settle_orders_by_account
oxarbitrage May 9, 2019
ce709f9
add get_assets_by_issuer api call
oxarbitrage May 9, 2019
ed53cb0
move back proposal index outside of the loop
oxarbitrage May 10, 2019
0968f95
fix c&p errors
oxarbitrage May 10, 2019
8994995
remove by_issuer_and_id index
oxarbitrage May 10, 2019
976b56b
paginate get_call_orders_by_account by asset_id
oxarbitrage May 10, 2019
d07c374
make start optional in htlc api calls
oxarbitrage May 10, 2019
dbb1fed
undo d07c374
oxarbitrage May 10, 2019
efc8181
add test cases
oxarbitrage May 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,21 @@ void application_impl::set_api_limit() {
if(_options->count("api-limit-get-htlc-by")) {
_app_options.api_limit_get_htlc_by = _options->at("api-limit-get-htlc-by").as<uint64_t>();
}
if(_options->count("api-limit-get-full-accounts")) {
_app_options.api_limit_get_full_accounts = _options->at("api-limit-get-full-accounts").as<uint64_t>();
}
if(_options->count("api-limit-get-full-accounts-lists")) {
_app_options.api_limit_get_full_accounts_lists = _options->at("api-limit-get-full-accounts-lists").as<uint64_t>();
}
if(_options->count("api-limit-get-call-orders")) {
_app_options.api_limit_get_call_orders = _options->at("api-limit-get-call-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-settle-orders")) {
_app_options.api_limit_get_settle_orders = _options->at("api-limit-get-settle-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-assets")) {
_app_options.api_limit_get_assets = _options->at("api-limit-get-assets").as<uint64_t>();
}
}

void application_impl::startup()
Expand Down Expand Up @@ -1020,6 +1035,18 @@ void application::set_program_options(boost::program_options::options_descriptio
"For asset_api::get_asset_holders to set its default limit value as 100")
("api-limit-get-key-references",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_key_references to set its default limit value as 100")
("api-limit-get-htlc-by",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_htlc_by_from and get_htlc_by_to to set its default limit value as 100")
("api-limit-get-full-accounts",boost::program_options::value<uint64_t>()->default_value(10),
"For database_api_impl::get_full_accounts to set its account default limit values as 10")
("api-limit-get-full-accounts-lists",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_full_accounts to set its lists default limit values as 100")
("api-limit-get-call-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_call_orders and get_call_orders_by_account to set its default limit values as 300")
("api-limit-get-settle-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_settle_orders and get_settle_orders_by_account to set its default limit values as 300")
("api-limit-get-assets",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::list_assets and get_assets_by_issuer to set its default limit values as 101")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down
263 changes: 204 additions & 59 deletions libraries/app/database_api.cpp

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ namespace graphene { namespace app {
uint64_t api_limit_get_asset_holders = 100;
uint64_t api_limit_get_key_references = 100;
uint64_t api_limit_get_htlc_by = 100;
uint64_t api_limit_get_full_accounts = 10;
uint64_t api_limit_get_full_accounts_lists = 100;
uint64_t api_limit_get_call_orders = 300;
uint64_t api_limit_get_settle_orders = 300;
uint64_t api_limit_get_assets = 101;
};

class application
Expand Down
33 changes: 33 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ class database_api
*/
uint64_t get_asset_count()const;

/**
* @brief Get asset objects issued from a given account
* @param account_name_or_id Account name or ID to get objects from
* @param start Asset objects(1.3.X) before this ID will be skipped in results. Pagination purposes.
* @param limit Maximum number of orders to retrieve
* @return The assets issued by the account
*/
vector<asset_object> get_assets_by_issuer(const std::string& issuer_name_or_id,
asset_id_type start, uint32_t limit)const;

/////////////////////
// Markets / feeds //
/////////////////////
Expand All @@ -444,6 +454,16 @@ class database_api
*/
vector<call_order_object> get_call_orders(const std::string& a, uint32_t limit)const;

/**
* @brief Get call orders from a given account
* @param account_name_or_id Account name or ID to get objects from
* @param start Asset objects(1.3.X) before this ID will be skipped in results. Pagination purposes.
* @param limit Maximum number of objects to retrieve
* @return The call orders of the account
*/
vector<call_order_object> get_call_orders_by_account(const std::string& account_name_or_id,
asset_id_type start, uint32_t limit)const;

/**
* @brief Get forced settlement orders in a given asset
* @param a Symbol or ID of asset being settled
Expand All @@ -452,6 +472,16 @@ class database_api
*/
vector<force_settlement_object> get_settle_orders(const std::string& a, uint32_t limit)const;

/**
* @brief Get forced settlement orders of a given account
* @param account_name_or_id Account name or ID to get objects from
* @param start Force settlement objects(1.4.X) before this ID will be skipped in results. Pagination purposes.
* @param limit Maximum number of orders to retrieve
* @return The settle orders of the account
*/
vector<force_settlement_object> get_settle_orders_by_account(const std::string& account_name_or_id,
force_settlement_id_type start, uint32_t limit)const;

/**
* @brief Get collateral_bid_objects for a given asset
* @param a Symbol or ID of asset
Expand Down Expand Up @@ -836,14 +866,17 @@ FC_API(graphene::app::database_api,
(list_assets)
(lookup_asset_symbols)
(get_asset_count)
(get_assets_by_issuer)
(get_asset_id_from_string)

// Markets / feeds
(get_order_book)
(get_limit_orders)
(get_account_limit_orders)
(get_call_orders)
(get_call_orders_by_account)
(get_settle_orders)
(get_settle_orders_by_account)
(get_margin_positions)
(get_collateral_bids)
(subscribe_to_market)
Expand Down
34 changes: 30 additions & 4 deletions libraries/app/include/graphene/app/full_account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@
namespace graphene { namespace app {
using namespace graphene::chain;

struct more_data
{
bool balances = false;
bool vesting_balances = false;
bool limit_orders = false;
bool call_orders = false;
bool settle_orders = false;
bool proposals = false;
bool assets = false;
bool withdraws_from = false;
bool withdraws_to = false;
bool htlcs_from = false;
bool htlcs_to = false;
};

struct full_account
{
account_object account;
Expand All @@ -47,12 +62,20 @@ namespace graphene { namespace app {
vector<force_settlement_object> settle_orders;
vector<proposal_object> proposals;
vector<asset_id_type> assets;
vector<withdraw_permission_object> withdraws;
vector<htlc_object> htlcs;
vector<withdraw_permission_object> withdraws_from;
vector<withdraw_permission_object> withdraws_to;
vector<htlc_object> htlcs_from;
vector<htlc_object> htlcs_to;
more_data more_data_available;
};

} }

FC_REFLECT( graphene::app::more_data,
(balances) (vesting_balances) (limit_orders) (call_orders)
(settle_orders) (proposals) (assets) (withdraws_from) (withdraws_to) (htlcs_from) (htlcs_to)
)

FC_REFLECT( graphene::app::full_account,
(account)
(statistics)
Expand All @@ -68,6 +91,9 @@ FC_REFLECT( graphene::app::full_account,
(settle_orders)
(proposals)
(assets)
(withdraws)
(htlcs)
(withdraws_from)
(withdraws_to)
(htlcs_from)
(htlcs_to)
(more_data_available)
)
7 changes: 6 additions & 1 deletion libraries/chain/include/graphene/chain/asset_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,17 @@ namespace graphene { namespace chain {
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_symbol>, member<asset_object, string, &asset_object::symbol> >,
ordered_non_unique< tag<by_issuer>, member<asset_object, account_id_type, &asset_object::issuer > >,
ordered_unique< tag<by_type>,
composite_key< asset_object,
const_mem_fun<asset_object, bool, &asset_object::is_market_issued>,
member< object, object_id_type, &object::id >
>
>,
ordered_unique< tag<by_issuer>,
composite_key< asset_object,
member< asset_object, account_id_type, &asset_object::issuer >,
member< object, object_id_type, &object::id >
>
>
>
> asset_object_multi_index_type;
Expand Down
3 changes: 0 additions & 3 deletions libraries/chain/include/graphene/chain/htlc_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ namespace graphene { namespace chain {
typedef account_id_type result_type;
const result_type& operator()(const htlc_object& o)const { return o.transfer.to; }
};

bool operator==(const htlc_object& in) { return this->id == in.id; }

};

struct by_from_id;
Expand Down
166 changes: 166 additions & 0 deletions tests/tests/database_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,4 +1121,170 @@ BOOST_AUTO_TEST_CASE( api_limit_get_key_references ){
throw;
}
}

BOOST_AUTO_TEST_CASE( api_limit_get_full_accounts ) {

try {
graphene::app::database_api db_api(db, &(this->app.get_options()));

const account_object& alice = create_account("alice");
const account_object& bob = create_account("bob");
const account_object& carl = create_account("carl");
const account_object& dan = create_account("dan");
const account_object& fred = create_account("fred");
const account_object& henry = create_account("henry");
const account_object& kevin = create_account("kevin");
const account_object& laura = create_account("laura");
const account_object& lucy = create_account("lucy");
const account_object& martin = create_account("martin");
const account_object& patty = create_account("patty");

vector<string> accounts;
accounts.push_back(alice.name);
accounts.push_back(bob.name);
accounts.push_back(carl.name);
accounts.push_back(dan.name);
accounts.push_back(fred.name);
accounts.push_back(henry.name);
accounts.push_back(kevin.name);
accounts.push_back(laura.name);
accounts.push_back(lucy.name);
accounts.push_back(martin.name);
accounts.push_back(patty.name);

GRAPHENE_CHECK_THROW(db_api.get_full_accounts(accounts, false), fc::exception);

accounts.erase(accounts.begin());
auto full_accounts = db_api.get_full_accounts(accounts, false);
BOOST_CHECK(full_accounts.size() == 10);

// not an account
accounts.erase(accounts.begin());
accounts.push_back("nosuchaccount");

// request fully fails even if 9 accounts are valid
GRAPHENE_CHECK_THROW(db_api.get_full_accounts(accounts, false), fc::exception);

} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_CASE( get_assets_by_issuer ) {
try {
graphene::app::database_api db_api(db, &(this->app.get_options()));

create_bitasset("CNY");
create_bitasset("EUR");
create_bitasset("USD");

generate_block();

auto assets = db_api.get_assets_by_issuer("witness-account", asset_id_type(), 10);

BOOST_CHECK(assets.size() == 3);
BOOST_CHECK(assets[0].symbol == "CNY");
BOOST_CHECK(assets[1].symbol == "EUR");
BOOST_CHECK(assets[2].symbol == "USD");

assets = db_api.get_assets_by_issuer("witness-account", asset_id_type(200), 100);
BOOST_CHECK(assets.size() == 0);

GRAPHENE_CHECK_THROW(db_api.get_assets_by_issuer("nosuchaccount", asset_id_type(), 100), fc::exception);

} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_CASE( get_call_orders_by_account ) {

try {
ACTORS((caller)(feedproducer));

graphene::app::database_api db_api(db, &(this->app.get_options()));

const auto &usd = create_bitasset("USD", feedproducer_id);
const auto &cny = create_bitasset("CNY", feedproducer_id);
const auto &core = asset_id_type()(db);

int64_t init_balance(1000000);
transfer(committee_account, caller_id, asset(init_balance));

update_feed_producers(usd, {feedproducer.id});
update_feed_producers(cny, {feedproducer.id});

price_feed current_feed;
current_feed.maintenance_collateral_ratio = 1750;
current_feed.maximum_short_squeeze_ratio = 1100;
current_feed.settlement_price = usd.amount(1) / core.amount(5);
publish_feed(usd, feedproducer, current_feed);

current_feed.maintenance_collateral_ratio = 1750;
current_feed.maximum_short_squeeze_ratio = 1100;
current_feed.settlement_price = cny.amount(1) / core.amount(5);
publish_feed(cny, feedproducer, current_feed);

auto call1 = borrow(caller, usd.amount(1000), asset(15000));
auto call2 = borrow(caller, cny.amount(1000), asset(15000));

auto calls = db_api.get_call_orders_by_account("caller", asset_id_type(), 100);

BOOST_CHECK(calls.size() == 2);
BOOST_CHECK(calls[0].id == call1->id);
BOOST_CHECK(calls[1].id == call2->id);

GRAPHENE_CHECK_THROW(db_api.get_call_orders_by_account("nosuchaccount", asset_id_type(), 100), fc::exception);

} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_CASE( get_settle_orders_by_account ) {
try {
ACTORS((creator)(settler)(caller)(feedproducer));

graphene::app::database_api db_api(db, &(this->app.get_options()));

const auto &usd = create_bitasset("USD", creator_id);
const auto &core = asset_id_type()(db);
asset_id_type usd_id = usd.id;

int64_t init_balance(1000000);
transfer(committee_account, settler_id, asset(init_balance));
transfer(committee_account, caller_id, asset(init_balance));

update_feed_producers(usd, {feedproducer.id});

price_feed current_feed;
current_feed.maintenance_collateral_ratio = 1750;
current_feed.maximum_short_squeeze_ratio = 1100;
current_feed.settlement_price = usd.amount(1) / core.amount(5);
publish_feed(usd, feedproducer, current_feed);

borrow(caller, usd.amount(1000), asset(15000));
generate_block();

transfer(caller.id, settler.id, asset(200, usd_id));

auto result = force_settle( settler, usd_id(db).amount(4));
generate_block();

auto settlements = db_api.get_settle_orders_by_account("settler", force_settlement_id_type(), 100);

BOOST_CHECK(settlements.size() == 1);
BOOST_CHECK(settlements[0].id == result.get<object_id_type>());

GRAPHENE_CHECK_THROW(db_api.get_settle_orders_by_account("nosuchaccount", force_settlement_id_type(), 100), fc::exception);

} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_SUITE_END()
4 changes: 2 additions & 2 deletions tests/tests/htlc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,10 +973,10 @@ try {
BOOST_CHECK_EQUAL( htlcs_dan[0].id.instance(), 2 );

auto full = db_api.get_full_accounts({alice.name}, false);
BOOST_CHECK_EQUAL( full[alice.name].htlcs.size(), 3 );
BOOST_CHECK_EQUAL( full[alice.name].htlcs_from.size(), 3 );

full = db_api.get_full_accounts({bob.name}, false);
BOOST_CHECK_EQUAL( full[bob.name].htlcs.size(), 1 );
BOOST_CHECK_EQUAL( full[bob.name].htlcs_to.size(), 1 );

} catch (fc::exception &e) {
edump((e.to_detail_string()));
Expand Down