diff options
author | Zachary Michaels <mikezackles@gmail.com> | 2014-09-09 10:58:53 -0400 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2014-09-15 15:54:59 +0200 |
commit | d03308734b1487540af062ab50c94cc7bb3e668e (patch) | |
tree | 59b26c94f7449bb6e57a9c4c7a0ec3983c1d2feb /src/wallet | |
parent | Add testnet seed nodes (diff) | |
download | monero-d03308734b1487540af062ab50c94cc7bb3e668e.tar.xz |
Separate testnet address prefix
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet2.cpp | 4 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 6 | ||||
-rw-r--r-- | src/wallet/wallet_errors.h | 37 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 4 |
4 files changed, 34 insertions, 17 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 78fac0e87..9ba6f245a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -496,7 +496,7 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri bool r = store_keys(m_keys_file, password); THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file); - r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str()); + r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet)); if(!r) LOG_PRINT_RED_L0("String with address text not saved"); cryptonote::block b; @@ -562,7 +562,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password) THROW_WALLET_EXCEPTION_IF(e || !exists, error::file_not_found, m_keys_file); load_keys(m_keys_file, password); - LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str()); + LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str(m_testnet)); //keys loaded ok! //try to load wallet file. but even if we failed, it is not big problem diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 28788f693..3311e3438 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -158,6 +158,8 @@ namespace tools void refresh(uint64_t start_height, size_t & blocks_fetched, bool& received_money); bool refresh(size_t & blocks_fetched, bool& received_money, bool& ok); + bool testnet() { return m_testnet; } + uint64_t balance(); uint64_t unlocked_balance(); template<typename T> @@ -360,7 +362,7 @@ namespace tools { THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination); needed_money += dt.amount; - THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee); + THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee, m_testnet); } // randomly select inputs for transaction @@ -465,7 +467,7 @@ namespace tools } bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time); - THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time); + THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet); THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit); std::string key_images; diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index aa29f281a..7914ff8e1 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -376,11 +376,18 @@ namespace tools typedef std::vector<cryptonote::tx_source_entry> sources_t; typedef std::vector<cryptonote::tx_destination_entry> destinations_t; - explicit tx_not_constructed(std::string&& loc, const sources_t& sources, const destinations_t& destinations, uint64_t unlock_time) - : transfer_error(std::move(loc), "transaction was not constructed") - , m_sources(sources) - , m_destinations(destinations) - , m_unlock_time(unlock_time) + explicit tx_not_constructed( + std::string && loc + , sources_t const & sources + , destinations_t const & destinations + , uint64_t unlock_time + , bool testnet + ) + : transfer_error {std::move(loc), "transaction was not constructed"} + , m_sources {sources} + , m_destinations {destinations} + , m_unlock_time {unlock_time} + , m_testnet {testnet} { } @@ -414,7 +421,7 @@ namespace tools for (size_t i = 0; i < m_destinations.size(); ++i) { const cryptonote::tx_destination_entry& dst = m_destinations[i]; - ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(dst.addr) << " " << + ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(m_testnet, dst.addr) << " " << cryptonote::print_money(dst.amount); } @@ -427,6 +434,7 @@ namespace tools sources_t m_sources; destinations_t m_destinations; uint64_t m_unlock_time; + bool m_testnet; }; //---------------------------------------------------------------------------------------------------- struct tx_rejected : public transfer_error @@ -457,10 +465,16 @@ namespace tools //---------------------------------------------------------------------------------------------------- struct tx_sum_overflow : public transfer_error { - explicit tx_sum_overflow(std::string&& loc, const std::vector<cryptonote::tx_destination_entry>& destinations, uint64_t fee) - : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max())) - , m_destinations(destinations) - , m_fee(fee) + explicit tx_sum_overflow( + std::string && loc + , const std::vector<cryptonote::tx_destination_entry>& destinations + , uint64_t fee + , bool testnet + ) + : transfer_error {std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max())} + , m_destinations {destinations} + , m_fee {fee} + , m_testnet {testnet} { } @@ -475,7 +489,7 @@ namespace tools ", destinations:"; for (const auto& dst : m_destinations) { - ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(dst.addr); + ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(m_testnet, dst.addr); } return ss.str(); } @@ -483,6 +497,7 @@ namespace tools private: std::vector<cryptonote::tx_destination_entry> m_destinations; uint64_t m_fee; + bool m_testnet; }; //---------------------------------------------------------------------------------------------------- struct tx_too_big : public transfer_error diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index fa0a5445e..995e97ede 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -101,7 +101,7 @@ namespace tools { try { - res.address = m_wallet.get_account().get_public_address_str(); + res.address = m_wallet.get_account().get_public_address_str(m_wallet.testnet()); } catch (std::exception& e) { @@ -118,7 +118,7 @@ namespace tools for (auto it = destinations.begin(); it != destinations.end(); it++) { cryptonote::tx_destination_entry de; - if(!get_account_address_from_str(de.addr, it->address)) + if(!get_account_address_from_str(de.addr, m_wallet.testnet(), it->address)) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + it->address; |