From e6486403441215b7bddc552ae81bc0ecd76cf89e Mon Sep 17 00:00:00 2001 From: Dan Notestein Date: Mon, 10 Apr 2017 15:45:26 +0000 Subject: [PATCH 1/4] Limit games to 3 gestures because GUI wallet only supports 3 gesture games currently. Note that cli-wallet also supports 5 gesture games in theory, and the code can be expanded to support any odd number of gestures by giving the gestures names. --- libraries/chain/tournament_evaluator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/chain/tournament_evaluator.cpp b/libraries/chain/tournament_evaluator.cpp index 1422c5dd..493ab6da 100644 --- a/libraries/chain/tournament_evaluator.cpp +++ b/libraries/chain/tournament_evaluator.cpp @@ -95,6 +95,9 @@ namespace graphene { namespace chain { "Time to reveal the move must not be greater than ${max}", ("max", maximum_time_per_reveal_move)); + //cli-wallet supports 5 gesture games as well, but limit to 3 now as GUI wallet only supports 3 gesture games currently + FC_ASSERT(game_options.number_of_gestures == 3, + "GUI Wallet only supports 3 gestures currently"); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } From 0329c0eadd439b4c46dbb32e84aad6e9fdd78af1 Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Mon, 22 May 2017 17:04:40 +0200 Subject: [PATCH 2/4] added acounts_list_plugin --- libraries/app/CMakeLists.txt | 2 +- libraries/app/api.cpp | 8 + libraries/app/include/graphene/app/api.hpp | 4 + libraries/plugins/CMakeLists.txt | 1 + .../accounts_list/accounts_list_plugin.cpp | 144 ++++++++++++++++++ .../accounts_list/accounts_list_plugin.hpp | 59 +++++++ .../wallet/include/graphene/wallet/wallet.hpp | 2 + libraries/wallet/wallet.cpp | 4 + programs/witness_node/main.cpp | 2 + 9 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 libraries/plugins/accounts_list/accounts_list_plugin.cpp create mode 100644 libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index 2dd91f63..a9430eb8 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -12,7 +12,7 @@ add_library( graphene_app ) # need to link graphene_debug_witness because plugins aren't sufficiently isolated #246 -target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness ) +target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_accounts_list graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness ) target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" ) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 0559c51f..cd9e8cf8 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -458,6 +458,13 @@ namespace graphene { namespace app { return result; } + vector history_api::list_core_accounts()const + { + auto list = _app.get_plugin( "accounts_list" ); + FC_ASSERT( list ); + return list->list_accounts(); + } + flat_set history_api::get_market_history_buckets()const { auto hist = _app.get_plugin( "market_history" ); @@ -490,6 +497,7 @@ namespace graphene { namespace app { } return result; } FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) } + crypto_api::crypto_api(){}; diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index eef2b6d9..81719723 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -29,6 +29,7 @@ #include #include +#include #include @@ -49,6 +50,7 @@ namespace graphene { namespace app { using namespace graphene::chain; using namespace graphene::market_history; + using namespace graphene::accounts_list; using namespace fc::ecc; using namespace std; @@ -113,6 +115,7 @@ namespace graphene { namespace app { vector get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const; vector get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const; + vector list_core_accounts()const; flat_set get_market_history_buckets()const; private: application& _app; @@ -316,6 +319,7 @@ FC_API(graphene::app::history_api, (get_fill_order_history) (get_market_history) (get_market_history_buckets) + (list_core_accounts) ) FC_API(graphene::app::network_broadcast_api, (broadcast_transaction) diff --git a/libraries/plugins/CMakeLists.txt b/libraries/plugins/CMakeLists.txt index 1add505b..7d3f5061 100644 --- a/libraries/plugins/CMakeLists.txt +++ b/libraries/plugins/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory( witness ) add_subdirectory( account_history ) +add_subdirectory( accounts_list ) add_subdirectory( market_history ) add_subdirectory( delayed_node ) add_subdirectory( generate_genesis ) diff --git a/libraries/plugins/accounts_list/accounts_list_plugin.cpp b/libraries/plugins/accounts_list/accounts_list_plugin.cpp new file mode 100644 index 00000000..bda31c42 --- /dev/null +++ b/libraries/plugins/accounts_list/accounts_list_plugin.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace graphene { namespace accounts_list { + +namespace detail +{ + + +class accounts_list_plugin_impl +{ + public: + accounts_list_plugin_impl(accounts_list_plugin& _plugin) + : _self( _plugin ) + { } + virtual ~accounts_list_plugin_impl(); + + + /** + */ + void list_accounts(); + + graphene::chain::database& database() + { + return _self.database(); + } + + accounts_list_plugin& _self; + vector _listed_accounts; + //map _listed_balances; +}; + +accounts_list_plugin_impl::~accounts_list_plugin_impl() +{ + return; +} + +void accounts_list_plugin_impl::list_accounts() +{ + graphene::chain::database& db = database(); + _listed_accounts.clear(); + + + std::vector db_balances; + auto& balance_index = db.get_index_type().indices().get(); + for (auto balance_iter = balance_index.begin(); + balance_iter != balance_index.end() && + balance_iter->asset_type == graphene::chain::asset_id_type() && + balance_iter->balance > 0; ++balance_iter) + { + idump((balance_iter->owner(db))(*balance_iter)); + _listed_accounts.emplace_back(balance_iter->owner); + db_balances.emplace_back(*balance_iter); + } + +} +} // end namespace detail + +accounts_list_plugin::accounts_list_plugin() : + my( new detail::accounts_list_plugin_impl(*this) ) +{ +} + +accounts_list_plugin::~accounts_list_plugin() +{ +} + +std::string accounts_list_plugin::plugin_name()const +{ + return "accounts_list"; +} + +void accounts_list_plugin::plugin_set_program_options( + boost::program_options::options_description& /*cli*/, + boost::program_options::options_description& /*cfg*/ + ) +{ +// cli.add_options() +// ("list-account", boost::program_options::value>()->composing()->multitoken(), "Account ID to list (may specify multiple times)") +// ; +// cfg.add(cli); +} + +void accounts_list_plugin::plugin_initialize(const boost::program_options::variables_map& /*options*/) +{ + ilog("accounts list plugin: plugin_initialize()"); + //database().add_index< primary_index< simple_index< operation_history_object > > >(); + //database().add_index< primary_index< simple_index< account_transaction_history_object > > >(); + + //LOAD_VALUE_SET(options, "listed-accounts", my->_listed_accounts, graphene::chain::account_id_type); + + list_accounts(); +} + +void accounts_list_plugin::plugin_startup() +{ + ilog("accounts list plugin: plugin_startup()"); +} + +std::vector accounts_list_plugin::list_accounts() const +{ + ilog("accounts list plugin: list_accounts()"); + my->list_accounts(); + idump((my->_listed_accounts)); + return my->_listed_accounts; +} + +} } diff --git a/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp b/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp new file mode 100644 index 00000000..ba5aa2cf --- /dev/null +++ b/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +#include + +namespace graphene { namespace accounts_list { +using namespace chain; + +namespace detail +{ + class accounts_list_plugin_impl; +} + +class accounts_list_plugin : public graphene::app::plugin +{ + public: + accounts_list_plugin(); + virtual ~accounts_list_plugin(); + + std::string plugin_name()const override; + virtual void plugin_set_program_options( + boost::program_options::options_description& cli, + boost::program_options::options_description& cfg) override; + virtual void plugin_initialize(const boost::program_options::variables_map& options) override; + virtual void plugin_startup() override; + + vector list_accounts()const; + + friend class detail::accounts_list_plugin_impl; + std::unique_ptr my; +}; + +} } //graphene::accounts_list + diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index a40f38d4..6f2412f5 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -340,6 +340,7 @@ class wallet_api */ vector get_account_history(string name, int limit)const; + vector list_core_accounts()const; vector get_market_history(string symbol, string symbol2, uint32_t bucket)const; vector get_limit_orders(string a, string b, uint32_t limit)const; @@ -1701,6 +1702,7 @@ FC_API( graphene::wallet::wallet_api, (get_block) (get_account_count) (get_account_history) + (list_core_accounts) (get_market_history) (get_global_properties) (get_dynamic_global_properties) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 456536c6..8985c933 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3328,6 +3328,10 @@ vector wallet_api::get_account_history(string name, int limit) return result; } +vector wallet_api::list_core_accounts()const +{ + return my->_remote_hist->list_core_accounts(); +} vector wallet_api::get_market_history( string symbol1, string symbol2, uint32_t bucket )const { diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index 0995899f..c284253d 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -76,6 +77,7 @@ int main(int argc, char** argv) { auto history_plug = node->register_plugin(); auto market_history_plug = node->register_plugin(); //auto generate_genesis_plug = node->register_plugin(); + auto list_plug = node->register_plugin(); try { From 3e4d9c2aa3292b1432436331cf172a3f024275e5 Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Mon, 22 May 2017 17:04:40 +0200 Subject: [PATCH 3/4] added acounts_list_plugin --- libraries/app/CMakeLists.txt | 2 +- libraries/app/api.cpp | 8 + libraries/app/include/graphene/app/api.hpp | 4 + libraries/plugins/CMakeLists.txt | 1 + .../plugins/accounts_list/CMakeLists.txt | 21 +++ .../accounts_list/accounts_list_plugin.cpp | 144 ++++++++++++++++++ .../accounts_list/accounts_list_plugin.hpp | 59 +++++++ .../wallet/include/graphene/wallet/wallet.hpp | 2 + libraries/wallet/wallet.cpp | 4 + programs/witness_node/main.cpp | 2 + 10 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 libraries/plugins/accounts_list/CMakeLists.txt create mode 100644 libraries/plugins/accounts_list/accounts_list_plugin.cpp create mode 100644 libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index 2dd91f63..a9430eb8 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -12,7 +12,7 @@ add_library( graphene_app ) # need to link graphene_debug_witness because plugins aren't sufficiently isolated #246 -target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness ) +target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_accounts_list graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness ) target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" ) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 0559c51f..cd9e8cf8 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -458,6 +458,13 @@ namespace graphene { namespace app { return result; } + vector history_api::list_core_accounts()const + { + auto list = _app.get_plugin( "accounts_list" ); + FC_ASSERT( list ); + return list->list_accounts(); + } + flat_set history_api::get_market_history_buckets()const { auto hist = _app.get_plugin( "market_history" ); @@ -490,6 +497,7 @@ namespace graphene { namespace app { } return result; } FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) } + crypto_api::crypto_api(){}; diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index eef2b6d9..81719723 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -29,6 +29,7 @@ #include #include +#include #include @@ -49,6 +50,7 @@ namespace graphene { namespace app { using namespace graphene::chain; using namespace graphene::market_history; + using namespace graphene::accounts_list; using namespace fc::ecc; using namespace std; @@ -113,6 +115,7 @@ namespace graphene { namespace app { vector get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const; vector get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const; + vector list_core_accounts()const; flat_set get_market_history_buckets()const; private: application& _app; @@ -316,6 +319,7 @@ FC_API(graphene::app::history_api, (get_fill_order_history) (get_market_history) (get_market_history_buckets) + (list_core_accounts) ) FC_API(graphene::app::network_broadcast_api, (broadcast_transaction) diff --git a/libraries/plugins/CMakeLists.txt b/libraries/plugins/CMakeLists.txt index 1add505b..7d3f5061 100644 --- a/libraries/plugins/CMakeLists.txt +++ b/libraries/plugins/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory( witness ) add_subdirectory( account_history ) +add_subdirectory( accounts_list ) add_subdirectory( market_history ) add_subdirectory( delayed_node ) add_subdirectory( generate_genesis ) diff --git a/libraries/plugins/accounts_list/CMakeLists.txt b/libraries/plugins/accounts_list/CMakeLists.txt new file mode 100644 index 00000000..3c2747c2 --- /dev/null +++ b/libraries/plugins/accounts_list/CMakeLists.txt @@ -0,0 +1,21 @@ +file(GLOB HEADERS "include/graphene/accouns_list/*.hpp") + +add_library( graphene_accounts_list + accounts_list_plugin.cpp + ) + +target_link_libraries( graphene_accounts_list graphene_chain graphene_app ) +target_include_directories( graphene_accounts_list + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + +if(MSVC) + set_source_files_properties( accounts_list_plugin.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) +endif(MSVC) + +install( TARGETS + graphene_accounts_list + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) diff --git a/libraries/plugins/accounts_list/accounts_list_plugin.cpp b/libraries/plugins/accounts_list/accounts_list_plugin.cpp new file mode 100644 index 00000000..bda31c42 --- /dev/null +++ b/libraries/plugins/accounts_list/accounts_list_plugin.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace graphene { namespace accounts_list { + +namespace detail +{ + + +class accounts_list_plugin_impl +{ + public: + accounts_list_plugin_impl(accounts_list_plugin& _plugin) + : _self( _plugin ) + { } + virtual ~accounts_list_plugin_impl(); + + + /** + */ + void list_accounts(); + + graphene::chain::database& database() + { + return _self.database(); + } + + accounts_list_plugin& _self; + vector _listed_accounts; + //map _listed_balances; +}; + +accounts_list_plugin_impl::~accounts_list_plugin_impl() +{ + return; +} + +void accounts_list_plugin_impl::list_accounts() +{ + graphene::chain::database& db = database(); + _listed_accounts.clear(); + + + std::vector db_balances; + auto& balance_index = db.get_index_type().indices().get(); + for (auto balance_iter = balance_index.begin(); + balance_iter != balance_index.end() && + balance_iter->asset_type == graphene::chain::asset_id_type() && + balance_iter->balance > 0; ++balance_iter) + { + idump((balance_iter->owner(db))(*balance_iter)); + _listed_accounts.emplace_back(balance_iter->owner); + db_balances.emplace_back(*balance_iter); + } + +} +} // end namespace detail + +accounts_list_plugin::accounts_list_plugin() : + my( new detail::accounts_list_plugin_impl(*this) ) +{ +} + +accounts_list_plugin::~accounts_list_plugin() +{ +} + +std::string accounts_list_plugin::plugin_name()const +{ + return "accounts_list"; +} + +void accounts_list_plugin::plugin_set_program_options( + boost::program_options::options_description& /*cli*/, + boost::program_options::options_description& /*cfg*/ + ) +{ +// cli.add_options() +// ("list-account", boost::program_options::value>()->composing()->multitoken(), "Account ID to list (may specify multiple times)") +// ; +// cfg.add(cli); +} + +void accounts_list_plugin::plugin_initialize(const boost::program_options::variables_map& /*options*/) +{ + ilog("accounts list plugin: plugin_initialize()"); + //database().add_index< primary_index< simple_index< operation_history_object > > >(); + //database().add_index< primary_index< simple_index< account_transaction_history_object > > >(); + + //LOAD_VALUE_SET(options, "listed-accounts", my->_listed_accounts, graphene::chain::account_id_type); + + list_accounts(); +} + +void accounts_list_plugin::plugin_startup() +{ + ilog("accounts list plugin: plugin_startup()"); +} + +std::vector accounts_list_plugin::list_accounts() const +{ + ilog("accounts list plugin: list_accounts()"); + my->list_accounts(); + idump((my->_listed_accounts)); + return my->_listed_accounts; +} + +} } diff --git a/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp b/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp new file mode 100644 index 00000000..ba5aa2cf --- /dev/null +++ b/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +#include + +namespace graphene { namespace accounts_list { +using namespace chain; + +namespace detail +{ + class accounts_list_plugin_impl; +} + +class accounts_list_plugin : public graphene::app::plugin +{ + public: + accounts_list_plugin(); + virtual ~accounts_list_plugin(); + + std::string plugin_name()const override; + virtual void plugin_set_program_options( + boost::program_options::options_description& cli, + boost::program_options::options_description& cfg) override; + virtual void plugin_initialize(const boost::program_options::variables_map& options) override; + virtual void plugin_startup() override; + + vector list_accounts()const; + + friend class detail::accounts_list_plugin_impl; + std::unique_ptr my; +}; + +} } //graphene::accounts_list + diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index a40f38d4..6f2412f5 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -340,6 +340,7 @@ class wallet_api */ vector get_account_history(string name, int limit)const; + vector list_core_accounts()const; vector get_market_history(string symbol, string symbol2, uint32_t bucket)const; vector get_limit_orders(string a, string b, uint32_t limit)const; @@ -1701,6 +1702,7 @@ FC_API( graphene::wallet::wallet_api, (get_block) (get_account_count) (get_account_history) + (list_core_accounts) (get_market_history) (get_global_properties) (get_dynamic_global_properties) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 456536c6..8985c933 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3328,6 +3328,10 @@ vector wallet_api::get_account_history(string name, int limit) return result; } +vector wallet_api::list_core_accounts()const +{ + return my->_remote_hist->list_core_accounts(); +} vector wallet_api::get_market_history( string symbol1, string symbol2, uint32_t bucket )const { diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index 0995899f..c284253d 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -76,6 +77,7 @@ int main(int argc, char** argv) { auto history_plug = node->register_plugin(); auto market_history_plug = node->register_plugin(); //auto generate_genesis_plug = node->register_plugin(); + auto list_plug = node->register_plugin(); try { From 0c14896a3d5fc3598518aeeead03c5be1066162d Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Mon, 22 May 2017 19:49:10 +0200 Subject: [PATCH 4/4] done acounts_list_plugin --- libraries/app/api.cpp | 2 +- libraries/app/include/graphene/app/api.hpp | 2 +- .../accounts_list/accounts_list_plugin.cpp | 27 +++++++------------ .../accounts_list/accounts_list_plugin.hpp | 3 ++- .../wallet/include/graphene/wallet/wallet.hpp | 2 +- libraries/wallet/wallet.cpp | 17 +++++++++++- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index cd9e8cf8..9b44887c 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -458,7 +458,7 @@ namespace graphene { namespace app { return result; } - vector history_api::list_core_accounts()const + vector history_api::list_core_accounts()const { auto list = _app.get_plugin( "accounts_list" ); FC_ASSERT( list ); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 81719723..bae73ece 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -115,7 +115,7 @@ namespace graphene { namespace app { vector get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const; vector get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const; - vector list_core_accounts()const; + vector list_core_accounts()const; flat_set get_market_history_buckets()const; private: application& _app; diff --git a/libraries/plugins/accounts_list/accounts_list_plugin.cpp b/libraries/plugins/accounts_list/accounts_list_plugin.cpp index bda31c42..aabf711d 100644 --- a/libraries/plugins/accounts_list/accounts_list_plugin.cpp +++ b/libraries/plugins/accounts_list/accounts_list_plugin.cpp @@ -62,8 +62,7 @@ class accounts_list_plugin_impl } accounts_list_plugin& _self; - vector _listed_accounts; - //map _listed_balances; + vector _listed_balances; }; accounts_list_plugin_impl::~accounts_list_plugin_impl() @@ -74,19 +73,16 @@ accounts_list_plugin_impl::~accounts_list_plugin_impl() void accounts_list_plugin_impl::list_accounts() { graphene::chain::database& db = database(); - _listed_accounts.clear(); + _listed_balances.clear(); - - std::vector db_balances; auto& balance_index = db.get_index_type().indices().get(); for (auto balance_iter = balance_index.begin(); balance_iter != balance_index.end() && balance_iter->asset_type == graphene::chain::asset_id_type() && balance_iter->balance > 0; ++balance_iter) { - idump((balance_iter->owner(db))(*balance_iter)); - _listed_accounts.emplace_back(balance_iter->owner); - db_balances.emplace_back(*balance_iter); + //idump((balance_iter->owner(db) .name)(*balance_iter)); + _listed_balances.emplace_back(*balance_iter); } } @@ -119,26 +115,21 @@ void accounts_list_plugin::plugin_set_program_options( void accounts_list_plugin::plugin_initialize(const boost::program_options::variables_map& /*options*/) { - ilog("accounts list plugin: plugin_initialize()"); - //database().add_index< primary_index< simple_index< operation_history_object > > >(); - //database().add_index< primary_index< simple_index< account_transaction_history_object > > >(); - - //LOAD_VALUE_SET(options, "listed-accounts", my->_listed_accounts, graphene::chain::account_id_type); - + //ilog("accounts list plugin: plugin_initialize()"); list_accounts(); } void accounts_list_plugin::plugin_startup() { - ilog("accounts list plugin: plugin_startup()"); + //ilog("accounts list plugin: plugin_startup()"); } -std::vector accounts_list_plugin::list_accounts() const + vector accounts_list_plugin::list_accounts() const { ilog("accounts list plugin: list_accounts()"); my->list_accounts(); - idump((my->_listed_accounts)); - return my->_listed_accounts; + //idump((my->_listed_balances)); + return my->_listed_balances; } } } diff --git a/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp b/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp index ba5aa2cf..d57e19eb 100644 --- a/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp +++ b/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp @@ -25,6 +25,7 @@ #include #include +#include #include @@ -49,7 +50,7 @@ class accounts_list_plugin : public graphene::app::plugin virtual void plugin_initialize(const boost::program_options::variables_map& options) override; virtual void plugin_startup() override; - vector list_accounts()const; + vectorlist_accounts()const; friend class detail::accounts_list_plugin_impl; std::unique_ptr my; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 6f2412f5..cf56bfdb 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -340,7 +340,7 @@ class wallet_api */ vector get_account_history(string name, int limit)const; - vector list_core_accounts()const; + vector list_core_accounts()const; vector get_market_history(string symbol, string symbol2, uint32_t bucket)const; vector get_limit_orders(string a, string b, uint32_t limit)const; diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 8985c933..3f00d58a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2403,6 +2403,21 @@ public: return ss.str(); }; + m["list_core_accounts"] = [this](variant result, const fc::variants& a) + { + std::stringstream ss; + + auto balances = result.as>(); + for (const account_balance_object& balance: balances) + { + const account_object& account = get_account(balance.owner); + //ss << account.name << " " << std::string(balance.id) << " " << balance.balance.value << "\n"; + ss << account.name << " " << std::string(balance.id) << " " << get_asset(balance.asset_type).amount_to_pretty_string(balance.balance) << "\n"; + } + + return ss.str(); + }; + m["get_blind_balances"] = [this](variant result, const fc::variants& a) { auto r = result.as>(); @@ -3328,7 +3343,7 @@ vector wallet_api::get_account_history(string name, int limit) return result; } -vector wallet_api::list_core_accounts()const +vector wallet_api::list_core_accounts()const { return my->_remote_hist->list_core_accounts(); }