Skip to content

Commit

Permalink
Merge hardfork into cjs-bsip87
Browse files Browse the repository at this point in the history
  • Loading branch information
christophersanborn committed May 4, 2020
2 parents 09a96da + ecc5cbb commit 453b30a
Show file tree
Hide file tree
Showing 59 changed files with 4,639 additions and 814 deletions.
3 changes: 3 additions & 0 deletions docker/default_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ rpc-endpoint = 0.0.0.0:8090
# For database_api_impl::get_limit_orders to set max limit value
# api-limit-get-limit-orders = 300

# For database_api_impl::get_limit_orders_by_account to set max limit value
# api-limit-get-limit-orders-by-account = 101

# For database_api_impl::get_order_book to set max limit value
# api-limit-get-order-book = 50

Expand Down
83 changes: 58 additions & 25 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,12 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
uint64_t api_limit_get_account_history=_app.get_options().api_limit_get_account_history;
FC_ASSERT( limit <= api_limit_get_account_history );

const auto configured_limit = _app.get_options().api_limit_get_account_history;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -387,12 +391,16 @@ namespace graphene { namespace app {
int operation_type,
operation_history_id_type start,
operation_history_id_type stop,
unsigned limit) const
unsigned limit ) const
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
uint64_t api_limit_get_account_history_operations=_app.get_options().api_limit_get_account_history_operations;
FC_ASSERT(limit <= api_limit_get_account_history_operations);

const auto configured_limit = _app.get_options().api_limit_get_account_history_operations;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -427,12 +435,16 @@ namespace graphene { namespace app {
vector<operation_history_object> history_api::get_relative_account_history( const std::string account_id_or_name,
uint64_t stop,
unsigned limit,
uint64_t start) const
uint64_t start ) const
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
uint64_t api_limit_get_relative_account_history=_app.get_options().api_limit_get_relative_account_history;
FC_ASSERT(limit <= api_limit_get_relative_account_history);

const auto configured_limit = _app.get_options().api_limit_get_relative_account_history;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -469,24 +481,38 @@ namespace graphene { namespace app {
return hist->tracked_buckets();
}

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)
history_operation_detail history_api::get_account_history_by_operations( const std::string account_id_or_name,
flat_set<uint16_t> operation_types,
uint32_t start, unsigned limit )const
{
uint64_t api_limit_get_account_history_by_operations=_app.get_options().api_limit_get_account_history_by_operations;
FC_ASSERT(limit <= api_limit_get_account_history_by_operations);
const auto configured_limit = _app.get_options().api_limit_get_account_history_by_operations;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

history_operation_detail result;
vector<operation_history_object> objs = get_relative_account_history(account_id_or_name, start, limit, limit + start - 1);
std::for_each(objs.begin(), objs.end(), [&](const operation_history_object &o) {
if (operation_types.empty() || find(operation_types.begin(), operation_types.end(), o.op.which()) != operation_types.end()) {
result.operation_history_objs.push_back(o);
}
});
vector<operation_history_object> objs = get_relative_account_history( account_id_or_name, start, limit,
limit + start - 1 );
result.total_count = objs.size();

if( operation_types.empty() )
result.operation_history_objs = std::move(objs);
else
{
for( const operation_history_object &o : objs )
{
if( operation_types.find(o.op.which()) != operation_types.end() ) {
result.operation_history_objs.push_back(o);
}
}
}

result.total_count = objs.size();
return result;
return result;
}

vector<bucket_object> history_api::get_market_history( std::string asset_a, std::string asset_b,
uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const
uint32_t bucket_seconds,
fc::time_point_sec start, fc::time_point_sec end )const
{ try {
FC_ASSERT(_app.chain_database());
const auto& db = *_app.chain_database();
Expand Down Expand Up @@ -577,9 +603,13 @@ namespace graphene { namespace app {
) { }
asset_api::~asset_api() { }

vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const {
uint64_t api_limit_get_asset_holders=_app.get_options().api_limit_get_asset_holders;
FC_ASSERT(limit <= api_limit_get_asset_holders);
vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const
{
const auto configured_limit = _app.get_options().api_limit_get_asset_holders;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

asset_id_type asset_id = database_api.get_asset_id_from_string( asset );
const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
Expand Down Expand Up @@ -660,8 +690,11 @@ namespace graphene { namespace app {
optional<price> start,
uint32_t limit )const
{
uint64_t api_limit_get_grouped_limit_orders=_app.get_options().api_limit_get_grouped_limit_orders;
FC_ASSERT( limit <= api_limit_get_grouped_limit_orders );
const auto configured_limit = _app.get_options().api_limit_get_grouped_limit_orders;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

auto plugin = _app.get_plugin<graphene::grouped_orders::grouped_orders_plugin>( "grouped_orders" );
FC_ASSERT( plugin );
const auto& limit_groups = plugin->limit_order_groups();
Expand Down
23 changes: 20 additions & 3 deletions libraries/app/api_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ market_ticker::market_ticker(const market_ticker_object& mto,
quote = asset_quote.symbol;
percent_change = "0";
lowest_ask = "0";
lowest_ask_base_size = "0";
lowest_ask_quote_size = "0";
highest_bid = "0";

highest_bid_base_size = "0";
highest_bid_quote_size = "0";
fc::uint128_t bv;
fc::uint128_t qv;
price latest_price = asset( mto.latest_base, mto.base ) / asset( mto.latest_quote, mto.quote );
Expand Down Expand Up @@ -68,9 +71,19 @@ market_ticker::market_ticker(const market_ticker_object& mto,
quote_volume = uint128_amount_to_string( qv, asset_quote.precision );

if(!orders.asks.empty())
lowest_ask = orders.asks[0].price;
{
lowest_ask = orders.asks[0].price;
lowest_ask_base_size = orders.asks[0].base;
lowest_ask_quote_size = orders.asks[0].quote;
}

if(!orders.bids.empty())
highest_bid = orders.bids[0].price;
{
highest_bid = orders.bids[0].price;
highest_bid_base_size = orders.bids[0].base;
highest_bid_quote_size = orders.bids[0].quote;
}

}

market_ticker::market_ticker(const fc::time_point_sec& now,
Expand All @@ -82,7 +95,11 @@ market_ticker::market_ticker(const fc::time_point_sec& now,
quote = asset_quote.symbol;
latest = "0";
lowest_ask = "0";
lowest_ask_base_size = "0";
lowest_ask_quote_size = "0";
highest_bid = "0";
highest_bid_base_size = "0";
highest_bid_quote_size = "0";
percent_change = "0";
base_volume = "0";
quote_volume = "0";
Expand Down
82 changes: 8 additions & 74 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <fc/io/fstream.hpp>
#include <fc/rpc/api_connection.hpp>
#include <fc/rpc/websocket_api.hpp>
#include <fc/network/resolve.hpp>
#include <fc/crypto/base64.hpp>

#include <boost/filesystem/path.hpp>
Expand Down Expand Up @@ -125,62 +124,22 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
if( _options->count("seed-node") )
{
auto seeds = _options->at("seed-node").as<vector<string>>();
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
_p2p_network->add_node(endpoint);
_p2p_network->connect_to_endpoint(endpoint);
}
} catch( const fc::exception& e ) {
wlog( "caught exception ${e} while adding seed node ${endpoint}",
("e", e.to_detail_string())("endpoint", endpoint_string) );
}
}
_p2p_network->add_seed_nodes(seeds);
}

if( _options->count("seed-nodes") )
{
auto seeds_str = _options->at("seed-nodes").as<string>();
auto seeds = fc::json::from_string(seeds_str).as<vector<string>>(2);
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
_p2p_network->add_node(endpoint);
}
} catch( const fc::exception& e ) {
wlog( "caught exception ${e} while adding seed node ${endpoint}",
("e", e.to_detail_string())("endpoint", endpoint_string) );
}
}
_p2p_network->add_seed_nodes(seeds);
}
else
{
// https://bitsharestalk.org/index.php/topic,23715.0.html
vector<string> seeds = {
#include "../egenesis/seed-nodes.txt"
};
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
_p2p_network->add_node(endpoint);
}
} catch( const fc::exception& e ) {
wlog( "caught exception ${e} while adding seed node ${endpoint}",
("e", e.to_detail_string())("endpoint", endpoint_string) );
}
}
_p2p_network->add_seed_nodes(seeds);
}

if( _options->count("p2p-endpoint") )
Expand All @@ -196,36 +155,6 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
std::vector<uint32_t>());
} FC_CAPTURE_AND_RETHROW() }

std::vector<fc::ip::endpoint> application_impl::resolve_string_to_ip_endpoints(const std::string& endpoint_string)
{
try
{
string::size_type colon_pos = endpoint_string.find(':');
if (colon_pos == std::string::npos)
FC_THROW("Missing required port number in endpoint string \"${endpoint_string}\"",
("endpoint_string", endpoint_string));
std::string port_string = endpoint_string.substr(colon_pos + 1);
try
{
uint16_t port = boost::lexical_cast<uint16_t>(port_string);

std::string hostname = endpoint_string.substr(0, colon_pos);
std::vector<fc::ip::endpoint> endpoints = fc::resolve(hostname, port);
if (endpoints.empty())
FC_THROW_EXCEPTION( fc::unknown_host_exception,
"The host name can not be resolved: ${hostname}",
("hostname", hostname) );
return endpoints;
}
catch (const boost::bad_lexical_cast&)
{
FC_THROW("Bad port: ${port}", ("port", port_string));
}
}
FC_CAPTURE_AND_RETHROW((endpoint_string))
}


void application_impl::new_connection( const fc::http::websocket_connection_ptr& c )
{
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_NET_MAX_NESTED_OBJECTS);
Expand Down Expand Up @@ -343,6 +272,9 @@ void application_impl::set_api_limit() {
if(_options->count("api-limit-get-limit-orders")){
_app_options.api_limit_get_limit_orders = _options->at("api-limit-get-limit-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-limit-orders-by-account")){
_app_options.api_limit_get_limit_orders_by_account = _options->at("api-limit-get-limit-orders-by-account").as<uint64_t>();
}
if(_options->count("api-limit-get-order-book")){
_app_options.api_limit_get_order_book = _options->at("api-limit-get-order-book").as<uint64_t>();
}
Expand Down Expand Up @@ -1079,6 +1011,8 @@ void application::set_program_options(boost::program_options::options_descriptio
"For database_api_impl::list_assets and get_assets_by_issuer to set max limit value")
("api-limit-get-limit-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_limit_orders to set max limit value")
("api-limit-get-limit-orders-by-account",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::get_limit_orders_by_account to set max limit value")
("api-limit-get-order-book",boost::program_options::value<uint64_t>()->default_value(50),
"For database_api_impl::get_order_book to set max limit value")
("api-limit-lookup-accounts",boost::program_options::value<uint64_t>()->default_value(1000),
Expand Down
2 changes: 0 additions & 2 deletions libraries/app/application_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class application_impl : public net::node_delegate

void reset_p2p_node(const fc::path& data_dir);

std::vector<fc::ip::endpoint> resolve_string_to_ip_endpoints(const std::string& endpoint_string);

void new_connection( const fc::http::websocket_connection_ptr& c );

void reset_websocket_server();
Expand Down
Loading

0 comments on commit 453b30a

Please sign in to comment.