From dc3f5882ef19f9ffd1a0857a0de27a1970ddcf99 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 31 Jan 2021 18:05:26 +0100 Subject: [PATCH] receiving list of htlc --- src/wallet/wallet2.cpp | 13 ++++++++++++- src/wallet/wallet2.h | 4 +++- src/wallet/wallet_public_structs_defs.h | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f222aeb9..e19452c6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -581,6 +581,11 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t uint64_t expired_if_more_then = td.m_ptx_wallet_info->m_block_height + hltc.expiration; m_htlcs[expired_if_more_then] = het; + if (het.is_wallet_owns_redeem) + { + td.m_flags |= WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM; + } + //active htlc auto amount_gindex_pair = std::make_pair(amount, td.m_global_output_index); m_active_htlcs[amount_gindex_pair] = transfer_index; @@ -2212,8 +2217,9 @@ void wallet2::detach_blockchain(uint64_t including_height) WLT_LOG_BLUE("Transfer [" << i << "] spent height: " << tr.m_spent_height << " -> 0, reason: detaching blockchain", LOG_LEVEL_1); tr.m_spent_height = 0; //check if it's hltc contract - if (tr.m_ptx_wallet_info->m_tx.vout[tr.m_internal_output_index].target == typeid(txout_htlc)) + if (tr.m_ptx_wallet_info->m_tx.vout[tr.m_internal_output_index].target == typeid(txout_htlc) && tr.m_flags & WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM) { + //only if htlc was spent as a redeem, then we put htlc back as active const txout_htlc& htlc = boost::get(tr.m_ptx_wallet_info->m_tx.vout[tr.m_internal_output_index].target); auto amount_gindex_pair = std::make_pair(tr.m_ptx_wallet_info->m_tx.vout[tr.m_internal_output_index].amount, tr.m_global_output_index); m_active_htlcs[amount_gindex_pair] = i; @@ -4027,6 +4033,10 @@ void wallet2::get_list_of_active_htlc(bool only_redeem_txs, std::list(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index].target); entry.sha256_hash = htlc.htlc_hash; + entry.is_redeem = td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM ? true : false; htlcs.push_back(entry); } } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index bb3f05ea..1629953e 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -53,6 +53,7 @@ #define WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION uint32_t(1 << 2) #define WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER uint32_t(1 << 3) #define WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION uint32_t(1 << 4) // transfer is reserved for cold-signing (unsigned tx was created and passed for signing) +#define WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM uint32_t(1 << 5) // for htlc keeps info if this htlc belong as redeem or as refund const uint64_t WALLET_MINIMUM_HEIGHT_UNSET_CONST = std::numeric_limits::max(); @@ -741,6 +742,7 @@ namespace tools a & m_htlcs; a & m_active_htlcs; + a & m_active_htlcs_txid; } @@ -987,7 +989,7 @@ private: bool is_wallet_owns_redeem; //specify if this HTLC belong to this wallet by pkey_redeem or by pkey_refund uint64_t transfer_index; }; - std::multimap m_htlcs; //uint64_t -> height of expiration + std::multimap m_htlcs; //map [expired_if_more_then] -> height of expiration amount_gindex_to_transfer_id_container m_active_htlcs; // map [amount; gindex] -> transfer index std::unordered_map m_active_htlcs_txid; // map [txid] -> transfer index, limitation: 1 transactiom -> 1 htlc diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index dc12e5ea..55498c7b 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -979,11 +979,13 @@ namespace wallet_public crypto::hash sha256_hash; crypto::hash tx_id; uint64_t amount; + bool is_redeem; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amount) KV_SERIALIZE(sha256_hash) KV_SERIALIZE(tx_id) + KV_SERIALIZE(is_redeem) END_KV_SERIALIZE_MAP() };