From 17a9ee3f8f2d8af23f9f4f3f27b38fd7f9d90c2b Mon Sep 17 00:00:00 2001 From: Neozaru Date: Sun, 25 May 2014 00:20:46 +0200 Subject: 'getaddress' wallet-rpc command --- src/wallet/wallet_rpc_server.cpp | 15 +++++++++++++++ src/wallet/wallet_rpc_server.h | 2 ++ src/wallet/wallet_rpc_server_commans_defs.h | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) (limited to 'src/wallet') diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index f1766c3b4..55f81aacc 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -71,6 +71,21 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_getaddress(const wallet_rpc::COMMAND_RPC_GET_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx) + { + try + { + res.address = m_wallet.get_account().get_public_address_str(); + } + catch (std::exception& e) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = e.what(); + return false; + } + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx) { diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index db49df574..ec29e0932 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -36,6 +36,7 @@ namespace tools BEGIN_URI_MAP2() BEGIN_JSON_RPC_MAP("/json_rpc") MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE) + MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_rpc::COMMAND_RPC_GET_ADDRESS) MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER) MAP_JON_RPC_WE("store", on_store, wallet_rpc::COMMAND_RPC_STORE) MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS) @@ -44,6 +45,7 @@ namespace tools //json_rpc bool on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_getaddress(const wallet_rpc::COMMAND_RPC_GET_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_get_payments(const wallet_rpc::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx); diff --git a/src/wallet/wallet_rpc_server_commans_defs.h b/src/wallet/wallet_rpc_server_commans_defs.h index b99d92ca2..cc005b29c 100644 --- a/src/wallet/wallet_rpc_server_commans_defs.h +++ b/src/wallet/wallet_rpc_server_commans_defs.h @@ -34,6 +34,24 @@ namespace wallet_rpc }; }; + struct COMMAND_RPC_GET_ADDRESS + { + struct request + { + BEGIN_KV_SERIALIZE_MAP() + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::string address; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(address) + END_KV_SERIALIZE_MAP() + }; + }; + struct trnsfer_destination { uint64_t amount; -- cgit v1.2.3 From 3a3a8176782a4fa75b0607fba0393c9d4a1746be Mon Sep 17 00:00:00 2001 From: mydesktop Date: Sun, 25 May 2014 13:06:40 -0400 Subject: 0.8.8update --- src/wallet/wallet2.cpp | 4 ++-- src/wallet/wallet2.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index e8d67eec2..111b76117 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -455,14 +455,14 @@ void wallet2::generate(const std::string& wallet_, const std::string& password) store(); } //---------------------------------------------------------------------------------------------------- -void wallet2::wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exitst) +void wallet2::wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists) { std::string keys_file, wallet_file; do_prepare_file_names(file_path, keys_file, wallet_file); boost::system::error_code ignore; keys_file_exists = boost::filesystem::exists(keys_file, ignore); - wallet_file_exitst = boost::filesystem::exists(wallet_file, ignore); + wallet_file_exists = boost::filesystem::exists(wallet_file, ignore); } //---------------------------------------------------------------------------------------------------- bool wallet2::prepare_file_names(const std::string& file_path) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index edbf31f2d..d2016f696 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -144,7 +144,7 @@ namespace tools a & m_payments; } - static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exitst); + static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists); private: bool store_keys(const std::string& keys_file_name, const std::string& password); @@ -326,7 +326,7 @@ namespace tools req.amounts.push_back(it->amount()); } - bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getrandom_outs.bin", req, daemon_resp, m_http_client, 200000); + bool r = epee::net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getrandom_outs.bin", req, daemon_resp, m_http_client, 200000); THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getrandom_outs.bin"); THROW_WALLET_EXCEPTION_IF(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin"); THROW_WALLET_EXCEPTION_IF(daemon_resp.status != CORE_RPC_STATUS_OK, error::get_random_outs_error, daemon_resp.status); @@ -421,7 +421,7 @@ namespace tools COMMAND_RPC_SEND_RAW_TX::request req; req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx)); COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp; - r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000); + r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000); THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "sendrawtransaction"); THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "sendrawtransaction"); THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status != CORE_RPC_STATUS_OK, error::tx_rejected, tx, daemon_send_resp.status); -- cgit v1.2.3 From 31a59785b0b3f678ea29fcfb63902f051c4e7ce0 Mon Sep 17 00:00:00 2001 From: mydesktop Date: Sun, 25 May 2014 20:25:37 -0400 Subject: temporary fix for block reward dos --- src/wallet/wallet2.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index d2016f696..f90fc4fac 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -102,7 +102,12 @@ namespace tools void store(); cryptonote::account_base& get_account(){return m_account;} - void init(const std::string& daemon_address = "http://localhost:8080", uint64_t upper_transaction_size_limit = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE*2 - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); + // upper_transaction_size_limit as defined below is set to + // approximately 125% of the fixed minimum allowable penalty + // free block size. TODO: fix this so that it actually takes + // into account the current median block size rather than + // the minimum block size. + void init(const std::string& daemon_address = "http://localhost:8080", uint64_t upper_transaction_size_limit = ((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); bool deinit(); void stop() { m_run.store(false, std::memory_order_relaxed); } -- cgit v1.2.3 From feacdded6b48fcfe18bc3218b05b27e94db2fc92 Mon Sep 17 00:00:00 2001 From: paybee Date: Tue, 27 May 2014 12:52:11 +0200 Subject: Added incoming_transfers RPC API method --- src/wallet/wallet_rpc_server.cpp | 64 +++++++++++++++++++++++++++++ src/wallet/wallet_rpc_server.h | 10 +++-- src/wallet/wallet_rpc_server_commans_defs.h | 36 ++++++++++++++++ src/wallet/wallet_rpc_server_error_codes.h | 2 + 4 files changed, 108 insertions(+), 4 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index f1766c3b4..7dc73d8bf 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -166,4 +166,68 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_incoming_transfers(const wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::response& res, epee::json_rpc::error& er, connection_context& cntx) + { + if(req.transfer_type.compare("all") != 0 && req.transfer_type.compare("available") != 0 && req.transfer_type.compare("unavailable") != 0) + { + er.code = WALLET_RPC_ERROR_CODE_TRANSFER_TYPE; + er.message = "Transfer type must be one of: all, available, or unavailable; provided: " + return false; + } + + bool filter = false; + bool available = false; + if (req.transfer_type.compare("available") == 0) + { + filter = true; + available = true; + } + else if (req.transfer_type.compare("unavailable") == 0) + { + filter = true; + available = false; + } + + wallet2::transfer_container transfers; + m_wallet.get_transfers(transfers); + + bool transfers_found = false; + for (const auto& td : transfers) + { + if (!filter || available != td.m_spent) + { + if (!transfers_found) + { + transfers_found = true; + } + wallet_rpc::transfer_details rpc_transfers; + rpc_transfers.amount = td.amount(); + rpc_transfers.spent = td.m_spent; + rpc_transfers.global_index = td.m_global_output_index; + rpc_transfers.tx_hash = boost::lexical_cast(cryptonote::get_transaction_hash(td.m_tx)); + res.transfers.push_back(rpc_transfers); + } + } + + if (!transfers_found) + { + er.code = WALLET_RPC_ERROR_CODE_NO_TRANSFERS; + if (!filter) + { + er.message = "No incoming transfers"; + } + else if (available) + { + er.message = "No incoming available transfers"; + } + else + { + er.message = "No incoming unavailable transfers"; + } + return false; + } + + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ } diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index db49df574..69cc9530a 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -35,10 +35,11 @@ namespace tools BEGIN_URI_MAP2() BEGIN_JSON_RPC_MAP("/json_rpc") - MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE) - MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER) - MAP_JON_RPC_WE("store", on_store, wallet_rpc::COMMAND_RPC_STORE) - MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS) + MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE) + MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER) + MAP_JON_RPC_WE("store", on_store, wallet_rpc::COMMAND_RPC_STORE) + MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS) + MAP_JON_RPC_WE("incoming_transfers", on_incoming_transfers, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS) END_JSON_RPC_MAP() END_URI_MAP2() @@ -47,6 +48,7 @@ namespace tools bool on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_get_payments(const wallet_rpc::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_incoming_transfers(const wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::response& res, epee::json_rpc::error& er, connection_context& cntx); bool handle_command_line(const boost::program_options::variables_map& vm); diff --git a/src/wallet/wallet_rpc_server_commans_defs.h b/src/wallet/wallet_rpc_server_commans_defs.h index b99d92ca2..7bdb49b2c 100644 --- a/src/wallet/wallet_rpc_server_commans_defs.h +++ b/src/wallet/wallet_rpc_server_commans_defs.h @@ -121,6 +121,42 @@ namespace wallet_rpc END_KV_SERIALIZE_MAP() }; }; + + struct transfer_details + { + uint64_t amount; + bool spent; + uint64_t global_index; + std::string tx_hash; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(amount) + KV_SERIALIZE(spent) + KV_SERIALIZE(global_index) + KV_SERIALIZE(tx_hash) + END_KV_SERIALIZE_MAP() + }; + + struct COMMAND_RPC_INCOMING_TRANSFERS + { + struct request + { + std::string transfer_type; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(transfer_type) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::list transfers; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(transfers) + END_KV_SERIALIZE_MAP() + }; + }; } } diff --git a/src/wallet/wallet_rpc_server_error_codes.h b/src/wallet/wallet_rpc_server_error_codes.h index 7fa536dac..fb3c1c1a9 100644 --- a/src/wallet/wallet_rpc_server_error_codes.h +++ b/src/wallet/wallet_rpc_server_error_codes.h @@ -10,3 +10,5 @@ #define WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY -3 #define WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR -4 #define WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID -5 +#define WALLET_RPC_ERROR_CODE_TRANSFER_TYPE -6 +#define WALLET_RPC_ERROR_CODE_NO_TRANSFERS -7 -- cgit v1.2.3 From 117393d562fc9782efed0e1b25f6470d9f8102b2 Mon Sep 17 00:00:00 2001 From: Neozaru Date: Mon, 2 Jun 2014 00:22:42 +0200 Subject: Added 'payment_id' optional argument to 'transfer' wallet RPC method --- src/wallet/wallet2.cpp | 14 ++++++++++++++ src/wallet/wallet2.h | 2 ++ src/wallet/wallet_rpc_server.cpp | 29 ++++++++++++++++++++++++++++- src/wallet/wallet_rpc_server_commans_defs.h | 2 ++ 4 files changed, 46 insertions(+), 1 deletion(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 111b76117..fb1e5575b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -19,6 +19,7 @@ using namespace epee; #include "profile_tools.h" #include "crypto/crypto.h" #include "serialization/binary_utils.h" +#include "cryptonote_protocol/blobdatatype.h" using namespace cryptonote; @@ -465,6 +466,19 @@ void wallet2::wallet_exists(const std::string& file_path, bool& keys_file_exists wallet_file_exists = boost::filesystem::exists(wallet_file, ignore); } //---------------------------------------------------------------------------------------------------- +bool wallet2::parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id) +{ + cryptonote::blobdata payment_id_data; + if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_data)) + return false; + + if(sizeof(crypto::hash) != payment_id_data.size()) + return false; + + payment_id = *reinterpret_cast(payment_id_data.data()); + return true; +} +//---------------------------------------------------------------------------------------------------- bool wallet2::prepare_file_names(const std::string& file_path) { do_prepare_file_names(file_path, m_keys_file, m_wallet_file); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f90fc4fac..9ca586425 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -151,6 +151,8 @@ namespace tools static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists); + static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id); + private: bool store_keys(const std::string& keys_file_name, const std::string& password); void load_keys(const std::string& keys_file_name, const std::string& password); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 55f81aacc..af195cfcc 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -102,10 +102,37 @@ namespace tools de.amount = it->amount; dsts.push_back(de); } + + std::vector extra; + if (!req.payment_id.empty()) { + + /* Just to clarify */ + const std::string& payment_id_str = req.payment_id; + + crypto::hash payment_id; + /* Parse payment ID */ + if (!wallet2::parse_payment_id(payment_id_str, payment_id)) { + er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; + er.message = "Payment id has invalid format: \"" + payment_id_str + "\", expected 64-character string"; + return false; + } + + std::string extra_nonce; + cryptonote::set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id); + + /* Append Payment ID data into extra */ + if (!cryptonote::add_extra_nonce_to_tx_extra(extra, extra_nonce)) { + er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID; + er.message = "Something went wront with payment_id. Please check its format: \"" + payment_id_str + "\", expected 64-character string"; + return false; + } + + } + try { cryptonote::transaction tx; - m_wallet.transfer(dsts, req.mixin, req.unlock_time, req.fee, std::vector(), tx); + m_wallet.transfer(dsts, req.mixin, req.unlock_time, req.fee, extra, tx); res.tx_hash = boost::lexical_cast(cryptonote::get_transaction_hash(tx)); return true; } diff --git a/src/wallet/wallet_rpc_server_commans_defs.h b/src/wallet/wallet_rpc_server_commans_defs.h index cc005b29c..df05b4e0a 100644 --- a/src/wallet/wallet_rpc_server_commans_defs.h +++ b/src/wallet/wallet_rpc_server_commans_defs.h @@ -70,12 +70,14 @@ namespace wallet_rpc uint64_t fee; uint64_t mixin; uint64_t unlock_time; + std::string payment_id; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(destinations) KV_SERIALIZE(fee) KV_SERIALIZE(mixin) KV_SERIALIZE(unlock_time) + KV_SERIALIZE(payment_id) END_KV_SERIALIZE_MAP() }; -- cgit v1.2.3 From 295c284c3e4ea6a7ec36353b9b23bb6f5db497f8 Mon Sep 17 00:00:00 2001 From: paybee Date: Mon, 2 Jun 2014 22:36:35 +0200 Subject: Added incoming_transfers RPC API method --- src/wallet/wallet_rpc_server.cpp | 15 +-------------- src/wallet/wallet_rpc_server_error_codes.h | 1 - 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 7dc73d8bf..b721a27ab 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -171,7 +171,7 @@ namespace tools if(req.transfer_type.compare("all") != 0 && req.transfer_type.compare("available") != 0 && req.transfer_type.compare("unavailable") != 0) { er.code = WALLET_RPC_ERROR_CODE_TRANSFER_TYPE; - er.message = "Transfer type must be one of: all, available, or unavailable; provided: " + er.message = "Transfer type must be one of: all, available, or unavailable"; return false; } @@ -211,19 +211,6 @@ namespace tools if (!transfers_found) { - er.code = WALLET_RPC_ERROR_CODE_NO_TRANSFERS; - if (!filter) - { - er.message = "No incoming transfers"; - } - else if (available) - { - er.message = "No incoming available transfers"; - } - else - { - er.message = "No incoming unavailable transfers"; - } return false; } diff --git a/src/wallet/wallet_rpc_server_error_codes.h b/src/wallet/wallet_rpc_server_error_codes.h index fb3c1c1a9..a37bde795 100644 --- a/src/wallet/wallet_rpc_server_error_codes.h +++ b/src/wallet/wallet_rpc_server_error_codes.h @@ -11,4 +11,3 @@ #define WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR -4 #define WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID -5 #define WALLET_RPC_ERROR_CODE_TRANSFER_TYPE -6 -#define WALLET_RPC_ERROR_CODE_NO_TRANSFERS -7 -- cgit v1.2.3 From 4f382b383005d09f6056371d0fecdc8b6ce37a08 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 4 Jun 2014 18:59:47 -0400 Subject: most functions prototyped/modified for wallet recovery --- src/wallet/wallet2.cpp | 6 ++++-- src/wallet/wallet2.h | 3 ++- src/wallet/wallet_errors.h | 11 +++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index fb1e5575b..b0c341615 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -38,6 +38,7 @@ void do_prepare_file_names(const std::string& file_path, std::string& keys_file, keys_file += ".keys"; } } + } //namespace namespace tools @@ -435,7 +436,7 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa THROW_WALLET_EXCEPTION_IF(!r, error::invalid_password); } //---------------------------------------------------------------------------------------------------- -void wallet2::generate(const std::string& wallet_, const std::string& password) +void wallet2::generate(const std::string& wallet_, const std::string& password, const crypto::secret_key& recovery_param, bool recover) { clear(); prepare_file_names(wallet_); @@ -444,7 +445,8 @@ void wallet2::generate(const std::string& wallet_, const std::string& password) THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file); THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file); - m_account.generate(); + m_account.generate(recovery_param, recover); + m_account_public_address = m_account.get_keys().m_account_address; bool r = store_keys(m_keys_file, password); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 9ca586425..87e1dcbd4 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -97,7 +97,7 @@ namespace tools END_SERIALIZE() }; - void generate(const std::string& wallet, const std::string& password); + void generate(const std::string& wallet, const std::string& password, const crypto::secret_key& recovery_param, bool recover = false); void load(const std::string& wallet, const std::string& password); void store(); cryptonote::account_base& get_account(){return m_account;} @@ -227,6 +227,7 @@ namespace boost namespace tools { + namespace detail { //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 0d42dbaf4..71c946545 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -188,6 +188,17 @@ namespace tools std::string to_string() const { return wallet_logic_error::to_string(); } }; + + //---------------------------------------------------------------------------------------------------- + struct invalid_pregenerated_random : public wallet_logic_error + { + explicit invalid_pregenerated_random (std::string&& loc) + : wallet_logic_error(std::move(loc), "invalid pregenerated random for wallet creation/recovery") + { + } + + std::string to_string() const { return wallet_logic_error::to_string(); } + }; //---------------------------------------------------------------------------------------------------- struct refresh_error : public wallet_logic_error { -- cgit v1.2.3 From f70bc3a345ea11190e5b40c0606bb222d7825ea8 Mon Sep 17 00:00:00 2001 From: tom Date: Wed, 4 Jun 2014 21:11:19 -0400 Subject: defaulted new parameters in modified functions --- src/wallet/wallet2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 87e1dcbd4..85ed344c3 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -97,7 +97,7 @@ namespace tools END_SERIALIZE() }; - void generate(const std::string& wallet, const std::string& password, const crypto::secret_key& recovery_param, bool recover = false); + void generate(const std::string& wallet, const std::string& password, const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false); void load(const std::string& wallet, const std::string& password); void store(); cryptonote::account_base& get_account(){return m_account;} -- cgit v1.2.3 From d22e458c6c680f4b5dcf56a58a37a5f79912e65c Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Fri, 6 Jun 2014 14:18:11 -0400 Subject: builds, but doesn't link. other than that, electrum-style recovery implemented (but not tested\!) --- src/wallet/wallet2.cpp | 5 +++-- src/wallet/wallet2.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b0c341615..59e1b0fa4 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -436,7 +436,7 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa THROW_WALLET_EXCEPTION_IF(!r, error::invalid_password); } //---------------------------------------------------------------------------------------------------- -void wallet2::generate(const std::string& wallet_, const std::string& password, const crypto::secret_key& recovery_param, bool recover) +crypto::secret_key wallet2::generate(const std::string& wallet_, const std::string& password, const crypto::secret_key& recovery_param, bool recover) { clear(); prepare_file_names(wallet_); @@ -445,7 +445,7 @@ void wallet2::generate(const std::string& wallet_, const std::string& password, THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file); THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file); - m_account.generate(recovery_param, recover); + crypto::secret_key retval = m_account.generate(recovery_param, recover); m_account_public_address = m_account.get_keys().m_account_address; @@ -456,6 +456,7 @@ void wallet2::generate(const std::string& wallet_, const std::string& password, if(!r) LOG_PRINT_RED_L0("String with address text not saved"); store(); + return retval; } //---------------------------------------------------------------------------------------------------- void wallet2::wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 85ed344c3..f54045b3a 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -97,7 +97,7 @@ namespace tools END_SERIALIZE() }; - void generate(const std::string& wallet, const std::string& password, const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false); + crypto::secret_key generate(const std::string& wallet, const std::string& password, const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false); void load(const std::string& wallet, const std::string& password); void store(); cryptonote::account_base& get_account(){return m_account;} -- cgit v1.2.3 From da37b6f15b6eb1f7b4ac9802a3350413d303a5c9 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Sun, 8 Jun 2014 20:04:32 -0400 Subject: allow two-random-numbers wallet generation (but not as default) --- src/wallet/wallet2.cpp | 4 ++-- src/wallet/wallet2.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 59e1b0fa4..a63eb4be7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -436,7 +436,7 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa THROW_WALLET_EXCEPTION_IF(!r, error::invalid_password); } //---------------------------------------------------------------------------------------------------- -crypto::secret_key wallet2::generate(const std::string& wallet_, const std::string& password, const crypto::secret_key& recovery_param, bool recover) +crypto::secret_key wallet2::generate(const std::string& wallet_, const std::string& password, const crypto::secret_key& recovery_param, bool recover, bool two_random) { clear(); prepare_file_names(wallet_); @@ -445,7 +445,7 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file); THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file); - crypto::secret_key retval = m_account.generate(recovery_param, recover); + crypto::secret_key retval = m_account.generate(recovery_param, recover, two_random); m_account_public_address = m_account.get_keys().m_account_address; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f54045b3a..534a0517b 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -97,7 +97,7 @@ namespace tools END_SERIALIZE() }; - crypto::secret_key generate(const std::string& wallet, const std::string& password, const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false); + crypto::secret_key generate(const std::string& wallet, const std::string& password, const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false, bool two_random = false); void load(const std::string& wallet, const std::string& password); void store(); cryptonote::account_base& get_account(){return m_account;} -- cgit v1.2.3