bus

package
v0.11.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBitcoindUnreachable indicates that an RPC call to the bitcoind node
	// was not successful. Use this error during sanity checks.
	ErrBitcoindUnreachable = errors.New("bitcoind unreachable")

	// ErrWalletDisabled indicates that wallet features have been disabled on
	// the connected Bitcoin node. SatStack relies on wallet RPCs to function.
	ErrWalletDisabled = errors.New("bitcoind wallet is disabled")

	// ErrCreateWallet indicates that the wallet RPC createwallet was not
	// successful.
	ErrCreateWallet = errors.New("failed to create wallet")

	// ErrLoadWallet indicates that the wallet RPC loadwallet was not
	// successful.
	ErrLoadWallet = errors.New("failed to load wallet")

	// ErrUnsupportedBitcoindVersion indicates that the connected bitcoind node
	// has a version that is not supported by SatStack.
	ErrUnsupportedBitcoindVersion = errors.New("unsupported bitcoind version")

	// ErrUnrecognizedChain indicates that the Chain returned by bitcoind in
	// its response to the getblockchaininfo RPC, is unrecognized by LSS.
	//
	// This usually means that the value doesn't correspond to a Currency or
	// network that libcore can understand.
	ErrUnrecognizedChain = errors.New("unrecognized chain")

	// ErrFailedToGetBlock indicates that an error was encountered while
	// trying to get a block.
	ErrFailedToGetBlock = errors.New("failed to get block")

	// ErrMalformedChainHash indicates that a chain hash (transaction or block)
	// could not be parsed.
	ErrMalformedChainHash = errors.New("malformed chain hash")

	// ErrFailedToDetectTxIndex indicates an irrecoverable error while trying
	// to detect presence of a transaction index. Normally, this error should
	// not be ignored silently.
	ErrFailedToDetectTxIndex = errors.New("failed to detect txindex")

	// ErrFailedToDetectBlockFilter indicates an irrecoverable error while trying
	// to detect presence of a compact block filter index. Normally, this error
	// should not be ignored silently.
	ErrFailedToDetectBlockFilter = errors.New("failed to detect block filter")

	// ErrInvalidDescriptor indicates that a malformed descriptor was
	// encountered.
	ErrInvalidDescriptor = errors.New("invalid descriptor")

	// ErrDeriveAddress indicates that an address could not be derived from a
	// descriptor.
	ErrDeriveAddress = errors.New("failed to derive address")

	// ErrAddressInfo indicates that an error was encountered while trying to
	// fetch address info.
	ErrAddressInfo = errors.New("failed to get address info")
)

Functions

func ChainParams

func ChainParams(chain string) (*chaincfg.Params, error)

ChainParams returns the *chaincfg.Params instance corresponding to the network that the underlying node is connected to.

This value is useful for several operations in btcd, and can be accessed via the Bus struct.

func DeriveAddress

func DeriveAddress(client *rpcclient.Client, descriptor string, index int) (*string, error)

func GetCanonicalDescriptor

func GetCanonicalDescriptor(client *rpcclient.Client, descriptor string) (*string, error)

GetCanonicalDescriptor returns the descriptor in canonical form, along with its computed checksum.

func ImportDescriptors

func ImportDescriptors(client *rpcclient.Client, descriptors []descriptor) error

Types

type Bus

type Bus struct {
	// Informational fields
	Chain       string
	Pruned      bool
	TxIndex     bool
	BlockFilter bool
	Currency    Currency // Based on Chain value, for interoperability with libcore

	// Thread-safe Bus cache, to query results typically by hash
	Cache *cache.Cache

	// btcd network params
	Params *chaincfg.Params

	// IsPendingScan is a boolean field to indicate if satstack is currently
	// waiting for descriptors to be scanned. One such example is when satstack
	// is "running the numbers".
	//
	// This value can be exported for use by other packages to avoid making
	// explorer requests before satstack is able to serve them.
	IsPendingScan bool
	// contains filtered or unexported fields
}

Bus represents a transport allowing access to Bitcoin RPC methods.

It maintains a pool of btcd rpcclient objects in a buffered channel to allow concurrent invocation of RPC methods.

func New

func New(host string, user string, pass string, noTLS bool) (*Bus, error)

New initializes a Bus struct that embeds a btcd RPC client.

func (*Bus) ClientFactory

func (b *Bus) ClientFactory() (*rpcclient.Client, error)

func (*Bus) Close

func (b *Bus) Close(ctx context.Context)

Close performs cleanup operations on the Bus, notably shutting down the rpcclient.Client connections.

The cleanup must be performed within a timeout set by the passed context, to prevent hanging on connections indefinitely held by bitcoind.

func (*Bus) EstimateSmartFee

func (b *Bus) EstimateSmartFee(target int64, mode string) btcutil.Amount

func (*Bus) FlushCache

func (b *Bus) FlushCache()

FlushCache clears the Bus cache storage, and sets the value of Bus.Cache to nil.

func (*Bus) GetBestBlockHash

func (b *Bus) GetBestBlockHash() (*chainhash.Hash, error)

func (*Bus) GetBlock

func (b *Bus) GetBlock(hash *chainhash.Hash) (*types.Block, error)

func (*Bus) GetBlockChainInfo

func (b *Bus) GetBlockChainInfo() (*btcjson.GetBlockChainInfoResult, error)

func (*Bus) GetBlockHash

func (b *Bus) GetBlockHash(height int64) (*chainhash.Hash, error)

func (*Bus) GetTransaction

func (b *Bus) GetTransaction(hash string) (*types.Transaction, error)

func (*Bus) GetTransactionHex

func (b *Bus) GetTransactionHex(hash *chainhash.Hash) (string, error)

func (*Bus) ImportAccounts

func (b *Bus) ImportAccounts(accounts []config.Account) error

ImportAccounts will import the descriptors corresponding to the accounts into the Bitcoin Core wallet. This is a blocking operation.

func (*Bus) ListTransactions

func (b *Bus) ListTransactions(blockHash *string) ([]btcjson.ListTransactionsResult, error)

func (*Bus) NewCache

func (b *Bus) NewCache()

NewCache initializes a new cache storage and assigns it to the Cache field of Bus.

func (*Bus) SendTransaction

func (b *Bus) SendTransaction(tx string) (*chainhash.Hash, error)

func (*Bus) UnloadWallet

func (b *Bus) UnloadWallet()

func (*Bus) Worker

func (b *Bus) Worker(config *config.Configuration)

type Currency

type Currency = string

Currency represents the currency type (btc) and the network params (Mainnet, testnet3, regtest, etc) in libcore parlance.

const (
	Testnet Currency = "btc_testnet"
	Mainnet Currency = "btc"
)

func CurrencyFromChain

func CurrencyFromChain(chain string) (Currency, error)

currencyFromChain is an adapter function to convert a chain (network) value to a Currency type that's understood by libcore.

type ExplorerStatus

type ExplorerStatus struct {
	Version      string   `json:"version"`
	TxIndex      bool     `json:"txindex"`
	BlockFilter  bool     `json:"block_filter"`
	Pruned       bool     `json:"pruned"`
	Chain        string   `json:"chain"`
	Currency     Currency `json:"currency"`
	Status       Status   `json:"status"`
	SyncProgress *float64 `json:"sync_progress,omitempty"`
	ScanProgress *float64 `json:"scan_progress,omitempty"`
}

ExplorerStatus represents the structure of payload returned by GetStatus service method.

type Status

type Status string

Status indicates the state of LSS with regards to the readiness of the connected Bitcoin Core node.

const (
	// Initializing is a Status to indicate the initial state of LSS, while it
	// is warming up.
	Initializing Status = "initializing"

	// NodeDisconnected is a Status to indicate that the bitcoind instance is
	// unreachable. This is typically returned in the response of the status
	// endpoint.
	NodeDisconnected Status = "node-disconnected"

	// Ready is a Status to indicate that LSS is ready to accept explorer API
	// requests from Ledger Live.
	Ready Status = "ready"

	// Syncing is a Status to indicate that the Bitcoin Core node is currently
	// downloading and validating blocks.
	Syncing Status = "syncing"

	// PendingScan is a Status to indicate that the worker is awaiting import
	// of descriptors. This is typically the case when LSS is launched, while it
	// is "running the numbers".
	//
	// Use this Status when Bus.IsPendingScan is set to true.
	PendingScan Status = "pending-scan"

	// Scanning is a Status to indicate that the Bitcoin Core node is currently
	// importing account descriptors into its wallet.
	Scanning Status = "scanning"
)

Jump to

Keyboard shortcuts

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