github.com/btcsuite/btcd@v0.24.0/blockchain/interfaces.go (about)

     1  package blockchain
     2  
     3  import (
     4  	"github.com/btcsuite/btcd/chaincfg"
     5  	"github.com/btcsuite/btcd/chaincfg/chainhash"
     6  )
     7  
     8  // ChainCtx is an interface that abstracts away blockchain parameters.
     9  type ChainCtx interface {
    10  	// ChainParams returns the chain's configured chaincfg.Params.
    11  	ChainParams() *chaincfg.Params
    12  
    13  	// BlocksPerRetarget returns the number of blocks before retargeting
    14  	// occurs.
    15  	BlocksPerRetarget() int32
    16  
    17  	// MinRetargetTimespan returns the minimum amount of time to use in the
    18  	// difficulty calculation.
    19  	MinRetargetTimespan() int64
    20  
    21  	// MaxRetargetTimespan returns the maximum amount of time to use in the
    22  	// difficulty calculation.
    23  	MaxRetargetTimespan() int64
    24  
    25  	// VerifyCheckpoint returns whether the passed height and hash match
    26  	// the checkpoint data. Not all instances of VerifyCheckpoint will use
    27  	// this function for validation.
    28  	VerifyCheckpoint(height int32, hash *chainhash.Hash) bool
    29  
    30  	// FindPreviousCheckpoint returns the most recent checkpoint that we
    31  	// have validated. Not all instances of FindPreviousCheckpoint will use
    32  	// this function for validation.
    33  	FindPreviousCheckpoint() (HeaderCtx, error)
    34  }
    35  
    36  // HeaderCtx is an interface that describes information about a block. This is
    37  // used so that external libraries can provide their own context (the header's
    38  // parent, bits, etc.) when attempting to contextually validate a header.
    39  type HeaderCtx interface {
    40  	// Height returns the header's height.
    41  	Height() int32
    42  
    43  	// Bits returns the header's bits.
    44  	Bits() uint32
    45  
    46  	// Timestamp returns the header's timestamp.
    47  	Timestamp() int64
    48  
    49  	// Parent returns the header's parent.
    50  	Parent() HeaderCtx
    51  
    52  	// RelativeAncestorCtx returns the header's ancestor that is distance
    53  	// blocks before it in the chain.
    54  	RelativeAncestorCtx(distance int32) HeaderCtx
    55  }