Adding wallet_create rpc.

This commit is contained in:
clemahieu 2014-12-28 13:43:43 -06:00
commit ce00533dcd
2 changed files with 32 additions and 0 deletions

View file

@ -2370,6 +2370,14 @@ void rai::rpc::operator () (boost::network::http::server <rai::rpc>::request con
response.content = "Bad account number";
}
}
else if (action == "wallet_create")
{
rai::keypair wallet_id;
auto wallet (client.wallets.create (wallet_id.prv));
boost::property_tree::ptree response_l;
response_l.put ("wallet", wallet_id.prv.to_string ());
set_response (response, response_l);
}
else
{
response = boost::network::http::server<rai::rpc>::response::stock_reply (boost::network::http::server<rai::rpc>::response::bad_request);

View file

@ -958,6 +958,30 @@ TEST (rpc, wallet_key_valid)
ASSERT_EQ ("1", exists_text);
}
TEST (rpc, wallet_create)
{
rai::system system (24000, 1);
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
rai::rpc rpc (system.service, pool, boost::asio::ip::address_v6::loopback (), 25000, *system.clients [0], true);
boost::network::http::server <rai::rpc>::request request;
boost::network::http::server <rai::rpc>::response response;
request.method = "POST";
boost::property_tree::ptree request_tree;
request_tree.put ("action", "wallet_create");
std::stringstream ostream;
boost::property_tree::write_json (ostream, request_tree);
request.body = ostream.str ();
rpc (request, response);
ASSERT_EQ (boost::network::http::server <rai::rpc>::response::ok, response.status);
boost::property_tree::ptree response_tree;
std::stringstream istream (response.content);
boost::property_tree::read_json (istream, response_tree);
std::string wallet_text (response_tree.get <std::string> ("wallet"));
rai::uint256_union wallet_id;
ASSERT_FALSE (wallet_id.decode_hex (wallet_text));
ASSERT_NE (system.clients [0]->wallets.items.end (), system.clients [0]->wallets.items.find (wallet_id));
}
TEST (parse_endpoint, valid)
{
std::string string ("127.0.0.1:24000");