pushtx

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRebroadcastInterval is the default period that we'll wait
	// between blocks to attempt another rebroadcast.
	DefaultRebroadcastInterval = time.Minute
)

Variables

View Source
var (
	// ErrBroadcastStopped is an error returned when we attempt to process a
	// request to broadcast a transaction but the Broadcaster has already
	// been stopped.
	ErrBroadcasterStopped = errors.New("broadcaster has been stopped")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func IsBroadcastError

func IsBroadcastError(err error, codes ...BroadcastErrorCode) bool

IsBroadcastError is a helper function that can be used to determine whether an error is a BroadcastError that matches any of the specified codes.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type BroadcastError

type BroadcastError struct {
	// Code is the uniquely identifying code of the broadcast error.
	Code BroadcastErrorCode

	// Reason is the string detailing the reason as to why the transaction
	// was rejected.
	Reason string
}

BroadcastError is an error type that encompasses the different possible broadcast errors returned by the network.

func ParseBroadcastError

func ParseBroadcastError(msg *wire.MsgReject, peerAddr string) *BroadcastError

ParseBroadcastError maps a peer's reject message for a transaction to a BroadcastError.

func (*BroadcastError) Error

func (e *BroadcastError) Error() string

Error returns the reason of the broadcast error.

type BroadcastErrorCode

type BroadcastErrorCode uint8

BroadcastErrorCode uniquely identifies the broadcast error.

const (
	// Unknown is the code used when a transaction has been rejected by some
	// unknown reason by a peer.
	Unknown BroadcastErrorCode = iota

	// Invalid is the code used when a transaction has been deemed invalid
	// by a peer.
	Invalid

	// InsufficientFee is the code used when a transaction has been deemed
	// as having an insufficient fee by a peer.
	InsufficientFee

	// Mempool is the code used when a transaction already exists in a
	// peer's mempool.
	Mempool

	// Confirmed is the code used when a transaction has been deemed as
	// confirmed in the chain by a peer.
	Confirmed
)

func (BroadcastErrorCode) String

func (c BroadcastErrorCode) String() string

type Broadcaster

type Broadcaster struct {
	// contains filtered or unexported fields
}

Broadcaster is a subsystem responsible for reliably broadcasting transactions to the network. Each transaction will be rebroadcast upon every new block being connected/disconnected to/from the chain.

func NewBroadcaster

func NewBroadcaster(cfg *Config) *Broadcaster

NewBroadcaster creates a new Broadcaster backed by the given config.

func (*Broadcaster) Broadcast

func (b *Broadcaster) Broadcast(tx *wire.MsgTx) error

Broadcast submits a request to the Broadcaster to reliably broadcast the given transaction. An error won't be returned if the transaction already exists within the mempool. Any transaction broadcast through this method will be rebroadcast upon every change of the tip of the chain.

func (*Broadcaster) Start

func (b *Broadcaster) Start() error

Start starts all of the necessary steps for the Broadcaster to begin properly carrying out its duties.

func (*Broadcaster) Stop

func (b *Broadcaster) Stop()

Stop halts the Broadcaster from rebroadcasting pending transactions.

type Config

type Config struct {
	// Broadcast broadcasts a transaction to the network. We expect certain
	// BroadcastError's to be returned to handle special cases, namely
	// errors with the codes Mempool and Confirmed.
	Broadcast func(*wire.MsgTx) error

	// SubscribeBlocks returns a block subscription that delivers block
	// notifications in order. This will be used to rebroadcast all
	// transactions once a new block arrives.
	SubscribeBlocks func() (*blockntfns.Subscription, error)

	// RebroadcastInterval is the interval that we'll continually try to
	// re-broadcast transactions in-between new block arrival.
	RebroadcastInterval time.Duration
}

Config contains all of the external dependencies required for the Broadcaster to properly carry out its duties.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL