diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 649eea3f..5bb36f65 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -480,12 +480,6 @@ namespace graphene { namespace app { /** * @brief Get status of all current connections to peers - * @brief Not reflected, thus not accessible to API clients. - * - * This function is registered to receive the applied_block - * signal from the chain database when a block is received. - * It then dispatches callbacks to clients who have requested - * to be notified when a particular txid is included in a block. */ std::vector get_connected_peers() const; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 590212fe..f4288d34 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1299,6 +1299,9 @@ class wallet_api void dbg_make_mia(string creator, string symbol); void flood_network(string prefix, uint32_t number_of_transactions); + void network_add_nodes( const vector& nodes ); + vector< variant > network_get_connected_peers(); + /** * Used to transfer from one set of blinded balances to another */ @@ -1449,6 +1452,8 @@ FC_API( graphene::wallet::wallet_api, (dbg_make_uia) (dbg_make_mia) (flood_network) + (network_add_nodes) + (network_get_connected_peers) (set_key_label) (get_key_label) (get_public_key) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 10c4a72a..ddcf65d1 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1996,6 +1996,48 @@ public: create_asset(get_account(creator).name, symbol, 2, opts, bopts, true); } + void use_network_node_api() + { + if( _remote_net_node ) + return; + try + { + _remote_net_node = _remote_api->network_node(); + } + catch( const fc::exception& e ) + { + std::cerr << "\nCouldn't get network node API. You probably are not configured\n" + "to access the network API on the witness_node you are\n" + "connecting to. Please follow the instructions in README.md to set up an apiaccess file.\n" + "\n"; + throw(e); + } + } + + void network_add_nodes( const vector& nodes ) + { + use_network_node_api(); + for( const string& node_address : nodes ) + { + (*_remote_net_node)->add_node( fc::ip::endpoint::from_string( node_address ) ); + } + } + + vector< variant > network_get_connected_peers() + { + use_network_node_api(); + const auto peers = (*_remote_net_node)->get_connected_peers(); + vector< variant > result; + result.reserve( peers.size() ); + for( const auto& peer : peers ) + { + variant v; + fc::to_variant( peer, v ); + result.push_back( v ); + } + return result; + } + void flood_network(string prefix, uint32_t number_of_transactions) { try @@ -2064,6 +2106,7 @@ public: fc::api _remote_db; fc::api _remote_net_broadcast; fc::api _remote_hist; + optional< fc::api > _remote_net_node; flat_map _prototype_ops; @@ -2712,6 +2755,16 @@ void wallet_api::dbg_make_mia(string creator, string symbol) my->dbg_make_mia(creator, symbol); } +void wallet_api::network_add_nodes( const vector& nodes ) +{ + my->network_add_nodes( nodes ); +} + +vector< variant > wallet_api::network_get_connected_peers() +{ + return my->network_get_connected_peers(); +} + void wallet_api::flood_network(string prefix, uint32_t number_of_transactions) { FC_ASSERT(!is_locked());