From 07470fd400ee30b84f6227edffb24094d03781cb Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 16 Jul 2014 13:30:15 -0400 Subject: Add testnet flag Source: cryptonotefoundation --- src/wallet/wallet2.cpp | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 48aa164ab..be857c78a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -420,9 +420,6 @@ bool wallet2::clear() { m_blockchain.clear(); m_transfers.clear(); - cryptonote::block b; - cryptonote::generate_genesis_block(b); - m_blockchain.push_back(get_block_hash(b)); m_local_bc_height = 1; return true; } @@ -501,6 +498,10 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str()); if(!r) LOG_PRINT_RED_L0("String with address text not saved"); + cryptonote::block b; + generate_genesis(b); + m_blockchain.push_back(get_block_hash(b)); + store(); return retval; } @@ -573,15 +574,28 @@ void wallet2::load(const std::string& wallet_, const std::string& password) m_account_public_address.m_view_public_key != m_account.get_keys().m_account_address.m_view_public_key, error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file); - if(m_blockchain.empty()) + cryptonote::block genesis; + generate_genesis(genesis); + crypto::hash genesis_hash = get_block_hash(genesis); + + if (m_blockchain.empty()) { - cryptonote::block b; - cryptonote::generate_genesis_block(b); - m_blockchain.push_back(get_block_hash(b)); + m_blockchain.push_back(genesis_hash); + } + else + { + check_genesis(genesis_hash); } + m_local_bc_height = m_blockchain.size(); } //---------------------------------------------------------------------------------------------------- +void wallet2::check_genesis(const crypto::hash& genesis_hash) { + std::string what("Genesis block missmatch. You probably use wallet without testnet flag with blockchain from test network or vice versa"); + + THROW_WALLET_EXCEPTION_IF(genesis_hash != m_blockchain[0], error::wallet_internal_error, what); +} +//---------------------------------------------------------------------------------------------------- void wallet2::store() { bool r = tools::serialize_obj_to_file(*this, m_wallet_file); @@ -918,4 +932,13 @@ std::vector wallet2::create_transactions(std::vector Date: Thu, 4 Sep 2014 22:14:36 -0400 Subject: Reorganize testnet constants --- src/connectivity_tool/conn_tool.cpp | 2 +- src/cryptonote_config.h | 52 ++++++++++++++--------- src/cryptonote_core/cryptonote_basic_impl.cpp | 6 +-- src/cryptonote_core/cryptonote_format_utils.cpp | 5 +-- src/p2p/net_node.h | 4 +- src/p2p/net_node.inl | 4 +- src/p2p/p2p_networks.h | 36 ---------------- src/rpc/core_rpc_server.cpp | 2 +- src/simplewallet/simplewallet.cpp | 4 +- src/wallet/wallet2.cpp | 2 +- tests/core_proxy/core_proxy.cpp | 5 ++- tests/functional_tests/transactions_flow_test.cpp | 12 ++++-- tests/unit_tests/base58.cpp | 6 +-- tests/unit_tests/test_format_utils.cpp | 8 +++- 14 files changed, 68 insertions(+), 80 deletions(-) delete mode 100644 src/p2p/p2p_networks.h (limited to 'src/wallet/wallet2.cpp') diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index c4364e225..abddd5245 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -259,7 +259,7 @@ bool handle_request_stat(po::variables_map& vm, peerid_type peer_id) pot.peer_id = peer_id; pot.time = time(NULL); crypto::public_key pubk = AUTO_VAL_INIT(pubk); - string_tools::hex_to_pod(P2P_STAT_TRUSTED_PUB_KEY, pubk); + string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pubk); crypto::hash h = tools::get_proof_of_trust_hash(pot); crypto::generate_signature(h, pubk, prvk, pot.sign); diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 251152d7e..39cf359b2 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -30,13 +30,14 @@ #pragma once +#include +#include + #define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000 #define CRYPTONOTE_MAX_BLOCK_SIZE 500000000 // block header blob limit, never used! #define CRYPTONOTE_GETBLOCKTEMPLATE_MAX_BLOCK_SIZE 196608 //size of block (bytes) that is the maximum that miners will produce #define CRYPTONOTE_MAX_TX_SIZE 1000000000 #define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0 -#define CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX 18 // addresses start with "4" -#define CRYPTONOTE_TESTNET_ADDRESS_BASE58_PREFIX 19 // addresses start with "5" #define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60 #define CURRENT_TRANSACTION_VERSION 1 #define CURRENT_BLOCK_MAJOR_VERSION 1 @@ -82,10 +83,6 @@ #define CRYPTONOTE_MEMPOOL_TX_LIVETIME 86400 //seconds, one day #define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week -#define P2P_DEFAULT_PORT 18080 -#define TESTNET_P2P_DEFAULT_PORT 28080 -#define RPC_DEFAULT_PORT 18081 -#define TESTNET_RPC_DEFAULT_PORT 28081 #define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT 1000 #define P2P_LOCAL_WHITE_PEERLIST_LIMIT 1000 @@ -99,22 +96,8 @@ #define P2P_DEFAULT_PING_CONNECTION_TIMEOUT 2000 //2 seconds #define P2P_DEFAULT_INVOKE_TIMEOUT 60*2*1000 //2 minutes #define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT 5000 //5 seconds -#define P2P_STAT_TRUSTED_PUB_KEY "0000000000000000000000000000000000000000000000000000000000000000" -#define TESTNET_P2P_STAT_TRUSTED_PUB_KEY "0000000000000000000000000000000000000000000000000000000000000000" #define P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT 70 -// reference these in src/p2p/p2p_networks.h -#define MAINNET_NETWORK_ID { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10 } -#define TESTNET_NETWORK_ID { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11 } - -// reference these in src/cryptonote_core/cryptonote_format_utils.cpp -#define MAINNET_GENESIS_HASH "010a01ff0001ffffffffffff0f029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121013c086a48c15fb637a96991bc6d53caf77068b5ba6eeb3c82357228c49790584a" -#define MAINNET_GENESIS_NONCE 10000 -#define TESTNET_GENESIS_HASH "CHANGEME" -#define TESTNET_GENESIS_NONCE CHANGEME - -// remember also to add seed nodes to src/p2p/net_node.inl for the testnet - #define ALLOW_DEBUG_COMMANDS #define CRYPTONOTE_NAME "bitmonero" @@ -126,3 +109,32 @@ #define THREAD_STACK_SIZE 5 * 1024 * 1024 +// New constants are intended to go here +namespace config +{ + uint64_t const DEFAULT_FEE_ATOMIC_XMR_PER_KB = 500; // Just a placeholder! Change me! + uint8_t const FEE_CALCULATION_MAX_RETRIES = 10; + uint64_t const DEFAULT_DUST_THRESHOLD = 5000000000; // 5 * 10^9 + std::string const P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY = "0000000000000000000000000000000000000000000000000000000000000000"; + + uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 18; // addresses start with "4" + uint16_t const P2P_DEFAULT_PORT = 18080; + uint16_t const RPC_DEFAULT_PORT = 18081; + boost::uuids::uuid const NETWORK_ID = { { + 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10 + } }; // Bender's nightmare + std::string const GENESIS_TX = "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017767aafcde9be00dcfd098715ebcf7f410daebc582fda69d24a28e9d0bc890d1"; + uint32_t const GENESIS_NONCE = 10000; + + namespace testnet + { + uint64_t const CRYPTONOTE_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 = { { + 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11 + } }; // Bender's daydream + std::string const GENESIS_TX = "CHANGEME"; + uint32_t const GENESIS_NONCE = 10001; + } +} diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp index 17e3063b4..398c63443 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.cpp +++ b/src/cryptonote_core/cryptonote_basic_impl.cpp @@ -105,7 +105,7 @@ namespace cryptonote { //----------------------------------------------------------------------- std::string get_account_address_as_str(const account_public_address& adr) { - return tools::base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(adr)); + return tools::base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(adr)); } //----------------------------------------------------------------------- bool is_coinbase(const transaction& tx) @@ -131,9 +131,9 @@ namespace cryptonote { return false; } - if (CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX != prefix) + if (config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX != prefix) { - LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX); + LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX); return false; } diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 47cd0e159..f7cddeded 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -672,8 +672,7 @@ namespace cryptonote blobdata txb = tx_to_blob(bl.miner_tx); std::string hex_tx_represent = string_tools::buff_to_hex_nodelimer(txb); - //hard code coinbase tx in genesis block, because "tru" generating tx use random, but genesis should be always the same - std::string genesis_coinbase_tx_hex = "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017767aafcde9be00dcfd098715ebcf7f410daebc582fda69d24a28e9d0bc890d1"; + std::string genesis_coinbase_tx_hex = config::GENESIS_TX; blobdata tx_bl; string_tools::parse_hexstr_to_binbuff(genesis_coinbase_tx_hex, tx_bl); @@ -682,7 +681,7 @@ namespace cryptonote bl.major_version = CURRENT_BLOCK_MAJOR_VERSION; bl.minor_version = CURRENT_BLOCK_MINOR_VERSION; bl.timestamp = 0; - bl.nonce = 10000; + bl.nonce = config::GENESIS_NONCE; miner::find_nonce_for_given_block(bl, 1, 0); return true; } diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index bca18c906..3a659dcd8 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -42,12 +42,12 @@ #include #include +#include "cryptonote_config.h" #include "warnings.h" #include "net/levin_server_cp2.h" #include "p2p_protocol_defs.h" #include "storages/levin_abstract_invoke2.h" #include "net_peerlist.h" -#include "p2p_networks.h" #include "math_helper.h" #include "net_node_common.h" #include "common/command_line.h" @@ -79,7 +79,7 @@ namespace nodetool public: typedef t_payload_net_handler payload_net_handler; // Some code - node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false), m_network_id(MONERO_NETWORK) + node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false), m_network_id(::config::NETWORK_ID) {} static void init_options(boost::program_options::options_description& desc); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 211f5064a..28c572513 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -60,7 +60,7 @@ namespace nodetool namespace { const command_line::arg_descriptor arg_p2p_bind_ip = {"p2p-bind-ip", "Interface for p2p network protocol", "0.0.0.0"}; - const command_line::arg_descriptor arg_p2p_bind_port = {"p2p-bind-port", "Port for p2p network protocol", boost::to_string(P2P_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_p2p_bind_port = {"p2p-bind-port", "Port for p2p network protocol", boost::to_string(config::P2P_DEFAULT_PORT)}; const command_line::arg_descriptor arg_p2p_external_port = {"p2p-external-port", "External port for p2p network protocol (if port forwarding used with NAT)", 0}; const command_line::arg_descriptor arg_p2p_allow_local_ip = {"allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes"}; const command_line::arg_descriptor > arg_p2p_add_peer = {"add-peer", "Manually add peer to local peerlist"}; @@ -848,7 +848,7 @@ namespace nodetool return false; } crypto::public_key pk = AUTO_VAL_INIT(pk); - epee::string_tools::hex_to_pod(P2P_STAT_TRUSTED_PUB_KEY, pk); + epee::string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pk); crypto::hash h = tools::get_proof_of_trust_hash(tr); if(!crypto::check_signature(h, pk, tr.sign)) { diff --git a/src/p2p/p2p_networks.h b/src/p2p/p2p_networks.h deleted file mode 100644 index b3193ee6a..000000000 --- a/src/p2p/p2p_networks.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2014, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - -#pragma once - -namespace nodetool -{ - const static boost::uuids::uuid MONERO_NETWORK = { { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10} }; //Bender's nightmare -} diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c74203cc3..e99f44929 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -46,7 +46,7 @@ namespace cryptonote namespace { const command_line::arg_descriptor arg_rpc_bind_ip = {"rpc-bind-ip", "", "127.0.0.1"}; - const command_line::arg_descriptor arg_rpc_bind_port = {"rpc-bind-port", "", std::to_string(RPC_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_rpc_bind_port = {"rpc-bind-port", "", std::to_string(config::RPC_DEFAULT_PORT)}; } //----------------------------------------------------------------------------------- diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 4312981e2..45bc6f847 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -331,7 +331,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if (m_daemon_host.empty()) m_daemon_host = "localhost"; if (!m_daemon_port) - m_daemon_port = RPC_DEFAULT_PORT; + m_daemon_port = config::RPC_DEFAULT_PORT; if (m_daemon_address.empty()) m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port); @@ -1157,7 +1157,7 @@ int main(int argc, char* argv[]) if (daemon_host.empty()) daemon_host = "localhost"; if (!daemon_port) - daemon_port = RPC_DEFAULT_PORT; + daemon_port = config::RPC_DEFAULT_PORT; if (daemon_address.empty()) daemon_address = std::string("http://") + daemon_host + ":" + std::to_string(daemon_port); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index be857c78a..bbf5bab61 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -543,7 +543,7 @@ bool wallet2::check_connection() net_utils::http::url_content u; net_utils::parse_url(m_daemon_address, u); if(!u.port) - u.port = RPC_DEFAULT_PORT; + u.port = config::RPC_DEFAULT_PORT; return m_http_client.connect(u.host, std::to_string(u.port), WALLET_RCP_CONNECTION_TIMEOUT); } //---------------------------------------------------------------------------------------------------- diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index 098b9878a..f973f548d 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -104,7 +104,10 @@ int main(int argc, char* argv[]) //create objects and link them tests::proxy_core pr_core; cryptonote::t_cryptonote_protocol_handler cprotocol(pr_core, NULL); - nodetool::node_server > p2psrv(cprotocol); + nodetool::node_server > p2psrv { + cprotocol + , std::move(config::NETWORK_ID) + }; cprotocol.set_p2p_endpoint(&p2psrv); //pr_core.set_cryptonote_protocol(&cprotocol); //daemon_cmmands_handler dch(p2psrv); diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 68c9f7ac7..2187ff250 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -37,6 +37,12 @@ using namespace epee; #include "wallet/wallet2.h" using namespace cryptonote; +namespace +{ + uint64_t const TEST_FEE = 5000000000; // 5 * 10^9 + uint64_t const TEST_DUST_THRESHOLD = 5000000000; // 5 * 10^9 +} + std::string generate_random_wallet_name() { std::stringstream ss; @@ -79,7 +85,7 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor, try { tools::wallet2::pending_tx ptx; - w1.transfer(dsts, mix_in_factor, 0, DEFAULT_FEE, std::vector(), tools::detail::null_split_strategy, tools::tx_dust_policy(DEFAULT_FEE), tx, ptx); + w1.transfer(dsts, mix_in_factor, 0, TEST_FEE, std::vector(), tools::detail::null_split_strategy, tools::tx_dust_policy(TEST_DUST_THRESHOLD), tx, ptx); w1.commit_tx(ptx); return true; } @@ -185,7 +191,7 @@ bool transactions_flow_test(std::string& working_folder, BOOST_FOREACH(tools::wallet2::transfer_details& td, incoming_transfers) { cryptonote::transaction tx_s; - bool r = do_send_money(w1, w1, 0, td.m_tx.vout[td.m_internal_output_index].amount - DEFAULT_FEE, tx_s, 50); + bool r = do_send_money(w1, w1, 0, td.m_tx.vout[td.m_internal_output_index].amount - TEST_FEE, tx_s, 50); CHECK_AND_ASSERT_MES(r, false, "Failed to send starter tx " << get_transaction_hash(tx_s)); LOG_PRINT_GREEN("Starter transaction sent " << get_transaction_hash(tx_s), LOG_LEVEL_0); if(++count >= FIRST_N_TRANSFERS) @@ -213,7 +219,7 @@ bool transactions_flow_test(std::string& working_folder, for(i = 0; i != transactions_count; i++) { uint64_t amount_to_tx = (amount_to_transfer - transfered_money) > transfer_size ? transfer_size: (amount_to_transfer - transfered_money); - while(w1.unlocked_balance() < amount_to_tx + DEFAULT_FEE) + while(w1.unlocked_balance() < amount_to_tx + TEST_FEE) { misc_utils::sleep_no_w(1000); LOG_PRINT_L0("not enough money, waiting for cashback or mining"); diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp index 5b82fb987..f61bb1b96 100644 --- a/tests/unit_tests/base58.cpp +++ b/tests/unit_tests/base58.cpp @@ -506,7 +506,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_prefix) TEST(get_account_address_from_str, fails_on_invalid_address_content) { - std::string addr_str = base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, test_serialized_keys.substr(1)); + std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, test_serialized_keys.substr(1)); cryptonote::account_public_address addr; ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); @@ -516,7 +516,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_spend_key) { std::string serialized_keys_copy = test_serialized_keys; serialized_keys_copy[0] = '\0'; - std::string addr_str = base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); + std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); @@ -526,7 +526,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_view_key) { std::string serialized_keys_copy = test_serialized_keys; serialized_keys_copy.back() = '\x01'; - std::string addr_str = base58::encode_addr(CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); + std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); diff --git a/tests/unit_tests/test_format_utils.cpp b/tests/unit_tests/test_format_utils.cpp index bed19c315..857b5b09f 100644 --- a/tests/unit_tests/test_format_utils.cpp +++ b/tests/unit_tests/test_format_utils.cpp @@ -35,6 +35,10 @@ #include "common/util.h" #include "cryptonote_core/cryptonote_format_utils.h" +namespace +{ + uint64_t const TEST_FEE = 5000000000; // 5 * 10^9 +} TEST(parse_tx_extra, handles_empty_extra) { @@ -135,7 +139,7 @@ TEST(parse_and_validate_tx_extra, is_valid_tx_extra_parsed) cryptonote::account_base acc; acc.generate(); cryptonote::blobdata b = "dsdsdfsdfsf"; - ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1)); + ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1)); crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(tx); ASSERT_NE(tx_pub_key, cryptonote::null_pkey); } @@ -145,7 +149,7 @@ TEST(parse_and_validate_tx_extra, fails_on_big_extra_nonce) cryptonote::account_base acc; acc.generate(); cryptonote::blobdata b(TX_EXTRA_NONCE_MAX_COUNT + 1, 0); - ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1)); + ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1)); } TEST(parse_and_validate_tx_extra, fails_on_wrong_size_in_extra_nonce) { -- cgit v1.2.3 From 658b6690a36f6f0b3b06dca5b85021b2b344c059 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 13:07:15 -0400 Subject: Separate rpc port for testnet --- src/daemon/daemon.cpp | 2 +- src/rpc/core_rpc_server.cpp | 28 +++++++++++++++++++++++----- src/rpc/core_rpc_server.h | 10 ++++++++-- src/simplewallet/simplewallet.cpp | 10 +++++++--- src/wallet/wallet2.cpp | 6 +++++- 5 files changed, 44 insertions(+), 12 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 1041aa439..04f6db4fa 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -220,7 +220,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); + res = rpc_server.init(vm, testnet_mode); 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/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index e99f44929..197e4ff83 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -46,7 +46,16 @@ namespace cryptonote namespace { const command_line::arg_descriptor arg_rpc_bind_ip = {"rpc-bind-ip", "", "127.0.0.1"}; - const command_line::arg_descriptor arg_rpc_bind_port = {"rpc-bind-port", "", std::to_string(config::RPC_DEFAULT_PORT)}; + const command_line::arg_descriptor arg_rpc_bind_port = { + "rpc-bind-port" + , "" + , std::to_string(config::RPC_DEFAULT_PORT) + }; + const command_line::arg_descriptor arg_testnet_rpc_bind_port = { + "testnet-rpc-bind-port" + , "" + , std::to_string(config::testnet::RPC_DEFAULT_PORT) + }; } //----------------------------------------------------------------------------------- @@ -54,22 +63,31 @@ namespace cryptonote { command_line::add_arg(desc, arg_rpc_bind_ip); command_line::add_arg(desc, arg_rpc_bind_port); + command_line::add_arg(desc, arg_testnet_rpc_bind_port); } //------------------------------------------------------------------------------------------------------------------------------ core_rpc_server::core_rpc_server(core& cr, nodetool::node_server >& p2p):m_core(cr), m_p2p(p2p) {} //------------------------------------------------------------------------------------------------------------------------------ - bool core_rpc_server::handle_command_line(const boost::program_options::variables_map& vm) + 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; + m_bind_ip = command_line::get_arg(vm, arg_rpc_bind_ip); - m_port = command_line::get_arg(vm, arg_rpc_bind_port); + m_port = command_line::get_arg(vm, p2p_bind_arg); return true; } //------------------------------------------------------------------------------------------------------------------------------ - bool core_rpc_server::init(const boost::program_options::variables_map& vm) + 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); + bool r = handle_command_line(vm, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to process command line in core_rpc_server"); return epee::http_server_impl_base::init(m_port, m_bind_ip); } diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 2e3f553ce..3f3d23f51 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -52,7 +52,10 @@ namespace cryptonote core_rpc_server(core& cr, nodetool::node_server >& p2p); static void init_options(boost::program_options::options_description& desc); - bool init(const boost::program_options::variables_map& vm); + bool init( + const boost::program_options::variables_map& vm + , bool testnet + ); private: CHAIN_HTTP_TO_MAP2(connection_context); //forward http requests to uri map @@ -105,7 +108,10 @@ namespace cryptonote bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_info_json(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); //----------------------- - bool handle_command_line(const boost::program_options::variables_map& vm); + bool handle_command_line( + const boost::program_options::variables_map& vm + , bool testnet + ); bool check_core_busy(); bool check_core_ready(); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 45bc6f847..6c97dc807 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -328,15 +328,19 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if(!ask_wallet_create_if_needed()) return false; } + bool testnet = command_line::get_arg(vm, arg_testnet); + if (m_daemon_host.empty()) m_daemon_host = "localhost"; + if (!m_daemon_port) - m_daemon_port = config::RPC_DEFAULT_PORT; + { + m_daemon_port = testnet ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT; + } + if (m_daemon_address.empty()) m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port); - bool testnet = command_line::get_arg(vm, arg_testnet); - tools::password_container pwd_container; if (command_line::has_arg(vm, arg_password)) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index bbf5bab61..b8b728425 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -542,8 +542,12 @@ bool wallet2::check_connection() net_utils::http::url_content u; net_utils::parse_url(m_daemon_address, u); + if(!u.port) - u.port = config::RPC_DEFAULT_PORT; + { + u.port = m_testnet ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT; + } + return m_http_client.connect(u.host, std::to_string(u.port), WALLET_RCP_CONNECTION_TIMEOUT); } //---------------------------------------------------------------------------------------------------- -- cgit v1.2.3 From 96eed84aad89e6e2799a9db91e2dd2e9fe0889f9 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 8 Sep 2014 15:09:59 -0400 Subject: Pass tx and nonce to genesis block constructor --- src/cryptonote_core/blockchain_storage.cpp | 32 ++++++++++++++++++------- src/cryptonote_core/cryptonote_format_utils.cpp | 18 +++++--------- src/cryptonote_core/cryptonote_format_utils.h | 7 ++++-- src/wallet/wallet2.cpp | 12 ++++++---- tests/core_proxy/core_proxy.cpp | 2 +- 5 files changed, 43 insertions(+), 28 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index cd20cd818..e664a39c5 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -114,7 +114,14 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet) LOG_PRINT_L0("Can't load blockchain storage from file, generating genesis block."); block bl = boost::value_initialized(); block_verification_context bvc = boost::value_initialized(); - generate_genesis_block(bl); + if (testnet) + { + generate_genesis_block(bl, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(bl, config::GENESIS_TX, config::GENESIS_NONCE); + } add_new_block(bl, bvc); CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed && bvc.m_added_to_main_chain, false, "Failed to add genesis block to blockchain"); } @@ -127,10 +134,14 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet) } } else { cryptonote::block b; - if (testnet) { - generate_testnet_genesis_block(b); - } else { - generate_genesis_block(b); + + if (testnet) + { + generate_genesis_block(b, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(b, config::GENESIS_TX, config::GENESIS_NONCE); } crypto::hash genesis_hash = get_block_hash(m_blocks[0].bl); @@ -151,10 +162,13 @@ bool blockchain_storage::store_genesis_block(bool testnet) { block bl = ::boost::value_initialized(); block_verification_context bvc = boost::value_initialized(); - if (testnet) { - generate_testnet_genesis_block(bl); - } else { - generate_genesis_block(bl); + if (testnet) + { + generate_genesis_block(bl, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(bl, config::GENESIS_TX, config::GENESIS_NONCE); } add_new_block(bl, bvc); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index f7cddeded..33cad30c4 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -660,7 +660,11 @@ namespace cryptonote return p; } //--------------------------------------------------------------- - bool generate_genesis_block(block& bl) + bool generate_genesis_block( + block& bl + , std::string const & genesis_tx + , uint32_t nonce + ) { //genesis block bl = boost::value_initialized(); @@ -681,20 +685,10 @@ namespace cryptonote bl.major_version = CURRENT_BLOCK_MAJOR_VERSION; bl.minor_version = CURRENT_BLOCK_MINOR_VERSION; bl.timestamp = 0; - bl.nonce = config::GENESIS_NONCE; + bl.nonce = nonce; miner::find_nonce_for_given_block(bl, 1, 0); return true; } - - bool generate_testnet_genesis_block(cryptonote::block& b) { - if (!generate_genesis_block(b)) { - return false; - } - - b.nonce += 1; - return true; - } - //--------------------------------------------------------------- bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) { diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 4457f6cc6..9fa7f0545 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -105,8 +105,11 @@ namespace cryptonote crypto::hash get_block_hash(const block& b); bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height); crypto::hash get_block_longhash(const block& b, uint64_t height); - bool generate_genesis_block(block& bl); - bool generate_testnet_genesis_block(block& bl); + bool generate_genesis_block( + block& bl + , std::string const & genesis_tx + , uint32_t nonce + ); bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b); bool get_inputs_money_amount(const transaction& tx, uint64_t& money); uint64_t get_outs_money_amount(const transaction& tx); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b8b728425..78fac0e87 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -35,6 +35,7 @@ #include "include_base_utils.h" using namespace epee; +#include "cryptonote_config.h" #include "wallet2.h" #include "cryptonote_core/cryptonote_format_utils.h" #include "rpc/core_rpc_server_commands_defs.h" @@ -939,10 +940,13 @@ std::vector wallet2::create_transactions(std::vector Date: Tue, 9 Sep 2014 10:58:53 -0400 Subject: Separate testnet address prefix --- src/cryptonote_config.h | 2 +- src/cryptonote_core/account.cpp | 4 +-- src/cryptonote_core/account.h | 2 +- src/cryptonote_core/cryptonote_basic_impl.cpp | 23 +++++++++++--- src/cryptonote_core/cryptonote_basic_impl.h | 14 +++++++-- src/cryptonote_core/cryptonote_core.cpp | 2 +- src/cryptonote_core/miner.cpp | 4 +-- src/cryptonote_core/miner.h | 2 +- src/daemon/daemon.cpp | 6 ++-- src/daemon/daemon_commands_handler.h | 10 ++++-- src/rpc/core_rpc_server.cpp | 21 ++++++++----- src/rpc/core_rpc_server.h | 9 ++++-- src/simplewallet/simplewallet.cpp | 15 +++++---- src/wallet/wallet2.cpp | 4 +-- src/wallet/wallet2.h | 6 ++-- src/wallet/wallet_errors.h | 37 ++++++++++++++++------- src/wallet/wallet_rpc_server.cpp | 4 +-- tests/core_tests/transaction_tests.cpp | 4 +-- tests/daemon_tests/transfers.cpp | 4 +-- tests/functional_tests/transactions_flow_test.cpp | 6 ++-- tests/unit_tests/base58.cpp | 16 +++++----- 21 files changed, 126 insertions(+), 69 deletions(-) (limited to 'src/wallet/wallet2.cpp') 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 >& m_srv; public: - daemon_cmmands_handler(nodetool::node_server >& srv):m_srv(srv) + daemon_cmmands_handler( + nodetool::node_server >& 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 > > 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 >& p2p):m_core(cr), m_p2p(p2p) + core_rpc_server::core_rpc_server( + core& cr + , nodetool::node_server >& 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::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 >& p2p); + core_rpc_server( + core& cr + , nodetool::node_server >& 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 >& 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& 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(2)); @@ -905,7 +908,7 @@ bool simple_wallet::transfer(const std::vector &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 &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 &args/* = std::vector()*/) { - 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 @@ -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 sources_t; typedef std::vector 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& destinations, uint64_t fee) - : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits::max())) - , m_destinations(destinations) - , m_fee(fee) + explicit tx_sum_overflow( + std::string && loc + , const std::vector& destinations + , uint64_t fee + , bool testnet + ) + : transfer_error {std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits::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 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; diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index 6f0dcee43..d46d48b07 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -54,7 +54,7 @@ bool test_transaction_generation_and_ring_signature() account_base miner_acc6; miner_acc6.generate(); - std::string add_str = miner_acc3.get_public_address_str(); + std::string add_str = miner_acc3.get_public_address_str(false); account_base rv_acc; @@ -150,7 +150,7 @@ bool test_block_creation() uint64_t vszs[] = {80,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,9391,476,476,475,475,474,475,8819,8301,475,472,4302,5316,14347,16620,19583,19403,19728,19442,19852,19015,19000,19016,19795,19749,18087,19787,19704,19750,19267,19006,19050,19445,19407,19522,19546,19788,19369,19486,19329,19370,18853,19600,19110,19320,19746,19474,19474,19743,19494,19755,19715,19769,19620,19368,19839,19532,23424,28287,30707}; std::vector szs(&vszs[0], &vszs[90]); account_public_address adr; - bool r = get_account_address_from_str(adr, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2"); + bool r = get_account_address_from_str(adr, false, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2"); CHECK_AND_ASSERT_MES(r, false, "failed to import"); block b; r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, adr, b.miner_tx, blobdata(), 11); diff --git a/tests/daemon_tests/transfers.cpp b/tests/daemon_tests/transfers.cpp index 8b4addf62..ff73e1931 100644 --- a/tests/daemon_tests/transfers.cpp +++ b/tests/daemon_tests/transfers.cpp @@ -54,7 +54,7 @@ TEST(Transfers, Transfers) miner.generate(); ASSERT_TRUE(miner.init()); ASSERT_TRUE(miner.store("miner.b2wallet")); - cout << "miner: " << miner.get_account().get_public_address_str() << endl; + cout << "miner: " << miner.get_account().get_public_address_str(false) << endl; for (int i = 0; i < ACCS; i++) { ostringstream s; @@ -69,7 +69,7 @@ TEST(Transfers, Transfers) { COMMAND_RPC_START_MINE::request req; - req.miner_address = miner.get_account().get_public_address_str(); + req.miner_address = miner.get_account().get_public_address_str(false); req.threads_count = 1; COMMAND_RPC_START_MINE::response res; bool r = net_utils::http::invoke_http_json_remote_command(daemon_address + "/start_mine", req, res, http_client); diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 2187ff250..806433ab6 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -151,8 +151,8 @@ bool transactions_flow_test(std::string& working_folder, w2.init(daemon_addr_b); LOG_PRINT_GREEN("Using wallets: " << ENDL - << "Source: " << w1.get_account().get_public_address_str() << ENDL << "Path: " << working_folder + "/" + path_source_wallet << ENDL - << "Target: " << w2.get_account().get_public_address_str() << ENDL << "Path: " << working_folder + "/" + path_terget_wallet, LOG_LEVEL_1); + << "Source: " << w1.get_account().get_public_address_str(false) << ENDL << "Path: " << working_folder + "/" + path_source_wallet << ENDL + << "Target: " << w2.get_account().get_public_address_str(false) << ENDL << "Path: " << working_folder + "/" + path_terget_wallet, LOG_LEVEL_1); //lets do some money epee::net_utils::http::http_simple_client http_client; @@ -163,7 +163,7 @@ bool transactions_flow_test(std::string& working_folder, COMMAND_RPC_START_MINING::request daemon_req = AUTO_VAL_INIT(daemon_req); COMMAND_RPC_START_MINING::response daemon_rsp = AUTO_VAL_INIT(daemon_rsp); - daemon_req.miner_address = w1.get_account().get_public_address_str(); + daemon_req.miner_address = w1.get_account().get_public_address_str(false); daemon_req.threads_count = 9; r = net_utils::invoke_http_json_remote_command2(daemon_addr_a + "/start_mining", daemon_req, daemon_rsp, http_client, 10000); CHECK_AND_ASSERT_MES(r, false, "failed to get getrandom_outs"); diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp index f61bb1b96..28fb27f25 100644 --- a/tests/unit_tests/base58.cpp +++ b/tests/unit_tests/base58.cpp @@ -473,14 +473,14 @@ TEST(get_account_address_as_str, works_correctly) { cryptonote::account_public_address addr; ASSERT_TRUE(serialization::parse_binary(test_serialized_keys, addr)); - std::string addr_str = cryptonote::get_account_address_as_str(addr); + std::string addr_str = cryptonote::get_account_address_as_str(false, addr); ASSERT_EQ(addr_str, test_keys_addr_str); } TEST(get_account_address_from_str, handles_valid_address) { cryptonote::account_public_address addr; - ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, test_keys_addr_str)); + ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, false, test_keys_addr_str)); std::string blob; ASSERT_TRUE(serialization::dump_binary(addr, blob)); @@ -493,7 +493,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_format) std::string addr_str = test_keys_addr_str; addr_str[0] = '0'; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_prefix) @@ -501,7 +501,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_prefix) std::string addr_str = base58::encode_addr(0, test_serialized_keys); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_content) @@ -509,7 +509,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_content) std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, test_serialized_keys.substr(1)); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_spend_key) @@ -519,7 +519,7 @@ TEST(get_account_address_from_str, fails_on_invalid_address_spend_key) std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, fails_on_invalid_address_view_key) @@ -529,11 +529,11 @@ TEST(get_account_address_from_str, fails_on_invalid_address_view_key) std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy); cryptonote::account_public_address addr; - ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, addr_str)); + ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str)); } TEST(get_account_address_from_str, parses_old_address_format) { cryptonote::account_public_address addr; - ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, "002391bbbb24dea6fd95232e97594a27769d0153d053d2102b789c498f57a2b00b69cd6f2f5c529c1660f2f4a2b50178d6640c20ce71fe26373041af97c5b10236fc")); + ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, false, "002391bbbb24dea6fd95232e97594a27769d0153d053d2102b789c498f57a2b00b69cd6f2f5c529c1660f2f4a2b50178d6640c20ce71fe26373041af97c5b10236fc")); } -- cgit v1.2.3