From e2fee6f8d48e6fbab92d62982e96e250e6bb7e8f Mon Sep 17 00:00:00 2001 From: Wisdom Arerosuoghene Date: Wed, 3 Feb 2021 04:49:29 +0100 Subject: [PATCH] correct tx tree determination logic --- server/asset/dcr/dcr.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/server/asset/dcr/dcr.go b/server/asset/dcr/dcr.go index 1f63d2fc72..a7016dfe0c 100644 --- a/server/asset/dcr/dcr.go +++ b/server/asset/dcr/dcr.go @@ -932,14 +932,30 @@ func (dcr *Backend) getTxOutInfo(ctx context.Context, txHash *chainhash.Hash, vo if err != nil { return nil, nil, nil, fmt.Errorf("failed to decode MsgTx from hex for transaction %s: %w", txHash, err) } - txTree := stake.DetermineTxType(msgTx, msgTx.Version == wire.TxVersionTreasury) - txOut, pkScript, err := dcr.getUnspentTxOut(ctx, txHash, vout, int8(txTree)) + tree := determineTxTree(msgTx) + txOut, pkScript, err := dcr.getUnspentTxOut(ctx, txHash, vout, tree) if err != nil { return nil, nil, nil, err } return txOut, verboseTx, pkScript, nil } +func determineTxTree(msgTx *wire.MsgTx) int8 { + // Try with treasury disabled first. + txType := stake.DetermineTxType(msgTx, false) + if txType != stake.TxTypeRegular { + return wire.TxTreeStake + } + + // Try with treasury enabled. + txType = stake.DetermineTxType(msgTx, true) + if txType != stake.TxTypeRegular { + return wire.TxTreeStake + } + + return wire.TxTreeRegular +} + // Get the block information, checking the cache first. Same as // getDcrBlock, but takes a string argument. func (dcr *Backend) getBlockInfo(ctx context.Context, blockid string) (*dcrBlock, error) {