diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 85eed0e8..54df1243 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1676,7 +1676,6 @@ namespace currency NLSAG_sources.push_back(&src_entr); } } - } if (ins_zc.elements.size()) diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index 2014873e..93cb23a3 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -27,6 +27,13 @@ namespace currency crypto::public_key stealth_address; // a.k.a output's one-time public key crypto::public_key concealing_point; // only for zarcaum outputs crypto::public_key amount_commitment; // only for zarcaum outputs + + BEGIN_SERIALIZE_OBJECT() + FIELD(out_reference) + FIELD(stealth_address) + FIELD(concealing_point) + FIELD(amount_commitment) + END_SERIALIZE() }; //typedef serializable_pair output_entry; // txout_ref_v is either global output index or ref_by_id; public_key - is output's stealth address diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d929e583..f6bdb3f5 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3263,7 +3263,7 @@ void wallet2::submit_transfer(const std::string& signed_tx_blob, currency::trans const auto& src = ft.ftp.sources[i]; THROW_IF_FALSE_WALLET_INT_ERR_EX(src.real_output < src.outputs.size(), "src.real_output is out of bounds: " << src.real_output); - const crypto::public_key& out_key = src.outputs[src.real_output].second; + const crypto::public_key& out_key = src.outputs[src.real_output].stealth_address; tri_ki_to_be_added.push_back(std::make_pair(src.transfer_index, ki)); pk_ki_to_be_added.push_back(std::make_pair(out_key, ki)); @@ -4654,9 +4654,9 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector= fake_outputs_count) break; @@ -4666,22 +4666,22 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector(a.first) >= td.m_global_output_index; + if (a.out_reference.type().hash_code() == typeid(uint64_t).hash_code()) + return static_cast(boost::get(a.out_reference) >= td.m_global_output_index); return false; // TODO: implement deterministics real output placement in case there're ref_by_id outs }); //size_t real_index = src.outputs.size() ? (rand() % src.outputs.size() ):0; - tx_output_entry real_oe; - real_oe.first = td.m_global_output_index; // TODO: use ref_by_id when neccessary + tx_output_entry real_oe = AUTO_VAL_INIT(real_oe); + real_oe.out_reference = td.m_global_output_index; // TODO: use ref_by_id when neccessary //@#@ VARIANT_SWITCH_BEGIN(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index]); VARIANT_CASE_CONST(tx_out_bare, o) { VARIANT_SWITCH_BEGIN(o.target); VARIANT_CASE_CONST(txout_to_key, o) - real_oe.second = o.key; + real_oe.stealth_address = o.key; VARIANT_CASE_CONST(txout_htlc, htlc) - real_oe.second = htlc.pkey_refund; + real_oe.stealth_address = htlc.pkey_refund; VARIANT_CASE_OTHER() { WLT_THROW_IF_FALSE_WITH_CODE(false, @@ -4774,8 +4774,8 @@ bool wallet2::prepare_tx_sources_htlc(crypto::hash htlc_tx_id, const std::string sources.push_back(AUTO_VAL_INIT(currency::tx_source_entry())); currency::tx_source_entry& src = sources.back(); tx_output_entry real_oe = AUTO_VAL_INIT(real_oe); - real_oe.first = td.m_global_output_index; // TODO: use ref_by_id when necessary - real_oe.second = htlc_out.pkey_redeem; + real_oe.out_reference = td.m_global_output_index; // TODO: use ref_by_id when necessary + real_oe.stealth_address = htlc_out.pkey_redeem; src.outputs.push_back(real_oe); //m_global_output_index should be prefetched src.amount = found_money = td.amount(); src.real_output_in_tx_index = td.m_internal_output_index; @@ -5380,7 +5380,7 @@ uint64_t wallet2::get_tx_expiration_median() const void wallet2::print_source_entry(const currency::tx_source_entry& src) const { std::ostringstream indexes; - std::for_each(src.outputs.begin(), src.outputs.end(), [&](const currency::tx_source_entry::output_entry& s_e) { indexes << s_e.first << " "; }); + std::for_each(src.outputs.begin(), src.outputs.end(), [&](const currency::tx_source_entry::output_entry& s_e) { indexes << s_e.out_reference << " "; }); WLT_LOG_L0("amount=" << currency::print_money(src.amount) << ", real_output=" << src.real_output << ", real_output_in_tx_index=" << src.real_output_in_tx_index << ", indexes: " << indexes.str()); } //---------------------------------------------------------------------------------------------------- @@ -5860,8 +5860,8 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public if (td.m_global_output_index == daemon_oe.global_amount_index) continue; tx_output_entry oe; - oe.first = daemon_oe.global_amount_index; - oe.second = daemon_oe.out_key; + oe.out_reference = daemon_oe.global_amount_index; + oe.stealth_address = daemon_oe.out_key; src.outputs.push_back(oe); if (src.outputs.size() >= fake_outs_count) break; @@ -5871,17 +5871,17 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public // insert real output into src.outputs auto it_to_insert = std::find_if(src.outputs.begin(), src.outputs.end(), [&](const tx_output_entry& a) { - if (a.first.type().hash_code() == typeid(uint64_t).hash_code()) - return boost::get(a.first) >= td.m_global_output_index; + if (a.out_reference.type().hash_code() == typeid(uint64_t).hash_code()) + return static_cast(boost::get(a.out_reference) >= td.m_global_output_index); return false; // TODO: implement deterministics real output placement in case there're ref_by_id outs }); - tx_output_entry real_oe; - real_oe.first = td.m_global_output_index; + tx_output_entry real_oe = AUTO_VAL_INIT(real_oe); + real_oe.out_reference = td.m_global_output_index; //@#@ if(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index].type() != typeid(tx_out_bare)) continue; const tx_out_bare& out_b = boost::get(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index]); - real_oe.second = boost::get(out_b.target).key; + real_oe.stealth_address = boost::get(out_b.target).key; auto inserted_it = src.outputs.insert(it_to_insert, real_oe); src.real_out_tx_key = get_tx_pub_key_from_extra(td.m_ptx_wallet_info->m_tx); src.real_output = inserted_it - src.outputs.begin(); diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index b9d1962e..94d615a4 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -312,7 +312,10 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector& events tx_source_entry se = AUTO_VAL_INIT(se); se.amount = boost::get(blk_0.miner_tx.vout[0]).amount; - se.outputs.push_back(make_serializable_pair(0, boost::get(boost::get(blk_0.miner_tx.vout[0]).target).key)); + currency::tx_source_entry::output_entry oe = AUTO_VAL_INIT(oe); + oe.out_reference = 0; + oe.stealth_address = boost::get(boost::get(blk_0.miner_tx.vout[0]).target).key; + se.outputs.push_back(oe); se.real_output = 0; se.real_out_tx_key = get_tx_pub_key_from_extra(blk_0.miner_tx); se.real_output_in_tx_index = 0; @@ -357,7 +360,10 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector tx_source_entry se = AUTO_VAL_INIT(se); se.amount = boost::get(blk_1.miner_tx.vout[0]).amount; - se.outputs.push_back(make_serializable_pair(0, boost::get(boost::get(blk_1.miner_tx.vout[0]).target).key)); + currency::tx_source_entry::output_entry oe = AUTO_VAL_INIT(oe); + oe.out_reference = 0; + oe.stealth_address = boost::get(boost::get(blk_1.miner_tx.vout[0]).target).key; + se.outputs.push_back(oe); se.real_output = 0; se.real_out_tx_key = get_tx_pub_key_from_extra(blk_1.miner_tx); se.real_output_in_tx_index = 0; diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 999ed870..24c805d1 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -779,11 +779,11 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons return false; //check that derivated key is equal with real output key - if (!(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].second)) + if (!(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].stealth_address)) { LOG_ERROR("derived public key missmatch with output public key! " << ENDL << "derived_key:" << epst::pod_to_hex(in_ephemeral.pub) << ENDL << "real output_public_key:" - << epst::pod_to_hex(src_entr.outputs[src_entr.real_output].second)); + << epst::pod_to_hex(src_entr.outputs[src_entr.real_output].stealth_address)); return false; } @@ -794,7 +794,7 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons //fill outputs array and use relative offsets BOOST_FOREACH(const currency::tx_source_entry::output_entry& out_entry, src_entr.outputs) - input_to_key.key_offsets.push_back(out_entry.first); + input_to_key.key_offsets.push_back(out_entry.out_reference); input_to_key.key_offsets = currency::absolute_output_offsets_to_relative(input_to_key.key_offsets); tx.vin.push_back(input_to_key); @@ -842,8 +842,8 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons std::vector keys_ptrs; BOOST_FOREACH(const currency::tx_source_entry::output_entry& o, src_entr.outputs) { - keys_ptrs.push_back(&o.second); - ss_ring_s << o.second << ENDL; + keys_ptrs.push_back(&o.stealth_address); + ss_ring_s << o.stealth_address << ENDL; } tx.signatures.push_back(currency::NLSAG_sig()); diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index 5fc89e29..cd8643ca 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -60,28 +60,28 @@ bool test_transaction_generation_and_ring_signature() src.amount = 70368744177663; { tx_output_entry oe; - oe.first = 0; - oe.second = boost::get(boost::get(tx_mine_1.vout[0]).target).key; + oe.out_reference = 0; + oe.stealth_address = boost::get(boost::get(tx_mine_1.vout[0]).target).key; src.outputs.push_back(oe); - oe.first = 1; - oe.second = boost::get(boost::get(tx_mine_2.vout[0]).target).key; + oe.out_reference = 1; + oe.stealth_address = boost::get(boost::get(tx_mine_2.vout[0]).target).key; src.outputs.push_back(oe); - oe.first = 2; - oe.second = boost::get(boost::get(tx_mine_3.vout[0]).target).key; + oe.out_reference = 2; + oe.stealth_address = boost::get(boost::get(tx_mine_3.vout[0]).target).key; src.outputs.push_back(oe); - oe.first = 3; - oe.second = boost::get(boost::get(tx_mine_4.vout[0]).target).key; + oe.out_reference = 3; + oe.stealth_address = boost::get(boost::get(tx_mine_4.vout[0]).target).key; src.outputs.push_back(oe); - oe.first = 4; - oe.second = boost::get(boost::get(tx_mine_5.vout[0]).target).key; + oe.out_reference = 4; + oe.stealth_address = boost::get(boost::get(tx_mine_5.vout[0]).target).key; src.outputs.push_back(oe); - oe.first = 5; - oe.second = boost::get(boost::get(tx_mine_6.vout[0]).target).key; + oe.out_reference = 5; + oe.stealth_address = boost::get(boost::get(tx_mine_6.vout[0]).target).key; src.outputs.push_back(oe); crypto::public_key tx_pub_key = null_pkey; diff --git a/tests/core_tests/tx_builder.h b/tests/core_tests/tx_builder.h index ed171b64..17828e5b 100644 --- a/tests/core_tests/tx_builder.h +++ b/tests/core_tests/tx_builder.h @@ -35,7 +35,7 @@ struct tx_builder // fill outputs array and use relative offsets for(const currency::tx_source_entry::output_entry& out_entry : src_entr.outputs) - input_to_key.key_offsets.push_back(out_entry.first); + input_to_key.key_offsets.push_back(out_entry.out_reference); input_to_key.key_offsets = currency::absolute_output_offsets_to_relative(input_to_key.key_offsets); m_tx.vin.push_back(input_to_key); @@ -106,7 +106,7 @@ struct tx_builder std::vector keys_ptrs; for(const currency::tx_source_entry::output_entry& o : src_entr.outputs) { - keys_ptrs.push_back(&o.second); + keys_ptrs.push_back(&o.stealth_address); } m_tx.signatures.push_back(currency::NLSAG_sig()); diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index 71b92a71..7382060b 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -273,7 +273,7 @@ bool gen_tx_key_offest_points_to_foreign_key::generate(std::vector(builder.m_tx.vin.front()); - in_to_key.key_offsets.front() = sources_alice.front().outputs.front().first; + in_to_key.key_offsets.front() = sources_alice.front().outputs.front().out_reference; builder.step3_fill_outputs(destinations_bob); builder.step4_calc_hash(); builder.step5_sign(sources_bob); @@ -329,7 +329,7 @@ bool gen_tx_mixed_key_offest_not_exist::generate(std::vector& std::vector destinations; fill_tx_sources_and_destinations(events, blk_2, bob_account, miner_account, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 1, sources, destinations); - sources.front().outputs[(sources.front().real_output + 1) % 2].first = std::numeric_limits::max(); + sources.front().outputs[(sources.front().real_output + 1) % 2].out_reference = std::numeric_limits::max(); tx_builder builder; builder.step1_init();