btcwallet

package
v0.4.2-beta Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOutputSpent is returned by the GetUtxo method if the target output
	// for lookup has already been spent.
	ErrOutputSpent = errors.New("target output has been spent")

	// ErrOutputNotFound signals that the desired output could not be
	// located.
	ErrOutputNotFound = errors.New("target output was not found")
)

Functions

func NetworkDir

func NetworkDir(dataDir string, chainParams *chaincfg.Params) string

NetworkDir returns the directory name of a network directory to hold wallet files.

Types

type BtcWallet

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

BtcWallet is an implementation of the lnwallet.WalletController interface backed by an active instance of btcwallet. At the time of the writing of this documentation, this implementation requires a full btcd node to operate.

func New

func New(cfg Config) (*BtcWallet, error)

New returns a new fully initialized instance of BtcWallet given a valid configuration struct.

func (*BtcWallet) BackEnd

func (b *BtcWallet) BackEnd() string

BackEnd returns the underlying ChainService's name as a string.

This is a part of the WalletController interface.

func (*BtcWallet) ComputeInputScript

func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx,
	signDesc *lnwallet.SignDescriptor) (*lnwallet.InputScript, error)

ComputeInputScript generates a complete InputIndex for the passed transaction with the signature as defined within the passed SignDescriptor. This method is capable of generating the proper input script for both regular p2wkh output and p2wkh outputs nested within a regular p2sh output.

This is a part of the WalletController interface.

func (*BtcWallet) ConfirmedBalance

func (b *BtcWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error)

ConfirmedBalance returns the sum of all the wallet's unspent outputs that have at least confs confirmations. If confs is set to zero, then all unspent outputs, including those currently in the mempool will be included in the final sum.

This is a part of the WalletController interface.

func (*BtcWallet) FetchInputInfo

func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error)

FetchInputInfo queries for the WalletController's knowledge of the passed outpoint. If the base wallet determines this output is under its control, then the original txout should be returned. Otherwise, a non-nil error value of ErrNotMine should be returned instead.

This is a part of the WalletController interface.

func (*BtcWallet) GetBestBlock

func (b *BtcWallet) GetBestBlock() (*chainhash.Hash, int32, error)

GetBestBlock returns the current height and hash of the best known block within the main chain.

This method is a part of the lnwallet.BlockChainIO interface.

func (*BtcWallet) GetBlock

func (b *BtcWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)

GetBlock returns a raw block from the server given its hash.

This method is a part of the lnwallet.BlockChainIO interface.

func (*BtcWallet) GetBlockHash

func (b *BtcWallet) GetBlockHash(blockHeight int64) (*chainhash.Hash, error)

GetBlockHash returns the hash of the block in the best blockchain at the given height.

This method is a part of the lnwallet.BlockChainIO interface.

func (*BtcWallet) GetPrivKey

func (b *BtcWallet) GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error)

GetPrivKey retrieves the underlying private key associated with the passed address. If the we're unable to locate the proper private key, then a non-nil error will be returned.

This is a part of the WalletController interface.

func (*BtcWallet) GetUtxo

func (b *BtcWallet) GetUtxo(op *wire.OutPoint, heightHint uint32) (*wire.TxOut, error)

GetUtxo returns the original output referenced by the passed outpoint.

This method is a part of the lnwallet.BlockChainIO interface.

func (*BtcWallet) InternalWallet

func (b *BtcWallet) InternalWallet() *base.Wallet

InternalWallet returns a pointer to the internal base wallet which is the core of btcwallet.

func (*BtcWallet) IsSynced

func (b *BtcWallet) IsSynced() (bool, int64, error)

IsSynced returns a boolean indicating if from the PoV of the wallet, it has fully synced to the current best block in the main chain.

This is a part of the WalletController interface.

func (*BtcWallet) ListTransactionDetails

func (b *BtcWallet) ListTransactionDetails() ([]*lnwallet.TransactionDetail, error)

ListTransactionDetails returns a list of all transactions which are relevant to the wallet.

This is a part of the WalletController interface.

func (*BtcWallet) ListUnspentWitness

func (b *BtcWallet) ListUnspentWitness(minConfs int32) ([]*lnwallet.Utxo, error)

ListUnspentWitness returns a slice of all the unspent outputs the wallet controls which pay to witness programs either directly or indirectly.

This is a part of the WalletController interface.

func (*BtcWallet) LockOutpoint

func (b *BtcWallet) LockOutpoint(o wire.OutPoint)

LockOutpoint marks an outpoint as locked meaning it will no longer be deemed as eligible for coin selection. Locking outputs are utilized in order to avoid race conditions when selecting inputs for usage when funding a channel.

This is a part of the WalletController interface.

func (*BtcWallet) NewAddress

func (b *BtcWallet) NewAddress(t lnwallet.AddressType, change bool) (btcutil.Address, error)

NewAddress returns the next external or internal address for the wallet dictated by the value of the `change` parameter. If change is true, then an internal address will be returned, otherwise an external address should be returned.

This is a part of the WalletController interface.

func (*BtcWallet) PublishTransaction

func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx) error

PublishTransaction performs cursory validation (dust checks, etc), then finally broadcasts the passed transaction to the Bitcoin network. If publishing the transaction fails, an error describing the reason is returned (currently ErrDoubleSpend). If the transaction is already published to the network (either in the mempool or chain) no error will be returned.

func (*BtcWallet) SendOutputs

func (b *BtcWallet) SendOutputs(outputs []*wire.TxOut,
	feeRate lnwallet.SatPerVByte) (*chainhash.Hash, error)

SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying out to the specified outputs. In the case the wallet has insufficient funds, or the outputs are non-standard, a non-nil error will be returned.

This is a part of the WalletController interface.

func (*BtcWallet) SignMessage

func (b *BtcWallet) SignMessage(pubKey *btcec.PublicKey,
	msg []byte) (*btcec.Signature, error)

SignMessage attempts to sign a target message with the private key that corresponds to the passed public key. If the target private key is unable to be found, then an error will be returned. The actual digest signed is the double SHA-256 of the passed message.

NOTE: This is a part of the MessageSigner interface.

func (*BtcWallet) SignOutputRaw

func (b *BtcWallet) SignOutputRaw(tx *wire.MsgTx,
	signDesc *lnwallet.SignDescriptor) ([]byte, error)

SignOutputRaw generates a signature for the passed transaction according to the data within the passed SignDescriptor.

This is a part of the WalletController interface.

func (*BtcWallet) Start

func (b *BtcWallet) Start() error

Start initializes the underlying rpc connection, the wallet itself, and begins syncing to the current available blockchain state.

This is a part of the WalletController interface.

func (*BtcWallet) Stop

func (b *BtcWallet) Stop() error

Stop signals the wallet for shutdown. Shutdown may entail closing any active sockets, database handles, stopping goroutines, etc.

This is a part of the WalletController interface.

func (*BtcWallet) SubscribeTransactions

func (b *BtcWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, error)

SubscribeTransactions returns a TransactionSubscription client which is capable of receiving async notifications as new transactions related to the wallet are seen within the network, or found in blocks.

This is a part of the WalletController interface.

func (*BtcWallet) UnlockOutpoint

func (b *BtcWallet) UnlockOutpoint(o wire.OutPoint)

UnlockOutpoint unlocks a previously locked output, marking it eligible for coin selection.

This is a part of the WalletController interface.

type Config

type Config struct {
	// DataDir is the name of the directory where the wallet's persistent
	// state should be stored.
	DataDir string

	// LogDir is the name of the directory which should be used to store
	// generated log files.
	LogDir string

	// PrivatePass is the private password to the underlying btcwallet
	// instance. Without this, the wallet cannot be decrypted and operated.
	PrivatePass []byte

	// PublicPass is the optional public password to btcwallet. This is
	// optionally used to encrypt public material such as public keys and
	// scripts.
	PublicPass []byte

	// HdSeed is an optional seed to feed into the wallet. If this is
	// unspecified, a new seed will be generated.
	HdSeed []byte

	// Birthday specifies the time at which this wallet was initially
	// created. It is used to bound rescans for used addresses.
	Birthday time.Time

	// RecoveryWindow specifies the address look-ahead for which to scan
	// when restoring a wallet. The recovery window will apply to all
	// default BIP44 derivation paths.
	RecoveryWindow uint32

	// ChainSource is the primary chain interface. This is used to operate
	// the wallet and do things such as rescanning, sending transactions,
	// notifications for received funds, etc.
	ChainSource chain.Interface

	// FeeEstimator is an instance of the fee estimator interface which
	// will be used by the wallet to dynamically set transaction fees when
	// crafting transactions.
	FeeEstimator lnwallet.FeeEstimator

	// NetParams is the net parameters for the target chain.
	NetParams *chaincfg.Params

	// CoinType specifies the BIP 44 coin type to be used for derivation.
	CoinType uint32
}

Config is a struct which houses configuration parameters which modify the instance of BtcWallet generated by the New() function.

Jump to

Keyboard shortcuts

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