Changing decode base.
Adding wallet_key_valid rpc.
This commit is contained in:
parent
0aa4c27368
commit
6e87c4ca78
4 changed files with 73 additions and 1 deletions
|
@ -1684,6 +1684,21 @@ void rai::rpc::operator () (boost::network::http::server <rai::rpc>::request con
|
|||
response.content = "RPC control is disabled";
|
||||
}
|
||||
}
|
||||
else if (action == "wallet_key_valid")
|
||||
{
|
||||
if (enable_control)
|
||||
{
|
||||
auto valid (client.wallet.valid_password ());
|
||||
boost::property_tree::ptree response_l;
|
||||
response_l.put ("valid", valid ? "1" : "0");
|
||||
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);
|
||||
response.content = "RPC control is disabled";
|
||||
}
|
||||
}
|
||||
else if (action == "validate_account")
|
||||
{
|
||||
std::string account_text (request_l.get <std::string> ("account"));
|
||||
|
@ -1704,7 +1719,7 @@ void rai::rpc::operator () (boost::network::http::server <rai::rpc>::request con
|
|||
{
|
||||
std::string amount_text (request_l.get <std::string> ("amount"));
|
||||
rai::amount amount;
|
||||
auto error (amount.decode_hex (amount_text));
|
||||
auto error (amount.decode_dec (amount_text));
|
||||
if (!error)
|
||||
{
|
||||
auto error (client.send (account, amount.number ()));
|
||||
|
|
|
@ -161,6 +161,36 @@ bool rai::uint128_union::decode_hex (std::string const & text)
|
|||
return result;
|
||||
}
|
||||
|
||||
void rai::uint128_union::encode_dec (std::string & text) const
|
||||
{
|
||||
assert (text.empty ());
|
||||
std::stringstream stream;
|
||||
stream << std::dec << std::noshowbase;
|
||||
stream << number ();
|
||||
text = stream.str ();
|
||||
}
|
||||
|
||||
bool rai::uint128_union::decode_dec (std::string const & text)
|
||||
{
|
||||
auto result (text.size () > 39);
|
||||
if (!result)
|
||||
{
|
||||
std::stringstream stream (text);
|
||||
stream << std::dec << std::noshowbase;
|
||||
rai::uint128_t number_l;
|
||||
try
|
||||
{
|
||||
stream >> number_l;
|
||||
*this = number_l;
|
||||
}
|
||||
catch (std::runtime_error &)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::uint128_union::clear ()
|
||||
{
|
||||
qwords.fill (0);
|
||||
|
|
|
@ -43,6 +43,8 @@ namespace rai
|
|||
bool operator == (rai::uint128_union const &) const;
|
||||
void encode_hex (std::string &) const;
|
||||
bool decode_hex (std::string const &);
|
||||
void encode_dec (std::string &) const;
|
||||
bool decode_dec (std::string const &);
|
||||
rai::uint128_t number () const;
|
||||
void clear ();
|
||||
std::array <uint8_t, 16> bytes;
|
||||
|
|
|
@ -749,6 +749,31 @@ TEST (rpc, wallet_list)
|
|||
}
|
||||
}
|
||||
|
||||
TEST (rpc, wallet_key_valid)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
|
||||
rai::rpc rpc (system.service, pool, 25000, *system.clients [0], true);
|
||||
std::string account;
|
||||
rai::test_genesis_key.pub.encode_base58check (account);
|
||||
system.clients [0]->wallet.insert (rai::test_genesis_key.prv);
|
||||
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_key_valid");
|
||||
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 exists_text (response_tree.get <std::string> ("valid"));
|
||||
ASSERT_EQ ("1", exists_text);
|
||||
}
|
||||
|
||||
TEST (parse_endpoint, valid)
|
||||
{
|
||||
std::string string ("127.0.0.1:24000");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue