From 8d62e84c7ac43fa2d133cc396ad9cdba2adcb120 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 22 Apr 2020 18:47:16 +0300 Subject: [PATCH 01/16] hardfork-related code minor refactoring --- src/currency_core/blockchain_storage.cpp | 22 +++++++++++----------- src/currency_core/core_runtime_config.h | 13 +++++++++---- src/currency_core/currency_config.h | 6 ++++-- src/wallet/wallet2.cpp | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 54b45be9..17f635c9 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1055,7 +1055,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con wide_difficulty_type& dif = pos ? m_cached_next_pos_difficulty : m_cached_next_pow_difficulty; TIME_MEASURE_FINISH_PD(target_calculating_enum_blocks); TIME_MEASURE_START_PD(target_calculating_calc); - if (m_db_blocks.size() > m_core_runtime_config.hard_fork1_starts_after_height) + if (m_db_blocks.size() > m_core_runtime_config.hard_fork_01_starts_after_height) { dif = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); } @@ -1094,7 +1094,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, co enum_blockchain(cb, alt_chain, split_height); wide_difficulty_type diff = 0; - if(abei.height > m_core_runtime_config.hard_fork1_starts_after_height) + if(abei.height > m_core_runtime_config.hard_fork_01_starts_after_height) diff = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); else diff = next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); @@ -1174,7 +1174,7 @@ bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t CHECK_AND_ASSERT_MES(b.miner_tx.vin[1].type() == typeid(txin_to_key), false, "coinstake transaction in the block has the wrong type"); } - if (height > m_core_runtime_config.hard_fork1_starts_after_height) + if (height > m_core_runtime_config.hard_fork_01_starts_after_height) { // new rules that allow different unlock time in coinbase outputs uint64_t max_unlock_time = 0; @@ -1345,7 +1345,7 @@ bool blockchain_storage::create_block_template(const create_block_template_param boost::multiprecision::uint128_t already_generated_coins; CRITICAL_REGION_BEGIN(m_read_lock); height = m_db_blocks.size(); - if(height <= m_core_runtime_config.hard_fork1_starts_after_height) + if(height <= m_core_runtime_config.hard_fork_01_starts_after_height) b.major_version = BLOCK_MAJOR_VERSION_INITAL; else b.major_version = CURRENT_BLOCK_MAJOR_VERSION; @@ -1713,7 +1713,7 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto:: if (abei.height >= m_core_runtime_config.pos_minimum_heigh) cumulative_diff_delta = correct_difficulty_with_sequence_factor(sequence_factor, cumulative_diff_delta); - if (abei.height > BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION && abei.height <= m_core_runtime_config.hard_fork1_starts_after_height && pos_block && sequence_factor > BLOCK_POS_STRICT_SEQUENCE_LIMIT) + if (abei.height > BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION && abei.height <= m_core_runtime_config.hard_fork_01_starts_after_height && pos_block && sequence_factor > BLOCK_POS_STRICT_SEQUENCE_LIMIT) { LOG_PRINT_RED_L0("Alternative block " << id << " @ " << abei.height << " has too big sequence factor: " << sequence_factor << ", rejected"); bvc.m_verification_failed = true; @@ -1838,7 +1838,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ const block_extended_info& alt_chain_bei = alt_chain.back()->second; const block_extended_info& connection_point = alt_chain.front()->second; - if (connection_point.height <= m_core_runtime_config.hard_fork1_starts_after_height) + if (connection_point.height <= m_core_runtime_config.hard_fork_01_starts_after_height) { //use pre-hard fork, old-style comparing if (main_chain_bei.cumulative_diff_adjusted < alt_chain_bei.cumulative_diff_adjusted) @@ -1859,7 +1859,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ return true; } } - else if (alt_chain_bei.height > m_core_runtime_config.hard_fork1_starts_after_height) + else if (alt_chain_bei.height > m_core_runtime_config.hard_fork_01_starts_after_height) { //new rules, applied after HARD_FORK_1 //to learn this algo please read https://github.com/hyle-team/docs/blob/master/zano/PoS_Analysis_and_improvements_proposal.pdf @@ -4501,7 +4501,7 @@ void blockchain_storage::get_pos_mining_estimate(uint64_t amount_coins, //------------------------------------------------------------------ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transaction& tx, const crypto::hash& tx_id, uint64_t block_height) const { - if (block_height <= m_core_runtime_config.hard_fork1_starts_after_height) + if (block_height <= m_core_runtime_config.hard_fork_01_starts_after_height) { // before hardfork 1 @@ -4528,7 +4528,7 @@ bool blockchain_storage::validate_pos_coinbase_outs_unlock_time(const transactio return true; } - CHECK_AND_ASSERT_MES(get_block_height(miner_tx) > m_core_runtime_config.hard_fork1_starts_after_height, false, "error in block [" << get_block_height(miner_tx) << "] etc_tx_details_unlock_time2 can exist only after hard fork point : " << m_core_runtime_config.hard_fork1_starts_after_height); + CHECK_AND_ASSERT_MES(get_block_height(miner_tx) > m_core_runtime_config.hard_fork_01_starts_after_height, false, "error in block [" << get_block_height(miner_tx) << "] etc_tx_details_unlock_time2 can exist only after hard fork point : " << m_core_runtime_config.hard_fork_01_starts_after_height); //etc_tx_details_unlock_time2 can be kept only after hard_fork_1 point etc_tx_details_unlock_time2 ut2 = AUTO_VAL_INIT(ut2); @@ -4633,7 +4633,7 @@ bool blockchain_storage::validate_pos_block(const block& b, r = check_tx_input(b.miner_tx, 1, coinstake_in, id, b.miner_tx.signatures[0], max_related_block_height, source_max_unlock_time_for_pos_coinbase); CHECK_AND_ASSERT_MES(r, false, "Failed to validate coinstake input in miner tx, block_id = " << get_block_hash(b)); - if (get_block_height(b) > m_core_runtime_config.hard_fork1_starts_after_height) + if (get_block_height(b) > m_core_runtime_config.hard_fork_01_starts_after_height) { uint64_t last_pow_h = get_last_x_block_height(false); CHECK_AND_ASSERT_MES(max_related_block_height <= last_pow_h, false, "Failed to validate coinbase in PoS block, condition failed: max_related_block_height(" << max_related_block_height << ") <= last_pow_h(" << last_pow_h << ")"); @@ -5263,7 +5263,7 @@ bool blockchain_storage::update_next_comulative_size_limit() //------------------------------------------------------------------ bool blockchain_storage::prevalidate_block(const block& bl) { - if (bl.major_version == BLOCK_MAJOR_VERSION_INITAL && get_block_height(bl) <= m_core_runtime_config.hard_fork1_starts_after_height) + if (bl.major_version == BLOCK_MAJOR_VERSION_INITAL && get_block_height(bl) <= m_core_runtime_config.hard_fork_01_starts_after_height) return true; if (bl.major_version != CURRENT_BLOCK_MAJOR_VERSION) { diff --git a/src/currency_core/core_runtime_config.h b/src/currency_core/core_runtime_config.h index 8e9d94b0..283d3efb 100644 --- a/src/currency_core/core_runtime_config.h +++ b/src/currency_core/core_runtime_config.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2020 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Boolberry developers // Distributed under the MIT/X11 software license, see the accompanying @@ -18,11 +18,13 @@ namespace currency uint64_t pos_minimum_heigh; //height uint64_t tx_pool_min_fee; uint64_t tx_default_fee; - uint64_t hard_fork1_starts_after_height; uint64_t max_alt_blocks; crypto::public_key alias_validation_pubkey; core_time_func_t get_core_time; - + + uint64_t hard_fork_01_starts_after_height; + uint64_t hard_fork_02_starts_after_height; + static uint64_t _default_core_time_function() { return time(NULL); @@ -37,7 +39,10 @@ namespace currency pc.tx_pool_min_fee = TX_MINIMUM_FEE; pc.tx_default_fee = TX_DEFAULT_FEE; pc.max_alt_blocks = CURRENCY_ALT_BLOCK_MAX_COUNT; - pc.hard_fork1_starts_after_height = ZANO_HARDFORK_1_AFTER_HEIGHT; + + pc.hard_fork_01_starts_after_height = ZANO_HARDFORK_01_AFTER_HEIGHT; + pc.hard_fork_02_starts_after_height = ZANO_HARDFORK_02_AFTER_HEIGHT; + pc.get_core_time = &core_runtime_config::_default_core_time_function; bool r = epee::string_tools::hex_to_pod(ALIAS_SHORT_NAMES_VALIDATION_PUB_KEY, pc.alias_validation_pubkey); CHECK_AND_ASSERT_THROW_MES(r, "failed to parse alias_validation_pub_key"); diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 8de1ee32..95eee0db 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -224,9 +224,11 @@ #define BLOCK_MINOR_VERSION_GENESIS 0 #define BLOCK_MAJOR_VERSION_INITAL 0 #ifndef TESTNET -#define ZANO_HARDFORK_1_AFTER_HEIGHT 194624 +#define ZANO_HARDFORK_01_AFTER_HEIGHT 194624 +#define ZANO_HARDFORK_02_AFTER_HEIGHT 999999 #else -#define ZANO_HARDFORK_1_AFTER_HEIGHT 1440 +#define ZANO_HARDFORK_01_AFTER_HEIGHT 1440 +#define ZANO_HARDFORK_02_AFTER_HEIGHT 999999 #endif diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5aaf395f..768a2e6b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2951,7 +2951,7 @@ bool wallet2::is_transfer_unlocked(const transfer_details& td, bool for_pos_mini uint64_t unlock_time = get_tx_unlock_time(td.m_ptx_wallet_info->m_tx, td.m_internal_output_index); - if (for_pos_mining && m_blockchain.size() > m_core_runtime_config.hard_fork1_starts_after_height) + if (for_pos_mining && m_blockchain.size() > m_core_runtime_config.hard_fork_01_starts_after_height) { //allowed of staking locked coins with stake_lock_time = unlock_time; From f7d6782250f8f3e4cb13fe08d024d40f505e4c06 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 22 Apr 2020 22:02:37 +0300 Subject: [PATCH 02/16] address/account refactoring in progress --- src/currency_core/account.cpp | 8 ++--- src/currency_core/blockchain_storage.cpp | 4 +-- .../blockchain_storage_boost_serialization.h | 4 +-- src/currency_core/currency_basic.h | 13 +++++--- .../currency_boost_serialization.h | 5 +++ src/currency_core/currency_format_utils.cpp | 26 +++++++-------- src/wallet/wallet2.cpp | 32 +++++++++---------- src/wallet/wallet2_escrow.cpp | 14 ++++---- 8 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/currency_core/account.cpp b/src/currency_core/account.cpp index c40a377c..3fb19b45 100644 --- a/src/currency_core/account.cpp +++ b/src/currency_core/account.cpp @@ -47,9 +47,9 @@ namespace currency //----------------------------------------------------------------- void account_base::generate() { - generate_brain_keys(m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key, m_seed, BRAINWALLET_DEFAULT_SEED_SIZE); + generate_brain_keys(m_keys.m_account_address.spend_public_key, m_keys.m_spend_secret_key, m_seed, BRAINWALLET_DEFAULT_SEED_SIZE); dependent_key(m_keys.m_spend_secret_key, m_keys.m_view_secret_key); - if (!crypto::secret_key_to_public_key(m_keys.m_view_secret_key, m_keys.m_account_address.m_view_public_key)) + if (!crypto::secret_key_to_public_key(m_keys.m_view_secret_key, m_keys.m_account_address.view_public_key)) throw std::runtime_error("Failed to create public view key"); @@ -85,7 +85,7 @@ namespace currency //CHECK_AND_ASSERT_MES(restore_data.size() == ACCOUNT_RESTORE_DATA_SIZE, false, "wrong restore data size"); if (restore_data.size() == BRAINWALLET_DEFAULT_SEED_SIZE) { - crypto::keys_from_default((unsigned char*)restore_data.data(), m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key, BRAINWALLET_DEFAULT_SEED_SIZE); + crypto::keys_from_default((unsigned char*)restore_data.data(), m_keys.m_account_address.spend_public_key, m_keys.m_spend_secret_key, BRAINWALLET_DEFAULT_SEED_SIZE); } else { @@ -94,7 +94,7 @@ namespace currency } m_seed = restore_data; crypto::dependent_key(m_keys.m_spend_secret_key, m_keys.m_view_secret_key); - bool r = crypto::secret_key_to_public_key(m_keys.m_view_secret_key, m_keys.m_account_address.m_view_public_key); + bool r = crypto::secret_key_to_public_key(m_keys.m_view_secret_key, m_keys.m_account_address.view_public_key); CHECK_AND_ASSERT_MES(r, false, "failed to secret_key_to_public_key for view key"); set_createtime(0); return true; diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 17f635c9..1bb2082e 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3263,11 +3263,11 @@ bool blockchain_storage::put_alias_info(const transaction & tx, extra_alias_entr //std::string signed_buff; //make_tx_extra_alias_entry(signed_buff, ai, true); std::string old_address = currency::get_account_address_as_str(local_alias_history.back().m_address); - bool r = crypto::check_signature(get_sign_buff_hash_for_alias_update(ai), local_alias_history.back().m_address.m_spend_public_key, ai.m_sign.back()); + bool r = crypto::check_signature(get_sign_buff_hash_for_alias_update(ai), local_alias_history.back().m_address.spend_public_key, ai.m_sign.back()); CHECK_AND_ASSERT_MES(r, false, "Failed to check signature, alias update failed." << ENDL << "alias: " << ai.m_alias << ENDL << "signed_buff_hash: " << get_sign_buff_hash_for_alias_update(ai) << ENDL - << "public key: " << local_alias_history.back().m_address.m_spend_public_key << ENDL + << "public key: " << local_alias_history.back().m_address.spend_public_key << ENDL << "new_address: " << get_account_address_as_str(ai.m_address) << ENDL << "signature: " << epee::string_tools::pod_to_hex(ai.m_sign) << ENDL << "alias_history.size() = " << local_alias_history.size()); diff --git a/src/currency_core/blockchain_storage_boost_serialization.h b/src/currency_core/blockchain_storage_boost_serialization.h index a16a36da..10c02a33 100644 --- a/src/currency_core/blockchain_storage_boost_serialization.h +++ b/src/currency_core/blockchain_storage_boost_serialization.h @@ -37,8 +37,8 @@ namespace boost template void serialize(archive_t & ar, currency::extra_alias_entry_base& ai, const unsigned int version) { - ar & ai.m_address.m_spend_public_key; - ar & ai.m_address.m_view_public_key; + ar & ai.m_address.spend_public_key; + ar & ai.m_address.view_public_key; ar & ai.m_view_key; ar & ai.m_sign; ar & ai.m_text_comment; diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 0a7091b8..204ce651 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -303,14 +303,12 @@ namespace currency std::string m_text_comment; std::vector m_view_key; // only one or zero elments expected (std::vector is using as memory efficient container for such a case) std::vector m_sign; // only one or zero elments expected (std::vector is using as memory efficient container for such a case) - //uint8_t flags; BEGIN_SERIALIZE() FIELD(m_address) FIELD(m_text_comment) FIELD(m_view_key) FIELD(m_sign) - //FIELD(flags) END_SERIALIZE() }; @@ -390,10 +388,15 @@ namespace currency END_SERIALIZE() }; - typedef boost::mpl::vector all_payload_types; - typedef boost::make_variant_over::type attachment_v; - typedef boost::make_variant_over::type extra_v; + typedef boost::mpl::vector< + tx_service_attachment, tx_comment, tx_payer, tx_receiver, tx_derivation_hint, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, + etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry, extra_user_data, extra_padding, etc_tx_uint16_t, etc_tx_details_unlock_time2 + > all_payload_types; + typedef boost::make_variant_over::type payload_items_v; + typedef payload_items_v extra_v; + typedef payload_items_v attachment_v; + class transaction_prefix { diff --git a/src/currency_core/currency_boost_serialization.h b/src/currency_core/currency_boost_serialization.h index 443c98c2..a050a878 100644 --- a/src/currency_core/currency_boost_serialization.h +++ b/src/currency_core/currency_boost_serialization.h @@ -100,6 +100,7 @@ namespace boost { a & x.acc_addr; } + template inline void serialize(Archive &a, currency::tx_crypto_checksum &x, const boost::serialization::version_type ver) { @@ -189,21 +190,25 @@ namespace boost { a & at.v; } + template inline void serialize(Archive &a, currency::etc_tx_details_unlock_time2 &at, const boost::serialization::version_type ver) { a & at.unlock_time_array; } + template inline void serialize(Archive &a, currency::etc_tx_details_expiration_time &at, const boost::serialization::version_type ver) { a & at.v; } + template inline void serialize(Archive &a, currency::etc_tx_details_flags &at, const boost::serialization::version_type ver) { a & at.v; } + template inline void serialize(Archive &a, currency::etc_tx_time &at, const boost::serialization::version_type ver) { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 4351ef9c..8d2058c4 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -227,8 +227,8 @@ namespace currency bool r = crypto::generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation); CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")"); - r = crypto::derive_public_key(recv_derivation, real_output_index, ack.m_account_address.m_spend_public_key, in_ephemeral.pub); - CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to derive_public_key(" << recv_derivation << ", " << real_output_index << ", " << ack.m_account_address.m_spend_public_key << ")"); + r = crypto::derive_public_key(recv_derivation, real_output_index, ack.m_account_address.spend_public_key, in_ephemeral.pub); + CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to derive_public_key(" << recv_derivation << ", " << real_output_index << ", " << ack.m_account_address.spend_public_key << ")"); crypto::derive_secret_key(recv_derivation, real_output_index, ack.m_spend_secret_key, in_ephemeral.sec); return true; @@ -510,11 +510,11 @@ namespace currency //--------------------------------------------------------------- bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key, crypto::key_derivation& derivation) { - bool r = crypto::generate_key_derivation(destination_addr.m_view_public_key, tx_sec_key, derivation); - CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << destination_addr.m_view_public_key << ", " << tx_sec_key << ")"); + bool r = crypto::generate_key_derivation(destination_addr.view_public_key, tx_sec_key, derivation); + CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << destination_addr.view_public_key << ", " << tx_sec_key << ")"); - r = crypto::derive_public_key(derivation, index, destination_addr.m_spend_public_key, out_eph_public_key); - CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to derive_public_key(" << derivation << ", " << index << ", " << destination_addr.m_view_public_key << ")"); + r = crypto::derive_public_key(derivation, index, destination_addr.spend_public_key, out_eph_public_key); + CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to derive_public_key(" << derivation << ", " << index << ", " << destination_addr.view_public_key << ")"); return r; } //--------------------------------------------------------------- @@ -561,7 +561,7 @@ namespace currency for (auto& apa : de.addr) { crypto::public_key out_eph_public_key = AUTO_VAL_INIT(out_eph_public_key); - if (apa.m_spend_public_key == null_pkey && apa.m_view_public_key == null_pkey) + if (apa.spend_public_key == null_pkey && apa.view_public_key == null_pkey) { //burning money(for example alias reward) out_eph_public_key = null_pkey; @@ -833,7 +833,7 @@ namespace currency void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key) { crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); - bool r = crypto::generate_key_derivation(destination_addr.m_view_public_key, tx_random_key.sec, derivation); + bool r = crypto::generate_key_derivation(destination_addr.view_public_key, tx_random_key.sec, derivation); CHECK_AND_ASSERT_MES(r, void(), "failed to generate_key_derivation"); bool was_attachment_crypted_entries = false; bool was_extra_crypted_entries = false; @@ -1524,7 +1524,7 @@ namespace currency bool is_out_to_acc(const account_keys& acc, const txout_to_key& out_key, const crypto::key_derivation& derivation, size_t output_index) { crypto::public_key pk; - if (!derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk)) + if (!derive_public_key(derivation, output_index, acc.m_account_address.spend_public_key, pk)) return false; return pk == out_key.key; } @@ -1532,7 +1532,7 @@ namespace currency bool is_out_to_acc(const account_keys& acc, const txout_multisig& out_multisig, const crypto::key_derivation& derivation, size_t output_index) { crypto::public_key pk; - if (!derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk)) + if (!derive_public_key(derivation, output_index, acc.m_account_address.spend_public_key, pk)) return false; auto it = std::find(out_multisig.keys.begin(), out_multisig.keys.end(), pk); if (out_multisig.keys.end() == it) @@ -2060,8 +2060,8 @@ namespace currency //--------------------------------------------------------------- bool get_aliases_reward_account(account_public_address& acc) { - bool r = string_tools::parse_tpod_from_hex_string(ALIAS_REWARDS_ACCOUNT_SPEND_PUB_KEY, acc.m_spend_public_key); - r &= string_tools::parse_tpod_from_hex_string(ALIAS_REWARDS_ACCOUNT_VIEW_PUB_KEY, acc.m_view_public_key); + bool r = string_tools::parse_tpod_from_hex_string(ALIAS_REWARDS_ACCOUNT_SPEND_PUB_KEY, acc.spend_public_key); + r &= string_tools::parse_tpod_from_hex_string(ALIAS_REWARDS_ACCOUNT_VIEW_PUB_KEY, acc.view_public_key); return r; } //------------------------------------------------------------------ @@ -2569,7 +2569,7 @@ namespace currency return false; } - if (!crypto::check_key(addr.m_spend_public_key) || !crypto::check_key(addr.m_view_public_key)) + if (!crypto::check_key(addr.spend_public_key) || !crypto::check_key(addr.view_public_key)) { LOG_PRINT_L1("Failed to validate address keys for address \"" << str << "\""); return false; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 768a2e6b..3add4a0d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -771,7 +771,7 @@ bool wallet2::handle_proposal(wallet_public::wallet_transfer_info& wti, const bc wallet_public::escrow_contract_details_basic& ed = epee::misc_utils::get_or_insert_value_initialized(m_contracts, ms_id); ed.expiration_time = currency::get_tx_expiration_time(prop.tx_template); ed.timestamp = wti.timestamp; - ed.is_a = cpd.a_addr.m_spend_public_key == m_account.get_keys().m_account_address.m_spend_public_key; + ed.is_a = cpd.a_addr.spend_public_key == m_account.get_keys().m_account_address.spend_public_key; change_contract_state(ed, wallet_public::escrow_contract_details_basic::proposal_sent, ms_id, wti); ed.private_detailes = cpd; currency::get_payment_id_from_tx(decrypted_items, ed.payment_id); @@ -1299,8 +1299,8 @@ bool wallet2::has_related_alias_entry_unconfirmed(const currency::transaction& t if (tei.m_alias.m_alias.size()) { //have some check address involved - if (tei.m_alias.m_address.m_spend_public_key == m_account.get_keys().m_account_address.m_spend_public_key && - tei.m_alias.m_address.m_view_public_key == m_account.get_keys().m_account_address.m_view_public_key) + if (tei.m_alias.m_address.spend_public_key == m_account.get_keys().m_account_address.spend_public_key && + tei.m_alias.m_address.view_public_key == m_account.get_keys().m_account_address.view_public_key) return true; //check if it's update and address before was our address @@ -1972,11 +1972,11 @@ void wallet2::load_keys(const std::string& buff, const std::string& password) const currency::account_keys& keys = m_account.get_keys(); r = epee::serialization::load_t_from_binary(m_account, account_data); - r = r && verify_keys(keys.m_view_secret_key, keys.m_account_address.m_view_public_key); + r = r && verify_keys(keys.m_view_secret_key, keys.m_account_address.view_public_key); if (keys.m_spend_secret_key == currency::null_skey) m_watch_only = true; else - r = r && verify_keys(keys.m_spend_secret_key, keys.m_account_address.m_spend_public_key); + r = r && verify_keys(keys.m_spend_secret_key, keys.m_account_address.spend_public_key); if (!r) { WLT_LOG_L0("Wrong password for wallet " << string_encoding::convert_to_ansii(m_wallet_file)); @@ -2412,7 +2412,7 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig THROW_IF_FALSE_WALLET_EX(r, error::wallet_common_error, "Failed to decrypt tx sources blob"); // make sure unsigned tx was created with the same keys - THROW_IF_FALSE_WALLET_EX(ft.ftp.spend_pub_key == m_account.get_keys().m_account_address.m_spend_public_key, error::wallet_common_error, "The was created in a different wallet, keys missmatch"); + THROW_IF_FALSE_WALLET_EX(ft.ftp.spend_pub_key == m_account.get_keys().m_account_address.spend_public_key, error::wallet_common_error, "The was created in a different wallet, keys missmatch"); finalize_transaction(ft.ftp, ft.tx, ft.one_time_key, false); @@ -2420,11 +2420,11 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX( crypto::generate_key_derivation( - m_account.get_keys().m_account_address.m_view_public_key, + m_account.get_keys().m_account_address.view_public_key, ft.one_time_key, derivation), "internal error: sign_transfer: failed to generate key derivation(" - << m_account.get_keys().m_account_address.m_view_public_key + << m_account.get_keys().m_account_address.view_public_key << ", view secret key: " << ft.one_time_key << ")"); for (size_t i = 0; i < ft.tx.vout.size(); ++i) @@ -2435,7 +2435,7 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig const txout_to_key& otk = boost::get(out.target); crypto::public_key ephemeral_pub = AUTO_VAL_INIT(ephemeral_pub); - if (!crypto::derive_public_key(derivation, i, m_account.get_keys().m_account_address.m_spend_public_key, ephemeral_pub)) + if (!crypto::derive_public_key(derivation, i, m_account.get_keys().m_account_address.spend_public_key, ephemeral_pub)) { WLT_LOG_ERROR("derive_public_key failed for tx " << get_transaction_hash(ft.tx) << ", out # " << i); } @@ -2496,7 +2496,7 @@ void wallet2::submit_transfer(const std::string& signed_tx_blob, currency::trans crypto::hash tx_hash = get_transaction_hash(tx); // foolproof - THROW_IF_FALSE_WALLET_CMN_ERR_EX(ft.ftp.spend_pub_key == m_account.get_keys().m_account_address.m_spend_public_key, "The given tx was created in a different wallet, keys missmatch, tx hash: " << tx_hash); + THROW_IF_FALSE_WALLET_CMN_ERR_EX(ft.ftp.spend_pub_key == m_account.get_keys().m_account_address.spend_public_key, "The given tx was created in a different wallet, keys missmatch, tx hash: " << tx_hash); try { @@ -3062,12 +3062,12 @@ void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::tr { throw std::runtime_error(std::string("wrong alias characters: ") + ai.m_alias); } - bool r = currency::sign_extra_alias_entry(ai, m_account.get_keys().m_account_address.m_spend_public_key, m_account.get_keys().m_spend_secret_key); + bool r = currency::sign_extra_alias_entry(ai, m_account.get_keys().m_account_address.spend_public_key, m_account.get_keys().m_spend_secret_key); CHECK_AND_ASSERT_THROW_MES(r, "Failed to sign alias update"); WLT_LOG_L2("Generated upodate alias info: " << ENDL << "alias: " << ai.m_alias << ENDL << "signature: " << currency::print_t_array(ai.m_sign) << ENDL - << "signed(owner) pub key: " << m_account.get_keys().m_account_address.m_spend_public_key << ENDL + << "signed(owner) pub key: " << m_account.get_keys().m_account_address.spend_public_key << ENDL << "transfered to address: " << get_account_address_as_str(ai.m_address) << ENDL << "signed_hash: " << currency::get_sign_buff_hash_for_alias_update(ai) ); @@ -3953,8 +3953,8 @@ bool wallet2::read_money_transfer2_details_from_tx(const transaction& tx, const PROFILE_FUNC("wallet2::read_money_transfer2_details_from_tx"); for (auto& d : splitted_dsts) { - if (d.addr.size() && d.addr.back().m_spend_public_key == m_account.get_keys().m_account_address.m_spend_public_key && - d.addr.back().m_view_public_key == m_account.get_keys().m_account_address.m_view_public_key) + if (d.addr.size() && d.addr.back().spend_public_key == m_account.get_keys().m_account_address.spend_public_key && + d.addr.back().view_public_key == m_account.get_keys().m_account_address.view_public_key) wtd.rcv.push_back(d.amount); } @@ -4191,7 +4191,7 @@ void wallet2::prepare_transaction(const construct_tx_param& ctp, finalize_tx_par ftp.shuffle = ctp.shuffle; ftp.flags = ctp.flags; ftp.multisig_id = ctp.multisig_id; - ftp.spend_pub_key = m_account.get_public_address().m_spend_public_key; + ftp.spend_pub_key = m_account.get_public_address().spend_public_key; /* TODO WLT_LOG_GREEN("[prepare_transaction]: get_needed_money_time: " << get_needed_money_time << " ms" @@ -4510,7 +4510,7 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public // ftp.selected_transfers -- needed only at stage of broadcasting or storing unsigned tx ftp.shuffle = false; // ftp.sources -- will be filled in try_construct_tx - ftp.spend_pub_key = m_account.get_public_address().m_spend_public_key; // needed for offline signing + ftp.spend_pub_key = m_account.get_public_address().spend_public_key; // needed for offline signing ftp.tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED; ftp.unlock_time = 0; diff --git a/src/wallet/wallet2_escrow.cpp b/src/wallet/wallet2_escrow.cpp index fe591d3d..dc57011f 100644 --- a/src/wallet/wallet2_escrow.cpp +++ b/src/wallet/wallet2_escrow.cpp @@ -93,13 +93,13 @@ bool wallet2::validate_escrow_proposal(const wallet_public::wallet_transfer_info crypto::public_key a_key = AUTO_VAL_INIT(a_key), b_key = AUTO_VAL_INIT(b_key); crypto::key_derivation der = AUTO_VAL_INIT(der); - r = crypto::generate_key_derivation(cpd.a_addr.m_view_public_key, prop.tx_onetime_secret_key, der); + r = crypto::generate_key_derivation(cpd.a_addr.view_public_key, prop.tx_onetime_secret_key, der); LOC_CHK(r, "generate_key_derivation failed: A"); - r = crypto::derive_public_key(der, ms_out_index, cpd.a_addr.m_spend_public_key, a_key); + r = crypto::derive_public_key(der, ms_out_index, cpd.a_addr.spend_public_key, a_key); LOC_CHK(r, "derive_public_key failed: A"); - r = crypto::generate_key_derivation(cpd.b_addr.m_view_public_key, prop.tx_onetime_secret_key, der); + r = crypto::generate_key_derivation(cpd.b_addr.view_public_key, prop.tx_onetime_secret_key, der); LOC_CHK(r, "generate_key_derivation failed: B"); - r = crypto::derive_public_key(der, ms_out_index, cpd.b_addr.m_spend_public_key, b_key); + r = crypto::derive_public_key(der, ms_out_index, cpd.b_addr.spend_public_key, b_key); LOC_CHK(r, "derive_public_key failed: B"); bool correct_keys = (ms.keys[0] == a_key && ms.keys[1] == b_key) || (ms.keys[0] == b_key && ms.keys[1] == a_key); LOC_CHK(correct_keys, "template has mulisig output with invalid keys: 0:" << ms.keys[0] << " 1:" << ms.keys[1]); @@ -186,7 +186,7 @@ bool wallet2::validate_escrow_release(const transaction& tx, bool release_type_n total_outputs_amount += tx.vout[i].amount; const txout_to_key& otk = boost::get(tx.vout[i].target); crypto::public_key ephemeral_pub_key = AUTO_VAL_INIT(ephemeral_pub_key); - r = crypto::derive_public_key(der, i, cpd.a_addr.m_spend_public_key, ephemeral_pub_key); + r = crypto::derive_public_key(der, i, cpd.a_addr.spend_public_key, ephemeral_pub_key); LOC_CHK(r, "derive_public_key failed for output #" << i); if (otk.key == ephemeral_pub_key) outputs_to_A_amount += tx.vout[i].amount; @@ -226,7 +226,7 @@ bool wallet2::validate_escrow_release(const transaction& tx, bool release_type_n r = crypto::generate_key_derivation(source_tx_pub_key, a_keys.m_view_secret_key, der); LOC_CHK(r, "generate_key_derivation failed"); crypto::public_key ephemeral_pub_key = AUTO_VAL_INIT(ephemeral_pub_key); - r = crypto::derive_public_key(der, source_ms_out_index, a_keys.m_account_address.m_spend_public_key, ephemeral_pub_key); + r = crypto::derive_public_key(der, source_ms_out_index, a_keys.m_account_address.spend_public_key, ephemeral_pub_key); LOC_CHK(r, "derive_public_key failed"); LOC_CHK(source_ms_out.keys.size() == 2, "internal error: invalid ms output keys array, size: " << source_ms_out.keys.size()); @@ -368,7 +368,7 @@ bool wallet2::validate_escrow_cancel_release(const currency::transaction& tx, co total_outputs_amount += tx.vout[i].amount; const txout_to_key& otk = boost::get(tx.vout[i].target); crypto::public_key ephemeral_pub_key = AUTO_VAL_INIT(ephemeral_pub_key); - r = crypto::derive_public_key(der, i, cpd.b_addr.m_spend_public_key, ephemeral_pub_key); + r = crypto::derive_public_key(der, i, cpd.b_addr.spend_public_key, ephemeral_pub_key); LOC_CHK(r, "derive_public_key failed for output #" << i); if (otk.key == ephemeral_pub_key) outputs_to_B_amount += tx.vout[i].amount; From fc475432fceac50f69e44e194aec28123698b988 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 22 Apr 2020 22:30:29 +0300 Subject: [PATCH 03/16] account_public_address spend_public_key/view_public_key changes --- src/currency_core/currency_basic.h | 12 ++++++------ src/currency_core/currency_boost_serialization.h | 4 ++-- src/simplewallet/simplewallet.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 204ce651..74f5c824 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -62,17 +62,17 @@ namespace currency #pragma pack(push, 1) struct account_public_address { - crypto::public_key m_spend_public_key; - crypto::public_key m_view_public_key; + crypto::public_key spend_public_key; + crypto::public_key view_public_key; BEGIN_SERIALIZE_OBJECT() - FIELD(m_spend_public_key) - FIELD(m_view_public_key) + FIELD(spend_public_key) + FIELD(view_public_key) END_SERIALIZE() BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_public_key) - KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_public_key) + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(spend_public_key) + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(view_public_key) END_KV_SERIALIZE_MAP() }; #pragma pack(pop) diff --git a/src/currency_core/currency_boost_serialization.h b/src/currency_core/currency_boost_serialization.h index a050a878..99928b7a 100644 --- a/src/currency_core/currency_boost_serialization.h +++ b/src/currency_core/currency_boost_serialization.h @@ -29,8 +29,8 @@ namespace boost template inline void serialize(Archive &a, currency::account_public_address &x, const boost::serialization::version_type ver) { - a & x.m_spend_public_key; - a & x.m_view_public_key; + a & x.spend_public_key; + a & x.view_public_key; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 36d23a7f..29616f54 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1334,7 +1334,7 @@ bool simple_wallet::spendkey(const std::vector &args) const account_keys& keys = m_wallet->get_account().get_keys(); std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.m_spend_secret_key) << std::endl; - std::cout << "public: " << epee::string_tools::pod_to_hex(keys.m_account_address.m_spend_public_key) << std::endl << std::flush; + std::cout << "public: " << epee::string_tools::pod_to_hex(keys.m_account_address.spend_public_key) << std::endl << std::flush; return true; } @@ -1346,7 +1346,7 @@ bool simple_wallet::viewkey(const std::vector &args) const account_keys& keys = m_wallet->get_account().get_keys(); std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.m_view_secret_key) << std::endl; - std::cout << "public: " << epee::string_tools::pod_to_hex(keys.m_account_address.m_view_public_key) << std::endl << std::flush; + std::cout << "public: " << epee::string_tools::pod_to_hex(keys.m_account_address.view_public_key) << std::endl << std::flush; return true; } From c7229c3062af215bd27a199da1884cb3273fc142 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 22 Apr 2020 23:30:03 +0300 Subject: [PATCH 04/16] account_keys improvements --- src/currency_core/account.cpp | 26 +++++----- src/currency_core/account.h | 20 +++---- .../account_boost_serialization.h | 6 +-- src/currency_core/currency_format_utils.cpp | 32 ++++++------ src/currency_core/currency_format_utils.h | 2 +- .../currency_format_utils_transactions.cpp | 4 +- src/simplewallet/simplewallet.cpp | 12 ++--- src/wallet/wallet2.cpp | 52 +++++++++---------- src/wallet/wallet2_escrow.cpp | 8 +-- src/wallet/wallet_helpers.h | 2 +- src/wallet/wallet_rpc_server.cpp | 2 +- src/wallet/wallets_manager.cpp | 2 +- 12 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/currency_core/account.cpp b/src/currency_core/account.cpp index 3fb19b45..543338ed 100644 --- a/src/currency_core/account.cpp +++ b/src/currency_core/account.cpp @@ -35,8 +35,8 @@ namespace currency void account_base::set_null() { // fill sensitive data with random bytes - crypto::generate_random_bytes(sizeof m_keys.m_spend_secret_key, &m_keys.m_spend_secret_key); - crypto::generate_random_bytes(sizeof m_keys.m_view_secret_key, &m_keys.m_view_secret_key); + crypto::generate_random_bytes(sizeof m_keys.spend_secret_key, &m_keys.spend_secret_key); + crypto::generate_random_bytes(sizeof m_keys.view_secret_key, &m_keys.view_secret_key); crypto::generate_random_bytes(m_seed.size(), &m_seed[0]); // clear @@ -47,9 +47,9 @@ namespace currency //----------------------------------------------------------------- void account_base::generate() { - generate_brain_keys(m_keys.m_account_address.spend_public_key, m_keys.m_spend_secret_key, m_seed, BRAINWALLET_DEFAULT_SEED_SIZE); - dependent_key(m_keys.m_spend_secret_key, m_keys.m_view_secret_key); - if (!crypto::secret_key_to_public_key(m_keys.m_view_secret_key, m_keys.m_account_address.view_public_key)) + generate_brain_keys(m_keys.account_address.spend_public_key, m_keys.spend_secret_key, m_seed, BRAINWALLET_DEFAULT_SEED_SIZE); + dependent_key(m_keys.spend_secret_key, m_keys.view_secret_key); + if (!crypto::secret_key_to_public_key(m_keys.view_secret_key, m_keys.account_address.view_public_key)) throw std::runtime_error("Failed to create public view key"); @@ -85,7 +85,7 @@ namespace currency //CHECK_AND_ASSERT_MES(restore_data.size() == ACCOUNT_RESTORE_DATA_SIZE, false, "wrong restore data size"); if (restore_data.size() == BRAINWALLET_DEFAULT_SEED_SIZE) { - crypto::keys_from_default((unsigned char*)restore_data.data(), m_keys.m_account_address.spend_public_key, m_keys.m_spend_secret_key, BRAINWALLET_DEFAULT_SEED_SIZE); + crypto::keys_from_default((unsigned char*)restore_data.data(), m_keys.account_address.spend_public_key, m_keys.spend_secret_key, BRAINWALLET_DEFAULT_SEED_SIZE); } else { @@ -93,8 +93,8 @@ namespace currency return false; } m_seed = restore_data; - crypto::dependent_key(m_keys.m_spend_secret_key, m_keys.m_view_secret_key); - bool r = crypto::secret_key_to_public_key(m_keys.m_view_secret_key, m_keys.m_account_address.view_public_key); + crypto::dependent_key(m_keys.spend_secret_key, m_keys.view_secret_key); + bool r = crypto::secret_key_to_public_key(m_keys.view_secret_key, m_keys.account_address.view_public_key); CHECK_AND_ASSERT_MES(r, false, "failed to secret_key_to_public_key for view key"); set_createtime(0); return true; @@ -126,7 +126,7 @@ namespace currency std::string account_base::get_public_address_str() const { //TODO: change this code into base 58 - return get_account_address_as_str(m_keys.m_account_address); + return get_account_address_as_str(m_keys.account_address); } //----------------------------------------------------------------- void account_base::make_account_watch_only() @@ -138,16 +138,16 @@ namespace currency // store to local tmp uint64_t local_ts = m_creation_timestamp; - account_public_address local_addr = m_keys.m_account_address; - crypto::secret_key local_view_sec = m_keys.m_view_secret_key; + account_public_address local_addr = m_keys.account_address; + crypto::secret_key local_view_sec = m_keys.view_secret_key; // clear set_null(); // restore m_creation_timestamp = local_ts; - m_keys.m_account_address = local_addr; - m_keys.m_view_secret_key = local_view_sec; + m_keys.account_address = local_addr; + m_keys.view_secret_key = local_view_sec; } //----------------------------------------------------------------- std::string transform_addr_to_str(const account_public_address& addr) diff --git a/src/currency_core/account.h b/src/currency_core/account.h index f39e1a61..0a049a89 100644 --- a/src/currency_core/account.h +++ b/src/currency_core/account.h @@ -29,14 +29,14 @@ namespace currency struct account_keys { - account_public_address m_account_address; - crypto::secret_key m_spend_secret_key; - crypto::secret_key m_view_secret_key; + account_public_address account_address; + crypto::secret_key spend_secret_key; + crypto::secret_key view_secret_key; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(m_account_address) - KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_secret_key) - KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_secret_key) + KV_SERIALIZE(account_address) + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(spend_secret_key) + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(view_secret_key) END_KV_SERIALIZE_MAP() }; @@ -49,7 +49,7 @@ namespace currency account_base(); void generate(); const account_keys& get_keys() const; - const account_public_address& get_public_address() const { return m_keys.m_account_address; }; + const account_public_address& get_public_address() const { return m_keys.account_address; }; std::string get_public_address_str() const; std::string get_restore_data() const; std::string get_restore_braindata() const; @@ -92,9 +92,9 @@ namespace currency inline bool operator==(const account_keys& lhs, const account_keys& rhs) { - return lhs.m_account_address == rhs.m_account_address && - lhs.m_spend_secret_key == rhs.m_spend_secret_key && - lhs.m_view_secret_key == rhs.m_view_secret_key; + return lhs.account_address == rhs.account_address && + lhs.spend_secret_key == rhs.spend_secret_key && + lhs.view_secret_key == rhs.view_secret_key; } inline bool operator!=(const account_keys& lhs, const account_keys& rhs) { diff --git a/src/currency_core/account_boost_serialization.h b/src/currency_core/account_boost_serialization.h index f4d3c616..f0f2d634 100644 --- a/src/currency_core/account_boost_serialization.h +++ b/src/currency_core/account_boost_serialization.h @@ -17,9 +17,9 @@ namespace boost template inline void serialize(Archive &a, currency::account_keys &x, const boost::serialization::version_type ver) { - a & x.m_account_address; - a & x.m_spend_secret_key; - a & x.m_view_secret_key; + a & x.account_address; + a & x.spend_secret_key; + a & x.view_secret_key; } } diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 8d2058c4..feeab899 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -224,13 +224,13 @@ namespace currency bool derive_ephemeral_key_helper(const account_keys& ack, const crypto::public_key& tx_public_key, size_t real_output_index, keypair& in_ephemeral) { crypto::key_derivation recv_derivation = AUTO_VAL_INIT(recv_derivation); - bool r = crypto::generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation); - CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")"); + bool r = crypto::generate_key_derivation(tx_public_key, ack.view_secret_key, recv_derivation); + CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.view_secret_key << ")"); - r = crypto::derive_public_key(recv_derivation, real_output_index, ack.m_account_address.spend_public_key, in_ephemeral.pub); - CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to derive_public_key(" << recv_derivation << ", " << real_output_index << ", " << ack.m_account_address.spend_public_key << ")"); + r = crypto::derive_public_key(recv_derivation, real_output_index, ack.account_address.spend_public_key, in_ephemeral.pub); + CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to derive_public_key(" << recv_derivation << ", " << real_output_index << ", " << ack.account_address.spend_public_key << ")"); - crypto::derive_secret_key(recv_derivation, real_output_index, ack.m_spend_secret_key, in_ephemeral.sec); + crypto::derive_secret_key(recv_derivation, real_output_index, ack.spend_secret_key, in_ephemeral.sec); return true; } //--------------------------------------------------------------- @@ -778,15 +778,15 @@ namespace currency { crypto::public_key tx_pub_key = currency::get_tx_pub_key_from_extra(tx); - bool r = crypto::generate_key_derivation(tx_pub_key, acc_keys.m_view_secret_key, derivation); + bool r = crypto::generate_key_derivation(tx_pub_key, acc_keys.view_secret_key, derivation); CHECK_AND_ASSERT_MES(r, null_derivation, "failed to generate_key_derivation"); - LOG_PRINT_GREEN("DECRYPTING ON KEY: " << epee::string_tools::pod_to_hex(derivation) << ", key derived from destination addr: " << currency::get_account_address_as_str(acc_keys.m_account_address), LOG_LEVEL_0); + LOG_PRINT_GREEN("DECRYPTING ON KEY: " << epee::string_tools::pod_to_hex(derivation) << ", key derived from destination addr: " << currency::get_account_address_as_str(acc_keys.account_address), LOG_LEVEL_0); } else { derivation = crypto_info.encrypted_key_derivation; - crypto::chacha_crypt(derivation, acc_keys.m_spend_secret_key); - LOG_PRINT_GREEN("DECRYPTING ON KEY: " << epee::string_tools::pod_to_hex(derivation) << ", key decrypted from sender address: " << currency::get_account_address_as_str(acc_keys.m_account_address), LOG_LEVEL_0); + crypto::chacha_crypt(derivation, acc_keys.spend_secret_key); + LOG_PRINT_GREEN("DECRYPTING ON KEY: " << epee::string_tools::pod_to_hex(derivation) << ", key decrypted from sender address: " << currency::get_account_address_as_str(acc_keys.account_address), LOG_LEVEL_0); } //validate derivation we here. Yoda style @@ -855,7 +855,7 @@ namespace currency chs.derivation_hash = *(uint32_t*)&hash_for_check_sum; //put encrypted derivation to let sender decrypt all this data from attachment/extra chs.encrypted_key_derivation = derivation; - crypto::chacha_crypt(chs.encrypted_key_derivation, sender_keys.m_spend_secret_key); + crypto::chacha_crypt(chs.encrypted_key_derivation, sender_keys.spend_secret_key); if (was_extra_crypted_entries) tx.extra.push_back(chs); else @@ -976,7 +976,7 @@ namespace currency { CHECK_AND_ASSERT_MES(destinations.size() <= CURRENCY_TX_MAX_ALLOWED_OUTS, false, "Too many outs (" << destinations.size() << ")! Tx can't be constructed."); - bool watch_only_mode = sender_account_keys.m_spend_secret_key == null_skey; + bool watch_only_mode = sender_account_keys.spend_secret_key == null_skey; bool append_mode = false; if (flags&TX_FLAG_SIGNATURE_MODE_SEPARATE && tx.vin.size()) @@ -1138,7 +1138,7 @@ namespace currency { CHECK_AND_ASSERT_MES(tsa.security.size() == 1, false, "Wrong tsa.security.size() = " << tsa.security.size()); - bool r = derive_public_key_from_target_address(sender_account_keys.m_account_address, one_time_secret_key, att_count, tsa.security.back()); + bool r = derive_public_key_from_target_address(sender_account_keys.account_address, one_time_secret_key, att_count, tsa.security.back()); CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_target_address"); } att_count++; @@ -1524,7 +1524,7 @@ namespace currency bool is_out_to_acc(const account_keys& acc, const txout_to_key& out_key, const crypto::key_derivation& derivation, size_t output_index) { crypto::public_key pk; - if (!derive_public_key(derivation, output_index, acc.m_account_address.spend_public_key, pk)) + if (!derive_public_key(derivation, output_index, acc.account_address.spend_public_key, pk)) return false; return pk == out_key.key; } @@ -1532,7 +1532,7 @@ namespace currency bool is_out_to_acc(const account_keys& acc, const txout_multisig& out_multisig, const crypto::key_derivation& derivation, size_t output_index) { crypto::public_key pk; - if (!derive_public_key(derivation, output_index, acc.m_account_address.spend_public_key, pk)) + if (!derive_public_key(derivation, output_index, acc.account_address.spend_public_key, pk)) return false; auto it = std::find(out_multisig.keys.begin(), out_multisig.keys.end(), pk); if (out_multisig.keys.end() == it) @@ -1576,7 +1576,7 @@ namespace currency bool lookup_acc_outs_genesis(const account_keys& acc, const transaction& tx, const crypto::public_key& tx_pub_key, std::vector& outs, uint64_t& money_transfered, crypto::key_derivation& derivation) { uint64_t offset = 0; - bool r = get_account_genesis_offset_by_address(get_account_address_as_str(acc.m_account_address), offset); + bool r = get_account_genesis_offset_by_address(get_account_address_as_str(acc.account_address), offset); if (!r) return true; @@ -1594,7 +1594,7 @@ namespace currency bool lookup_acc_outs(const account_keys& acc, const transaction& tx, const crypto::public_key& tx_pub_key, std::vector& outs, uint64_t& money_transfered, crypto::key_derivation& derivation) { money_transfered = 0; - bool r = generate_key_derivation(tx_pub_key, acc.m_view_secret_key, derivation); + bool r = generate_key_derivation(tx_pub_key, acc.view_secret_key, derivation); CHECK_AND_ASSERT_MES(r, false, "unable to generate derivation from tx_pub = " << tx_pub_key << " * view_sec, invalid tx_pub?"); if (is_coinbase(tx) && get_block_height(tx) == 0 && tx_pub_key == ggenesis_tx_pub_key) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 01d08170..4405b24d 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -348,7 +348,7 @@ namespace currency bool is_out_to_acc(const account_keys& acc, const tx_out_t& out_key, const crypto::public_key& tx_pub_key, size_t output_index) { crypto::key_derivation derivation; - generate_key_derivation(tx_pub_key, acc.m_view_secret_key, derivation); + generate_key_derivation(tx_pub_key, acc.view_secret_key, derivation); return is_out_to_acc(acc, out_key, derivation, output_index); } //---------------------------------------------------------------------------------------------------- diff --git a/src/currency_core/currency_format_utils_transactions.cpp b/src/currency_core/currency_format_utils_transactions.cpp index da78894f..6e84961a 100644 --- a/src/currency_core/currency_format_utils_transactions.cpp +++ b/src/currency_core/currency_format_utils_transactions.cpp @@ -16,10 +16,10 @@ namespace currency { for (const auto& de : destinations) { - if (de.addr.size() == 1 && sender_account_keys.m_account_address != de.addr.back()) + if (de.addr.size() == 1 && sender_account_keys.account_address != de.addr.back()) return de.addr.back(); // return the first destination address that is non-multisig and not equal to the sender's address } - return sender_account_keys.m_account_address; // otherwise, fallback to sender's address + return sender_account_keys.account_address; // otherwise, fallback to sender's address } //------------------------------------------------------------------ bool is_tx_expired(const transaction& tx, uint64_t expiration_ts_median) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 29616f54..65cdba9e 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -385,7 +385,7 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas { m_wallet->generate(epee::string_encoding::utf8_to_wstring(m_wallet_file), password); message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str(); - std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl << std::flush; + std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().view_secret_key) << std::endl << std::flush; if(m_do_not_set_date) m_wallet->reset_creation_time(0); @@ -427,7 +427,7 @@ bool simple_wallet::restore_wallet(const std::string &wallet_file, const std::st { m_wallet->restore(epee::string_encoding::utf8_to_wstring(wallet_file), password, restore_seed); message_writer(epee::log_space::console_color_white, true) << "Wallet restored: " << m_wallet->get_account().get_public_address_str(); - std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl << std::flush; + std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().view_secret_key) << std::endl << std::flush; if (m_do_not_set_date) m_wallet->reset_creation_time(0); } @@ -1333,8 +1333,8 @@ bool simple_wallet::spendkey(const std::vector &args) << "WARNING! Anyone who knows the following secret key can access your wallet and spend your coins."; const account_keys& keys = m_wallet->get_account().get_keys(); - std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.m_spend_secret_key) << std::endl; - std::cout << "public: " << epee::string_tools::pod_to_hex(keys.m_account_address.spend_public_key) << std::endl << std::flush; + std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.spend_secret_key) << std::endl; + std::cout << "public: " << epee::string_tools::pod_to_hex(keys.account_address.spend_public_key) << std::endl << std::flush; return true; } @@ -1345,8 +1345,8 @@ bool simple_wallet::viewkey(const std::vector &args) << "WARNING! Anyone who knows the following secret key can view your wallet (but can not spend your coins)."; const account_keys& keys = m_wallet->get_account().get_keys(); - std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.m_view_secret_key) << std::endl; - std::cout << "public: " << epee::string_tools::pod_to_hex(keys.m_account_address.view_public_key) << std::endl << std::flush; + std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.view_secret_key) << std::endl; + std::cout << "public: " << epee::string_tools::pod_to_hex(keys.account_address.view_public_key) << std::endl << std::flush; return true; } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 3add4a0d..4691854e 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -771,7 +771,7 @@ bool wallet2::handle_proposal(wallet_public::wallet_transfer_info& wti, const bc wallet_public::escrow_contract_details_basic& ed = epee::misc_utils::get_or_insert_value_initialized(m_contracts, ms_id); ed.expiration_time = currency::get_tx_expiration_time(prop.tx_template); ed.timestamp = wti.timestamp; - ed.is_a = cpd.a_addr.spend_public_key == m_account.get_keys().m_account_address.spend_public_key; + ed.is_a = cpd.a_addr.spend_public_key == m_account.get_keys().account_address.spend_public_key; change_contract_state(ed, wallet_public::escrow_contract_details_basic::proposal_sent, ms_id, wti); ed.private_detailes = cpd; currency::get_payment_id_from_tx(decrypted_items, ed.payment_id); @@ -1299,8 +1299,8 @@ bool wallet2::has_related_alias_entry_unconfirmed(const currency::transaction& t if (tei.m_alias.m_alias.size()) { //have some check address involved - if (tei.m_alias.m_address.spend_public_key == m_account.get_keys().m_account_address.spend_public_key && - tei.m_alias.m_address.view_public_key == m_account.get_keys().m_account_address.view_public_key) + if (tei.m_alias.m_address.spend_public_key == m_account.get_keys().account_address.spend_public_key && + tei.m_alias.m_address.view_public_key == m_account.get_keys().account_address.view_public_key) return true; //check if it's update and address before was our address @@ -1972,11 +1972,11 @@ void wallet2::load_keys(const std::string& buff, const std::string& password) const currency::account_keys& keys = m_account.get_keys(); r = epee::serialization::load_t_from_binary(m_account, account_data); - r = r && verify_keys(keys.m_view_secret_key, keys.m_account_address.view_public_key); - if (keys.m_spend_secret_key == currency::null_skey) + r = r && verify_keys(keys.view_secret_key, keys.account_address.view_public_key); + if (keys.spend_secret_key == currency::null_skey) m_watch_only = true; else - r = r && verify_keys(keys.m_spend_secret_key, keys.m_account_address.spend_public_key); + r = r && verify_keys(keys.spend_secret_key, keys.account_address.spend_public_key); if (!r) { WLT_LOG_L0("Wrong password for wallet " << string_encoding::convert_to_ansii(m_wallet_file)); @@ -2404,7 +2404,7 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig THROW_IF_FALSE_WALLET_EX(!m_watch_only, error::wallet_common_error, "watch-only wallet is unable to sign transfers, you need to use normal wallet for that"); // decrypt the blob - std::string decrypted_src_blob = crypto::chacha_crypt(tx_sources_blob, m_account.get_keys().m_view_secret_key); + std::string decrypted_src_blob = crypto::chacha_crypt(tx_sources_blob, m_account.get_keys().view_secret_key); // deserialize args finalized_tx ft = AUTO_VAL_INIT(ft); @@ -2412,7 +2412,7 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig THROW_IF_FALSE_WALLET_EX(r, error::wallet_common_error, "Failed to decrypt tx sources blob"); // make sure unsigned tx was created with the same keys - THROW_IF_FALSE_WALLET_EX(ft.ftp.spend_pub_key == m_account.get_keys().m_account_address.spend_public_key, error::wallet_common_error, "The was created in a different wallet, keys missmatch"); + THROW_IF_FALSE_WALLET_EX(ft.ftp.spend_pub_key == m_account.get_keys().account_address.spend_public_key, error::wallet_common_error, "The was created in a different wallet, keys missmatch"); finalize_transaction(ft.ftp, ft.tx, ft.one_time_key, false); @@ -2420,11 +2420,11 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX( crypto::generate_key_derivation( - m_account.get_keys().m_account_address.view_public_key, + m_account.get_keys().account_address.view_public_key, ft.one_time_key, derivation), "internal error: sign_transfer: failed to generate key derivation(" - << m_account.get_keys().m_account_address.view_public_key + << m_account.get_keys().account_address.view_public_key << ", view secret key: " << ft.one_time_key << ")"); for (size_t i = 0; i < ft.tx.vout.size(); ++i) @@ -2435,7 +2435,7 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig const txout_to_key& otk = boost::get(out.target); crypto::public_key ephemeral_pub = AUTO_VAL_INIT(ephemeral_pub); - if (!crypto::derive_public_key(derivation, i, m_account.get_keys().m_account_address.spend_public_key, ephemeral_pub)) + if (!crypto::derive_public_key(derivation, i, m_account.get_keys().account_address.spend_public_key, ephemeral_pub)) { WLT_LOG_ERROR("derive_public_key failed for tx " << get_transaction_hash(ft.tx) << ", out # " << i); } @@ -2445,7 +2445,7 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig // this is the output to the given keys // derive secret key and calculate key image crypto::secret_key ephemeral_sec = AUTO_VAL_INIT(ephemeral_sec); - crypto::derive_secret_key(derivation, i, m_account.get_keys().m_spend_secret_key, ephemeral_sec); + crypto::derive_secret_key(derivation, i, m_account.get_keys().spend_secret_key, ephemeral_sec); crypto::key_image ki = AUTO_VAL_INIT(ki); crypto::generate_key_image(ephemeral_pub, ephemeral_sec, ki); @@ -2455,7 +2455,7 @@ void wallet2::sign_transfer(const std::string& tx_sources_blob, std::string& sig // serialize and encrypt the result signed_tx_blob = t_serializable_object_to_blob(ft); - crypto::chacha_crypt(signed_tx_blob, m_account.get_keys().m_view_secret_key); + crypto::chacha_crypt(signed_tx_blob, m_account.get_keys().view_secret_key); tx = ft.tx; } @@ -2486,7 +2486,7 @@ bool wallet2::get_utxo_distribution(std::map& distribution) void wallet2::submit_transfer(const std::string& signed_tx_blob, currency::transaction& tx) { // decrypt sources - std::string decrypted_src_blob = crypto::chacha_crypt(signed_tx_blob, m_account.get_keys().m_view_secret_key); + std::string decrypted_src_blob = crypto::chacha_crypt(signed_tx_blob, m_account.get_keys().view_secret_key); // deserialize tx data finalized_tx ft = AUTO_VAL_INIT(ft); @@ -2496,7 +2496,7 @@ void wallet2::submit_transfer(const std::string& signed_tx_blob, currency::trans crypto::hash tx_hash = get_transaction_hash(tx); // foolproof - THROW_IF_FALSE_WALLET_CMN_ERR_EX(ft.ftp.spend_pub_key == m_account.get_keys().m_account_address.spend_public_key, "The given tx was created in a different wallet, keys missmatch, tx hash: " << tx_hash); + THROW_IF_FALSE_WALLET_CMN_ERR_EX(ft.ftp.spend_pub_key == m_account.get_keys().account_address.spend_public_key, "The given tx was created in a different wallet, keys missmatch, tx hash: " << tx_hash); try { @@ -2687,17 +2687,17 @@ bool wallet2::prepare_and_sign_pos_block(currency::block& b, //derive secret key crypto::key_derivation pos_coin_derivation = AUTO_VAL_INIT(pos_coin_derivation); bool r = crypto::generate_key_derivation(source_tx_pub_key, - m_account.get_keys().m_view_secret_key, + m_account.get_keys().view_secret_key, pos_coin_derivation); WLT_CHECK_AND_ASSERT_MES(r, false, "internal error: pos coin base generator: failed to generate_key_derivation(" << source_tx_pub_key - << ", view secret key: " << m_account.get_keys().m_view_secret_key << ")"); + << ", view secret key: " << m_account.get_keys().view_secret_key << ")"); crypto::secret_key derived_secret_ephemeral_key = AUTO_VAL_INIT(derived_secret_ephemeral_key); crypto::derive_secret_key(pos_coin_derivation, in_tx_output_index, - m_account.get_keys().m_spend_secret_key, + m_account.get_keys().spend_secret_key, derived_secret_ephemeral_key); // sign block actually in coinbase transaction @@ -2967,7 +2967,7 @@ bool wallet2::is_transfer_unlocked(const transfer_details& td, bool for_pos_mini void wallet2::push_offer(const bc_services::offer_details_ex& od, currency::transaction& res_tx) { currency::tx_destination_entry tx_dest; - tx_dest.addr.push_back(m_account.get_keys().m_account_address); + tx_dest.addr.push_back(m_account.get_keys().account_address); tx_dest.amount = m_core_runtime_config.tx_default_fee; std::vector destinations; std::vector extra; @@ -3012,7 +3012,7 @@ void wallet2::cancel_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, uin void wallet2::update_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, const bc_services::offer_details_ex& od, currency::transaction& res_tx) { currency::tx_destination_entry tx_dest; - tx_dest.addr.push_back(m_account.get_keys().m_account_address); + tx_dest.addr.push_back(m_account.get_keys().account_address); tx_dest.amount = m_core_runtime_config.tx_default_fee; std::vector destinations; std::vector extra; @@ -3062,12 +3062,12 @@ void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::tr { throw std::runtime_error(std::string("wrong alias characters: ") + ai.m_alias); } - bool r = currency::sign_extra_alias_entry(ai, m_account.get_keys().m_account_address.spend_public_key, m_account.get_keys().m_spend_secret_key); + bool r = currency::sign_extra_alias_entry(ai, m_account.get_keys().account_address.spend_public_key, m_account.get_keys().spend_secret_key); CHECK_AND_ASSERT_THROW_MES(r, "Failed to sign alias update"); WLT_LOG_L2("Generated upodate alias info: " << ENDL << "alias: " << ai.m_alias << ENDL << "signature: " << currency::print_t_array(ai.m_sign) << ENDL - << "signed(owner) pub key: " << m_account.get_keys().m_account_address.spend_public_key << ENDL + << "signed(owner) pub key: " << m_account.get_keys().account_address.spend_public_key << ENDL << "transfered to address: " << get_account_address_as_str(ai.m_address) << ENDL << "signed_hash: " << currency::get_sign_buff_hash_for_alias_update(ai) ); @@ -3953,8 +3953,8 @@ bool wallet2::read_money_transfer2_details_from_tx(const transaction& tx, const PROFILE_FUNC("wallet2::read_money_transfer2_details_from_tx"); for (auto& d : splitted_dsts) { - if (d.addr.size() && d.addr.back().spend_public_key == m_account.get_keys().m_account_address.spend_public_key && - d.addr.back().view_public_key == m_account.get_keys().m_account_address.view_public_key) + if (d.addr.size() && d.addr.back().spend_public_key == m_account.get_keys().account_address.spend_public_key && + d.addr.back().view_public_key == m_account.get_keys().account_address.view_public_key) wtd.rcv.push_back(d.amount); } @@ -4128,7 +4128,7 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money, currency::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts); if (needed_money < found_money) { - change_dts.addr.push_back(m_account.get_keys().m_account_address); + change_dts.addr.push_back(m_account.get_keys().account_address); change_dts.amount = found_money - needed_money; } WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(found_money >= needed_money, "needed_money==" << needed_money << " < found_money==" << found_money); @@ -4330,7 +4330,7 @@ bool wallet2::store_unsigned_tx_to_file_and_reserve_transfers(const finalize_tx_ { TIME_MEASURE_START(store_unsigned_tx_time); blobdata bl = t_serializable_object_to_blob(ftp); - crypto::chacha_crypt(bl, m_account.get_keys().m_view_secret_key); + crypto::chacha_crypt(bl, m_account.get_keys().view_secret_key); if (!filename.empty()) { diff --git a/src/wallet/wallet2_escrow.cpp b/src/wallet/wallet2_escrow.cpp index dc57011f..4c5f1d65 100644 --- a/src/wallet/wallet2_escrow.cpp +++ b/src/wallet/wallet2_escrow.cpp @@ -176,7 +176,7 @@ bool wallet2::validate_escrow_release(const transaction& tx, bool release_type_n // (3/5) outputs crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(tx); crypto::key_derivation der = AUTO_VAL_INIT(der); - r = crypto::generate_key_derivation(tx_pub_key, a_keys.m_view_secret_key, der); + r = crypto::generate_key_derivation(tx_pub_key, a_keys.view_secret_key, der); LOC_CHK(r, "generate_key_derivation failed"); uint64_t total_outputs_amount = 0, outputs_to_A_amount = 0, outputs_to_null_addr_amount = 0; for (size_t i = 0; i != tx.vout.size(); ++i) @@ -223,10 +223,10 @@ bool wallet2::validate_escrow_release(const transaction& tx, bool release_type_n // Having a_keys, we determine index of A key in multisig output keys array. // Thus it's possible to determine the order of signatures (A, B or B, A), and, eventually, validate B signature. crypto::public_key source_tx_pub_key = get_tx_pub_key_from_extra(source_tx); - r = crypto::generate_key_derivation(source_tx_pub_key, a_keys.m_view_secret_key, der); + r = crypto::generate_key_derivation(source_tx_pub_key, a_keys.view_secret_key, der); LOC_CHK(r, "generate_key_derivation failed"); crypto::public_key ephemeral_pub_key = AUTO_VAL_INIT(ephemeral_pub_key); - r = crypto::derive_public_key(der, source_ms_out_index, a_keys.m_account_address.spend_public_key, ephemeral_pub_key); + r = crypto::derive_public_key(der, source_ms_out_index, a_keys.account_address.spend_public_key, ephemeral_pub_key); LOC_CHK(r, "derive_public_key failed"); LOC_CHK(source_ms_out.keys.size() == 2, "internal error: invalid ms output keys array, size: " << source_ms_out.keys.size()); @@ -358,7 +358,7 @@ bool wallet2::validate_escrow_cancel_release(const currency::transaction& tx, co // (3/5) outputs crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(tx); crypto::key_derivation der = AUTO_VAL_INIT(der); - r = crypto::generate_key_derivation(tx_pub_key, b_keys.m_view_secret_key, der); + r = crypto::generate_key_derivation(tx_pub_key, b_keys.view_secret_key, der); LOC_CHK(r, "generate_key_derivation failed"); uint64_t total_outputs_amount = 0, outputs_to_B_amount = 0; for (size_t i = 0; i != tx.vout.size(); ++i) diff --git a/src/wallet/wallet_helpers.h b/src/wallet/wallet_helpers.h index 365890da..be227c62 100644 --- a/src/wallet/wallet_helpers.h +++ b/src/wallet/wallet_helpers.h @@ -15,7 +15,7 @@ namespace tools { wi = AUTO_VAL_INIT_T(view::wallet_info); wi.address = w.get_account().get_public_address_str(); - wi.tracking_hey = epee::string_tools::pod_to_hex(w.get_account().get_keys().m_view_secret_key); + wi.tracking_hey = epee::string_tools::pod_to_hex(w.get_account().get_keys().view_secret_key); uint64_t fake = 0; wi.balance = w.balance(wi.unlocked_balance, fake, fake, wi.mined_total); wi.path = epee::string_encoding::wstring_to_utf8(w.get_wallet_path()); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index e4d3fb67..040ef071 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -293,7 +293,7 @@ namespace tools if (req.push_payer) { currency::tx_payer txp = AUTO_VAL_INIT(txp); - txp.acc_addr = m_wallet.get_account().get_keys().m_account_address; + txp.acc_addr = m_wallet.get_account().get_keys().account_address; extra.push_back(txp); } if (!req.hide_receiver) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index ec505ff6..019b7ca9 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1201,7 +1201,7 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par if (tp.push_payer) { currency::tx_payer txp = AUTO_VAL_INIT(txp); - txp.acc_addr = w->get()->get_account().get_keys().m_account_address; + txp.acc_addr = w->get()->get_account().get_keys().account_address; extra.push_back(txp); } if (!tp.hide_receiver) From 5724cd969c88058f17ae964d33ceba7dbae84c8b Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 11:12:17 +0300 Subject: [PATCH 05/16] clean up --- src/currency_core/currency_format_utils.h | 75 +---------------------- 1 file changed, 1 insertion(+), 74 deletions(-) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 4405b24d..ae76dc55 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -47,9 +47,6 @@ - - - namespace currency { bool operator ==(const currency::transaction& a, const currency::transaction& b); @@ -57,9 +54,8 @@ namespace currency bool operator ==(const currency::extra_attachment_info& a, const currency::extra_attachment_info& b); - typedef boost::multiprecision::uint128_t uint128_tl; - + struct tx_extra_info { @@ -71,72 +67,6 @@ namespace currency }; //--------------------------------------------------------------------------------------------------------------- - struct genesis_payment_entry - { - std::string paid_prm; - std::string prm_usd_price; - std::string paid_xmr; - std::string xmr_usd_price; - std::string paid_qtum; - std::string qtum_usd_price; - std::string paid_bch; - std::string bch_usd_price; - std::string paid_rep; - std::string rep_usd_price; - std::string paid_dash; - std::string dash_usd_price; - std::string paid_ltc; - std::string ltc_usd_price; - std::string paid_eos; - std::string eos_usd_price; - std::string paid_eth; - std::string eth_usd_price; - std::string paid_btc; - std::string btc_usd_price; - std::string address_this; - double amount_this_coin_fl; - double amount_this_coin_int; - std::string this_usd_price; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(paid_prm) - KV_SERIALIZE(prm_usd_price) - KV_SERIALIZE(paid_xmr) - KV_SERIALIZE(xmr_usd_price) - KV_SERIALIZE(paid_qtum) - KV_SERIALIZE(qtum_usd_price) - KV_SERIALIZE(paid_bch) - KV_SERIALIZE(bch_usd_price) - KV_SERIALIZE(paid_rep) - KV_SERIALIZE(rep_usd_price) - KV_SERIALIZE(paid_dash) - KV_SERIALIZE(dash_usd_price) - KV_SERIALIZE(paid_ltc) - KV_SERIALIZE(ltc_usd_price) - KV_SERIALIZE(paid_eos) - KV_SERIALIZE(eos_usd_price) - KV_SERIALIZE(paid_eth) - KV_SERIALIZE(eth_usd_price) - KV_SERIALIZE(paid_btc) - KV_SERIALIZE(btc_usd_price) - KV_SERIALIZE(address_this) - KV_SERIALIZE_N(amount_this_coin_fl, "amount_this") - KV_SERIALIZE(this_usd_price) - END_KV_SERIALIZE_MAP() - }; - struct genesis_config_json_struct - { - std::list payments; - std::string proof_string; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(payments) - KV_SERIALIZE(proof_string) - END_KV_SERIALIZE_MAP() - }; - - - //--------------------------------------------------------------- bool construct_miner_tx(size_t height, size_t median_size, const boost::multiprecision::uint128_t& already_generated_coins, size_t current_block_size, uint64_t fee, @@ -615,6 +545,3 @@ namespace currency } // namespace currency - - - From 145dd6b024493295bba172bda3afd70fe4f8c2c0 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 14:56:03 +0300 Subject: [PATCH 06/16] unit_tests fixed --- tests/core_tests/chaingen.h | 10 +++++----- tests/core_tests/chaingen_helpers.h | 4 ++-- tests/unit_tests/base58.cpp | 8 ++++---- tests/unit_tests/test_format_utils.cpp | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 7c8367a1..b5ce2d0d 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -900,10 +900,10 @@ namespace crypto { return o << "account: " << std::endl << " addr: " << get_account_address_as_str(acc.get_public_address()) << std::endl << - " spend secret key: " << acc.get_keys().m_spend_secret_key << std::endl << - " spend public key: " << acc.get_public_address().m_spend_public_key << std::endl << - " view secret key: " << acc.get_keys().m_view_secret_key << std::endl << - " view public key: " << acc.get_public_address().m_view_public_key << std::endl << + " spend secret key: " << acc.get_keys().spend_secret_key << std::endl << + " spend public key: " << acc.get_public_address().spend_public_key << std::endl << + " view secret key: " << acc.get_keys().view_secret_key << std::endl << + " view public key: " << acc.get_public_address().view_public_key << std::endl << " timestamp: " << acc.get_createtime(); } } @@ -1140,7 +1140,7 @@ void append_vector_by_another_vector(U& dst, const V& src) #define MAKE_MINER_TX_AND_KEY_MANUALLY(TX, PREV_BLOCK, P_KEYPAIR) \ transaction TX; \ if (!construct_miner_tx_manually(get_block_height(PREV_BLOCK) + 1, generator.get_already_generated_coins(PREV_BLOCK), \ - miner_account.get_keys().m_account_address, TX, 0, P_KEYPAIR)) \ + miner_account.get_keys().account_address, TX, 0, P_KEYPAIR)) \ return false; #define MAKE_MINER_TX_MANUALLY(TX, PREV_BLOCK) MAKE_MINER_TX_AND_KEY_MANUALLY(TX, PREV_BLOCK, nullptr) diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index fcd77038..958085ac 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -193,9 +193,9 @@ inline bool resign_tx(const currency::account_keys& sender_keys, const std::vect crypto::secret_key in_ephemeral_sec = AUTO_VAL_INIT(in_ephemeral_sec); crypto::key_derivation recv_derivation = AUTO_VAL_INIT(recv_derivation); - if (!crypto::generate_key_derivation(se.real_out_tx_key, sender_keys.m_view_secret_key, recv_derivation)) + if (!crypto::generate_key_derivation(se.real_out_tx_key, sender_keys.view_secret_key, recv_derivation)) return false; - crypto::derive_secret_key(recv_derivation, se.real_output_in_tx_index, sender_keys.m_spend_secret_key, in_ephemeral_sec); + crypto::derive_secret_key(recv_derivation, se.real_output_in_tx_index, sender_keys.spend_secret_key, in_ephemeral_sec); tx.signatures.push_back(std::vector()); std::vector& sigs = tx.signatures.back(); diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp index 482d86cd..d55c9a74 100644 --- a/tests/unit_tests/base58.cpp +++ b/tests/unit_tests/base58.cpp @@ -518,8 +518,8 @@ TEST(integ_address, payment_id_sizes) crypto::generate_random_bytes(pid_size, &payment_id.front()); currency::account_public_address addr; - addr.m_spend_public_key = currency::keypair::generate().pub; - addr.m_view_public_key = currency::keypair::generate().pub; + addr.spend_public_key = currency::keypair::generate().pub; + addr.view_public_key = currency::keypair::generate().pub; std::string addr_str = currency::get_account_address_and_payment_id_as_str(addr, payment_id); @@ -538,8 +538,8 @@ TEST(integ_address, payment_id_sizes) crypto::generate_random_bytes(pid_size, &payment_id.front()); currency::account_public_address addr; - addr.m_spend_public_key = currency::keypair::generate().pub; - addr.m_view_public_key = currency::keypair::generate().pub; + addr.spend_public_key = currency::keypair::generate().pub; + addr.view_public_key = currency::keypair::generate().pub; // the following line is expected to handle oversized payment id well std::string addr_str = currency::get_account_address_and_payment_id_as_str(addr, payment_id); diff --git a/tests/unit_tests/test_format_utils.cpp b/tests/unit_tests/test_format_utils.cpp index 39b40816..44f47e9b 100644 --- a/tests/unit_tests/test_format_utils.cpp +++ b/tests/unit_tests/test_format_utils.cpp @@ -14,7 +14,7 @@ TEST(parse_and_validate_tx_extra, is_correct_parse_and_validate_tx_extra) currency::account_base acc; acc.generate(); currency::blobdata b = "dsdsdfsdfsf"; - bool r = currency::construct_miner_tx(0, 0, 10000000000000, 1000, TESTS_DEFAULT_FEE, acc.get_keys().m_account_address, acc.get_keys().m_account_address, tx, b, 1); + bool r = currency::construct_miner_tx(0, 0, 10000000000000, 1000, TESTS_DEFAULT_FEE, acc.get_keys().account_address, acc.get_keys().account_address, tx, b, 1); ASSERT_TRUE(r); crypto::public_key tx_pub_key; r = currency::parse_and_validate_tx_extra(tx, tx_pub_key); @@ -26,7 +26,7 @@ TEST(parse_and_validate_tx_extra, is_correct_extranonce_too_big) currency::account_base acc; acc.generate(); currency::blobdata b(260, 0); - bool r = currency::construct_miner_tx(0, 0, 10000000000000, 1000, TESTS_DEFAULT_FEE, acc.get_keys().m_account_address, acc.get_keys().m_account_address, tx, b, 1); + bool r = currency::construct_miner_tx(0, 0, 10000000000000, 1000, TESTS_DEFAULT_FEE, acc.get_keys().account_address, acc.get_keys().account_address, tx, b, 1); ASSERT_FALSE(r); } @@ -90,8 +90,8 @@ void force_random(forced_to_pod_t& o) // currency::tx_extra_info ei = AUTO_VAL_INIT(ei); // bool r = parse_and_validate_tx_extra(miner_tx, ei); // ASSERT_TRUE(r); -// if(!(ei.m_alias.m_address.m_spend_public_key == alias.m_address.m_spend_public_key && -// ei.m_alias.m_address.m_view_public_key == alias.m_address.m_view_public_key && +// if(!(ei.m_alias.m_address.spend_public_key == alias.m_address.spend_public_key && +// ei.m_alias.m_address.view_public_key == alias.m_address.view_public_key && // ei.m_alias.m_alias == alias.m_alias && // ei.m_alias.m_sign == alias.m_sign && // ei.m_alias.m_text_comment == alias.m_text_comment && @@ -110,8 +110,8 @@ void force_random(forced_to_pod_t& o) // ei = AUTO_VAL_INIT(ei); // r = parse_and_validate_tx_extra(miner_tx, ei); // ASSERT_TRUE(r); -// if (!(ei.m_alias.m_address.m_spend_public_key == alias.m_address.m_spend_public_key && -// ei.m_alias.m_address.m_view_public_key == alias.m_address.m_view_public_key && +// if (!(ei.m_alias.m_address.spend_public_key == alias.m_address.spend_public_key && +// ei.m_alias.m_address.view_public_key == alias.m_address.view_public_key && // ei.m_alias.m_alias == alias.m_alias && // ei.m_alias.m_sign == alias.m_sign && // ei.m_alias.m_text_comment == alias.m_text_comment && From f532e4637e551d0d26cb042098431e11616fa880 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 15:41:40 +0300 Subject: [PATCH 07/16] coretests fixed --- tests/core_tests/alias_tests.cpp | 96 +++++++++---------- tests/core_tests/block_validation.cpp | 8 +- tests/core_tests/chaingen.cpp | 43 +++++---- tests/core_tests/chaingen.h | 5 +- tests/core_tests/double_spend.inl | 2 +- tests/core_tests/escrow_wallet_common.h | 18 ++-- tests/core_tests/hard_fork_1.cpp | 14 +-- .../core_tests/hard_fork_1_bad_pos_source.cpp | 4 +- .../core_tests/hard_fork_1_consensus_test.cpp | 4 +- .../hard_fork_1_locked_pos_test.cpp | 4 +- tests/core_tests/integer_overflow.cpp | 4 +- tests/core_tests/multisig_wallet_tests.cpp | 4 +- tests/core_tests/pos_block_builder.cpp | 8 +- tests/core_tests/pos_validation.cpp | 2 +- tests/core_tests/transaction_tests.cpp | 14 +-- tests/core_tests/tx_builder.h | 10 +- tests/core_tests/tx_validation.cpp | 2 +- tests/core_tests/wallet_tests.cpp | 16 ++-- 18 files changed, 133 insertions(+), 125 deletions(-) diff --git a/tests/core_tests/alias_tests.cpp b/tests/core_tests/alias_tests.cpp index ac974d0a..81d9a219 100644 --- a/tests/core_tests/alias_tests.cpp +++ b/tests/core_tests/alias_tests.cpp @@ -44,7 +44,7 @@ bool put_alias_via_tx_to_list(std::vector& events, ex.push_back(ai2); account_base reward_acc; account_keys& ak = const_cast(reward_acc.get_keys()); - currency::get_aliases_reward_account(ak.m_account_address, ak.m_view_secret_key); + currency::get_aliases_reward_account(ak.account_address, ak.view_secret_key); uint64_t fee_median = generator.get_last_n_blocks_fee_median(get_block_hash(head_block)); uint64_t reward = currency::get_alias_coast_from_fee(ai2.m_alias, fee_median); @@ -80,7 +80,7 @@ bool put_alias_via_tx_to_list(std::vector& events, { currency::extra_alias_entry ai2 = AUTO_VAL_INIT(ai2); ai2.m_alias = alias_name; - ai2.m_address = alias_acc.get_keys().m_account_address; + ai2.m_address = alias_acc.get_keys().account_address; ai2.m_text_comment = "ssdss"; return put_alias_via_tx_to_list(events, tx_set, head_block, miner_acc, ai2, generator); } @@ -112,7 +112,7 @@ bool put_next_block_with_alias_in_tx(std::vector& events, { currency::extra_alias_entry ai2 = AUTO_VAL_INIT(ai2); ai2.m_alias = alias_name; - ai2.m_address = alias_acc.get_keys().m_account_address; + ai2.m_address = alias_acc.get_keys().account_address; ai2.m_text_comment = "ssdss"; return put_next_block_with_alias_in_tx(events, b, head_block, miner_acc, ai2, generator); @@ -171,13 +171,13 @@ bool gen_alias_tests::generate(std::vector& events) const currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = FIRST_ALIAS_NAME; ai.m_text_comment = "first@first.com blablabla"; - ai.m_address = first_acc.get_keys().m_account_address; + ai.m_address = first_acc.get_keys().account_address; MAKE_BLOCK_WITH_ALIAS_INFO_IN_TX(events, blk_2, blk_1, miner_account, ai); // 4N+7,4N+8 DO_CALLBACK(events, "check_first_alias_added"); // 4N+9 ai.m_alias = SECOND_ALIAS_NAME; ai.m_text_comment = "second@second.com blablabla"; - ai.m_address = second_acc.get_keys().m_account_address; + ai.m_address = second_acc.get_keys().account_address; MAKE_BLOCK_WITH_ALIAS_INFO_IN_TX(events, blk_3, blk_2, miner_account, ai); // 4N+10,4N+11 DO_CALLBACK(events, "check_second_alias_added"); // 4N+12 @@ -195,9 +195,9 @@ bool gen_alias_tests::generate(std::vector& events) const currency::extra_alias_entry ai_upd = AUTO_VAL_INIT(ai_upd); ai_upd.m_alias = FIRST_ALIAS_NAME; - ai_upd.m_address =third_acc.get_keys().m_account_address; + ai_upd.m_address =third_acc.get_keys().account_address; ai_upd.m_text_comment = "changed alias haha"; - r = sign_extra_alias_entry(ai_upd, first_acc.get_keys().m_account_address.m_spend_public_key, first_acc.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai_upd, first_acc.get_keys().account_address.spend_public_key, first_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "failed to sign update_alias"); MAKE_BLOCK_WITH_ALIAS_INFO_IN_TX(events, blk_6, blk_5, miner_account, ai_upd); // 4N+20,N+21 DO_CALLBACK(events, "check_alias_changed"); // 4N+22 @@ -205,9 +205,9 @@ bool gen_alias_tests::generate(std::vector& events) const //try to make fake alias change currency::extra_alias_entry ai_upd_fake = AUTO_VAL_INIT(ai_upd_fake); ai_upd_fake.m_alias = SECOND_ALIAS_NAME; - ai_upd_fake.m_address =third_acc.get_keys().m_account_address; + ai_upd_fake.m_address =third_acc.get_keys().account_address; ai_upd_fake.m_text_comment = "changed alias haha"; - r = sign_extra_alias_entry(ai_upd_fake, second_acc.get_keys().m_account_address.m_spend_public_key, second_acc.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai_upd_fake, second_acc.get_keys().account_address.spend_public_key, second_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "failed to sign update_alias"); ai_upd_fake.m_text_comment = "changed alias haha - fake"; // changed text, signature became wrong std::list tx_list; @@ -283,8 +283,8 @@ bool gen_alias_tests::check_first_alias_added(currency::core& c, size_t ev_index currency::extra_alias_entry_base ai = AUTO_VAL_INIT(ai); bool r = c.get_blockchain_storage().get_alias_info(FIRST_ALIAS_NAME, ai); CHECK_AND_ASSERT_MES(r, false, "first alias name check failed"); - CHECK_AND_ASSERT_MES(ai.m_address.m_spend_public_key == first_acc.get_keys().m_account_address.m_spend_public_key - && ai.m_address.m_view_public_key == first_acc.get_keys().m_account_address.m_view_public_key, false, "first alias name check failed"); + CHECK_AND_ASSERT_MES(ai.m_address.spend_public_key == first_acc.get_keys().account_address.spend_public_key + && ai.m_address.view_public_key == first_acc.get_keys().account_address.view_public_key, false, "first alias name check failed"); return true; } bool gen_alias_tests::check_second_alias_added(currency::core& c, size_t ev_index, const std::vector& events) @@ -294,8 +294,8 @@ bool gen_alias_tests::check_second_alias_added(currency::core& c, size_t ev_inde currency::extra_alias_entry_base ai = AUTO_VAL_INIT(ai); bool r = c.get_blockchain_storage().get_alias_info(SECOND_ALIAS_NAME, ai); CHECK_AND_ASSERT_MES(r, false, "first alias name check failed"); - CHECK_AND_ASSERT_MES(ai.m_address.m_spend_public_key == second_acc.get_keys().m_account_address.m_spend_public_key - && ai.m_address.m_view_public_key == second_acc.get_keys().m_account_address.m_view_public_key, false, "second alias name check failed"); + CHECK_AND_ASSERT_MES(ai.m_address.spend_public_key == second_acc.get_keys().account_address.spend_public_key + && ai.m_address.view_public_key == second_acc.get_keys().account_address.view_public_key, false, "second alias name check failed"); return true; } @@ -352,8 +352,8 @@ bool gen_alias_tests::check_alias_changed(currency::core& c, size_t ev_index, co currency::extra_alias_entry_base ai = AUTO_VAL_INIT(ai); bool r = c.get_blockchain_storage().get_alias_info(FIRST_ALIAS_NAME, ai); CHECK_AND_ASSERT_MES(r, false, "first alias name check failed"); - CHECK_AND_ASSERT_MES(ai.m_address.m_spend_public_key == third_acc.get_keys().m_account_address.m_spend_public_key - && ai.m_address.m_view_public_key == third_acc.get_keys().m_account_address.m_view_public_key, false, "first alias update name check failed"); + CHECK_AND_ASSERT_MES(ai.m_address.spend_public_key == third_acc.get_keys().account_address.spend_public_key + && ai.m_address.view_public_key == third_acc.get_keys().account_address.view_public_key, false, "first alias update name check failed"); return true; } @@ -452,10 +452,10 @@ bool gen_alias_strange_data::generate(std::vector& events) con // empty comment currency::extra_alias_entry ai_upd = AUTO_VAL_INIT(ai_upd); ai_upd.m_alias = ai.m_alias; - ai_upd.m_address.m_spend_public_key = null_pkey; - ai_upd.m_address.m_view_public_key = null_pkey; + ai_upd.m_address.spend_public_key = null_pkey; + ai_upd.m_address.view_public_key = null_pkey; ai_upd.m_text_comment = ""; - r = sign_extra_alias_entry(ai_upd, m_alice.get_public_address().m_spend_public_key, m_alice.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai_upd, m_alice.get_public_address().spend_public_key, m_alice.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "failed to sign update_alias"); MAKE_BLOCK_WITH_ALIAS_INFO_IN_TX(events, blk_2, blk_1, miner_acc, ai_upd); @@ -468,14 +468,14 @@ bool gen_alias_strange_data::generate(std::vector& events) con ai.m_alias = std::string(255, 'x'); ai.m_text_comment = std::string(255, 'c'); ai.m_address = m_alice.get_public_address(); - ai.m_view_key.push_back(m_alice.get_keys().m_view_secret_key); + ai.m_view_key.push_back(m_alice.get_keys().view_secret_key); r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); MAKE_NEXT_BLOCK_TX_LIST(events, blk_3, blk_2, miner_acc, tx_list); tx_list.clear(); ai.m_text_comment = std::string(255, '\0'); - r = sign_extra_alias_entry(ai, m_alice.get_public_address().m_spend_public_key, m_alice.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai, m_alice.get_public_address().spend_public_key, m_alice.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -489,7 +489,7 @@ bool gen_alias_strange_data::check_alias_changed(currency::core& c, size_t ev_in currency::extra_alias_entry ai; bool r = c.get_blockchain_storage().get_alias_info(std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'), ai); CHECK_AND_ASSERT_MES(r, false, "get_alias_info failed"); - CHECK_AND_ASSERT_MES(ai.m_address.m_spend_public_key == null_pkey && ai.m_address.m_view_public_key == null_pkey, false, "alias didn't change"); + CHECK_AND_ASSERT_MES(ai.m_address.spend_public_key == null_pkey && ai.m_address.view_public_key == null_pkey, false, "alias didn't change"); return true; } @@ -519,13 +519,13 @@ bool gen_alias_concurrency_with_switch::generate(std::vector& ai.m_text_comment = ""; ai.m_address = miner_acc.get_public_address(); //ai.m_address = *reinterpret_cast(invalid_addr); - ai.m_view_key.push_back(miner_acc.get_keys().m_view_secret_key); + ai.m_view_key.push_back(miner_acc.get_keys().view_secret_key); bool r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); // 2nd std::list tx_list2; - ai.m_address.m_spend_public_key = null_pkey, ai.m_address.m_view_public_key = null_pkey; + ai.m_address.spend_public_key = null_pkey, ai.m_address.view_public_key = null_pkey; DO_CALLBACK(events, "mark_invalid_tx"); // because tx with a duplicate alias request (?) r = put_alias_via_tx_to_list(events, tx_list2, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -557,7 +557,7 @@ bool gen_alias_concurrency_with_switch::check_alias(currency::core& c, size_t ev currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); bool r = c.get_blockchain_storage().get_alias_info(std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'), ai); CHECK_AND_ASSERT_MES(r, false, "get_alias_info failed"); - CHECK_AND_ASSERT_MES(ai.m_address.m_spend_public_key == null_pkey && ai.m_address.m_view_public_key == null_pkey, false, "wrong alias"); + CHECK_AND_ASSERT_MES(ai.m_address.spend_public_key == null_pkey && ai.m_address.view_public_key == null_pkey, false, "wrong alias"); return true; } @@ -579,12 +579,12 @@ bool gen_alias_same_alias_in_tx_pool::generate(std::vector& ev currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'); ai.m_address = miner_acc.get_public_address(); - ai.m_view_key.push_back(miner_acc.get_keys().m_view_secret_key); + ai.m_view_key.push_back(miner_acc.get_keys().view_secret_key); bool r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); - ai.m_address.m_spend_public_key = null_pkey, ai.m_address.m_view_public_key = null_pkey; - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + ai.m_address.spend_public_key = null_pkey, ai.m_address.view_public_key = null_pkey; + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); DO_CALLBACK(events, "mark_invalid_tx"); // because tx with a duplicate alias request r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); @@ -597,14 +597,14 @@ bool gen_alias_same_alias_in_tx_pool::generate(std::vector& ev // 2. add to the pool two txs: 1) update previously registered alias 2) update it once again tx_list.clear(); - ai.m_address.m_spend_public_key = miner_acc.get_public_address().m_spend_public_key; - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + ai.m_address.spend_public_key = miner_acc.get_public_address().spend_public_key; + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); ai.m_text_comment = "Oops, I forgot a comment!"; - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); DO_CALLBACK(events, "mark_invalid_tx"); // because tx with a duplicate alias request r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); @@ -653,7 +653,7 @@ bool gen_alias_switch_and_tx_pool::generate(std::vector& event currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'); ai.m_address = miner_acc.get_public_address(); - ai.m_view_key.push_back(miner_acc.get_keys().m_view_secret_key); + ai.m_view_key.push_back(miner_acc.get_keys().view_secret_key); bool r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -663,8 +663,8 @@ bool gen_alias_switch_and_tx_pool::generate(std::vector& event // 2. update the alias tx_list.clear(); - ai.m_address.m_spend_public_key = null_pkey, ai.m_address.m_view_public_key = null_pkey; - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + ai.m_address.spend_public_key = null_pkey, ai.m_address.view_public_key = null_pkey; + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); r = put_alias_via_tx_to_list(events, tx_list, blk_0r, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -682,7 +682,7 @@ bool gen_alias_switch_and_tx_pool::generate(std::vector& event ai = AUTO_VAL_INIT(ai); ai.m_alias = std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'); ai.m_address = alice.get_public_address(); - ai.m_view_key.push_back(alice.get_keys().m_view_secret_key); + ai.m_view_key.push_back(alice.get_keys().view_secret_key); DO_CALLBACK(events, "mark_invalid_tx"); // tx is rejected, because tx pool already has tx with reg/upd this alias r = put_alias_via_tx_to_list(events, tx_list, blk_4, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -708,7 +708,7 @@ bool gen_alias_switch_and_tx_pool::check_alias(currency::core& c, size_t ev_inde currency::extra_alias_entry_base ai; bool r = c.get_blockchain_storage().get_alias_info(alias_name, ai); CHECK_AND_ASSERT_MES(r, false, "get_alias_info failed"); - CHECK_AND_ASSERT_MES(ai.m_address == alice.get_public_address() && !ai.m_view_key.empty() && ai.m_view_key.front() == alice.get_keys().m_view_secret_key, false, "wrong alias"); + CHECK_AND_ASSERT_MES(ai.m_address == alice.get_public_address() && !ai.m_view_key.empty() && ai.m_view_key.front() == alice.get_keys().view_secret_key, false, "wrong alias"); return true; } @@ -740,7 +740,7 @@ bool gen_alias_update_after_addr_changed::generate(std::vector tx_list.clear(); ai.m_text_comment = "upd1"; ai.m_address = alice.get_public_address(); - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); r = put_alias_via_tx_to_list(events, tx_list, blk_1, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -750,7 +750,7 @@ bool gen_alias_update_after_addr_changed::generate(std::vector // try to update the alias on behalf of miner (should fail because it must be alice who can sign it) tx_list.clear(); ai.m_text_comment = "upd2"; - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); r = put_alias_via_tx_to_list(events, tx_list, blk_2, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -765,7 +765,7 @@ bool gen_alias_update_after_addr_changed::generate(std::vector // try to update the alias on behalf of alice (should be ok) tx_list.clear(); ai.m_address = miner_acc.get_public_address(); - r = sign_extra_alias_entry(ai, alice.get_public_address().m_spend_public_key, alice.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai, alice.get_public_address().spend_public_key, alice.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); r = put_alias_via_tx_to_list(events, tx_list, blk_2, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -775,7 +775,7 @@ bool gen_alias_update_after_addr_changed::generate(std::vector // try to change the alias on behalf on alice again (should fail) tx_list.clear(); ai.m_text_comment = "upd3"; - r = sign_extra_alias_entry(ai, alice.get_public_address().m_spend_public_key, alice.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai, alice.get_public_address().spend_public_key, alice.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); r = put_alias_via_tx_to_list(events, tx_list, blk_3, miner_acc, ai, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); @@ -887,7 +887,7 @@ bool gen_alias_blocking_update_by_invalid_tx::generate(std::vector& events) extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'); ai.m_address = miner_acc.get_public_address(); - ai.m_view_key.push_back(miner_acc.get_keys().m_view_secret_key); + ai.m_view_key.push_back(miner_acc.get_keys().view_secret_key); std::vector extra; extra.push_back(ai); @@ -994,7 +994,7 @@ bool gen_alias_too_much_reward::check_alias(currency::core& c, size_t ev_index, currency::extra_alias_entry_base ai; bool r = c.get_blockchain_storage().get_alias_info(std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'), ai); CHECK_AND_ASSERT_MES(r, false, "get_alias_info failed"); - CHECK_AND_ASSERT_MES(ai.m_address == miner_acc.get_public_address() && ai.m_view_key.size() == 1 && ai.m_view_key.front() == miner_acc.get_keys().m_view_secret_key, false, "wrong alias"); + CHECK_AND_ASSERT_MES(ai.m_address == miner_acc.get_public_address() && ai.m_view_key.size() == 1 && ai.m_view_key.front() == miner_acc.get_keys().view_secret_key, false, "wrong alias"); return true; } @@ -1111,7 +1111,7 @@ bool gen_alias_too_small_reward::make_tx_reg_alias(std::vector extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = alias; ai.m_address = alias_addr; - ai.m_view_key.push_back(miner_acc.get_keys().m_view_secret_key); + ai.m_view_key.push_back(miner_acc.get_keys().view_secret_key); if (alias.size() < ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED) @@ -1168,7 +1168,7 @@ bool gen_alias_too_small_reward::check_alias(currency::core& c, size_t ev_index, r = c.get_blockchain_storage().get_alias_info(ae.name, ai); CHECK_AND_ASSERT_MES(r, false, "get_alias_info failed"); - CHECK_AND_ASSERT_MES(ai.m_address == ae.addr && ai.m_view_key.size() == 1 && ai.m_view_key.front() == miner_acc.get_keys().m_view_secret_key, false, "wrong alias registration: " << ae.name); + CHECK_AND_ASSERT_MES(ai.m_address == ae.addr && ai.m_view_key.size() == 1 && ai.m_view_key.front() == miner_acc.get_keys().view_secret_key, false, "wrong alias registration: " << ae.name); return true; } @@ -1261,7 +1261,7 @@ bool gen_alias_switch_and_check_block_template::generate(std::vector extra(1, ai); @@ -1443,7 +1443,7 @@ bool gen_alias_update_for_free::generate(std::vector& events) // update the alias - pay nothing ai.m_text_comment = "miner@mail.com"; - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); std::vector extra(1, ai); @@ -1505,8 +1505,8 @@ bool gen_alias_in_coinbase::generate(std::vector& events) cons // update an alias using coinbase ai.m_text_comment = "A Party member is expected to have no private emotions and no respites from enthusiasm."; - ai.m_view_key.push_back(miner_acc.get_keys().m_view_secret_key); - r = sign_extra_alias_entry(ai, miner_acc.get_public_address().m_spend_public_key, miner_acc.get_keys().m_spend_secret_key); + ai.m_view_key.push_back(miner_acc.get_keys().view_secret_key); + r = sign_extra_alias_entry(ai, miner_acc.get_public_address().spend_public_key, miner_acc.get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); block blk_2 = AUTO_VAL_INIT(blk_2); diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index 9e65c8ec..5be9160f 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -320,7 +320,7 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector& events sources.push_back(se); tx_destination_entry de = AUTO_VAL_INIT(de); - de.addr.push_back(miner_account.get_keys().m_account_address); + de.addr.push_back(miner_account.get_keys().account_address); de.amount = se.amount; std::vector destinations; destinations.push_back(de); @@ -363,7 +363,7 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector sources.push_back(se); tx_destination_entry de = AUTO_VAL_INIT(de); - de.addr.push_back(miner_account.get_keys().m_account_address); + de.addr.push_back(miner_account.get_keys().account_address); de.amount = se.amount; std::vector destinations; destinations.push_back(de); @@ -444,8 +444,8 @@ bool gen_block_miner_tx_has_out_to_alice::generate(std::vector crypto::key_derivation derivation; crypto::public_key out_eph_public_key; - crypto::generate_key_derivation(alice.get_keys().m_account_address.m_view_public_key, txkey.sec, derivation); - crypto::derive_public_key(derivation, 1, alice.get_keys().m_account_address.m_spend_public_key, out_eph_public_key); + crypto::generate_key_derivation(alice.get_keys().account_address.view_public_key, txkey.sec, derivation); + crypto::derive_public_key(derivation, 1, alice.get_keys().account_address.spend_public_key, out_eph_public_key); tx_out out_to_alice; out_to_alice.amount = miner_tx.vout[0].amount / 2; diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 471af00f..4093e710 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -48,17 +48,23 @@ crypto::signature create_invalid_signature() const crypto::signature invalid_signature = create_invalid_signature(); test_generator::test_generator() - : m_wallet_test_core_proxy(new wallet_test_core_proxy()), - m_do_pos_to_low_timestamp(false), - m_ignore_last_pow_in_wallets(false), - m_last_found_timestamp(0), - m_hardfork_after_heigh(CURRENCY_MAX_BLOCK_NUMBER) + : m_wallet_test_core_proxy(new wallet_test_core_proxy()) + , m_do_pos_to_low_timestamp(false) + , m_ignore_last_pow_in_wallets(false) + , m_last_found_timestamp(0) + , m_hardfork_01_after_heigh(CURRENCY_MAX_BLOCK_NUMBER) + , m_hardfork_02_after_heigh(CURRENCY_MAX_BLOCK_NUMBER) { } -void test_generator::set_hardfork_height(uint64_t h) +void test_generator::set_hardfork_height(size_t hardfork_id, uint64_t h) { - m_hardfork_after_heigh = h; + switch (hardfork_id) + { + case 1: m_hardfork_01_after_heigh = h; break; + case 2: m_hardfork_02_after_heigh = h; break; + default: CHECK_AND_ASSERT_THROW_MES(false, "invalid hardfork id: " << hardfork_id) + } } void test_generator::get_block_chain(std::vector& blockchain, const crypto::hash& head, size_t n) const @@ -203,7 +209,7 @@ bool test_generator::construct_block(currency::block& blk, const std::list& tx_list, const std::list& coin_stake_sources)//in case of PoS block { - if (height > m_hardfork_after_heigh) + if (height > m_hardfork_01_after_heigh) blk.major_version = CURRENT_BLOCK_MAJOR_VERSION; else blk.major_version = BLOCK_MAJOR_VERSION_INITAL; @@ -270,8 +276,8 @@ bool test_generator::construct_block(currency::block& blk, already_generated_coins, target_block_size, total_fee, - miner_acc.get_keys().m_account_address, - miner_acc.get_keys().m_account_address, + miner_acc.get_keys().account_address, + miner_acc.get_keys().account_address, blk.miner_tx, blobdata(), test_generator::get_test_gentime_settings().miner_tx_max_outs, @@ -400,7 +406,8 @@ bool test_generator::build_wallets(const blockchain_vector& blocks, currency::core_runtime_config pc = cc; pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; - pc.hard_fork1_starts_after_height = m_hardfork_after_heigh; + pc.hard_fork_01_starts_after_height = m_hardfork_01_after_heigh; + pc.hard_fork_02_starts_after_height = m_hardfork_02_after_heigh; wallets.back()->set_core_runtime_config(pc); } @@ -485,7 +492,7 @@ bool test_generator::find_kernel(const std::list& accs, uint64_t& found_timestamp, crypto::hash& found_kh) { - bool is_after_hardfork = blck_chain.size() > m_hardfork_after_heigh ? true : false; + bool is_after_hardfork_01 = blck_chain.size() > m_hardfork_01_after_heigh ? true : false; uint64_t median_timestamp = get_timestamps_median(blck_chain); wide_difficulty_type basic_diff = 0; @@ -1050,7 +1057,7 @@ bool init_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const { const transaction &tx = *vtx[i]; crypto::key_derivation derivation; - bool r = generate_key_derivation(get_tx_pub_key_from_extra(tx), acc_keys.m_view_secret_key, derivation); + bool r = generate_key_derivation(get_tx_pub_key_from_extra(tx), acc_keys.view_secret_key, derivation); CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed"); for (size_t j = 0; j < tx.vout.size(); ++j) @@ -1329,13 +1336,13 @@ bool fill_tx_sources_and_destinations(const std::vector& event if (minimum_sigs != SIZE_MAX) destinations.back().minimum_sigs = minimum_sigs; // set custom minimum_sigs only if != SIZE_MAX, use default in tx_destination_entry::ctor() otherwise if (cache_back > 0) - destinations.push_back(tx_destination_entry(cache_back, from.m_account_address)); + destinations.push_back(tx_destination_entry(cache_back, from.account_address)); } else { tx_destination_entry change_dst = AUTO_VAL_INIT(change_dst); if (cache_back > 0) - change_dst = tx_destination_entry(cache_back, from.m_account_address); + change_dst = tx_destination_entry(cache_back, from.account_address); std::vector dsts(1, tx_destination_entry(amount, to.back())); uint64_t dust = 0; const test_gentime_settings& tgs = test_generator::get_test_gentime_settings(); @@ -1417,8 +1424,8 @@ bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins crypto::key_derivation derivation; crypto::public_key out_eph_public_key; - crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation); - crypto::derive_public_key(derivation, 0, miner_address.m_spend_public_key, out_eph_public_key); + crypto::generate_key_derivation(miner_address.view_public_key, txkey.sec, derivation); + crypto::derive_public_key(derivation, 0, miner_address.spend_public_key, out_eph_public_key); tx_out out; out.amount = block_reward; @@ -1544,7 +1551,7 @@ bool construct_tx_with_many_outputs(std::vector& events, const uint64_t sources_amount = get_sources_total_amount(sources); if (sources_amount > total_amount + fee) - destinations.push_back(tx_destination_entry(sources_amount - (total_amount + fee), keys_from.m_account_address)); // change + destinations.push_back(tx_destination_entry(sources_amount - (total_amount + fee), keys_from.account_address)); // change return construct_tx(keys_from, sources, destinations, empty_attachment, tx, 0); } diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index b5ce2d0d..8351521c 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -524,14 +524,15 @@ public: static void set_test_gentime_settings_default() { m_test_gentime_settings = m_test_gentime_settings_default; } void set_pos_to_low_timestamp(bool do_pos_to_low_timestamp) { m_do_pos_to_low_timestamp = do_pos_to_low_timestamp; } void set_ignore_last_pow_in_wallets(bool ignore_last_pow_in_wallets) { m_ignore_last_pow_in_wallets = ignore_last_pow_in_wallets; } - void set_hardfork_height(uint64_t h); + void set_hardfork_height(size_t hardfork_id, uint64_t h); private: bool m_do_pos_to_low_timestamp; bool m_ignore_last_pow_in_wallets; uint64_t m_last_found_timestamp; - uint64_t m_hardfork_after_heigh; + uint64_t m_hardfork_01_after_heigh; + uint64_t m_hardfork_02_after_heigh; std::unordered_map m_blocks_info; static test_gentime_settings m_test_gentime_settings; diff --git a/tests/core_tests/double_spend.inl b/tests/core_tests/double_spend.inl index 57ab653e..8b50d334 100644 --- a/tests/core_tests/double_spend.inl +++ b/tests/core_tests/double_spend.inl @@ -88,7 +88,7 @@ bool gen_double_spend_in_tx::generate(std::vector destinations; destinations.push_back(de); diff --git a/tests/core_tests/escrow_wallet_common.h b/tests/core_tests/escrow_wallet_common.h index d7775cf5..25568bdb 100644 --- a/tests/core_tests/escrow_wallet_common.h +++ b/tests/core_tests/escrow_wallet_common.h @@ -186,29 +186,29 @@ inline bool build_custom_escrow_template(const std::vector& ev int64_t change = get_sources_total_amount(sources) - a_inputs_amount; CHECK_AND_ASSERT_MES(change >= 0, false, "fill_tx_sources failed (2)"); if (change > 0) - destinations.push_back(tx_destination_entry(change, a_keys.m_account_address)); + destinations.push_back(tx_destination_entry(change, a_keys.account_address)); if (custom_config_mask & eccf_template_no_multisig) - destinations.push_back(tx_destination_entry(ms_amount, a_keys.m_account_address)); // incorrect + destinations.push_back(tx_destination_entry(ms_amount, a_keys.account_address)); // incorrect else if (custom_config_mask & eccf_template_inv_multisig) - destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.m_account_address, a_keys.m_account_address }))); // incorrect + destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.account_address, a_keys.account_address }))); // incorrect else if (custom_config_mask & eccf_template_inv_multisig_2) { - destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.m_account_address, a_keys.m_account_address, a_keys.m_account_address }))); // incorrect + destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.account_address, a_keys.account_address, a_keys.account_address }))); // incorrect destinations.back().minimum_sigs = 2; // pretend to be correct } else if (custom_config_mask & eccf_template_inv_multisig_low_min_sig) { - destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.m_account_address, cpd.b_addr }))); // seems to be correct + destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.account_address, cpd.b_addr }))); // seems to be correct destinations.back().minimum_sigs = 1; // incorrect } else if (custom_config_mask & eccf_template_more_than_1_multisig) { - destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.m_account_address, cpd.b_addr }))); // seems to be correct - destinations.push_back(tx_destination_entry(TESTS_DEFAULT_FEE, std::list({ a_keys.m_account_address, cpd.b_addr }))); // double multisig - incorrect + destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.account_address, cpd.b_addr }))); // seems to be correct + destinations.push_back(tx_destination_entry(TESTS_DEFAULT_FEE, std::list({ a_keys.account_address, cpd.b_addr }))); // double multisig - incorrect } else - destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.m_account_address, cpd.b_addr }))); // truly correct + destinations.push_back(tx_destination_entry(ms_amount, std::list({ a_keys.account_address, cpd.b_addr }))); // truly correct tx_service_attachment sa = AUTO_VAL_INIT(sa); sa.service_id = BC_ESCROW_SERVICE_ID; @@ -302,7 +302,7 @@ inline bool build_custom_escrow_proposal(const std::vector& ev int64_t change = get_sources_total_amount(sources) - a_fee_proposal; CHECK_AND_ASSERT_MES(change >= 0, false, "fill_tx_sources failed (2)"); if (change > 0) - destinations.push_back(tx_destination_entry(change, a_keys.m_account_address)); + destinations.push_back(tx_destination_entry(change, a_keys.account_address)); account_public_address crypt_addr = cpd.b_addr; diff --git a/tests/core_tests/hard_fork_1.cpp b/tests/core_tests/hard_fork_1.cpp index ed278cba..9a6ff10a 100644 --- a/tests/core_tests/hard_fork_1.cpp +++ b/tests/core_tests/hard_fork_1.cpp @@ -35,7 +35,7 @@ bool hard_fork_1_base_test::configure_core(currency::core& c, size_t ev_index, c currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; - pc.hard_fork1_starts_after_height = m_hardfork_height; + pc.hard_fork_01_starts_after_height = m_hardfork_height; c.get_blockchain_storage().set_core_runtime_config(pc); return true; } @@ -57,7 +57,7 @@ bool hard_fork_1_unlock_time_2_in_normal_tx::generate(std::vector& GENERATE_ACCOUNT(miner_acc); GENERATE_ACCOUNT(alice_acc); MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); - generator.set_hardfork_height(m_hardfork_height); + generator.set_hardfork_height(1, m_hardfork_height); DO_CALLBACK(events, "configure_core"); REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); @@ -310,7 +310,7 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector& GENERATE_ACCOUNT(miner_acc); GENERATE_ACCOUNT(alice_acc); MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); - generator.set_hardfork_height(m_hardfork_height); + generator.set_hardfork_height(1, m_hardfork_height); DO_CALLBACK(events, "configure_core"); DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(2 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 7)); REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); @@ -477,7 +477,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e GENERATE_ACCOUNT(alice_acc); GENERATE_ACCOUNT(bob_acc); MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); - generator.set_hardfork_height(m_hardfork_height); + generator.set_hardfork_height(1, m_hardfork_height); DO_CALLBACK(events, "configure_core"); REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); @@ -699,7 +699,7 @@ bool hard_fork_1_pos_locked_height_vs_time::generate(std::vector& events) std::list miner_acc_lst(1, miner_acc); MAKE_GENESIS_BLOCK(events, blk_0, preminer_acc, 1564434616); - generator.set_hardfork_height(get_hardfork_height()); + generator.set_hardfork_height(1, get_hardfork_height()); DO_CALLBACK(events, "configure_core"); REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5); @@ -72,7 +72,7 @@ bool hard_fork_1_bad_pos_source::configure_core(currency::core& c, size_t ev_ind currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; //four blocks pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; //four blocks - pc.hard_fork1_starts_after_height = get_hardfork_height(); + pc.hard_fork_01_starts_after_height = get_hardfork_height(); c.get_blockchain_storage().set_core_runtime_config(pc); return true; diff --git a/tests/core_tests/hard_fork_1_consensus_test.cpp b/tests/core_tests/hard_fork_1_consensus_test.cpp index 60bafdb7..70c51342 100644 --- a/tests/core_tests/hard_fork_1_consensus_test.cpp +++ b/tests/core_tests/hard_fork_1_consensus_test.cpp @@ -29,7 +29,7 @@ bool hard_fork_1_cumulative_difficulty_base::generate(std::vector miner_acc_lst(1, miner_acc); MAKE_GENESIS_BLOCK(events, blk_0, preminer_acc, 1564434616); - generator.set_hardfork_height(get_hardfork_height()); + generator.set_hardfork_height(1, get_hardfork_height()); DO_CALLBACK(events, "configure_core"); REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); @@ -62,7 +62,7 @@ bool hard_fork_1_cumulative_difficulty_base::configure_core(currency::core& c, s currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; //four blocks pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; //four blocks - pc.hard_fork1_starts_after_height = get_hardfork_height(); + pc.hard_fork_01_starts_after_height = get_hardfork_height(); c.get_blockchain_storage().set_core_runtime_config(pc); return true; diff --git a/tests/core_tests/hard_fork_1_locked_pos_test.cpp b/tests/core_tests/hard_fork_1_locked_pos_test.cpp index 5c6696e9..dbb003d4 100644 --- a/tests/core_tests/hard_fork_1_locked_pos_test.cpp +++ b/tests/core_tests/hard_fork_1_locked_pos_test.cpp @@ -31,7 +31,7 @@ bool hard_fork_1_locked_mining_test::generate(std::vector& eve std::list miner_acc_lst(1, miner_acc); MAKE_GENESIS_BLOCK(events, blk_0, preminer_acc, 1564434616); - generator.set_hardfork_height(get_hardfork_height()); + generator.set_hardfork_height(1, get_hardfork_height()); DO_CALLBACK(events, "configure_core"); REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); @@ -103,7 +103,7 @@ bool hard_fork_1_locked_mining_test::configure_core(currency::core& c, size_t ev currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; //four blocks pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; //four blocks - pc.hard_fork1_starts_after_height = get_hardfork_height(); + pc.hard_fork_01_starts_after_height = get_hardfork_height(); c.get_blockchain_storage().set_core_runtime_config(pc); return true; diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp index 014d7302..858a2fb3 100644 --- a/tests/core_tests/integer_overflow.cpp +++ b/tests/core_tests/integer_overflow.cpp @@ -146,7 +146,7 @@ bool gen_uint_overflow_2::generate(std::vector& events) const } std::vector destinations; - const account_public_address& bob_addr = bob_account.get_keys().m_account_address; + const account_public_address& bob_addr = bob_account.get_keys().account_address; destinations.push_back(tx_destination_entry(TX_MAX_TRANSFER_AMOUNT, bob_addr)); destinations.push_back(tx_destination_entry(TX_MAX_TRANSFER_AMOUNT - 1, bob_addr)); // sources.front().amount = destinations[0].amount + destinations[2].amount + destinations[3].amount + TESTS_DEFAULT_FEE @@ -174,7 +174,7 @@ bool gen_uint_overflow_2::generate(std::vector& events) const destinations.clear(); currency::tx_destination_entry de; - de.addr.push_back(alice_account.get_keys().m_account_address); + de.addr.push_back(alice_account.get_keys().account_address); de.amount = TX_MAX_TRANSFER_AMOUNT - TESTS_DEFAULT_FEE; destinations.push_back(de); destinations.push_back(de); diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index c9990045..a796a04e 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -1370,10 +1370,10 @@ bool multisig_and_coinbase::generate(std::vector& events) cons for (auto& p : participants) { crypto::key_derivation der = AUTO_VAL_INIT(der); - r = crypto::generate_key_derivation(p.m_view_public_key, tx_key.sec, der); + r = crypto::generate_key_derivation(p.view_public_key, tx_key.sec, der); CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed"); crypto::public_key key = AUTO_VAL_INIT(key); - r = crypto::derive_public_key(der, multisig_out_idx, p.m_spend_public_key, key); + r = crypto::derive_public_key(der, multisig_out_idx, p.spend_public_key, key); CHECK_AND_ASSERT_MES(r, false, "derive_public_key failed"); ms_out_target.keys.push_back(key); } diff --git a/tests/core_tests/pos_block_builder.cpp b/tests/core_tests/pos_block_builder.cpp index 4127e948..44e1b3d8 100644 --- a/tests/core_tests/pos_block_builder.cpp +++ b/tests/core_tests/pos_block_builder.cpp @@ -163,11 +163,11 @@ void pos_block_builder::step5_sign(const crypto::public_key& stake_tx_pub_key, s CHECK_AND_ASSERT_THROW_MES(m_step == 4, "pos_block_builder: incorrect step sequence"); crypto::key_derivation pos_coin_derivation = AUTO_VAL_INIT(pos_coin_derivation); - bool r = crypto::generate_key_derivation(stake_tx_pub_key, stakeholder_account.get_keys().m_view_secret_key, pos_coin_derivation); // derivation(tx_pub; view_sec) + bool r = crypto::generate_key_derivation(stake_tx_pub_key, stakeholder_account.get_keys().view_secret_key, pos_coin_derivation); // derivation(tx_pub; view_sec) CHECK_AND_ASSERT_THROW_MES(r, "generate_key_derivation failed"); crypto::secret_key derived_secret_ephemeral_key = AUTO_VAL_INIT(derived_secret_ephemeral_key); - crypto::derive_secret_key(pos_coin_derivation, stake_tx_out_index, stakeholder_account.get_keys().m_spend_secret_key, derived_secret_ephemeral_key); // derivation.derive(spend_sec, out_idx) => input ephemeral secret key + crypto::derive_secret_key(pos_coin_derivation, stake_tx_out_index, stakeholder_account.get_keys().spend_secret_key, derived_secret_ephemeral_key); // derivation.derive(spend_sec, out_idx) => input ephemeral secret key // sign block actually in coinbase transaction crypto::hash block_hash = currency::get_block_hash(m_block); @@ -216,7 +216,7 @@ bool construct_homemade_pos_miner_tx(size_t height, size_t median_size, const bo } // reward - bool burn_money = reward_receiving_address.m_spend_public_key == null_pkey && reward_receiving_address.m_view_public_key == null_pkey; // if true, burn reward, so no one on Earth can spend them + bool burn_money = reward_receiving_address.spend_public_key == null_pkey && reward_receiving_address.view_public_key == null_pkey; // if true, burn reward, so no one on Earth can spend them for (size_t output_index = 0; output_index < out_amounts.size(); ++output_index) { txout_to_key tk; @@ -236,7 +236,7 @@ bool construct_homemade_pos_miner_tx(size_t height, size_t median_size, const bo } // stake - burn_money = stakeholder_address.m_spend_public_key == null_pkey && stakeholder_address.m_view_public_key == null_pkey; // if true, burn stake + burn_money = stakeholder_address.spend_public_key == null_pkey && stakeholder_address.view_public_key == null_pkey; // if true, burn stake { txout_to_key tk; tk.key = null_pkey; // null means burn money diff --git a/tests/core_tests/pos_validation.cpp b/tests/core_tests/pos_validation.cpp index d8d338c1..df2afe97 100644 --- a/tests/core_tests/pos_validation.cpp +++ b/tests/core_tests/pos_validation.cpp @@ -254,7 +254,7 @@ bool gen_pos_extra_nonce::generate(std::vector& events) const currency::blobdata extra_none(255, 'x'); currency::extra_alias_entry alias = AUTO_VAL_INIT(alias); alias.m_alias = std::string(255, 'a'); - alias.m_address = miner.get_keys().m_account_address; + alias.m_address = miner.get_keys().account_address; alias.m_text_comment = std::string(255, 'y'); pb.step4_generate_coinbase_tx(generator.get_timestamps_median(prev_id), generator.get_already_generated_coins(blk_0r), alice.get_public_address(), extra_none, CURRENCY_MINER_TX_MAX_OUTS, alias); pb.step5_sign(stake_tx_pub_key, stake_output_idx, stake_output_pubkey, miner); diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index d6809e20..02cd2a3c 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -39,17 +39,17 @@ bool test_transaction_generation_and_ring_signature() account_base rv_acc2; rv_acc2.generate(); transaction tx_mine_1; - construct_miner_tx(0, 0, 0, 10, 0, miner_acc1.get_keys().m_account_address, miner_acc1.get_keys().m_account_address, tx_mine_1); + construct_miner_tx(0, 0, 0, 10, 0, miner_acc1.get_keys().account_address, miner_acc1.get_keys().account_address, tx_mine_1); transaction tx_mine_2; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc2.get_keys().m_account_address, miner_acc2.get_keys().m_account_address, tx_mine_2); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc2.get_keys().account_address, miner_acc2.get_keys().account_address, tx_mine_2); transaction tx_mine_3; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc3.get_keys().m_account_address, miner_acc3.get_keys().m_account_address, tx_mine_3); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc3.get_keys().account_address, miner_acc3.get_keys().account_address, tx_mine_3); transaction tx_mine_4; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc4.get_keys().m_account_address, miner_acc4.get_keys().m_account_address, tx_mine_4); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc4.get_keys().account_address, miner_acc4.get_keys().account_address, tx_mine_4); transaction tx_mine_5; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc5.get_keys().m_account_address, miner_acc5.get_keys().m_account_address, tx_mine_5); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc5.get_keys().account_address, miner_acc5.get_keys().account_address, tx_mine_5); transaction tx_mine_6; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc6.get_keys().m_account_address, miner_acc6.get_keys().m_account_address, tx_mine_6); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc6.get_keys().account_address, miner_acc6.get_keys().account_address, tx_mine_6); //fill inputs entry typedef tx_source_entry::output_entry tx_output_entry; @@ -91,7 +91,7 @@ bool test_transaction_generation_and_ring_signature() } //fill outputs entry tx_destination_entry td; - td.addr.push_back(rv_acc.get_keys().m_account_address); + td.addr.push_back(rv_acc.get_keys().account_address); td.amount = 69368744177663; std::vector destinations; destinations.push_back(td); diff --git a/tests/core_tests/tx_builder.h b/tests/core_tests/tx_builder.h index 5ffff52e..03a2dd61 100644 --- a/tests/core_tests/tx_builder.h +++ b/tests/core_tests/tx_builder.h @@ -57,11 +57,11 @@ struct tx_builder // one destination address - create txout_to_key crypto::public_key out_eph_public_key = currency::null_pkey; // null_pkey means "burn" money currency::account_public_address addr = dst_entr.addr.front(); - if (addr.m_view_public_key != currency::null_pkey && addr.m_spend_public_key != currency::null_pkey) + if (addr.view_public_key != currency::null_pkey && addr.spend_public_key != currency::null_pkey) { crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); - crypto::generate_key_derivation(addr.m_view_public_key, m_tx_key.sec, derivation); - crypto::derive_public_key(derivation, output_index, addr.m_spend_public_key, out_eph_public_key); + crypto::generate_key_derivation(addr.view_public_key, m_tx_key.sec, derivation); + crypto::derive_public_key(derivation, output_index, addr.spend_public_key, out_eph_public_key); } currency::txout_to_key tk = AUTO_VAL_INIT(tk); tk.mix_attr = mix_attr; @@ -76,10 +76,10 @@ struct tx_builder for (auto& addr : dst_entr.addr) { crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); - bool r = crypto::generate_key_derivation(addr.m_view_public_key, m_tx_key.sec, derivation); + bool r = crypto::generate_key_derivation(addr.view_public_key, m_tx_key.sec, derivation); CHECK_AND_ASSERT_MES(r, void(0), "generate_key_derivation failed for ms output #" << output_index); crypto::public_key out_eph_public_key = AUTO_VAL_INIT(out_eph_public_key); - r = crypto::derive_public_key(derivation, output_index, addr.m_spend_public_key, out_eph_public_key); + r = crypto::derive_public_key(derivation, output_index, addr.spend_public_key, out_eph_public_key); CHECK_AND_ASSERT_MES(r, void(0), "derive_public_key failed for ms output #" << output_index); ms.keys.push_back(out_eph_public_key); } diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index 58c45063..83109915 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -789,7 +789,7 @@ bool gen_crypted_attachments::generate(std::vector& events) co REWIND_BLOCKS_N_WITH_TIME(events, blk_5, blk_4, miner_account, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); DO_CALLBACK(events, "set_blockchain_height"); - pr.acc_addr = miner_account.get_keys().m_account_address; + pr.acc_addr = miner_account.get_keys().account_address; cm.comment = "Comandante Che Guevara"; //ms.msg = "Hasta Siempre, Comandante"; diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 870f3099..1900c59e 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -58,15 +58,15 @@ bool determine_tx_real_inputs(currency::core& c, const currency::transaction& tx crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(validated_tx); crypto::key_derivation derivation; - bool r = generate_key_derivation(tx_pub_key, m_keys.m_view_secret_key, derivation); + bool r = generate_key_derivation(tx_pub_key, m_keys.view_secret_key, derivation); CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed"); crypto::secret_key ephemeral_secret_key; - derive_secret_key(derivation, output_tx_index, m_keys.m_spend_secret_key, ephemeral_secret_key); + derive_secret_key(derivation, output_tx_index, m_keys.spend_secret_key, ephemeral_secret_key); crypto::public_key output_public_key = boost::get(out.target).key; /*crypto::public_key ephemeral_public_key; - derive_public_key(derivation, output_tx_index, m_keys.m_account_address.m_spend_public_key, ephemeral_public_key);*/ + derive_public_key(derivation, output_tx_index, m_keys.account_address.spend_public_key, ephemeral_public_key);*/ crypto::key_image ki; generate_key_image(output_public_key, ephemeral_secret_key, ki); @@ -1436,7 +1436,7 @@ bool gen_wallet_decrypted_attachments::generate(std::vector& e // these attachments will be use across all the transactions in this test currency::tx_payer a_tx_payer = AUTO_VAL_INIT(a_tx_payer); - a_tx_payer.acc_addr = miner_acc.get_keys().m_account_address; + a_tx_payer.acc_addr = miner_acc.get_keys().account_address; currency::tx_comment a_tx_comment = AUTO_VAL_INIT(a_tx_comment); a_tx_comment.comment = "Comandante Che Guevara"; std::string a_tx_message = AUTO_VAL_INIT(a_tx_message); @@ -1622,7 +1622,7 @@ bool gen_wallet_alias_and_unconfirmed_txs::c1(currency::core& c, size_t ev_index currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'a'); ai.m_address = m_accounts[BOB_ACC_IDX].get_public_address(); - ai.m_view_key.push_back(m_accounts[BOB_ACC_IDX].get_keys().m_view_secret_key); + ai.m_view_key.push_back(m_accounts[BOB_ACC_IDX].get_keys().view_secret_key); uint64_t alias_reward = get_alias_coast_from_fee(ai.m_alias, TESTS_DEFAULT_FEE); bool r = check_balance_via_wallet(*bob_wlt.get(), "bob_wlt", alias_reward * 2); @@ -1659,7 +1659,7 @@ bool gen_wallet_alias_and_unconfirmed_txs::c2(currency::core& c, size_t ev_index currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = std::string(ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED, 'b'); ai.m_address = someone.get_public_address(); - ai.m_view_key.push_back(someone.get_keys().m_view_secret_key); + ai.m_view_key.push_back(someone.get_keys().view_secret_key); uint64_t alias_reward = get_alias_coast_from_fee(ai.m_alias, TESTS_DEFAULT_FEE); bool r = check_balance_via_wallet(*bob_wlt.get(), "bob_wlt", alias_reward * 2); @@ -1694,9 +1694,9 @@ bool gen_wallet_alias_and_unconfirmed_txs::c3(currency::core& c, size_t ev_index currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); ai.m_alias = "alicealice"; ai.m_address = m_accounts[MINER_ACC_IDX].get_public_address(); - ai.m_view_key.push_back(m_accounts[MINER_ACC_IDX].get_keys().m_view_secret_key); + ai.m_view_key.push_back(m_accounts[MINER_ACC_IDX].get_keys().view_secret_key); - bool r = sign_extra_alias_entry(ai, m_accounts[ALICE_ACC_IDX].get_keys().m_account_address.m_spend_public_key, m_accounts[ALICE_ACC_IDX].get_keys().m_spend_secret_key); + bool r = sign_extra_alias_entry(ai, m_accounts[ALICE_ACC_IDX].get_keys().account_address.spend_public_key, m_accounts[ALICE_ACC_IDX].get_keys().spend_secret_key); CHECK_AND_ASSERT_MES(r, false, "sign_extra_alias_entry failed"); std::vector stub_events_vec; From e7c4ea6accb9adc6d67c9c059e9751b489756b23 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 16:07:18 +0300 Subject: [PATCH 08/16] all tests are adapted --- tests/functional_tests/generate_test_genesis.cpp | 10 ++++++++-- tests/functional_tests/transactions_flow_test.cpp | 4 ++-- tests/performance_tests/derive_public_key.h | 4 ++-- tests/performance_tests/derive_secret_key.h | 4 ++-- tests/performance_tests/generate_key_derivation.h | 2 +- tests/performance_tests/generate_key_image.h | 6 +++--- tests/performance_tests/single_tx_test_base.h | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tests/functional_tests/generate_test_genesis.cpp b/tests/functional_tests/generate_test_genesis.cpp index 17f587cb..bdabb79c 100644 --- a/tests/functional_tests/generate_test_genesis.cpp +++ b/tests/functional_tests/generate_test_genesis.cpp @@ -8,10 +8,13 @@ #include "storages/portable_storage_template_helper.h" #include "currency_core/currency_format_utils.h" - void generate_test_genesis(size_t amount_of_accounts) { + +#if 0 // TODO: This test should be reviewed for correctness. + // commented out by sowle 2020-04-23, this test should be reviewed + currency::account_base acc; currency::genesis_config_json_struct gcjs = AUTO_VAL_INIT(gcjs); for (size_t i = 0; i != amount_of_accounts; i++) @@ -27,4 +30,7 @@ void generate_test_genesis(size_t amount_of_accounts) { LOG_ERROR("Failed to store genesis JSON"); } -} \ No newline at end of file + +#endif + +} diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index cf4fc411..2ab26623 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -55,7 +55,7 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor, for (size_t i = 0; i < parts; ++i) { currency::tx_destination_entry de; - de.addr.push_back(w2.get_account().get_keys().m_account_address); + de.addr.push_back(w2.get_account().get_keys().account_address); if (i < parts - 1) de.amount = random(max_part); @@ -157,7 +157,7 @@ bool do_send_money_by_fractions(tools::wallet2& w1, tools::wallet2& w2, size_t m for (size_t i = 0; i < ESTIMATE_INPUTS_COUNT_LIMIT_FOR_TX_BLOWUP; ++i) { currency::tx_destination_entry de; - de.addr.push_back(w2.get_account().get_keys().m_account_address); + de.addr.push_back(w2.get_account().get_keys().account_address); if (i == ESTIMATE_INPUTS_COUNT_LIMIT_FOR_TX_BLOWUP - 1) { diff --git a/tests/performance_tests/derive_public_key.h b/tests/performance_tests/derive_public_key.h index d100ae74..9cd3b680 100644 --- a/tests/performance_tests/derive_public_key.h +++ b/tests/performance_tests/derive_public_key.h @@ -19,8 +19,8 @@ public: if (!single_tx_test_base::init()) return false; - crypto::generate_key_derivation(m_tx_pub_key, m_bob.get_keys().m_view_secret_key, m_key_derivation); - m_spend_public_key = m_bob.get_keys().m_account_address.m_spend_public_key; + crypto::generate_key_derivation(m_tx_pub_key, m_bob.get_keys().view_secret_key, m_key_derivation); + m_spend_public_key = m_bob.get_keys().account_address.spend_public_key; return true; } diff --git a/tests/performance_tests/derive_secret_key.h b/tests/performance_tests/derive_secret_key.h index 9f30b421..a4a9c3df 100644 --- a/tests/performance_tests/derive_secret_key.h +++ b/tests/performance_tests/derive_secret_key.h @@ -19,8 +19,8 @@ public: if (!single_tx_test_base::init()) return false; - crypto::generate_key_derivation(m_tx_pub_key, m_bob.get_keys().m_view_secret_key, m_key_derivation); - m_spend_secret_key = m_bob.get_keys().m_spend_secret_key; + crypto::generate_key_derivation(m_tx_pub_key, m_bob.get_keys().view_secret_key, m_key_derivation); + m_spend_secret_key = m_bob.get_keys().spend_secret_key; return true; } diff --git a/tests/performance_tests/generate_key_derivation.h b/tests/performance_tests/generate_key_derivation.h index 65d0d7cb..8b1aa501 100644 --- a/tests/performance_tests/generate_key_derivation.h +++ b/tests/performance_tests/generate_key_derivation.h @@ -34,7 +34,7 @@ public: for (auto &a : accounts) { crypto::key_derivation recv_derivation = AUTO_VAL_INIT(recv_derivation); - crypto::generate_key_derivation(m_tx_pub_key, a.get_keys().m_view_secret_key, recv_derivation); + crypto::generate_key_derivation(m_tx_pub_key, a.get_keys().view_secret_key, recv_derivation); g_antioptimisation ^= *(uint64_t*)(&recv_derivation); } diff --git a/tests/performance_tests/generate_key_image.h b/tests/performance_tests/generate_key_image.h index d94747a2..95bb2930 100644 --- a/tests/performance_tests/generate_key_image.h +++ b/tests/performance_tests/generate_key_image.h @@ -24,10 +24,10 @@ public: account_keys bob_keys = m_bob.get_keys(); crypto::key_derivation recv_derivation; - crypto::generate_key_derivation(m_tx_pub_key, bob_keys.m_view_secret_key, recv_derivation); + crypto::generate_key_derivation(m_tx_pub_key, bob_keys.view_secret_key, recv_derivation); - crypto::derive_public_key(recv_derivation, 0, bob_keys.m_account_address.m_spend_public_key, m_in_ephemeral.pub); - crypto::derive_secret_key(recv_derivation, 0, bob_keys.m_spend_secret_key, m_in_ephemeral.sec); + crypto::derive_public_key(recv_derivation, 0, bob_keys.account_address.spend_public_key, m_in_ephemeral.pub); + crypto::derive_secret_key(recv_derivation, 0, bob_keys.spend_secret_key, m_in_ephemeral.sec); return true; } diff --git a/tests/performance_tests/single_tx_test_base.h b/tests/performance_tests/single_tx_test_base.h index 3e24d660..28a6d6ea 100644 --- a/tests/performance_tests/single_tx_test_base.h +++ b/tests/performance_tests/single_tx_test_base.h @@ -17,7 +17,7 @@ public: m_bob.generate(); - if (!construct_miner_tx(0, 0, 0, 2, 0, m_bob.get_keys().m_account_address, m_bob.get_keys().m_account_address, m_tx, blobdata(), CURRENCY_MINER_TX_MAX_OUTS)) + if (!construct_miner_tx(0, 0, 0, 2, 0, m_bob.get_keys().account_address, m_bob.get_keys().account_address, m_tx, blobdata(), CURRENCY_MINER_TX_MAX_OUTS)) return false; m_tx_pub_key = get_tx_pub_key_from_extra(m_tx); From 43ea2cb9dbadd3dc18d62b800bd1193b10364ab5 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 17:12:26 +0300 Subject: [PATCH 09/16] more fixes for performance tests --- tests/performance_tests/check_ring_signature.h | 2 +- tests/performance_tests/construct_tx.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/performance_tests/check_ring_signature.h b/tests/performance_tests/check_ring_signature.h index a016e84f..5a56a783 100644 --- a/tests/performance_tests/check_ring_signature.h +++ b/tests/performance_tests/check_ring_signature.h @@ -34,7 +34,7 @@ public: m_alice.generate(); std::vector destinations; - destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().m_account_address)); + destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().account_address)); if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, m_tx, 0)) return false; diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h index 747160b6..682a4b84 100644 --- a/tests/performance_tests/construct_tx.h +++ b/tests/performance_tests/construct_tx.h @@ -34,7 +34,7 @@ public: for (size_t i = 0; i < out_count; ++i) { - m_destinations.push_back(tx_destination_entry(this->m_source_amount / out_count, m_alice.get_keys().m_account_address)); + m_destinations.push_back(tx_destination_entry(this->m_source_amount / out_count, m_alice.get_keys().account_address)); } return true; From 2aa1db2636cea00007c960aa17421dadb99a435a Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 17:12:26 +0300 Subject: [PATCH 10/16] more fixes for performance tests --- tests/performance_tests/check_ring_signature.h | 2 +- tests/performance_tests/construct_tx.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/performance_tests/check_ring_signature.h b/tests/performance_tests/check_ring_signature.h index a016e84f..5a56a783 100644 --- a/tests/performance_tests/check_ring_signature.h +++ b/tests/performance_tests/check_ring_signature.h @@ -34,7 +34,7 @@ public: m_alice.generate(); std::vector destinations; - destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().m_account_address)); + destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().account_address)); if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, m_tx, 0)) return false; diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h index 747160b6..682a4b84 100644 --- a/tests/performance_tests/construct_tx.h +++ b/tests/performance_tests/construct_tx.h @@ -34,7 +34,7 @@ public: for (size_t i = 0; i < out_count; ++i) { - m_destinations.push_back(tx_destination_entry(this->m_source_amount / out_count, m_alice.get_keys().m_account_address)); + m_destinations.push_back(tx_destination_entry(this->m_source_amount / out_count, m_alice.get_keys().account_address)); } return true; From 78d960fe0846129a1ebcdc32946bcda327d356f8 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 17:33:15 +0300 Subject: [PATCH 11/16] get rid of obsolete function argument modifier --- contrib/epee/include/file_io_utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/epee/include/file_io_utils.h b/contrib/epee/include/file_io_utils.h index 3e850493..7ece78b1 100644 --- a/contrib/epee/include/file_io_utils.h +++ b/contrib/epee/include/file_io_utils.h @@ -79,7 +79,7 @@ namespace file_io_utils #ifdef BOOST_LEXICAL_CAST_INCLUDED inline - bool get_not_used_filename(const std::string& folder, OUT std::string& result_name) + bool get_not_used_filename(const std::string& folder, std::string& result_name) { DWORD folder_attr = ::GetFileAttributesA(folder.c_str()); if(folder_attr == INVALID_FILE_ATTRIBUTES) @@ -359,7 +359,7 @@ namespace file_io_utils } */ inline - bool get_file_time(const std::string& path_to_file, OUT time_t& ft) + bool get_file_time(const std::string& path_to_file, time_t& ft) { boost::system::error_code ec; ft = boost::filesystem::last_write_time(epee::string_encoding::utf8_to_wstring(path_to_file), ec); @@ -538,7 +538,7 @@ namespace file_io_utils } */ #ifdef WINDOWS_PLATFORM - inline bool get_folder_content(const std::string& path, std::list& OUT target_list) + inline bool get_folder_content(const std::string& path, std::list& target_list) { WIN32_FIND_DATAA find_data = {0}; HANDLE hfind = ::FindFirstFileA((path + "\\*.*").c_str(), &find_data); @@ -556,7 +556,7 @@ namespace file_io_utils return true; } #endif - inline bool get_folder_content(const std::string& path, std::list& OUT target_list, bool only_files = false) + inline bool get_folder_content(const std::string& path, std::list& target_list, bool only_files = false) { try { From e50bc239df17ecd6adc32224b551daf05dabc7d4 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 17:42:22 +0300 Subject: [PATCH 12/16] genesis_config_json_struct restored --- src/currency_core/currency_format_utils.h | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index ae76dc55..48441033 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -67,6 +67,72 @@ namespace currency }; //--------------------------------------------------------------------------------------------------------------- + struct genesis_payment_entry + { + std::string paid_prm; + std::string prm_usd_price; + std::string paid_xmr; + std::string xmr_usd_price; + std::string paid_qtum; + std::string qtum_usd_price; + std::string paid_bch; + std::string bch_usd_price; + std::string paid_rep; + std::string rep_usd_price; + std::string paid_dash; + std::string dash_usd_price; + std::string paid_ltc; + std::string ltc_usd_price; + std::string paid_eos; + std::string eos_usd_price; + std::string paid_eth; + std::string eth_usd_price; + std::string paid_btc; + std::string btc_usd_price; + std::string address_this; + double amount_this_coin_fl; + double amount_this_coin_int; + std::string this_usd_price; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(paid_prm) + KV_SERIALIZE(prm_usd_price) + KV_SERIALIZE(paid_xmr) + KV_SERIALIZE(xmr_usd_price) + KV_SERIALIZE(paid_qtum) + KV_SERIALIZE(qtum_usd_price) + KV_SERIALIZE(paid_bch) + KV_SERIALIZE(bch_usd_price) + KV_SERIALIZE(paid_rep) + KV_SERIALIZE(rep_usd_price) + KV_SERIALIZE(paid_dash) + KV_SERIALIZE(dash_usd_price) + KV_SERIALIZE(paid_ltc) + KV_SERIALIZE(ltc_usd_price) + KV_SERIALIZE(paid_eos) + KV_SERIALIZE(eos_usd_price) + KV_SERIALIZE(paid_eth) + KV_SERIALIZE(eth_usd_price) + KV_SERIALIZE(paid_btc) + KV_SERIALIZE(btc_usd_price) + KV_SERIALIZE(address_this) + KV_SERIALIZE_N(amount_this_coin_fl, "amount_this") + KV_SERIALIZE(this_usd_price) + END_KV_SERIALIZE_MAP() + }; + struct genesis_config_json_struct + { + std::list payments; + std::string proof_string; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(payments) + KV_SERIALIZE(proof_string) + END_KV_SERIALIZE_MAP() + }; + + + //--------------------------------------------------------------- bool construct_miner_tx(size_t height, size_t median_size, const boost::multiprecision::uint128_t& already_generated_coins, size_t current_block_size, uint64_t fee, From 898d6c7f2d0511945cc6e9099f2571f3bacf3f2e Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 25 Apr 2020 17:17:47 +0300 Subject: [PATCH 13/16] typo fixed --- .../currency_format_utils_abstract.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/currency_core/currency_format_utils_abstract.h b/src/currency_core/currency_format_utils_abstract.h index 142740ad..212e133e 100644 --- a/src/currency_core/currency_format_utils_abstract.h +++ b/src/currency_core/currency_format_utils_abstract.h @@ -68,12 +68,12 @@ namespace currency return t_unserializable_object_from_blob(b, b_blob); } //--------------------------------------------------------------- - template + template bool have_type_in_variant_container(const variant_t_container& av) { for (auto& ai : av) { - if (ai.type() == typeid(specic_type_t)) + if (ai.type() == typeid(specific_type_t)) { return true; } @@ -81,26 +81,26 @@ namespace currency return false; } //--------------------------------------------------------------- - template + template size_t count_type_in_variant_container(const variant_t_container& av) { size_t result = 0; for (auto& ai : av) { - if (ai.type() == typeid(specic_type_t)) + if (ai.type() == typeid(specific_type_t)) ++result; } return result; } //--------------------------------------------------------------- - template - bool get_type_in_variant_container(const variant_t_container& av, specic_type_t& a) + template + bool get_type_in_variant_container(const variant_t_container& av, specific_type_t& a) { for (auto& ai : av) { - if (ai.type() == typeid(specic_type_t)) + if (ai.type() == typeid(specific_type_t)) { - a = boost::get(ai); + a = boost::get(ai); return true; } } From 3883c598e5560a9b1a2fb4cf762c698b22d22e18 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 25 Apr 2020 17:22:34 +0300 Subject: [PATCH 14/16] handle_2_alternative_types_in_variant_container --- .../currency_format_utils_abstract.h | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/currency_core/currency_format_utils_abstract.h b/src/currency_core/currency_format_utils_abstract.h index 212e133e..d6a48212 100644 --- a/src/currency_core/currency_format_utils_abstract.h +++ b/src/currency_core/currency_format_utils_abstract.h @@ -107,6 +107,28 @@ namespace currency return false; } //--------------------------------------------------------------- + template + bool handle_2_alternative_types_in_variant_container(const container_t& container, callback_t& cb) + { + bool found = false; + for (auto& item : container) + { + if (item.type() == typeid(A)) + { + found = true; + if (!cb(boost::get(item))) + break; + } + else if (item.type() == typeid(B)) + { + found = true; + if (!cb(boost::get(item))) + break; + } + } + return found; + } + //--------------------------------------------------------------- template bool check_allowed_types_in_variant_container(const variant_container_t& container, const std::unordered_set& allowed_types, bool elements_must_be_unique = true) { From 00304fbb7d903277ca1e604c22f530598cb9c943 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 25 Apr 2020 17:23:05 +0300 Subject: [PATCH 15/16] wallet2::get_top_block_height --- src/wallet/wallet2.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index aa866008..4e3daada 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -633,6 +633,8 @@ namespace tools bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id); uint64_t get_blockchain_current_height() const { return m_blockchain.size(); } + + uint64_t get_top_block_height() const { return m_blockchain.empty() ? 0 : m_blockchain.size() - 1; } template inline void serialize(t_archive &a, const unsigned int ver) @@ -751,7 +753,10 @@ namespace tools static uint64_t get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const money_transfer2_details& td); bool get_utxo_distribution(std::map& distribution); uint64_t get_sync_progress(); + + private: + void add_transfers_to_expiration_list(const std::vector& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id); void remove_transfer_from_expiration_list(uint64_t transfer_index); void load_keys(const std::string& keys_file_name, const std::string& password); From 97265d06b4fd1be74f8231709ae2247c0943a24b Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 27 Apr 2020 18:11:18 +0300 Subject: [PATCH 16/16] typo fixed --- src/wallet/wallet_public_structs_defs.h | 4 ++-- tests/core_tests/wallet_rpc_tests.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 9c354700..574a1ba6 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -300,7 +300,7 @@ namespace wallet_public - struct trnsfer_destination + struct transfer_destination { uint64_t amount; std::string address; @@ -314,7 +314,7 @@ namespace wallet_public { struct request { - std::list destinations; + std::list destinations; uint64_t fee; uint64_t mixin; //uint64_t unlock_time; diff --git a/tests/core_tests/wallet_rpc_tests.cpp b/tests/core_tests/wallet_rpc_tests.cpp index 554c93bf..12bb2f8a 100644 --- a/tests/core_tests/wallet_rpc_tests.cpp +++ b/tests/core_tests/wallet_rpc_tests.cpp @@ -117,7 +117,7 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind tools::wallet_public::COMMAND_RPC_TRANSFER::request req = AUTO_VAL_INIT(req); req.fee = TESTS_DEFAULT_FEE; req.mixin = 0; - tools::wallet_public::trnsfer_destination tds = AUTO_VAL_INIT(tds); + tools::wallet_public::transfer_destination tds = AUTO_VAL_INIT(tds); tds.address = alice_integrated_address; tds.amount = MK_TEST_COINS(3); req.destinations.push_back(tds); @@ -152,7 +152,7 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind // 3. standard address + invalid external payment id => fail req.destinations.clear(); - tools::wallet_public::trnsfer_destination tds2 = AUTO_VAL_INIT(tds2); + tools::wallet_public::transfer_destination tds2 = AUTO_VAL_INIT(tds2); tds2.address = m_accounts[ALICE_ACC_IDX].get_public_address_str(); tds2.amount = MK_TEST_COINS(7); req.destinations.push_back(tds2);