func (idx *ExistsAddrIndex) ExistsAddress(addr hcashutil.Address) (bool, error) {
	k, err := addrToKey(addr, idx.chainParams)
	if err != nil {
		return false, err
	}
	var exists bool
	err = idx.db.View(func(dbTx database.Tx) error {
		meta := dbTx.Metadata()
		existsAddrIndex := meta.Bucket(existsAddrIndexKey)
		exists = existsAddrIndex.Get(k[:]) != nil
		return nil
	})
	if err != nil {
		return false, err
	}
	if !exists {
		idx.unconfirmedLock.RLock()
		_, exists = idx.mpExistsAddr[k]
		idx.unconfirmedLock.RUnlock()
	}
	return exists, nil
}
ExistsAddress is the concurrency safe, exported function that returns
whether or not an address has been seen before.
package indexers
import (
	"sync"
	"github.com/HcashOrg/hcashd/blockchain"
	"github.com/HcashOrg/hcashd/blockchain/stake"
	"github.com/HcashOrg/hcashd/chaincfg"
	"github.com/HcashOrg/hcashd/database"
	"github.com/HcashOrg/hcashd/txscript"
	"github.com/HcashOrg/hcashd/wire"
	"github.com/HcashOrg/hcashutil"
)
var (
	existsAddressIndexName = "exists address index"
	existsAddrIndexKey = []byte("existsaddridx")
)
type ExistsAddrIndex struct {
	db          database.DB
	chainParams *chaincfg.Params
	unconfirmedLock sync.RWMutex
	mpExistsAddr    map[[addrKeySize]byte]struct{}
}
func NewExistsAddrIndex(db database.DB, chainParams *chaincfg.Params) *ExistsAddrIndex {
	return &ExistsAddrIndex{
		db:           db,
		chainParams:  chainParams,
		mpExistsAddr: make(map[[addrKeySize]byte]struct{}),
	}
}
var _ Indexer = (*ExistsAddrIndex)(nil)
var _ NeedsInputser = (*ExistsAddrIndex)(nil)
func (idx *ExistsAddrIndex) NeedsInputs() bool {
	return false
}
func (idx *ExistsAddrIndex) Init() error {
	return nil
}
func (idx *ExistsAddrIndex) Key() []byte {
	return existsAddrIndexKey
}
func (idx *ExistsAddrIndex) Name() string {
	return existsAddressIndexName
}
func (idx *ExistsAddrIndex) Create(dbTx database.Tx) error {
	_, err := dbTx.Metadata().CreateBucket(existsAddrIndexKey)
	return err
}
func dbPutExistsAddr(bucket database.Bucket, addrKey [addrKeySize]byte) error {
	return bucket.Put(addrKey[:], nil)
}
func (idx *ExistsAddrIndex) existsAddress(bucket database.Bucket, k [addrKeySize]byte) bool {
	if bucket.Get(k[:]) != nil {
		return true
	}
	idx.unconfirmedLock.RLock()
	_, exists := idx.mpExistsAddr[k]
	idx.unconfirmedLock.RUnlock()
	return exists
}