cli_wallet: Expose network_node API

This commit is contained in:
theoreticalbts 2015-09-02 13:42:05 -04:00
parent e450861166
commit d2092e0d3a
3 changed files with 58 additions and 6 deletions

View file

@ -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<net::peer_status> get_connected_peers() const;

View file

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

View file

@ -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<string>& 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<database_api> _remote_db;
fc::api<network_broadcast_api> _remote_net_broadcast;
fc::api<history_api> _remote_hist;
optional< fc::api<network_node_api> > _remote_net_node;
flat_map<string, operation> _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<string>& 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());