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 | |
parent | Add testnet seed nodes (diff) | |
download | monero-d03308734b1487540af062ab50c94cc7bb3e668e.tar.xz |
Separate testnet address prefix
Diffstat (limited to '')
-rw-r--r-- | src/cryptonote_config.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/account.cpp | 4 | ||||
-rw-r--r-- | src/cryptonote_core/account.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_basic_impl.cpp | 23 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_basic_impl.h | 14 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 2 | ||||
-rw-r--r-- | src/cryptonote_core/miner.cpp | 4 | ||||
-rw-r--r-- | src/cryptonote_core/miner.h | 2 | ||||
-rw-r--r-- | src/daemon/daemon.cpp | 6 | ||||
-rw-r--r-- | src/daemon/daemon_commands_handler.h | 10 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 21 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.h | 9 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 15 | ||||
-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 |
17 files changed, 111 insertions, 54 deletions
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index eb04984b9..f8f35470d 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -128,7 +128,7 @@ namespace config namespace testnet { - uint64_t const CRYPTONOTE_ADDRESS_BASE58_PREFIX = 19; // addresses start with "5" + uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 19; // addresses start with "5" uint16_t const P2P_DEFAULT_PORT = 28080; uint16_t const RPC_DEFAULT_PORT = 28081; boost::uuids::uuid const NETWORK_ID = { { diff --git a/src/cryptonote_core/account.cpp b/src/cryptonote_core/account.cpp index d07dad33f..36043238d 100644 --- a/src/cryptonote_core/account.cpp +++ b/src/cryptonote_core/account.cpp @@ -93,10 +93,10 @@ DISABLE_VS_WARNINGS(4244 4345) return m_keys; } //----------------------------------------------------------------- - std::string account_base::get_public_address_str() + std::string account_base::get_public_address_str(bool testnet) { //TODO: change this code into base 58 - return get_account_address_as_str(m_keys.m_account_address); + return get_account_address_as_str(testnet, m_keys.m_account_address); } //----------------------------------------------------------------- } diff --git a/src/cryptonote_core/account.h b/src/cryptonote_core/account.h index 06bd700a9..dd6618542 100644 --- a/src/cryptonote_core/account.h +++ b/src/cryptonote_core/account.h @@ -59,7 +59,7 @@ namespace cryptonote account_base(); crypto::secret_key generate(const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false, bool two_random = false); const account_keys& get_keys() const; - std::string get_public_address_str(); + std::string get_public_address_str(bool testnet); uint64_t get_createtime() const { return m_creation_timestamp; } void set_createtime(uint64_t val) { m_creation_timestamp = val; } diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp index 398c63443..9cec666f2 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.cpp +++ b/src/cryptonote_core/cryptonote_basic_impl.cpp @@ -103,9 +103,15 @@ namespace cryptonote { return summ; } //----------------------------------------------------------------------- - std::string get_account_address_as_str(const account_public_address& adr) + std::string get_account_address_as_str( + bool testnet + , account_public_address const & adr + ) { - return tools::base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(adr)); + uint64_t address_prefix = testnet ? + config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX; + + return tools::base58::encode_addr(address_prefix, t_serializable_object_to_blob(adr)); } //----------------------------------------------------------------------- bool is_coinbase(const transaction& tx) @@ -119,8 +125,15 @@ namespace cryptonote { return true; } //----------------------------------------------------------------------- - bool get_account_address_from_str(account_public_address& adr, const std::string& str) + bool get_account_address_from_str( + account_public_address& adr + , bool testnet + , std::string const & str + ) { + uint64_t address_prefix = testnet ? + config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX; + if (2 * sizeof(public_address_outer_blob) != str.size()) { blobdata data; @@ -131,9 +144,9 @@ namespace cryptonote { return false; } - if (config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX != prefix) + if (address_prefix != prefix) { - LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX); + LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << address_prefix); return false; } diff --git a/src/cryptonote_core/cryptonote_basic_impl.h b/src/cryptonote_core/cryptonote_basic_impl.h index a3184378e..ddef677cb 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.h +++ b/src/cryptonote_core/cryptonote_basic_impl.h @@ -66,8 +66,18 @@ namespace cryptonote { size_t get_max_tx_size(); bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward); uint8_t get_account_address_checksum(const public_address_outer_blob& bl); - std::string get_account_address_as_str(const account_public_address& adr); - bool get_account_address_from_str(account_public_address& adr, const std::string& str); + + std::string get_account_address_as_str( + bool testnet + , const account_public_address& adr + ); + + bool get_account_address_from_str( + account_public_address& adr + , bool testnet + , const std::string& str + ); + bool is_coinbase(const transaction& tx); bool operator ==(const cryptonote::transaction& a, const cryptonote::transaction& b); diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 72e5ee209..964d61e2f 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -127,7 +127,7 @@ namespace cryptonote r = m_blockchain_storage.init(m_config_folder, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); - r = m_miner.init(vm); + r = m_miner.init(vm, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); return load_state_data(); diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp index 81dc4a692..b2adfe39c 100644 --- a/src/cryptonote_core/miner.cpp +++ b/src/cryptonote_core/miner.cpp @@ -171,7 +171,7 @@ namespace cryptonote command_line::add_arg(desc, arg_mining_threads); } //----------------------------------------------------------------------------------------------------- - bool miner::init(const boost::program_options::variables_map& vm) + bool miner::init(const boost::program_options::variables_map& vm, bool testnet) { if(command_line::has_arg(vm, arg_extra_messages)) { @@ -198,7 +198,7 @@ namespace cryptonote if(command_line::has_arg(vm, arg_start_mining)) { - if(!cryptonote::get_account_address_from_str(m_mine_address, command_line::get_arg(vm, arg_start_mining))) + if(!cryptonote::get_account_address_from_str(m_mine_address, testnet, command_line::get_arg(vm, arg_start_mining))) { LOG_ERROR("Target account address " << command_line::get_arg(vm, arg_start_mining) << " has wrong format, starting daemon canceled"); return false; diff --git a/src/cryptonote_core/miner.h b/src/cryptonote_core/miner.h index a96d42d75..44844428c 100644 --- a/src/cryptonote_core/miner.h +++ b/src/cryptonote_core/miner.h @@ -56,7 +56,7 @@ namespace cryptonote public: miner(i_miner_handler* phandler); ~miner(); - bool init(const boost::program_options::variables_map& vm); + bool init(const boost::program_options::variables_map& vm, bool testnet); static void init_options(boost::program_options::options_description& desc); bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height); bool on_block_chain_update(); diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index fd1b18356..12990800a 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -218,10 +218,10 @@ int main(int argc, char* argv[]) cprotocol , testnet_mode ? std::move(config::testnet::NETWORK_ID) : std::move(config::NETWORK_ID) }; - cryptonote::core_rpc_server rpc_server(ccore, p2psrv); + cryptonote::core_rpc_server rpc_server {ccore, p2psrv, testnet_mode}; cprotocol.set_p2p_endpoint(&p2psrv); ccore.set_cryptonote_protocol(&cprotocol); - daemon_cmmands_handler dch(p2psrv); + daemon_cmmands_handler dch(p2psrv, testnet_mode); //initialize objects LOG_PRINT_L0("Initializing P2P server..."); @@ -235,7 +235,7 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Protocol initialized OK"); LOG_PRINT_L0("Initializing core RPC server..."); - res = rpc_server.init(vm, testnet_mode); + res = rpc_server.init(vm); CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core RPC server."); LOG_PRINT_GREEN("Core RPC server initialized OK on port: " << rpc_server.get_binded_port(), LOG_LEVEL_0); diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 5dc0be7dd..58112e166 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -50,7 +50,12 @@ class daemon_cmmands_handler { nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& m_srv; public: - daemon_cmmands_handler(nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& srv):m_srv(srv) + daemon_cmmands_handler( + nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& srv + , bool testnet + ) + : m_srv(srv) + , m_testnet {testnet} { m_cmd_binder.set_handler("help", boost::bind(&daemon_cmmands_handler::help, this, _1), "Show this help"); m_cmd_binder.set_handler("print_pl", boost::bind(&daemon_cmmands_handler::print_pl, this, _1), "Print peer list"); @@ -84,6 +89,7 @@ public: private: epee::srv_console_handlers_binder<nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> > > m_cmd_binder; + bool m_testnet; //-------------------------------------------------------------------------------- std::string get_commands_str() @@ -368,7 +374,7 @@ private: } cryptonote::account_public_address adr; - if(!cryptonote::get_account_address_from_str(adr, args.front())) + if(!cryptonote::get_account_address_from_str(adr, m_testnet, args.front())) { std::cout << "target account address has wrong format" << std::endl; return true; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index deadd25fc..22e95a1fc 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -72,15 +72,21 @@ namespace cryptonote command_line::add_arg(desc, arg_testnet_rpc_bind_port); } //------------------------------------------------------------------------------------------------------------------------------ - core_rpc_server::core_rpc_server(core& cr, nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& p2p):m_core(cr), m_p2p(p2p) + core_rpc_server::core_rpc_server( + core& cr + , nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& p2p + , bool testnet + ) + : m_core(cr) + , m_p2p(p2p) + , m_testnet {testnet} {} //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::handle_command_line( const boost::program_options::variables_map& vm - , bool testnet ) { - auto p2p_bind_arg = testnet ? arg_testnet_rpc_bind_port : arg_rpc_bind_port; + auto p2p_bind_arg = m_testnet ? arg_testnet_rpc_bind_port : arg_rpc_bind_port; m_bind_ip = command_line::get_arg(vm, arg_rpc_bind_ip); m_port = command_line::get_arg(vm, p2p_bind_arg); @@ -89,11 +95,10 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::init( const boost::program_options::variables_map& vm - , bool testnet ) { m_net_server.set_threads_prefix("RPC"); - bool r = handle_command_line(vm, testnet); + bool r = handle_command_line(vm); CHECK_AND_ASSERT_MES(r, false, "Failed to process command line in core_rpc_server"); return epee::http_server_impl_base<core_rpc_server, connection_context>::init(m_port, m_bind_ip); } @@ -302,7 +307,7 @@ namespace cryptonote { CHECK_CORE_READY(); account_public_address adr; - if(!get_account_address_from_str(adr, req.miner_address)) + if(!get_account_address_from_str(adr, m_testnet, req.miner_address)) { res.status = "Failed, wrong address"; return true; @@ -342,7 +347,7 @@ namespace cryptonote res.speed = lMiner.get_speed(); res.threads_count = lMiner.get_threads_count(); const account_public_address& lMiningAdr = lMiner.get_mining_address(); - res.address = get_account_address_as_str(lMiningAdr); + res.address = get_account_address_as_str(m_testnet, lMiningAdr); } res.status = CORE_RPC_STATUS_OK; @@ -426,7 +431,7 @@ namespace cryptonote cryptonote::account_public_address acc = AUTO_VAL_INIT(acc); - if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(acc, req.wallet_address)) + if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(acc, m_testnet, req.wallet_address)) { error_resp.code = CORE_RPC_ERROR_CODE_WRONG_WALLET_ADDRESS; error_resp.message = "Failed to parse wallet address"; diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 3f3d23f51..02bc533c9 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -49,12 +49,15 @@ namespace cryptonote public: typedef epee::net_utils::connection_context_base connection_context; - core_rpc_server(core& cr, nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& p2p); + core_rpc_server( + core& cr + , nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& p2p + , bool testnet + ); static void init_options(boost::program_options::options_description& desc); bool init( const boost::program_options::variables_map& vm - , bool testnet ); private: @@ -110,7 +113,6 @@ namespace cryptonote //----------------------- bool handle_command_line( const boost::program_options::variables_map& vm - , bool testnet ); bool check_core_busy(); bool check_core_ready(); @@ -123,5 +125,6 @@ namespace cryptonote nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& m_p2p; std::string m_port; std::string m_bind_ip; + bool m_testnet; }; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 6c97dc807..fbe7c4730 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -441,7 +441,9 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas try { recovery_val = m_wallet->generate(wallet_file, password, recovery_key, recover, two_random); - message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str() << std::endl << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key); + message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " + << m_wallet->get_account().get_public_address_str(m_wallet->testnet()) << std::endl << "view key: " + << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key); } catch (const std::exception& e) { @@ -487,7 +489,8 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa try { m_wallet->load(m_wallet_file, password); - message_writer(epee::log_space::console_color_white, true) << "Opened wallet: " << m_wallet->get_account().get_public_address_str(); + message_writer(epee::log_space::console_color_white, true) << "Opened wallet: " + << m_wallet->get_account().get_public_address_str(m_wallet->testnet()); } catch (const std::exception& e) { @@ -548,7 +551,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args) return true; COMMAND_RPC_START_MINING::request req; - req.miner_address = m_wallet->get_account().get_public_address_str(); + req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet()); bool ok = true; size_t max_mining_threads_count = (std::max)(std::thread::hardware_concurrency(), static_cast<unsigned>(2)); @@ -905,7 +908,7 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_) for (size_t i = 0; i < local_args.size(); i += 2) { cryptonote::tx_destination_entry de; - if(!get_account_address_from_str(de.addr, local_args[i])) + if(!get_account_address_from_str(de.addr, m_wallet->testnet(), local_args[i])) { fail_msg_writer() << "wrong address: " << local_args[i]; return true; @@ -1035,7 +1038,7 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::run() { - std::string addr_start = m_wallet->get_account().get_public_address_str().substr(0, 6); + std::string addr_start = m_wallet->get_account().get_public_address_str(m_wallet->testnet()).substr(0, 6); return m_cmd_binder.run_handling("[wallet " + addr_start + "]: ", ""); } //---------------------------------------------------------------------------------------------------- @@ -1047,7 +1050,7 @@ void simple_wallet::stop() //---------------------------------------------------------------------------------------------------- bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { - success_msg_writer() << m_wallet->get_account().get_public_address_str(); + success_msg_writer() << m_wallet->get_account().get_public_address_str(m_wallet->testnet()); return true; } //---------------------------------------------------------------------------------------------------- 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; |