func (s *Store) UniqueTxDetails(ns walletdb.ReadBucket, txHash *hash.Hash,
	block *Block) (*TxDetails, error) {
	if block == nil {
		v := existsRawUnMined(ns, txHash[:])
		if v == nil {
			return nil, nil
		}
		return s.unMinedTxDetails(ns, txHash, v)
	}
	k, v := existsTxRecord(ns, txHash, block)
	if v == nil {
		return nil, nil
	}
	return s.minedTxDetails(ns, txHash, k, v)
}
UniqueTxDetails looks up all recorded details for a transaction recorded
mined in some particular block, or an unMined transaction if block is nil.

Not finding a transaction with this hash from this block is not an error.  In
this case, a nil TxDetails is returned.
package wtxmgr
import (
	"fmt"
	"github.com/Qitmeer/qitmeer-wallet/walletdb"
	"github.com/Qitmeer/qitmeer/common/hash"
	"github.com/Qitmeer/qitmeer/core/types"
)
type CreditRecord struct {
	Amount types.Amount
	Index  uint32
	Spent  bool
	Change bool
}
type DebitRecord struct {
	Amount types.Amount
	Index  uint32
}
type TxDetails struct {
	TxRecord
	Block   BlockMeta
	Credits []CreditRecord
	Debits  []DebitRecord
}
func (s *Store) minedTxDetails(ns walletdb.ReadBucket, txHash *hash.Hash, recKey, recVal []byte) (*TxDetails, error) {
	var details TxDetails
	err := readRawTxRecord(txHash, recVal, &details.TxRecord)
	if err != nil {
		return nil, err
	}
	err = readRawTxRecordBlock(recKey, &details.Block.Block)
	if err != nil {
		return nil, err
	}
	details.Block.Time, err = fetchBlockTime(ns, uint32(details.Block.Order))
	if err != nil {
		return nil, err
	}
	credIter := makeReadCreditIterator(ns, recKey)
	for credIter.next() {
		if int(credIter.elem.Index) >= len(details.MsgTx.TxOut) {
			str := "saved credit index exceeds number of outputs"
			return nil, storeError(ErrData, str, nil)
		}
		if !credIter.elem.Spent {
			k := canonicalOutPoint(txHash, credIter.elem.Index)
			spent := existsRawUnMinedInput(ns, k) != nil
			credIter.elem.Spent = spent
		}
		details.Credits = append(details.Credits, credIter.elem)
	}
	if credIter.err != nil {
		return nil, credIter.err
	}
	debIter := makeReadDebitIterator(ns, recKey)
	for debIter.next() {
		if int(debIter.elem.Index) >= len(details.MsgTx.TxIn) {
			str := "saved debit index exceeds number of inputs"
			return nil, storeError(ErrData, str, nil)
		}
		details.Debits = append(details.Debits, debIter.elem)
	}
	return &details, debIter.err
}
func (s *Store) unMinedTxDetails(ns walletdb.ReadBucket, txHash *hash.Hash, v []byte) (*TxDetails, error) {
	details := TxDetails{
		Block: BlockMeta{Block: Block{Order: -1}},
	}
	err := readRawTxRecord(txHash, v, &details.TxRecord)
	if err != nil {
		return nil, err
	}
	it := makeReadUnMinedCreditIterator(ns, txHash)
	for it.next() {
		if int(it.elem.Index) >= len(details.MsgTx.TxOut) {
			str := "saved credit index exceeds number of outputs"
			return nil, storeError(ErrData, str, nil)
		}
		it.elem.Spent = existsRawUnMinedInput(ns, it.ck) != nil
		details.Credits = append(details.Credits, it.elem)
	}
	if it.err != nil {
		return nil, it.err
	}
	for i, output := range details.MsgTx.TxIn {
		opKey := canonicalOutPoint(&output.PreviousOut.Hash,
			output.PreviousOut.OutIndex)
		credKey := existsRawUnspent(ns, opKey)
		if credKey != nil {
			v := existsRawCredit(ns, credKey)
			amount, err := fetchRawCreditAmount(v)
			if err != nil {
				return nil, err
			}
			details.Debits = append(details.Debits, DebitRecord{
				Amount: amount,
				Index:  uint32(i),
			})
			continue
		}
		v := existsRawUnMinedCredit(ns, opKey)
		if v == nil {
			continue
		}
		amount, err := fetchRawCreditAmount(v)
		if err != nil {
			return nil, err
		}
		details.Debits = append(details.Debits, DebitRecord{
			Amount: amount,
			Index:  uint32(i),
		})
	}
	return &details, nil
}
func (s *Store) TxDetails(ns walletdb.ReadBucket, txHash *hash.Hash) (*TxDetails, error) {
	v := existsRawUnMined(ns, txHash[:])
	if v != nil {
		return s.unMinedTxDetails(ns, txHash, v)
	}
	k, v := latestTxRecord(ns, txHash)
	if v == nil {
		return nil, nil
	}
	return s.minedTxDetails(ns, txHash, k, v)
}