From ba14c8d4244b7926a55da73c3d6d41c6191a3634 Mon Sep 17 00:00:00 2001 From: "roman.khlopkov" <roman.khlopkov@demlabs.net> Date: Tue, 18 Mar 2025 13:24:38 +0300 Subject: [PATCH] [*] Unspent conditional OUTs listing fix --- modules/net/dap_chain_ledger.c | 5 +++-- modules/service/voting/dap_chain_net_srv_voting.c | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/net/dap_chain_ledger.c b/modules/net/dap_chain_ledger.c index f5859e3343..1575502221 100644 --- a/modules/net/dap_chain_ledger.c +++ b/modules/net/dap_chain_ledger.c @@ -5681,9 +5681,10 @@ dap_chain_tx_out_cond_t *dap_ledger_out_cond_unspent_find_by_addr(dap_ledger_t * continue; // Get 'out_cond' item from transaction byte_t *l_item; size_t l_size; int i, l_out_idx = 0; + dap_chain_tx_out_cond_subtype_t l_subtype = DAP_CHAIN_TX_OUT_COND_SUBTYPE_UNDEFINED; TX_ITEM_ITER_TX_TYPE(l_item, TX_ITEM_TYPE_OUT_ALL, l_size, i, it->tx) { if (*l_item == TX_ITEM_TYPE_OUT_COND) { - dap_chain_tx_out_cond_subtype_t l_subtype = ((dap_chain_tx_out_cond_t *)l_item)->header.subtype; + l_subtype = ((dap_chain_tx_out_cond_t *)l_item)->header.subtype; if (l_subtype == a_subtype || (a_subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_ALL && l_subtype != DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE)) { ret = (dap_chain_tx_out_cond_t *)l_item; @@ -5695,7 +5696,7 @@ dap_chain_tx_out_cond_t *dap_ledger_out_cond_unspent_find_by_addr(dap_ledger_t * // Don't return regular tx or spent conditions if (!ret || !dap_hash_fast_is_blank(&it->cache_data.tx_hash_spent_fast[l_out_idx])) continue; - dap_hash_fast_t l_owner_tx_hash = dap_ledger_get_first_chain_tx_hash(a_ledger, it->tx, a_subtype); + dap_hash_fast_t l_owner_tx_hash = dap_ledger_get_first_chain_tx_hash(a_ledger, it->tx, l_subtype); dap_chain_datum_tx_t *l_tx = dap_hash_fast_is_blank(&l_owner_tx_hash) ? it->tx : dap_ledger_tx_find_by_hash(a_ledger, &l_owner_tx_hash); if (!l_tx) { diff --git a/modules/service/voting/dap_chain_net_srv_voting.c b/modules/service/voting/dap_chain_net_srv_voting.c index fb8f37c799..82f420b369 100644 --- a/modules/service/voting/dap_chain_net_srv_voting.c +++ b/modules/service/voting/dap_chain_net_srv_voting.c @@ -320,10 +320,12 @@ static int s_vote_verificator(dap_ledger_t *a_ledger, dap_chain_tx_item_type_t a // Get last sign item from transaction dap_hash_fast_t l_pkey_hash = {}; - dap_sign_t *l_pkey_sign = NULL; + dap_sign_t *l_pkey_sign = NULL, *l_wallet_sign = NULL; uint8_t *l_tx_item = NULL; size_t l_size; int i, l_sign_num = 0; TX_ITEM_ITER_TX_TYPE(l_tx_item, TX_ITEM_TYPE_SIG, l_size, i, a_tx_in) { l_pkey_sign = dap_chain_datum_tx_item_sign_get_sig((dap_chain_tx_sig_t *)l_tx_item); + if (!l_wallet_sign) + l_wallet_sign = l_pkey_sign; l_sign_num++; } dap_sign_get_pkey_hash(l_pkey_sign, &l_pkey_hash); @@ -428,8 +430,10 @@ static int s_vote_verificator(dap_ledger_t *a_ledger, dap_chain_tx_item_type_t a if (!l_prev_out || l_prev_out->header.item_type != TX_ITEM_TYPE_OUT_COND || l_prev_out->header.subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE) return -16; - if (!dap_ledger_check_condition_owner(a_ledger, &l_hash, l_prev_out->header.subtype, l_out_idx, l_pkey_sign)) + if (!dap_ledger_check_condition_owner(a_ledger, &l_hash, l_prev_out->header.subtype, l_out_idx, l_wallet_sign)) { + log_it(L_WARNING, "TX hash %s out #%d owner verification error", dap_hash_fast_to_str_static(&l_hash), l_out_idx); return -17; + } if (s_datum_tx_voting_coin_check_cond_out(a_ledger->net, l_vote_tx_item->voting_hash, l_hash, l_out_idx, l_old_vote ? &l_pkey_hash : NULL)) return -15; -- GitLab