added acounts_list_plugin

This commit is contained in:
Roman Olearski 2017-05-22 17:04:40 +02:00
parent 2259224078
commit 0329c0eadd
9 changed files with 225 additions and 1 deletions

View file

@ -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" )

View file

@ -458,6 +458,13 @@ namespace graphene { namespace app {
return result;
}
vector<account_id_type> history_api::list_core_accounts()const
{
auto list = _app.get_plugin<accounts_list_plugin>( "accounts_list" );
FC_ASSERT( list );
return list->list_accounts();
}
flat_set<uint32_t> history_api::get_market_history_buckets()const
{
auto hist = _app.get_plugin<market_history_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(){};

View file

@ -29,6 +29,7 @@
#include <graphene/chain/protocol/confidential.hpp>
#include <graphene/market_history/market_history_plugin.hpp>
#include <graphene/accounts_list/accounts_list_plugin.hpp>
#include <graphene/debug_witness/debug_api.hpp>
@ -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<order_history_object> get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const;
vector<bucket_object> 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<account_id_type> list_core_accounts()const;
flat_set<uint32_t> 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)

View file

@ -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 )

View file

@ -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 <graphene/accounts_list/accounts_list_plugin.hpp>
#include <graphene/app/impacted.hpp>
#include <graphene/chain/account_evaluator.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/config.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>
#include <fc/smart_ref_impl.hpp>
#include <fc/thread/thread.hpp>
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<account_id_type> _listed_accounts;
//map<string, account_balance_object> _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<account_balance_object> db_balances;
auto& balance_index = db.get_index_type<graphene::chain::account_balance_index>().indices().get<graphene::chain::by_asset_balance>();
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<std::vector<std::string>>()->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<account_id_type> accounts_list_plugin::list_accounts() const
{
ilog("accounts list plugin: list_accounts()");
my->list_accounts();
idump((my->_listed_accounts));
return my->_listed_accounts;
}
} }

View file

@ -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 <graphene/app/plugin.hpp>
#include <graphene/chain/database.hpp>
#include <fc/thread/future.hpp>
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<account_id_type> list_accounts()const;
friend class detail::accounts_list_plugin_impl;
std::unique_ptr<detail::accounts_list_plugin_impl> my;
};
} } //graphene::accounts_list

View file

@ -340,6 +340,7 @@ class wallet_api
*/
vector<operation_detail> get_account_history(string name, int limit)const;
vector<account_id_type> list_core_accounts()const;
vector<bucket_object> get_market_history(string symbol, string symbol2, uint32_t bucket)const;
vector<limit_order_object> 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)

View file

@ -3328,6 +3328,10 @@ vector<operation_detail> wallet_api::get_account_history(string name, int limit)
return result;
}
vector<account_id_type> wallet_api::list_core_accounts()const
{
return my->_remote_hist->list_core_accounts();
}
vector<bucket_object> wallet_api::get_market_history( string symbol1, string symbol2, uint32_t bucket )const
{

View file

@ -25,6 +25,7 @@
#include <graphene/witness/witness.hpp>
#include <graphene/account_history/account_history_plugin.hpp>
#include <graphene/accounts_list/accounts_list_plugin.hpp>
#include <graphene/market_history/market_history_plugin.hpp>
#include <graphene/generate_genesis/generate_genesis_plugin.hpp>
@ -76,6 +77,7 @@ int main(int argc, char** argv) {
auto history_plug = node->register_plugin<account_history::account_history_plugin>();
auto market_history_plug = node->register_plugin<market_history::market_history_plugin>();
//auto generate_genesis_plug = node->register_plugin<generate_genesis_plugin::generate_genesis_plugin>();
auto list_plug = node->register_plugin<accounts_list::accounts_list_plugin>();
try
{