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

Issue: Early withdrawal claims #23

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c4527a8
Implemented "plugins" config variable
pmconrad May 24, 2017
83cc453
Use range-based loop instead of iterator
pmconrad May 29, 2017
cbdb015
Avoid duplicate options in default config file
pmconrad May 30, 2017
f04c2d4
Fixed #284 using API calls
pmconrad Jul 1, 2017
6887f55
Created unit test for #325
pmconrad Jul 12, 2017
6f7fb42
Merge pull request #326 from pmconrad/develop
oxarbitrage Jul 13, 2017
fa5c92c
trying to change block_summary_object index from flat to generic
oxarbitrage Jul 16, 2017
854651d
for issue 328
oxarbitrage Jul 17, 2017
50e535e
improve performance
oxarbitrage Jul 17, 2017
74c650d
Merge pull request #330 from oxarbitrage/issue328
oxarbitrage Jul 18, 2017
80d81ac
Add api-access console log to node startup when present
oxarbitrage Jul 21, 2017
bf76c59
finish sentence in readme
oxarbitrage Jul 21, 2017
3801533
Create initial 64k block_summary_objects
pmconrad Jul 21, 2017
3e49787
Merge pull request #1 from pmconrad/issue325
oxarbitrage Jul 24, 2017
9d301cb
Partial fix for #303
pmconrad Jul 28, 2017
165c914
Log db rewind
pmconrad Jul 28, 2017
d970eec
Adaptions for HF 385
pmconrad Jul 28, 2017
3b68864
check if file exist
oxarbitrage Jul 29, 2017
1f0ee24
add account_id to get_trade_history call
oxarbitrage Jul 31, 2017
5815865
Merge pull request #335 from oxarbitrage/issue325
oxarbitrage Jul 31, 2017
b9889e0
Merge pull request #332 from oxarbitrage/issue331
oxarbitrage Jul 31, 2017
c9cbd1e
add test that reproduce something-for-nothing fill bug #184 after har…
takaaki7 Aug 2, 2017
95eb8bc
make trade_amount_equals_zero fail because of bug
takaaki7 Aug 2, 2017
300cf74
add account_id of the 2 sides of the trade to get_trade_history api call
oxarbitrage Aug 2, 2017
88941de
fix get_account_history may terminate early #168
takaaki7 Aug 4, 2017
b90a86f
Merge pull request #347 from takaaki7/fix_get_account_history_edge
oxarbitrage Aug 4, 2017
b7f600e
Re-added separate delayed_node
pmconrad Aug 5, 2017
ed492c1
Merge pull request #344 from oxarbitrage/issue329
oxarbitrage Aug 5, 2017
a4e4257
Removed duplicate
pmconrad Aug 6, 2017
ce15e94
Merge pull request #288 from pmconrad/configurable_plugins
oxarbitrage Aug 6, 2017
c3de107
Merge pull request #321 from pmconrad/issue_284
oxarbitrage Aug 9, 2017
8e22263
database api changes in witnesses, committee members and workers calls.
oxarbitrage Aug 9, 2017
023c48e
Merge pull request #337 from pmconrad/hf_385
oxarbitrage Aug 13, 2017
999bb46
Merge pull request #336 from pmconrad/issue_303
oxarbitrage Aug 14, 2017
0b8a650
get_relative_account_history changes for issue #298
oxarbitrage Aug 14, 2017
ecffbc5
requested changes
oxarbitrage Aug 17, 2017
2dcf529
change distance() in get_full_accounts to size()
oxarbitrage Aug 17, 2017
51fee3f
removing optional
oxarbitrage Aug 17, 2017
dbf51aa
stop subscribing after 100 in get_full_accounts
oxarbitrage Aug 18, 2017
0011d5f
Fix #367 - use unique options list for parsing config file
pmconrad Aug 18, 2017
fc8eb09
Merge pull request #368 from pmconrad/configurable_plugins
oxarbitrage Aug 18, 2017
8b56fc5
Merge pull request #352 from oxarbitrage/database_api_changes
oxarbitrage Aug 20, 2017
0f89069
changed subscribed size to < 100
oxarbitrage Aug 20, 2017
0dba643
Merge pull request #364 from oxarbitrage/develop
oxarbitrage Aug 21, 2017
b58389e
Merge pull request #345 from takaaki7/trade_amount_equals_zero_test
oxarbitrage Aug 23, 2017
e01e6c3
- Fix: Withdrawal claims before the first period are incorrectly allowed
TheTaconator Dec 8, 2016
b3fa084
- Tests: Varying withdrawal claims across multiple periods
TheTaconator Dec 17, 2016
6b3179a
- Fix and tests for Issue #23 updated to handle proper behavior befor…
TheTaconator Jan 2, 2017
9c88361
- Fix: Typos in test comments
TheTaconator Jan 17, 2017
8a70136
- Moved withdrawal_period_descriptor object into unit tests
TheTaconator Aug 31, 2017
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ API 0 is accessible using regular JSON-RPC:
Accessing restricted API's
--------------------------

You can restrict API's to particular users by specifying an `apiaccess` file in `config.ini`. Here is an example `apiaccess` file which allows
You can restrict API's to particular users by specifying an `api-access` file in `config.ini` or by using the `--api-access /full/path/to/api-access.json` startup node command. Here is an example `api-access` file which allows
user `bytemaster` with password `supersecret` to access four different API's, while allowing any other user to access the three public API's
necessary to use the wallet:

Expand Down
8 changes: 7 additions & 1 deletion libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ namespace graphene { namespace app {
node = nullptr;
else node = &node->next(db);
}

if( stop.instance.value == 0 && account_transaction_history_id_type()(db).account == account && result.size() < limit )
result.push_back( account_transaction_history_id_type()(db).operation_id(db) );
return result;
}

Expand Down Expand Up @@ -491,6 +492,11 @@ namespace graphene { namespace app {
node = nullptr;
else node = &node->next(db);
}
if( stop.instance.value == 0 && result.size() < limit ) {
const account_transaction_history_object head = account_transaction_history_id_type()(db);
if( head.account == account && head.operation_id(db).op.which() == operation_id )
result.push_back(head.operation_id(db));
}
return result;
}

Expand Down
61 changes: 51 additions & 10 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,22 @@ namespace detail {
_force_validate = true;
}

if( _options->count("api-access") )
_apiaccess = fc::json::from_file( _options->at("api-access").as<boost::filesystem::path>() )
.as<api_access>();
if( _options->count("api-access") ) {

if(fc::exists(_options->at("api-access").as<boost::filesystem::path>()))
{
_apiaccess = fc::json::from_file( _options->at("api-access").as<boost::filesystem::path>() ).as<api_access>();
ilog("Using api access file from ${path}",
("path", _options->at("api-access").as<boost::filesystem::path>().string()));
}
else
{
elog("Failed to load file from ${path}",
("path", _options->at("api-access").as<boost::filesystem::path>().string()));
std::exit(EXIT_FAILURE);
}
}

else
{
// TODO: Remove this generous default access policy
Expand Down Expand Up @@ -930,7 +943,8 @@ namespace detail {
std::shared_ptr<fc::http::websocket_server> _websocket_server;
std::shared_ptr<fc::http::websocket_tls_server> _websocket_tls_server;

std::map<string, std::shared_ptr<abstract_plugin>> _plugins;
std::map<string, std::shared_ptr<abstract_plugin>> _active_plugins;
std::map<string, std::shared_ptr<abstract_plugin>> _available_plugins;

bool _is_finished_syncing = false;
};
Expand Down Expand Up @@ -969,6 +983,7 @@ void application::set_program_options(boost::program_options::options_descriptio
("genesis-json", bpo::value<boost::filesystem::path>(), "File to read Genesis State from")
("dbg-init-key", bpo::value<string>(), "Block signing key to use for init witnesses, overrides genesis file")
("api-access", bpo::value<boost::filesystem::path>(), "JSON file specifying API permissions")
("plugins", bpo::value<string>(), "Space-separated list of plugins to activate")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down Expand Up @@ -1014,6 +1029,22 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti

std::exit(EXIT_SUCCESS);
}

std::vector<string> wanted;
if( options.count("plugins") )
{
boost::split(wanted, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});
}
else
{
wanted.push_back("witness");
wanted.push_back("account_history");
wanted.push_back("market_history");
}
for (auto& it : wanted)
{
if (!it.empty()) enable_plugin(it);
}
}

void application::startup()
Expand All @@ -1031,7 +1062,7 @@ void application::startup()

std::shared_ptr<abstract_plugin> application::get_plugin(const string& name) const
{
return my->_plugins[name];
return my->_active_plugins[name];
}

net::node_ptr application::p2p_node()
Expand Down Expand Up @@ -1064,14 +1095,21 @@ bool application::is_finished_syncing() const
return my->_is_finished_syncing;
}

void graphene::app::application::add_plugin(const string& name, std::shared_ptr<graphene::app::abstract_plugin> p)
void graphene::app::application::enable_plugin(const string& name)
{
my->_plugins[name] = p;
FC_ASSERT(my->_available_plugins[name], "Unknown plugin '" + name + "'");
my->_active_plugins[name] = my->_available_plugins[name];
my->_active_plugins[name]->plugin_set_app(this);
}

void graphene::app::application::add_available_plugin(std::shared_ptr<graphene::app::abstract_plugin> p)
{
my->_available_plugins[p->plugin_name()] = p;
}

void application::shutdown_plugins()
{
for( auto& entry : my->_plugins )
for( auto& entry : my->_active_plugins )
entry.second->plugin_shutdown();
return;
}
Expand All @@ -1080,19 +1118,22 @@ void application::shutdown()
if( my->_p2p_network )
my->_p2p_network->close();
if( my->_chain_db )
{
my->_chain_db->close();
my->_chain_db = nullptr;
}
}

void application::initialize_plugins( const boost::program_options::variables_map& options )
{
for( auto& entry : my->_plugins )
for( auto& entry : my->_active_plugins )
entry.second->plugin_initialize( options );
return;
}

void application::startup_plugins()
{
for( auto& entry : my->_plugins )
for( auto& entry : my->_active_plugins )
entry.second->plugin_startup();
return;
}
Expand Down
129 changes: 103 additions & 26 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
* Copyright (c) 2017 Cryptonomex, Inc., and contributors.
*
* The MIT License
*
Expand Down Expand Up @@ -54,6 +54,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
database_api_impl( graphene::chain::database& db );
~database_api_impl();


// Objects
fc::variants get_objects(const vector<object_id_type>& ids)const;

Expand All @@ -78,7 +79,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>

// Keys
vector<vector<account_id_type>> get_key_references( vector<public_key_type> key )const;
bool is_public_key_registered(string public_key) const;
bool is_public_key_registered(string public_key) const;

// Accounts
vector<optional<account_object>> get_accounts(const vector<account_id_type>& account_ids)const;
Expand Down Expand Up @@ -123,6 +124,12 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
vector<optional<committee_member_object>> get_committee_members(const vector<committee_member_id_type>& committee_member_ids)const;
fc::optional<committee_member_object> get_committee_member_by_account(account_id_type account)const;
map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const;
uint64_t get_committee_count()const;

// Workers
vector<worker_object> get_all_workers()const;
vector<optional<worker_object>> get_workers_by_account(account_id_type account)const;
uint64_t get_worker_count()const;

// Votes
vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;
Expand All @@ -143,6 +150,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// Blinded balances
vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;


//private:
template<typename T>
void subscribe_to_item( const T& i )const
Expand Down Expand Up @@ -618,9 +626,10 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const

if( subscribe )
{
FC_ASSERT( std::distance(_subscribed_accounts.begin(), _subscribed_accounts.end()) <= 100 );
_subscribed_accounts.insert( account->get_id() );
subscribe_to_item( account->id );
if(_subscribed_accounts.size() < 100) {
_subscribed_accounts.insert( account->get_id() );
subscribe_to_item( account->id );
}
}

// fc::mutable_variant_object full_account;
Expand Down Expand Up @@ -1031,9 +1040,16 @@ vector<call_order_object> database_api_impl::get_call_orders(asset_id_type a, ui
const auto& call_index = _db.get_index_type<call_order_index>().indices().get<by_price>();
const asset_object& mia = _db.get(a);
price index_price = price::min(mia.bitasset_data(_db).options.short_backing_asset, mia.get_id());

return vector<call_order_object>(call_index.lower_bound(index_price.min()),
call_index.lower_bound(index_price.max()));

vector< call_order_object> result;
auto itr_min = call_index.lower_bound(index_price.min());
auto itr_max = call_index.lower_bound(index_price.max());
while( itr_min != itr_max && result.size() < limit )
{
result.emplace_back(*itr_min);
++itr_min;
}
return result;
}

vector<force_settlement_object> database_api::get_settle_orders(asset_id_type a, uint32_t limit)const
Expand All @@ -1045,8 +1061,16 @@ vector<force_settlement_object> database_api_impl::get_settle_orders(asset_id_ty
{
const auto& settle_index = _db.get_index_type<force_settlement_index>().indices().get<by_expiration>();
const asset_object& mia = _db.get(a);
return vector<force_settlement_object>(settle_index.lower_bound(mia.get_id()),
settle_index.upper_bound(mia.get_id()));

vector<force_settlement_object> result;
auto itr_min = settle_index.lower_bound(mia.get_id());
auto itr_max = settle_index.upper_bound(mia.get_id());
while( itr_min != itr_max && result.size() < limit )
{
result.emplace_back(*itr_min);
++itr_min;
}
return result;
}

vector<call_order_object> database_api::get_margin_positions( const account_id_type& id )const
Expand Down Expand Up @@ -1293,6 +1317,12 @@ vector<market_trade> database_api_impl::get_trade_history( const string& base,
trade.date = itr->time;
trade.price = trade.value / trade.amount;

trade.side1_account_id = itr->op.account_id;

auto next_itr = std::next(itr);

trade.side2_account_id = next_itr->op.account_id;

result.push_back( trade );
++count;
}
Expand All @@ -1316,22 +1346,6 @@ vector<optional<witness_object>> database_api::get_witnesses(const vector<witnes
return my->get_witnesses( witness_ids );
}

vector<worker_object> database_api::get_workers_by_account(account_id_type account)const
{
const auto& idx = my->_db.get_index_type<worker_index>().indices().get<by_account>();
auto itr = idx.find(account);
vector<worker_object> result;

if( itr != idx.end() && itr->worker_account == account )
{
result.emplace_back( *itr );
++itr;
}

return result;
}


vector<optional<witness_object>> database_api_impl::get_witnesses(const vector<witness_id_type>& witness_ids)const
{
vector<optional<witness_object>> result; result.reserve(witness_ids.size());
Expand Down Expand Up @@ -1461,6 +1475,69 @@ map<string, committee_member_id_type> database_api_impl::lookup_committee_member
return committee_members_by_account_name;
}

uint64_t database_api::get_committee_count()const
{
return my->get_committee_count();
}

uint64_t database_api_impl::get_committee_count()const
{
return _db.get_index_type<committee_member_index>().indices().size();
}


//////////////////////////////////////////////////////////////////////
// //
// Workers //
// //
//////////////////////////////////////////////////////////////////////

vector<worker_object> database_api::get_all_workers()const
{
return my->get_all_workers();
}

vector<worker_object> database_api_impl::get_all_workers()const
{
vector<worker_object> result;
const auto& workers_idx = _db.get_index_type<worker_index>().indices().get<by_id>();
for( const auto& w : workers_idx )
{
result.push_back( w );
}
return result;
}

vector<optional<worker_object>> database_api::get_workers_by_account(account_id_type account)const
{
return my->get_workers_by_account( account );
}

vector<optional<worker_object>> database_api_impl::get_workers_by_account(account_id_type account)const
{
vector<optional<worker_object>> result;
const auto& workers_idx = _db.get_index_type<worker_index>().indices().get<by_account>();

for( const auto& w : workers_idx )
{
if( w.worker_account == account )
result.push_back( w );
}
return result;
}

uint64_t database_api::get_worker_count()const
{
return my->get_worker_count();
}

uint64_t database_api_impl::get_worker_count()const
{
return _db.get_index_type<worker_index>().indices().size();
}



//////////////////////////////////////////////////////////////////////
// //
// Votes //
Expand Down
5 changes: 3 additions & 2 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace graphene { namespace app {
if( !plugin_cfg_options.options().empty() )
_cfg_options.add(plugin_cfg_options);

add_plugin( plug->plugin_name(), plug );
add_available_plugin( plug );
return plug;
}
std::shared_ptr<abstract_plugin> get_plugin( const string& name )const;
Expand All @@ -89,7 +89,8 @@ namespace graphene { namespace app {
boost::signals2::signal<void()> syncing_finished;

private:
void add_plugin( const string& name, std::shared_ptr<abstract_plugin> p );
void enable_plugin( const string& name );
void add_available_plugin( std::shared_ptr<abstract_plugin> p );
std::shared_ptr<detail::application_impl> my;

boost::program_options::options_description _cli_options;
Expand Down
Loading