From fd561c8f3036ad6ce0847d28eb2872e1b9404b37 Mon Sep 17 00:00:00 2001 From: "roman.khlopkov" <roman.khlopkov@demlabs.net> Date: Tue, 18 Mar 2025 14:28:56 +0300 Subject: [PATCH] [*] Unspent conditional OUTs listing fix --- dap-sdk | 2 +- modules/ledger/dap_chain_ledger.c | 5 +++-- modules/service/voting/dap_chain_net_srv_voting.c | 13 ++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dap-sdk b/dap-sdk index f0560a37dd..c47bebb9b0 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit f0560a37ddece95c816d47ca0ae20eea9da800ad +Subproject commit c47bebb9b024f89871024063485f90156ef28ef8 diff --git a/modules/ledger/dap_chain_ledger.c b/modules/ledger/dap_chain_ledger.c index 2249b14b5e..50b22b0e2a 100644 --- a/modules/ledger/dap_chain_ledger.c +++ b/modules/ledger/dap_chain_ledger.c @@ -1433,9 +1433,10 @@ dap_chain_tx_out_cond_t *dap_ledger_out_cond_unspent_find_by_addr(dap_ledger_t * ret = NULL; // 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; @@ -1447,7 +1448,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->out_metadata[l_out_idx].tx_spent_hash_fast)) continue; - dap_hash_fast_t l_owner_tx_hash = dap_ledger_get_first_chain_tx_hash(a_ledger, a_subtype, &it->tx_hash_fast); + dap_hash_fast_t l_owner_tx_hash = dap_ledger_get_first_chain_tx_hash(a_ledger, l_subtype, &it->tx_hash_fast); 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 bbd028763d..3965207130 100644 --- a/modules/service/voting/dap_chain_net_srv_voting.c +++ b/modules/service/voting/dap_chain_net_srv_voting.c @@ -328,10 +328,12 @@ static int s_vote_verificator(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx // 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_sig_get_sign((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); @@ -394,10 +396,15 @@ static int s_vote_verificator(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx dap_chain_datum_tx_t *l_tx_prev_temp = dap_ledger_tx_find_by_hash(a_ledger, &l_tx_hash); dap_chain_tx_out_cond_t *l_prev_out = (dap_chain_tx_out_cond_t *)dap_chain_datum_tx_out_get_by_out_idx(l_tx_prev_temp, l_out_idx); 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) + l_prev_out->header.subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE) { + log_it(L_WARNING, "TX hash %s out #%d subtype %s is restricted", dap_hash_fast_to_str_static(&l_tx_hash), l_out_idx, + l_prev_out ? dap_chain_tx_out_cond_subtype_to_str(l_prev_out->header.subtype) : "(null)"); return -16; - if (!dap_ledger_check_condition_owner(a_ledger, &l_tx_hash, l_prev_out->header.subtype, l_out_idx, l_pkey_sign)) + } + if (!dap_ledger_check_condition_owner(a_ledger, &l_tx_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_tx_hash), l_out_idx); return -17; + } break; } default: -- GitLab