mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-11 00:26:44 +00:00

* Revert "[NOD-214] Remove Fee transaction from addrindex (#321)" This reverts commit e4b2d869d49471021c56cb27cbc3001134b94dfd. * Revert "[NOD-195] Make fee tx implicit (#315)" This reverts commit ccca580a4b3ff8a44138041c0ce3bc0ce5847a4d.
105 lines
3.2 KiB
Go
105 lines
3.2 KiB
Go
// Copyright (c) 2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
/*
|
|
Package indexers implements optional block chain indexes.
|
|
*/
|
|
package indexers
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
|
|
"github.com/daglabs/btcd/blockdag"
|
|
"github.com/daglabs/btcd/database"
|
|
"github.com/daglabs/btcd/util"
|
|
)
|
|
|
|
var (
|
|
// byteOrder is the preferred byte order used for serializing numeric
|
|
// fields for storage in the database.
|
|
byteOrder = binary.LittleEndian
|
|
|
|
// errInterruptRequested indicates that an operation was cancelled due
|
|
// to a user-requested interrupt.
|
|
errInterruptRequested = errors.New("interrupt requested")
|
|
)
|
|
|
|
// NeedsInputser provides a generic interface for an indexer to specify the it
|
|
// requires the ability to look up inputs for a transaction.
|
|
type NeedsInputser interface {
|
|
NeedsInputs() bool
|
|
}
|
|
|
|
// Indexer provides a generic interface for an indexer that is managed by an
|
|
// index manager such as the Manager type provided by this package.
|
|
type Indexer interface {
|
|
// Key returns the key of the index as a byte slice.
|
|
Key() []byte
|
|
|
|
// Name returns the human-readable name of the index.
|
|
Name() string
|
|
|
|
// Create is invoked when the indexer manager determines the index needs
|
|
// to be created for the first time.
|
|
Create(dbTx database.Tx) error
|
|
|
|
// Init is invoked when the index manager is first initializing the
|
|
// index. This differs from the Create method in that it is called on
|
|
// every load, including the case the index was just created.
|
|
Init(db database.DB, dag *blockdag.BlockDAG) error
|
|
|
|
// ConnectBlock is invoked when the index manager is notified that a new
|
|
// block has been connected to the DAG.
|
|
ConnectBlock(dbTx database.Tx, block *util.Block, dag *blockdag.BlockDAG, _ blockdag.MultiBlockTxsAcceptanceData, _ blockdag.MultiBlockTxsAcceptanceData) error
|
|
}
|
|
|
|
// AssertError identifies an error that indicates an internal code consistency
|
|
// issue and should be treated as a critical and unrecoverable error.
|
|
type AssertError string
|
|
|
|
// Error returns the assertion error as a huma-readable string and satisfies
|
|
// the error interface.
|
|
func (e AssertError) Error() string {
|
|
return "assertion failed: " + string(e)
|
|
}
|
|
|
|
// errDeserialize signifies that a problem was encountered when deserializing
|
|
// data.
|
|
type errDeserialize string
|
|
|
|
// Error implements the error interface.
|
|
func (e errDeserialize) Error() string {
|
|
return string(e)
|
|
}
|
|
|
|
// isDeserializeErr returns whether or not the passed error is an errDeserialize
|
|
// error.
|
|
func isDeserializeErr(err error) bool {
|
|
_, ok := err.(errDeserialize)
|
|
return ok
|
|
}
|
|
|
|
// internalBucket is an abstraction over a database bucket. It is used to make
|
|
// the code easier to test since it allows mock objects in the tests to only
|
|
// implement these functions instead of everything a database.Bucket supports.
|
|
type internalBucket interface {
|
|
Get(key []byte) []byte
|
|
Put(key []byte, value []byte) error
|
|
Delete(key []byte) error
|
|
}
|
|
|
|
// interruptRequested returns true when the provided channel has been closed.
|
|
// This simplifies early shutdown slightly since the caller can just use an if
|
|
// statement instead of a select.
|
|
func interruptRequested(interrupted <-chan struct{}) bool {
|
|
select {
|
|
case <-interrupted:
|
|
return true
|
|
default:
|
|
}
|
|
|
|
return false
|
|
}
|