func (s *Store) UnMinedTxHashes(ns walletdb.ReadBucket) ([]*hash.Hash, error) {
	return s.unMinedTxHashes(ns)
}
UnMinedTxHashes returns the hashes of all transactions not known to have been
mined in a block.
package wtxmgr
import (
	"github.com/Qitmeer/qitmeer-wallet/walletdb"
	"github.com/Qitmeer/qitmeer/common/hash"
	"github.com/Qitmeer/qitmeer/core/types"
	"github.com/Qitmeer/qitmeer/log"
)
func (s *Store) insertMemPoolTx(ns walletdb.ReadWriteBucket, rec *TxRecord) error {
	if existsRawUnMined(ns, rec.Hash[:]) != nil {
		return nil
	}
	for i := range rec.MsgTx.TxOut {
		k := canonicalOutPoint(&rec.Hash, uint32(i))
		if existsRawUnspent(ns, k) != nil {
			return nil
		}
	}
	log.Trace("Inserting unconfirmed transaction ", "rec.Hash", rec.Hash)
	v, err := valueTxRecord(rec)
	if err != nil {
		return err
	}
	err = putRawUnMined(ns, rec.Hash[:], v)
	if err != nil {
		return err
	}
	for _, input := range rec.MsgTx.TxIn {
		prevOut := &input.PreviousOut
		k := canonicalOutPoint(&prevOut.Hash, prevOut.OutIndex)
		err = putRawUnMinedInput(ns, k, rec.Hash[:])
		if err != nil {
			return err
		}
	}
	return nil
}
func (s *Store) removeDoubleSpends(ns walletdb.ReadWriteBucket, rec *TxRecord) error {
	for _, input := range rec.MsgTx.TxIn {
		prevOut := &input.PreviousOut
		prevOutKey := canonicalOutPoint(&prevOut.Hash, prevOut.OutIndex)
		doubleSpendHashes := fetchUnMinedInputSpendTxHashes(ns, prevOutKey)
		for _, doubleSpendHash := range doubleSpendHashes {
			doubleSpendVal := existsRawUnMined(ns, doubleSpendHash[:])
			if doubleSpendVal == nil {
				continue
			}
			var doubleSpend TxRecord
			doubleSpend.Hash = doubleSpendHash
			err := readRawTxRecord(
				&doubleSpend.Hash, doubleSpendVal, &doubleSpend,
			)
			if err != nil {
				return err
			}
			log.Debug("Removing double spending transaction %v",
				doubleSpend.Hash)
			if err := s.removeConflict(ns, &doubleSpend); err != nil {
				return err
			}
		}
	}
	return nil
}
func (s *Store) removeConflict(ns walletdb.ReadWriteBucket, rec *TxRecord) error {
	for i := range rec.MsgTx.TxOut {
		k := canonicalOutPoint(&rec.Hash, uint32(i))
		spenderHashes := fetchUnMinedInputSpendTxHashes(ns, k)
		for _, spenderHash := range spenderHashes {
			spenderVal := existsRawUnMined(ns, spenderHash[:])
			if spenderVal == nil {
				continue
			}
			var spender TxRecord
			spender.Hash = spenderHash
			err := readRawTxRecord(&spender.Hash, spenderVal, &spender)
			if err != nil {
				return err
			}
			log.Debug("Transaction %v is part of a removed conflict "+
				"chain -- removing as well", spender.Hash)
			if err := s.removeConflict(ns, &spender); err != nil {
				return err
			}
		}
		if err := deleteRawUnMinedCredit(ns, k); err != nil {
			return err
		}
	}
	for _, input := range rec.MsgTx.TxIn {
		prevOut := &input.PreviousOut
		k := canonicalOutPoint(&prevOut.Hash, prevOut.OutIndex)
		if err := deleteRawUnMinedInput(ns, k); err != nil {
			return err
		}
	}
	return deleteRawUnmMined(ns, rec.Hash[:])
}
func (s *Store) UnMinedTxs(ns walletdb.ReadBucket) ([]*types.Transaction, error) {
	recSet, err := s.unMinedTxRecords(ns)
	if err != nil {
		return nil, err
	}
	txSet := make(map[hash.Hash]*types.Transaction, len(recSet))
	for txHash, txRec := range recSet {
		txSet[txHash] = &txRec.MsgTx
	}
	return DependencySort(txSet), nil
}
func (s *Store) unMinedTxRecords(ns walletdb.ReadBucket) (map[hash.Hash]*TxRecord, error) {
	unMined := make(map[hash.Hash]*TxRecord)
	err := ns.NestedReadBucket(bucketUnMined).ForEach(func(k, v []byte) error {
		var txHash hash.Hash
		err := readRawUnMinedHash(k, &txHash)
		if err != nil {
			return err
		}
		rec := new(TxRecord)
		err = readRawTxRecord(&txHash, v, rec)
		if err != nil {
			return err
		}
		unMined[rec.Hash] = rec
		return nil
	})
	return unMined, err
}