diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 5e21bd02..558997da 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2475,6 +2475,11 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU << out_ptr->out_no << " more than transaction outputs = " << tx_ptr->tx.vout.size() << ", for tx id = " << out_ptr->tx_id); const transaction& tx = tx_ptr->tx; + if (tx.vout[out_ptr->out_no].target.type() == typeid(txout_htlc)) + { + //silently return false, it's ok + return false; + } CHECK_AND_ASSERT_MES(tx.vout[out_ptr->out_no].target.type() == typeid(txout_to_key), false, "unknown tx out type"); const txout_to_key& otk = boost::get(tx.vout[out_ptr->out_no].target); @@ -3323,7 +3328,7 @@ bool blockchain_storage::push_transaction_to_global_outs_index(const transaction size_t i = 0; BOOST_FOREACH(const auto& ot, tx.vout) { - if (ot.target.type() == typeid(txout_to_key)) + if (ot.target.type() == typeid(txout_to_key) || ot.target.type() == typeid(txout_htlc)) { m_db_outputs.push_back_item(ot.amount, global_output_entry::construct(tx_id, i)); global_indexes.push_back(m_db_outputs.get_item_size(ot.amount) - 1); @@ -3364,8 +3369,14 @@ bool blockchain_storage::get_outs(uint64_t amount, std::list auto tx_ptr = m_db_transactions.find(out_entry_ptr->tx_id); CHECK_AND_ASSERT_MES(tx_ptr, false, "transactions outs global index consistency broken: can't find tx " << out_entry_ptr->tx_id << " in DB, for amount: " << amount << ", gindex: " << i); CHECK_AND_ASSERT_MES(tx_ptr->tx.vout.size() > out_entry_ptr->out_no, false, "transactions outs global index consistency broken: index in tx_outx == " << out_entry_ptr->out_no << " is greather than tx.vout size == " << tx_ptr->tx.vout.size() << ", for amount: " << amount << ", gindex: " << i); - CHECK_AND_ASSERT_MES(tx_ptr->tx.vout[out_entry_ptr->out_no].target.type() == typeid(txout_to_key), false, "transactions outs global index consistency broken: out #" << out_entry_ptr->out_no << " in tx " << out_entry_ptr->tx_id << " has wrong type, for amount: " << amount << ", gindex: " << i); - pkeys.push_back(boost::get(tx_ptr->tx.vout[out_entry_ptr->out_no].target).key); + //CHECK_AND_ASSERT_MES(tx_ptr->tx.vout[out_entry_ptr->out_no].target.type() == typeid(txout_to_key), false, "transactions outs global index consistency broken: out #" << out_entry_ptr->out_no << " in tx " << out_entry_ptr->tx_id << " has wrong type, for amount: " << amount << ", gindex: " << i); + if (tx_ptr->tx.vout[out_entry_ptr->out_no].target.type() == typeid(txout_to_key)) + { + pkeys.push_back(boost::get(tx_ptr->tx.vout[out_entry_ptr->out_no].target).key); + }else if(tx_ptr->tx.vout[out_entry_ptr->out_no].target.type() == typeid(txout_htlc)) + { + pkeys.push_back(boost::get(tx_ptr->tx.vout[out_entry_ptr->out_no].target).pkey_redeem); + } } return true; @@ -3377,7 +3388,7 @@ bool blockchain_storage::pop_transaction_from_global_index(const transaction& tx size_t i = tx.vout.size()-1; BOOST_REVERSE_FOREACH(const auto& ot, tx.vout) { - if (ot.target.type() == typeid(txout_to_key)) + if (ot.target.type() == typeid(txout_to_key) || ot.target.type() == typeid(txout_htlc)) { uint64_t sz= m_db_outputs.get_item_size(ot.amount); CHECK_AND_ASSERT_MES(sz, false, "transactions outs global index: empty index for amount: " << ot.amount); diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 771d6c5e..9c96f225 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -641,7 +641,7 @@ namespace currency tx_out out; out.amount = de.amount; - if (de.htlc_options.htlc_hash != null_hash) + if (de.htlc_options.expiration != 0) { const destination_option_htlc_out& htlc_dest = de.htlc_options; //out htlc @@ -665,7 +665,7 @@ namespace currency result.htlc_origin = generate_origin_for_htlc(htlc, self); //calculate hash - if (htlc.flags&CURRENCY_TXOUT_HTLC_FLAGS_HASH_TYPE_MASK) + if (!htlc.flags&CURRENCY_TXOUT_HTLC_FLAGS_HASH_TYPE_MASK) { htlc.htlc_hash = crypto::sha256_hash(result.htlc_origin.data(), result.htlc_origin.size()); } @@ -679,7 +679,7 @@ namespace currency { htlc.htlc_hash = htlc_dest.htlc_hash; } - + out.target = htlc; } else if (target_keys.size() == 1) { @@ -1679,6 +1679,14 @@ namespace currency if (!check_key(boost::get(out.target).key)) return false; } + else if (out.target.type() == typeid(txout_htlc)) + { + const txout_htlc& htlc = boost::get(out.target); + if (!check_key(htlc.pkey_redeem)) + return false; + if (!check_key(htlc.pkey_refund)) + return false; + } else if (out.target.type() == typeid(txout_multisig)) { const txout_multisig& ms = boost::get(out.target); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index ce272372..21a2e43b 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -172,6 +172,11 @@ namespace tools //for multisig we don't split splitted_dsts.push_back(de); } + else if (de.htlc_options.expiration != 0) + { + //for htlc we don't do split + splitted_dsts.push_back(de); + } else { currency::decompose_amount_into_digits(de.amount, dust_threshold, diff --git a/tests/core_tests/atomic_tests.cpp b/tests/core_tests/atomic_tests.cpp index d45d5581..f94941e5 100644 --- a/tests/core_tests/atomic_tests.cpp +++ b/tests/core_tests/atomic_tests.cpp @@ -124,9 +124,11 @@ bool atomic_simple_test::c1(currency::core& c, size_t ev_index, const std::vecto std::string alice_origin; //will be deterministically generated by Alice's A wallet currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - alice_a_wlt_instance->create_htlc_proposal(transfer_amount, bob_a_wlt_instance->get_account().get_public_address(), 20, res_tx, alice_origin); - - + alice_a_wlt_instance->create_htlc_proposal(transfer_amount - TESTS_DEFAULT_FEE, bob_a_wlt_instance->get_account().get_public_address(), 20, res_tx, alice_origin); + r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + alice_a_wlt_instance->refresh(); + bob_a_wlt_instance->refresh(); return r; }