electrum

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultConnectTimeout is a default timeout used for a single attempt of
	// Electrum connection establishment.
	DefaultConnectTimeout = 10 * time.Second
	// DefaultConnectRetryTimeout is a default timeout used for Electrum
	// connection establishment retries.
	DefaultConnectRetryTimeout = 1 * time.Minute
	// DefaultRequestTimeout is a default timeout used for a single attempt of
	// Electrum protocol request.
	DefaultRequestTimeout = 30 * time.Second
	// DefaultRequestRetryTimeout is a default timeout used for Electrum protocol
	// request retries.
	DefaultRequestRetryTimeout = 2 * time.Minute
	// DefaultKeepAliveInterval is a default interval used for Electrum server
	// connection keep alive requests.
	DefaultKeepAliveInterval = 5 * time.Minute
)

Variables

This section is empty.

Functions

func Connect

func Connect(parentCtx context.Context, config Config) (bitcoin.Chain, error)

Connect initializes handle with provided Config.

Types

type Config

type Config struct {
	// URL to the Electrum server in format: `scheme://hostname:port`.
	URL string
	// Timeout for a single attempt of Electrum connection establishment.
	ConnectTimeout time.Duration
	// Timeout for Electrum connection establishment retries.
	ConnectRetryTimeout time.Duration
	// Timeout for a single attempt of Electrum protocol request.
	RequestTimeout time.Duration
	// Timeout for Electrum protocol request retries.
	RequestRetryTimeout time.Duration
	// Interval for connection keep alive requests.
	// An Electrum server may disconnect clients that have not sent any requests
	// for roughly 10 minutes.
	KeepAliveInterval time.Duration
}

Config holds configurable properties.

type Connection

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

Connection is a handle for interactions with Electrum server.

func (*Connection) BroadcastTransaction

func (c *Connection) BroadcastTransaction(
	transaction *bitcoin.Transaction,
) error

BroadcastTransaction broadcasts the given transaction over the network of the Bitcoin chain nodes. If the broadcast action could not be done, this function returns an error. This function does not give any guarantees regarding transaction mining. The transaction may be mined or rejected eventually.

func (*Connection) EstimateSatPerVByteFee

func (c *Connection) EstimateSatPerVByteFee(blocks uint32) (int64, error)

EstimateSatPerVByteFee returns the estimated sat/vbyte fee for a transaction to be confirmed within the given number of blocks.

func (*Connection) GetBlockHeader

func (c *Connection) GetBlockHeader(
	blockHeight uint,
) (*bitcoin.BlockHeader, error)

GetBlockHeader gets the block header for the given block height. If the block with the given height was not found on the chain, this function returns an error.

func (*Connection) GetCoinbaseTxHash

func (c *Connection) GetCoinbaseTxHash(blockHeight uint) (bitcoin.Hash, error)

GetCoinbaseTxHash gets the hash of the coinbase transaction for the given block height.

func (*Connection) GetLatestBlockHeight

func (c *Connection) GetLatestBlockHeight() (uint, error)

GetLatestBlockHeight gets the height of the latest block (tip). If the latest block was not determined, this function returns an error.

func (*Connection) GetMempoolForPublicKeyHash

func (c *Connection) GetMempoolForPublicKeyHash(
	publicKeyHash [20]byte,
) ([]*bitcoin.Transaction, error)

GetMempoolForPublicKeyHash gets the unconfirmed mempool transactions that pays the given public key hash using either a P2PKH or P2WPKH script. The returned transactions are in an indefinite order.

func (*Connection) GetMempoolUtxosForPublicKeyHash

func (c *Connection) GetMempoolUtxosForPublicKeyHash(
	publicKeyHash [20]byte,
) ([]*bitcoin.UnspentTransactionOutput, error)

GetMempoolUtxosForPublicKeyHash gets unspent outputs of unconfirmed transactions that are controlled by the given public key hash (either a P2PKH or P2WPKH script). The returned UTXOs are in an indefinite order. The returned list does not contain unspent outputs of confirmed transactions. Outputs used as inputs of confirmed or mempool transactions are not returned as well because they are no longer UTXOs.

func (*Connection) GetTransaction

func (c *Connection) GetTransaction(
	transactionHash bitcoin.Hash,
) (*bitcoin.Transaction, error)

GetTransaction gets the transaction with the given transaction hash. If the transaction with the given hash was not found on the chain, this function returns an error.

func (*Connection) GetTransactionConfirmations

func (c *Connection) GetTransactionConfirmations(
	transactionHash bitcoin.Hash,
) (uint, error)

GetTransactionConfirmations gets the number of confirmations for the transaction with the given transaction hash. If the transaction with the given hash was not found on the chain, this function returns an error.

func (*Connection) GetTransactionMerkleProof

func (c *Connection) GetTransactionMerkleProof(
	transactionHash bitcoin.Hash,
	blockHeight uint,
) (*bitcoin.TransactionMerkleProof, error)

GetTransactionMerkleProof gets the Merkle proof for a given transaction. The transaction's hash and the block the transaction was included in the blockchain need to be provided.

func (*Connection) GetTransactionsForPublicKeyHash

func (c *Connection) GetTransactionsForPublicKeyHash(
	publicKeyHash [20]byte,
	limit int,
) ([]*bitcoin.Transaction, error)

GetTransactionsForPublicKeyHash gets confirmed transactions that pays the given public key hash using either a P2PKH or P2WPKH script. The returned transactions are ordered by block height in the ascending order, i.e. the latest transaction is at the end of the list. The returned list does not contain unconfirmed transactions living in the mempool at the moment of request. The returned transactions list can be limited using the `limit` parameter. For example, if `limit` is set to `5`, only the latest five transactions will be returned. Note that taking an unlimited transaction history may be time-consuming as this function fetches complete transactions with all necessary data.

func (*Connection) GetTxHashesForPublicKeyHash

func (c *Connection) GetTxHashesForPublicKeyHash(
	publicKeyHash [20]byte,
) ([]bitcoin.Hash, error)

GetTxHashesForPublicKeyHash gets hashes of confirmed transactions that pays the given public key hash using either a P2PKH or P2WPKH script. The returned transactions hashes are ordered by block height in the ascending order, i.e. the latest transaction hash is at the end of the list. The returned list does not contain unconfirmed transactions hashes living in the mempool at the moment of request.

func (*Connection) GetUtxosForPublicKeyHash

func (c *Connection) GetUtxosForPublicKeyHash(
	publicKeyHash [20]byte,
) ([]*bitcoin.UnspentTransactionOutput, error)

GetUtxosForPublicKeyHash gets unspent outputs of confirmed transactions that are controlled by the given public key hash (either a P2PKH or P2WPKH script). The returned UTXOs are ordered by block height in the ascending order, i.e. the latest UTXO is at the end of the list. The returned list does not contain unspent outputs of unconfirmed transactions living in the mempool at the moment of request. Outputs used as inputs of confirmed or mempool transactions are not returned as well because they are no longer UTXOs.

Jump to

Keyboard shortcuts

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