From 0329c0eadd439b4c46dbb32e84aad6e9fdd78af1 Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Mon, 22 May 2017 17:04:40 +0200 Subject: [PATCH] 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 {