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..9b44887c 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..bae73ece 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 b18415f8..62e6a612 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..aabf711d --- /dev/null +++ b/libraries/plugins/accounts_list/accounts_list_plugin.cpp @@ -0,0 +1,135 @@ +/* + * 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_balances; +}; + +accounts_list_plugin_impl::~accounts_list_plugin_impl() +{ + return; +} + +void accounts_list_plugin_impl::list_accounts() +{ + graphene::chain::database& db = database(); + _listed_balances.clear(); + + 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) .name)(*balance_iter)); + _listed_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()"); + list_accounts(); +} + +void accounts_list_plugin::plugin_startup() +{ + //ilog("accounts list plugin: plugin_startup()"); +} + + vector accounts_list_plugin::list_accounts() const +{ + ilog("accounts list plugin: list_accounts()"); + my->list_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 new file mode 100644 index 00000000..d57e19eb --- /dev/null +++ b/libraries/plugins/accounts_list/include/graphene/accounts_list/accounts_list_plugin.hpp @@ -0,0 +1,60 @@ +/* + * 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 + +#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; + + vectorlist_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 0ac0b88a..d16754b9 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; @@ -1740,6 +1741,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 8f24192a..7c6fec1e 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2461,6 +2461,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>(); @@ -3386,6 +3401,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 2f41676c..d3efe2ce 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -25,6 +25,7 @@ #include #include +#include #include //#include //#include @@ -78,6 +79,7 @@ int main(int argc, char** argv) { auto market_history_plug = node->register_plugin(); //auto generate_genesis_plug = node->register_plugin(); //auto generate_uia_sharedrop_genesis_plug = node->register_plugin(); + auto list_plug = node->register_plugin(); try {