From 661d5ed94c116a9038a4290a025b134127b3a61c Mon Sep 17 00:00:00 2001 From: SergiySW Date: Wed, 5 Apr 2017 22:30:35 +0300 Subject: [PATCH] Porting RPC from CLI account_get, account_key, key_create, key_expand --- rai/node/rpc.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ rai/node/rpc.hpp | 4 +++ 2 files changed, 85 insertions(+) diff --git a/rai/node/rpc.cpp b/rai/node/rpc.cpp index 1c7f1d86..9cc6e898 100755 --- a/rai/node/rpc.cpp +++ b/rai/node/rpc.cpp @@ -220,6 +220,40 @@ void rai::rpc_handler::account_create () } } +void rai::rpc_handler::account_get () +{ + std::string key_text (request.get ("key")); + rai::uint256_union pub; + auto error (pub.decode_hex (key_text)); + if (!error) + { + boost::property_tree::ptree response_l; + response_l.put ("account", pub.to_account ()); + response (response_l); + } + else + { + error_response (response, "Bad public key"); + } +} + +void rai::rpc_handler::account_key () +{ + std::string account_text (request.get ("account")); + rai::account account; + auto error (account.decode_account (account_text)); + if (!error) + { + boost::property_tree::ptree response_l; + response_l.put ("key", account.to_string ()); + response (response_l); + } + else + { + error_response (response, "Bad account number"); + } +} + void rai::rpc_handler::account_list () { std::string wallet_text (request.get ("wallet")); @@ -714,6 +748,37 @@ void rai::rpc_handler::keepalive () } } +void rai::rpc_handler::key_create () +{ + boost::property_tree::ptree response_l; + rai::keypair pair; + response_l.put ("private", pair.prv.data.to_string ()); + response_l.put ("public", pair.pub.to_string ()); + response_l.put ("account", pair.pub.to_account ()); + response (response_l); +} + +void rai::rpc_handler::key_expand () +{ + std::string key_text (request.get ("key")); + rai::uint256_union prv; + auto error (prv.decode_hex (key_text)); + if (!error) + { + boost::property_tree::ptree response_l; + rai::uint256_union pub; + ed25519_publickey (prv.bytes.data (), pub.bytes.data ()); + response_l.put ("private", prv.to_string ()); + response_l.put ("public", pub.to_string ()); + response_l.put ("account", pub.to_account ()); + response (response_l); + } + else + { + error_response (response, "Bad private key"); + } +} + void rai::rpc_handler::mrai_from_raw () { std::string amount_text (request.get ("amount")); @@ -1733,6 +1798,14 @@ void rai::rpc_handler::process_request () { account_create (); } + else if (action == "account_get") + { + account_get (); + } + else if (action == "account_key") + { + account_key (); + } else if (action == "account_list") { account_list (); @@ -1793,6 +1866,14 @@ void rai::rpc_handler::process_request () { keepalive (); } + else if (action == "key_create") + { + key_create (); + } + else if (action == "key_expand") + { + key_expand (); + } else if (action == "krai_from_raw") { krai_from_raw (); diff --git a/rai/node/rpc.hpp b/rai/node/rpc.hpp index 9d38dd5d..e3cf2a45 100644 --- a/rai/node/rpc.hpp +++ b/rai/node/rpc.hpp @@ -90,6 +90,8 @@ public: void process_request (); void account_balance (); void account_create (); + void account_get (); + void account_key (); void account_list (); void account_move (); void account_representative (); @@ -105,6 +107,8 @@ public: void frontier_count (); void history (); void keepalive (); + void key_create (); + void key_expand (); void krai_to_raw (); void krai_from_raw (); void mrai_to_raw ();