1
0
Fork 0
forked from lthn/blockchain

receiving list of htlc

This commit is contained in:
cryptozoidberg 2021-01-31 18:05:26 +01:00
parent 66387d2bd5
commit dc3f5882ef
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
3 changed files with 17 additions and 2 deletions

View file

@ -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<txout_htlc>(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<htlc_entry
{
for (auto htlc_entry : m_active_htlcs_txid)
{
if (only_redeem_txs && !(td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM))
{
continue;
}
htlc_entry_info entry = AUTO_VAL_INIT(entry);
entry.tx_id = htlc_entry.first;
const transfer_details& td = m_transfers[htlc_entry.second];
@ -4035,6 +4045,7 @@ void wallet2::get_list_of_active_htlc(bool only_redeem_txs, std::list<htlc_entry
"[get_list_of_active_htlc]Internal error: unexpected type of out");
const txout_htlc& htlc = boost::get<txout_htlc>(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);
}
}

View file

@ -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<uint64_t>::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<uint64_t, htlc_expiration_trigger> m_htlcs; //uint64_t -> height of expiration
std::multimap<uint64_t, htlc_expiration_trigger> 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<crypto::hash, uint64_t> m_active_htlcs_txid; // map [txid] -> transfer index, limitation: 1 transactiom -> 1 htlc

View file

@ -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()
};