Skip to content

Commit e3d1226

Browse files
authored
Merge pull request #1761 from bitshares/release
Merge release to master for 3.1.0
2 parents 623aea2 + c737ea5 commit e3d1226

File tree

89 files changed

+2207
-790
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2207
-790
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif()
2323
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" )
2424

2525
set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
26-
set(GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR}/genesis.json" )
26+
set(GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR}/libraries/egenesis/genesis.json" )
2727

2828
#set (ENABLE_INSTALLER 1)
2929
#set (USE_PCH 1)
@@ -80,6 +80,7 @@ if( WIN32 )
8080
set(CRYPTO_LIB)
8181

8282
if( MSVC )
83+
add_definitions(-DWIN32_LEAN_AND_MEAN)
8384
#looks like this flag can have different default on some machines.
8485
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
8586
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")

libraries/app/api.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ namespace graphene { namespace app {
317317
{
318318
FC_ASSERT( _app.chain_database() );
319319
const auto& db = *_app.chain_database();
320-
FC_ASSERT( limit <= 100 );
320+
uint64_t api_limit_get_account_history=_app.get_options().api_limit_get_account_history;
321+
FC_ASSERT( limit <= api_limit_get_account_history );
321322
vector<operation_history_object> result;
322323
account_id_type account;
323324
try {
@@ -353,7 +354,8 @@ namespace graphene { namespace app {
353354
{
354355
FC_ASSERT( _app.chain_database() );
355356
const auto& db = *_app.chain_database();
356-
FC_ASSERT( limit <= 100 );
357+
uint64_t api_limit_get_account_history_operations=_app.get_options().api_limit_get_account_history_operations;
358+
FC_ASSERT(limit <= api_limit_get_account_history_operations);
357359
vector<operation_history_object> result;
358360
account_id_type account;
359361
try {
@@ -392,7 +394,8 @@ namespace graphene { namespace app {
392394
{
393395
FC_ASSERT( _app.chain_database() );
394396
const auto& db = *_app.chain_database();
395-
FC_ASSERT(limit <= 100);
397+
uint64_t api_limit_get_relative_account_history=_app.get_options().api_limit_get_relative_account_history;
398+
FC_ASSERT(limit <= api_limit_get_relative_account_history);
396399
vector<operation_history_object> result;
397400
account_id_type account;
398401
try {
@@ -431,7 +434,8 @@ namespace graphene { namespace app {
431434

432435
history_operation_detail history_api::get_account_history_by_operations(const std::string account_id_or_name, vector<uint16_t> operation_types, uint32_t start, unsigned limit)
433436
{
434-
FC_ASSERT(limit <= 100);
437+
uint64_t api_limit_get_account_history_by_operations=_app.get_options().api_limit_get_account_history_by_operations;
438+
FC_ASSERT(limit <= api_limit_get_account_history_by_operations);
435439
history_operation_detail result;
436440
vector<operation_history_object> objs = get_relative_account_history(account_id_or_name, start, limit, limit + start - 1);
437441
std::for_each(objs.begin(), objs.end(), [&](const operation_history_object &o) {
@@ -530,16 +534,16 @@ namespace graphene { namespace app {
530534

531535
// asset_api
532536
asset_api::asset_api(graphene::app::application& app) :
533-
_db( *app.chain_database()),
534-
database_api( std::ref(*app.chain_database()), &(app.get_options())
537+
_app(app),
538+
_db( *app.chain_database()),
539+
database_api( std::ref(*app.chain_database()), &(app.get_options())
535540
) { }
536541
asset_api::~asset_api() { }
537542

538543
vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const {
539-
FC_ASSERT(limit <= 100);
540-
544+
uint64_t api_limit_get_asset_holders=_app.get_options().api_limit_get_asset_holders;
545+
FC_ASSERT(limit <= api_limit_get_asset_holders);
541546
asset_id_type asset_id = database_api.get_asset_id_from_string( asset );
542-
543547
const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
544548
auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
545549

@@ -571,7 +575,6 @@ namespace graphene { namespace app {
571575
}
572576
// get number of asset holders.
573577
int asset_api::get_asset_holders_count( std::string asset ) const {
574-
575578
const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
576579
asset_id_type asset_id = database_api.get_asset_id_from_string( asset );
577580
auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
@@ -582,9 +585,7 @@ namespace graphene { namespace app {
582585
}
583586
// function to get vector of system assets with holders count.
584587
vector<asset_holders> asset_api::get_all_asset_holders() const {
585-
586588
vector<asset_holders> result;
587-
588589
vector<asset_id_type> total_assets;
589590
for( const asset_object& asset_obj : _db.get_index_type<asset_index>().indices() )
590591
{
@@ -622,8 +623,9 @@ namespace graphene { namespace app {
622623
optional<price> start,
623624
uint32_t limit )const
624625
{
625-
FC_ASSERT( limit <= 101 );
626-
auto plugin = _app.get_plugin<grouped_orders_plugin>( "grouped_orders" );
626+
uint64_t api_limit_get_grouped_limit_orders=_app.get_options().api_limit_get_grouped_limit_orders;
627+
FC_ASSERT( limit <= api_limit_get_grouped_limit_orders );
628+
auto plugin = _app.get_plugin<graphene::grouped_orders::grouped_orders_plugin>( "grouped_orders" );
627629
FC_ASSERT( plugin );
628630
const auto& limit_groups = plugin->limit_order_groups();
629631
vector< limit_order_group > result;

libraries/app/application.cpp

+58-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace detail {
8181
auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
8282
dlog("Allocating all stake to ${key}", ("key", utilities::key_to_wif(nathan_key)));
8383
graphene::chain::genesis_state_type initial_state;
84-
initial_state.initial_parameters.current_fees = fee_schedule::get_default();//->set_all_fees(GRAPHENE_BLOCKCHAIN_PRECISION);
84+
initial_state.initial_parameters.get_mutable_fees() = fee_schedule::get_default();
8585
initial_state.initial_active_witnesses = GRAPHENE_DEFAULT_MIN_WITNESS_COUNT;
8686
initial_state.initial_timestamp = time_point_sec(time_point::now().sec_since_epoch() /
8787
initial_state.initial_parameters.block_interval *
@@ -316,6 +316,35 @@ void application_impl::set_dbg_init_key( graphene::chain::genesis_state_type& ge
316316
genesis.initial_witness_candidates[i].block_signing_key = init_pubkey;
317317
}
318318

319+
320+
321+
void application_impl::set_api_limit() {
322+
if (_options->count("api-limit-get-account-history-operations")) {
323+
_app_options.api_limit_get_account_history_operations = _options->at("api-limit-get-account-history-operations").as<uint64_t>();
324+
}
325+
if(_options->count("api-limit-get-account-history")){
326+
_app_options.api_limit_get_account_history = _options->at("api-limit-get-account-history").as<uint64_t>();
327+
}
328+
if(_options->count("api-limit-get-grouped-limit-orders")){
329+
_app_options.api_limit_get_grouped_limit_orders = _options->at("api-limit-get-grouped-limit-orders").as<uint64_t>();
330+
}
331+
if(_options->count("api-limit-get-relative-account-history")){
332+
_app_options.api_limit_get_relative_account_history = _options->at("api-limit-get-relative-account-history").as<uint64_t>();
333+
}
334+
if(_options->count("api-limit-get-account-history-by-operations")){
335+
_app_options.api_limit_get_account_history_by_operations = _options->at("api-limit-get-account-history-by-operations").as<uint64_t>();
336+
}
337+
if(_options->count("api-limit-get-asset-holders")){
338+
_app_options.api_limit_get_asset_holders = _options->at("api-limit-get-asset-holders").as<uint64_t>();
339+
}
340+
if(_options->count("api-limit-get-key-references")){
341+
_app_options.api_limit_get_key_references = _options->at("api-limit-get-key-references").as<uint64_t>();
342+
}
343+
if(_options->count("api-limit-get-htlc-by")) {
344+
_app_options.api_limit_get_htlc_by = _options->at("api-limit-get-htlc-by").as<uint64_t>();
345+
}
346+
}
347+
319348
void application_impl::startup()
320349
{ try {
321350
fc::create_directories(_data_dir / "blockchain");
@@ -437,6 +466,8 @@ void application_impl::startup()
437466
if ( _options->count("enable-subscribe-to-all") )
438467
_app_options.enable_subscribe_to_all = _options->at( "enable-subscribe-to-all" ).as<bool>();
439468

469+
set_api_limit();
470+
440471
if( _active_plugins.find( "market_history" ) != _active_plugins.end() )
441472
_app_options.has_market_history_plugin = true;
442473

@@ -975,6 +1006,20 @@ void application::set_program_options(boost::program_options::options_descriptio
9751006
("enable-standby-votes-tracking", bpo::value<bool>()->implicit_value(true),
9761007
"Whether to enable tracking of votes of standby witnesses and committee members. "
9771008
"Set it to true to provide accurate data to API clients, set to false for slightly better performance.")
1009+
("api-limit-get-account-history-operations",boost::program_options::value<uint64_t>()->default_value(100),
1010+
"For history_api::get_account_history_operations to set its default limit value as 100")
1011+
("api-limit-get-account-history",boost::program_options::value<uint64_t>()->default_value(100),
1012+
"For history_api::get_account_history to set its default limit value as 100")
1013+
("api-limit-get-grouped-limit-orders",boost::program_options::value<uint64_t>()->default_value(101),
1014+
"For orders_api::get_grouped_limit_orders to set its default limit value as 101")
1015+
("api-limit-get-relative-account-history",boost::program_options::value<uint64_t>()->default_value(100),
1016+
"For history_api::get_relative_account_history to set its default limit value as 100")
1017+
("api-limit-get-account-history-by-operations",boost::program_options::value<uint64_t>()->default_value(100),
1018+
"For history_api::get_account_history_by_operations to set its default limit value as 100")
1019+
("api-limit-get-asset-holders",boost::program_options::value<uint64_t>()->default_value(100),
1020+
"For asset_api::get_asset_holders to set its default limit value as 100")
1021+
("api-limit-get-key-references",boost::program_options::value<uint64_t>()->default_value(100),
1022+
"For database_api_impl::get_key_references to set its default limit value as 100")
9781023
;
9791024
command_line_options.add(configuration_file_options);
9801025
command_line_options.add_options()
@@ -1014,6 +1059,18 @@ void application::startup()
10141059
}
10151060
}
10161061

1062+
void application::set_api_limit()
1063+
{
1064+
try {
1065+
my->set_api_limit();
1066+
} catch ( const fc::exception& e ) {
1067+
elog( "${e}", ("e",e.to_detail_string()) );
1068+
throw;
1069+
} catch ( ... ) {
1070+
elog( "unexpected exception" );
1071+
throw;
1072+
}
1073+
}
10171074
std::shared_ptr<abstract_plugin> application::get_plugin(const string& name) const
10181075
{
10191076
return my->_active_plugins[name];

libraries/app/application_impl.hxx

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class application_impl : public net::node_delegate
4141
}
4242

4343
void set_dbg_init_key( graphene::chain::genesis_state_type& genesis, const std::string& init_key );
44+
void set_api_limit();
4445

4546
void startup();
4647

@@ -66,7 +67,7 @@ class application_impl : public net::node_delegate
6667

6768
virtual void handle_transaction(const graphene::net::trx_message& transaction_message) override;
6869

69-
void handle_message(const graphene::net::message& message_to_process);
70+
void handle_message(const graphene::net::message& message_to_process) override;
7071

7172
bool is_included_block(const graphene::chain::block_id_type& block_id);
7273

libraries/app/config_util.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,22 @@ static void create_new_config_file(const fc::path& config_ini_path, const fc::pa
258258
};
259259
deduplicator dedup(modify_option_defaults);
260260
std::ofstream out_cfg(config_ini_path.preferred_string());
261+
std::string plugin_header_surrounding( 78, '=' );
261262
for( const boost::shared_ptr<bpo::option_description> opt : cfg_options.options() )
262263
{
263264
const boost::shared_ptr<bpo::option_description> od = dedup.next(opt);
264265
if( !od ) continue;
265266

267+
if( od->long_name().find("plugin-cfg-header-") == 0 ) // it's a plugin header
268+
{
269+
out_cfg << "\n";
270+
out_cfg << "# " << plugin_header_surrounding << "\n";
271+
out_cfg << "# " << od->description() << "\n";
272+
out_cfg << "# " << plugin_header_surrounding << "\n";
273+
out_cfg << "\n";
274+
continue;
275+
}
276+
266277
if( !od->description().empty() )
267278
out_cfg << "# " << od->description() << "\n";
268279
boost::any store;
@@ -284,6 +295,10 @@ static void create_new_config_file(const fc::path& config_ini_path, const fc::pa
284295
}
285296

286297
out_cfg << "\n"
298+
<< "# " << plugin_header_surrounding << "\n"
299+
<< "# logging options\n"
300+
<< "# " << plugin_header_surrounding << "\n"
301+
<< "#\n"
287302
<< "# Logging configuration is loaded from logging.ini by default.\n"
288303
<< "# If logging.ini exists, logging configuration added in this file will be ignored.\n";
289304
out_cfg.close();

libraries/app/database_api.cpp

+87-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
168168
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;
169169
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;
170170

171+
// HTLC
172+
optional<htlc_object> get_htlc(htlc_id_type id) const;
173+
vector<htlc_object> get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const;
174+
vector<htlc_object> get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const;
175+
171176
//private:
172177
static string price_to_string( const price& _price, const asset_object& _base, const asset_object& _quote );
173178

@@ -668,7 +673,6 @@ dynamic_global_property_object database_api_impl::get_dynamic_global_properties(
668673

669674
vector<vector<account_id_type>> database_api::get_key_references( vector<public_key_type> key )const
670675
{
671-
FC_ASSERT(key.size() <= 100, "Number of keys must be 100 or less");
672676
return my->get_key_references( key );
673677
}
674678

@@ -677,6 +681,8 @@ vector<vector<account_id_type>> database_api::get_key_references( vector<public_
677681
*/
678682
vector<vector<account_id_type>> database_api_impl::get_key_references( vector<public_key_type> keys )const
679683
{
684+
uint64_t api_limit_get_key_references=_app_options->api_limit_get_key_references;
685+
FC_ASSERT(keys.size() <= api_limit_get_key_references);
680686
const auto& idx = _db.get_index_type<account_index>();
681687
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
682688
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
@@ -968,7 +974,18 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
968974
acnt.withdraws.emplace_back(withdraw);
969975
});
970976

971-
977+
// get htlcs
978+
auto htlc_from_range = _db.get_index_type<htlc_index>().indices().get<by_from_id>().equal_range(account->id);
979+
std::for_each(htlc_from_range.first, htlc_from_range.second,
980+
[&acnt] (const htlc_object& htlc) {
981+
acnt.htlcs.emplace_back(htlc);
982+
});
983+
auto htlc_to_range = _db.get_index_type<htlc_index>().indices().get<by_to_id>().equal_range(account->id);
984+
std::for_each(htlc_to_range.first, htlc_to_range.second,
985+
[&acnt] (const htlc_object& htlc) {
986+
if ( std::find(acnt.htlcs.begin(), acnt.htlcs.end(), htlc) == acnt.htlcs.end() )
987+
acnt.htlcs.emplace_back(htlc);
988+
});
972989
results[account_name_or_id] = acnt;
973990
}
974991
return results;
@@ -2381,6 +2398,74 @@ vector<withdraw_permission_object> database_api_impl::get_withdraw_permissions_b
23812398
return result;
23822399
}
23832400

2401+
//////////////////////////////////////////////////////////////////////
2402+
// //
2403+
// HTLC //
2404+
// //
2405+
//////////////////////////////////////////////////////////////////////
2406+
2407+
optional<htlc_object> database_api::get_htlc(htlc_id_type id)const
2408+
{
2409+
return my->get_htlc(id);
2410+
}
2411+
2412+
fc::optional<htlc_object> database_api_impl::get_htlc(htlc_id_type id) const
2413+
{
2414+
auto obj = get_objects( { id }).front();
2415+
if ( !obj.is_null() )
2416+
{
2417+
return fc::optional<htlc_object>(obj.template as<htlc_object>(GRAPHENE_MAX_NESTED_OBJECTS));
2418+
}
2419+
return fc::optional<htlc_object>();
2420+
}
2421+
2422+
vector<htlc_object> database_api::get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const
2423+
{
2424+
return my->get_htlc_by_from(account_id_or_name, start, limit);
2425+
}
2426+
2427+
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
2428+
{
2429+
FC_ASSERT( limit <= _app_options->api_limit_get_htlc_by );
2430+
vector<htlc_object> result;
2431+
2432+
const auto& htlc_idx = _db.get_index_type< htlc_index >().indices().get< by_from_id >();
2433+
auto htlc_index_end = htlc_idx.end();
2434+
const account_id_type account = get_account_from_string(account_id_or_name)->id;
2435+
auto htlc_itr = htlc_idx.lower_bound(boost::make_tuple(account, start));
2436+
2437+
while(htlc_itr != htlc_index_end && htlc_itr->transfer.from == account && result.size() < limit)
2438+
{
2439+
result.push_back(*htlc_itr);
2440+
++htlc_itr;
2441+
}
2442+
return result;
2443+
}
2444+
2445+
vector<htlc_object> database_api::get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const
2446+
{
2447+
return my->get_htlc_by_to(account_id_or_name, start, limit);
2448+
}
2449+
2450+
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
2451+
{
2452+
2453+
FC_ASSERT( limit <= _app_options->api_limit_get_htlc_by );
2454+
vector<htlc_object> result;
2455+
2456+
const auto& htlc_idx = _db.get_index_type< htlc_index >().indices().get< by_to_id >();
2457+
auto htlc_index_end = htlc_idx.end();
2458+
const account_id_type account = get_account_from_string(account_id_or_name)->id;
2459+
auto htlc_itr = htlc_idx.lower_bound(boost::make_tuple(account, start));
2460+
2461+
while(htlc_itr != htlc_index_end && htlc_itr->transfer.to == account && result.size() < limit)
2462+
{
2463+
result.push_back(*htlc_itr);
2464+
++htlc_itr;
2465+
}
2466+
return result;
2467+
}
2468+
23842469
//////////////////////////////////////////////////////////////////////
23852470
// //
23862471
// Private methods //

libraries/app/include/graphene/app/api.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ namespace graphene { namespace app {
464464
vector<asset_holders> get_all_asset_holders() const;
465465

466466
private:
467+
graphene::app::application& _app;
467468
graphene::chain::database& _db;
468469
graphene::app::database_api database_api;
469470
};

0 commit comments

Comments
 (0)