Documentation ¶
Index ¶
- Variables
- func DisableLog()
- func UseLogger(logger slog.Logger)
- type BlockConnectedEvent
- type BlockDisconnectedEvent
- type ChainEvent
- type ChainSource
- type ErrBlockAfterTip
- type Event
- type FindFunc
- type FoundCallback
- type Historical
- type HistoricalChainSource
- type MatchField
- type Option
- func WithCancelChan(c <-chan struct{}) Option
- func WithCompleteChan(c chan struct{}) Option
- func WithEndHeight(endHeight int32) Option
- func WithFoundCallback(cb FoundCallback) Option
- func WithFoundChan(c chan<- Event) Option
- func WithStartHeight(startHeight int32) Option
- func WithStartWatchHeightChan(c chan int32) Option
- type PkScript
- type Target
- func ConfirmedOutPoint(out wire.OutPoint, version uint16, pkscript []byte) Target
- func ConfirmedScript(version uint16, pkscript []byte) Target
- func ConfirmedTransaction(txh chainhash.Hash, version uint16, pkscript []byte) Target
- func SpentOutPoint(out wire.OutPoint, version uint16, pkscript []byte) Target
- func SpentScript(version uint16, pkscript []byte) Target
- type TargetAndOptions
- type TipChainSource
- type TipWatcher
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedScriptType is an error returned when we attempt to // parse/re-compute an output script into a PkScript struct. ErrUnsupportedScriptType = errors.New("unsupported script type") )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type BlockConnectedEvent ¶
type BlockConnectedEvent struct { Hash chainhash.Hash Height int32 PrevHash chainhash.Hash CFKey [16]byte Filter *gcs.FilterV2 Header *wire.BlockHeader }
func (BlockConnectedEvent) BlockHash ¶
func (e BlockConnectedEvent) BlockHash() *chainhash.Hash
func (BlockConnectedEvent) BlockHeader ¶ added in v0.6.0
func (e BlockConnectedEvent) BlockHeader() *wire.BlockHeader
func (BlockConnectedEvent) BlockHeight ¶
func (e BlockConnectedEvent) BlockHeight() int32
func (BlockConnectedEvent) PrevBlockHash ¶
func (e BlockConnectedEvent) PrevBlockHash() *chainhash.Hash
type BlockDisconnectedEvent ¶
type BlockDisconnectedEvent struct { Hash chainhash.Hash Height int32 PrevHash chainhash.Hash Header *wire.BlockHeader }
func (BlockDisconnectedEvent) BlockHash ¶
func (e BlockDisconnectedEvent) BlockHash() *chainhash.Hash
func (BlockDisconnectedEvent) BlockHeader ¶ added in v0.6.0
func (e BlockDisconnectedEvent) BlockHeader() *wire.BlockHeader
func (BlockDisconnectedEvent) BlockHeight ¶
func (e BlockDisconnectedEvent) BlockHeight() int32
func (BlockDisconnectedEvent) PrevBlockHash ¶
func (e BlockDisconnectedEvent) PrevBlockHash() *chainhash.Hash
type ChainEvent ¶
type ChainSource ¶
type ErrBlockAfterTip ¶
type ErrBlockAfterTip struct {
Height int32
}
ErrBlockAfterTip should be returned by chains when the requested block is after the currently known tip. Scanners may choose not to fail their run if this specific error is returned.
func (ErrBlockAfterTip) Error ¶
func (e ErrBlockAfterTip) Error() string
func (ErrBlockAfterTip) Is ¶
func (e ErrBlockAfterTip) Is(err error) bool
type Event ¶
type FoundCallback ¶
type Historical ¶
type Historical struct {
// contains filtered or unexported fields
}
func NewHistorical ¶
func NewHistorical(chain HistoricalChainSource) *Historical
func (*Historical) FindMany ¶
func (h *Historical) FindMany(targets []TargetAndOptions) error
FindMany attempts to search for many targets at once. This is better than making individual calls to Find() when they should be searched for at the same starting height since all specified targets are guaranteed to be included in the same search batch.
This function is safe for concurrent calls in multiple goroutines, including inside functions specified with WithFoundCallback() options.
type HistoricalChainSource ¶
type HistoricalChainSource interface { ChainSource // GetCFilter MUST return the block hash, key and filter for the given // mainchain block height. // // If a height higher than the current mainchain tip is specified, the // chain source MUST return ErrBlockAfterTip so that the historical // scanner will correctly handle targets specified with an invalid // ending height. GetCFilter(context.Context, int32) (*chainhash.Hash, [16]byte, *gcs.FilterV2, error) }
type MatchField ¶
type MatchField uint8
const ( MatchTxIn MatchField = 1 << iota MatchTxOut )
func (MatchField) String ¶
func (m MatchField) String() string
type Option ¶
type Option func(*target)
func WithCancelChan ¶
func WithCancelChan(c <-chan struct{}) Option
WithCancelChan allows a caller to specify a channel that, once closed, removes the provided target from being scanned for.
func WithCompleteChan ¶
func WithCompleteChan(c chan struct{}) Option
WithCompleteChan allows a caller to specify a channel that gets closed once the endHeight was reached for the target.
func WithEndHeight ¶
WithEndHeight allows a caller to specify a block height after which scans should no longer happen.
func WithFoundCallback ¶
func WithFoundCallback(cb FoundCallback) Option
WithFoundCallback allows a caller to specify a callback that is called synchronously in relation to a scanner when the related target is found in a block.
This callback is called in the same goroutine that performs scans, therefore it is *NOT* safe to perform any receives or sends on channels that also affect this or other target's searches (such as waiting for a StartWatchingHeight, FoundChan or other signals).
It is also generally not advised to perform lengthy operations inside this callback since it blocks all other searches from progressing.
This callback is intended to be used in situations where the caller needs to add new targets to search for as a result of having found a match within a block.
There are two ways to add addicional targets during the execution of the foundCallback:
Via additional Find() calls of the scanner (which _are_ safe for direct calling by the foundCallback). This allows callers to start to search for additional targets on any block (either further along the chain or in the past).
Via the second argument to the foundCallback. That function can add targets to search for, starting at the _current_ block, transaction list and transaction index. This is useful (for example) when detecting a specific script was used in an output should trigger a search for other scripts including in the same block. Note that when adding new targets using this method, they MUST include a WithStartingHeight(event.BlockHeight+1) option (even though the search will also be carried in later transactions of the current block being scanned).
The callback function may be called multiple times for a given target.
func WithFoundChan ¶
WithFoundChan allows a caller to specify a channel that receives events when a match for a given target is found. This event is called concurrently with the rest of the search process.
Callers are responsible for draining this channel once the search completes, otherwise data may leak. They should also ensure the channel is _not_ closed until the search completes, otherwise the scanner may panic.
The channel may be sent to multiple times.
func WithStartHeight ¶
WithStartHeight allows a caller to specify a block height after which a scan should trigger events when this target is found.
func WithStartWatchHeightChan ¶
WithStartWatchHeightChan allows a caller to specify a channel that receives the block height after which events will be triggered if the target is found.
type PkScript ¶
type PkScript struct {
// contains filtered or unexported fields
}
PkScript is a wrapper struct around a byte array, allowing it to be used as a map index.
func ComputePkScript ¶
ComputePkScript computes the pkScript of an transaction output by looking at the transaction input's signature script.
NOTE: Only P2PKH and P2SH redeem scripts are supported. Only the standard secp256k1 keys are supported (alternative suites are not).
func ParsePkScript ¶
ParsePkScript parses an output script into the PkScript struct. ErrUnsupportedScriptType is returned when attempting to parse an unsupported script type.
func (PkScript) Class ¶
func (s PkScript) Class() stdscript.ScriptType
Class returns the script type.
func (PkScript) Equal ¶
Equal returns true if the other pkscript is equal to this one (has the same values).
func (PkScript) Script ¶
Script returns the script as a byte slice without any padding. This is a copy of the original script, therefore it's safe for modification.
func (PkScript) ScriptVersion ¶
ScriptVersion returns the recorded script version of the pkscript.
type Target ¶
type Target interface {
// contains filtered or unexported methods
}
Target represents the desired target (outpoint, pkscript, etc) of a search.
NOTE: targets are *not* safe for reuse for multiple searches.
func ConfirmedOutPoint ¶
ConfirmedOutPoint tries to match against a TxOut that spends the provided script but only as long as the output itself fulfills the specified outpoint (that is, the output is created in the transaction specified by out.Hash and at the out.Index position).
func ConfirmedScript ¶
func ConfirmedTransaction ¶
func SpentOutPoint ¶
SpentOutPoint tries to match against a TxIn that spends the given outpoint and pkscript combination.
NOTE: If the provided pkscript does _not_ actually correspond to the outpoint, the search may never trigger a match.
func SpentScript ¶
SpentScript tries to match against a TxIn that spends the provided script.
NOTE: only version 0 scripts are currently supported. Also, the match is a best effort one, based on the "shape" of the signature script of the txin. See ComputePkScript for details on supported script types.
type TargetAndOptions ¶
type TipChainSource ¶
type TipChainSource interface { ChainSource // ChainEvents MUST return a channel that is sent ChainEvent's until // the passed context is canceled. ChainEvents(context.Context) <-chan ChainEvent }
TipChainSource defines the required backend functions for the TipWatcher scanner to perform its duties.
type TipWatcher ¶
type TipWatcher struct {
// contains filtered or unexported fields
}
func NewTipWatcher ¶
func NewTipWatcher(chain TipChainSource) *TipWatcher
func (*TipWatcher) ChainEvents ¶
func (tw *TipWatcher) ChainEvents(ctx context.Context) <-chan ChainEvent
ChainEvents follows the same semantics as the TipChainSource ChainEvents but ensures all channels are only signalled _after_ the tip watcher has processed them.
func (*TipWatcher) ForceRescan ¶
func (tw *TipWatcher) ForceRescan(ctx context.Context, e *BlockConnectedEvent) error