2016-03-22 21:00:31 +01:00
|
|
|
package lnwallet
|
|
|
|
|
|
|
|
import (
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/btcec"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
|
|
"github.com/btcsuite/btcutil"
|
2016-03-22 21:00:31 +01:00
|
|
|
)
|
|
|
|
|
2018-04-18 04:02:04 +02:00
|
|
|
// AddressType is an enum-like type which denotes the possible address types
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// WalletController supports.
|
|
|
|
type AddressType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
// WitnessPubKey represents a p2wkh address.
|
2018-02-18 00:36:53 +01:00
|
|
|
WitnessPubKey AddressType = iota
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
|
|
|
|
// NestedWitnessPubKey represents a p2sh output which is itself a
|
|
|
|
// nested p2wkh output.
|
|
|
|
NestedWitnessPubKey
|
|
|
|
|
2018-02-18 00:36:53 +01:00
|
|
|
// UnknownAddressType represents an output with an unknown or non-standard
|
|
|
|
// script.
|
|
|
|
UnknownAddressType
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
)
|
|
|
|
|
2018-04-08 23:34:00 +02:00
|
|
|
var (
|
|
|
|
// DefaultPublicPassphrase is the default public passphrase used for the
|
|
|
|
// wallet.
|
|
|
|
DefaultPublicPassphrase = []byte("public")
|
|
|
|
|
|
|
|
// DefaultPrivatePassphrase is the default private passphrase used for
|
|
|
|
// the wallet.
|
|
|
|
DefaultPrivatePassphrase = []byte("hello")
|
|
|
|
|
|
|
|
// ErrDoubleSpend is returned from PublishTransaction in case the
|
|
|
|
// tx being published is spending an output spent by a conflicting
|
|
|
|
// transaction.
|
|
|
|
ErrDoubleSpend = errors.New("Transaction rejected: output already spent")
|
|
|
|
|
|
|
|
// ErrNotMine is an error denoting that a WalletController instance is
|
|
|
|
// unable to spend a specified output.
|
|
|
|
ErrNotMine = errors.New("the passed output doesn't belong to the wallet")
|
|
|
|
)
|
2018-01-15 23:26:35 +01:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// Utxo is an unspent output denoted by its outpoint, and output value of the
|
|
|
|
// original output.
|
|
|
|
type Utxo struct {
|
2017-10-03 03:52:45 +02:00
|
|
|
AddressType AddressType
|
|
|
|
Value btcutil.Amount
|
|
|
|
PkScript []byte
|
|
|
|
RedeemScript []byte
|
|
|
|
WitnessScript []byte
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
wire.OutPoint
|
|
|
|
}
|
|
|
|
|
2016-10-15 05:03:34 +02:00
|
|
|
// TransactionDetail describes a transaction with either inputs which belong to
|
|
|
|
// the wallet, or has outputs that pay to the wallet.
|
|
|
|
type TransactionDetail struct {
|
|
|
|
// Hash is the transaction hash of the transaction.
|
2017-01-05 22:56:27 +01:00
|
|
|
Hash chainhash.Hash
|
2016-10-15 05:03:34 +02:00
|
|
|
|
|
|
|
// Value is the net value of this transaction (in satoshis) from the
|
|
|
|
// PoV of the wallet. If this transaction purely spends from the
|
|
|
|
// wallet's funds, then this value will be negative. Similarly, if this
|
|
|
|
// transaction credits the wallet, then this value will be positive.
|
|
|
|
Value btcutil.Amount
|
|
|
|
|
|
|
|
// NumConfirmations is the number of confirmations this transaction
|
|
|
|
// has. If the transaction is unconfirmed, then this value will be
|
|
|
|
// zero.
|
|
|
|
NumConfirmations int32
|
|
|
|
|
|
|
|
// BlockHeight is the hash of the block which includes this
|
|
|
|
// transaction. Unconfirmed transactions will have a nil value for this
|
|
|
|
// field.
|
2017-01-05 22:56:27 +01:00
|
|
|
BlockHash *chainhash.Hash
|
2016-10-15 05:03:34 +02:00
|
|
|
|
|
|
|
// BlockHeight is the height of the block including this transaction.
|
|
|
|
// Unconfirmed transaction will show a height of zero.
|
|
|
|
BlockHeight int32
|
|
|
|
|
|
|
|
// Timestamp is the unix timestamp of the block including this
|
|
|
|
// transaction. If the transaction is unconfirmed, then this will be a
|
|
|
|
// timestamp of txn creation.
|
|
|
|
Timestamp int64
|
|
|
|
|
|
|
|
// TotalFees is the total fee in satoshis paid by this transaction.
|
|
|
|
TotalFees int64
|
2017-12-06 18:19:37 +01:00
|
|
|
|
|
|
|
// DestAddresses are the destinations for a transaction
|
|
|
|
DestAddresses []btcutil.Address
|
2016-10-15 05:03:34 +02:00
|
|
|
}
|
2016-10-15 23:07:05 +02:00
|
|
|
|
|
|
|
// TransactionSubscription is an interface which describes an object capable of
|
|
|
|
// receiving notifications of new transaction related to the underlying wallet.
|
|
|
|
// TODO(roasbeef): add balance updates?
|
|
|
|
type TransactionSubscription interface {
|
|
|
|
// ConfirmedTransactions returns a channel which will be sent on as new
|
|
|
|
// relevant transactions are confirmed.
|
|
|
|
ConfirmedTransactions() chan *TransactionDetail
|
|
|
|
|
|
|
|
// UnconfirmedTransactions returns a channel which will be sent on as
|
|
|
|
// new relevant transactions are seen within the network.
|
|
|
|
UnconfirmedTransactions() chan *TransactionDetail
|
|
|
|
|
|
|
|
// Cancel finalizes the subscription, cleaning up any resources
|
|
|
|
// allocated.
|
|
|
|
Cancel()
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:00:31 +01:00
|
|
|
// WalletController defines an abstract interface for controlling a local Pure
|
|
|
|
// Go wallet, a local or remote wallet via an RPC mechanism, or possibly even
|
|
|
|
// a daemon assisted hardware wallet. This interface serves the purpose of
|
|
|
|
// allowing LightningWallet to be seamlessly compatible with several wallets
|
|
|
|
// such as: uspv, btcwallet, Bitcoin Core, Electrum, etc. This interface then
|
|
|
|
// serves as a "base wallet", with Lightning Network awareness taking place at
|
|
|
|
// a "higher" level of abstraction. Essentially, an overlay wallet.
|
2016-08-04 07:31:20 +02:00
|
|
|
// Implementors of this interface must closely adhere to the documented
|
|
|
|
// behavior of all interface methods in order to ensure identical behavior
|
|
|
|
// across all concrete implementations.
|
2016-03-22 21:00:31 +01:00
|
|
|
type WalletController interface {
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// 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.
|
|
|
|
FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error)
|
|
|
|
|
2016-03-22 21:00:31 +01:00
|
|
|
// 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.
|
2018-02-18 00:36:53 +01:00
|
|
|
//
|
|
|
|
// NOTE: Only witness outputs should be included in the computation of
|
|
|
|
// the total spendable balance of the wallet. We require this as only
|
|
|
|
// witness inputs can be used for funding channels.
|
|
|
|
ConfirmedBalance(confs int32) (btcutil.Amount, error)
|
2016-04-13 06:36:41 +02:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// NewAddress returns the next external or internal address for the
|
2016-12-22 21:34:51 +01:00
|
|
|
// wallet dictated by the value of the `change` parameter. If change is
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// true, then an internal address should be used, otherwise an external
|
|
|
|
// address should be returned. The type of address returned is dictated
|
2018-02-18 00:36:53 +01:00
|
|
|
// by the wallet's capabilities, and may be of type: p2sh, p2wkh,
|
|
|
|
// p2wsh, etc.
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
NewAddress(addrType AddressType, change bool) (btcutil.Address, error)
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2018-09-28 05:58:46 +02:00
|
|
|
// IsOurAddress checks if the passed address belongs to this wallet
|
|
|
|
IsOurAddress(a btcutil.Address) bool
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2018-07-28 03:20:58 +02:00
|
|
|
// 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, an error should be returned.
|
|
|
|
// This method also takes the target fee expressed in sat/kw that should
|
|
|
|
// be used when crafting the transaction.
|
2017-11-23 07:28:56 +01:00
|
|
|
SendOutputs(outputs []*wire.TxOut,
|
2018-11-05 12:30:32 +01:00
|
|
|
feeRate SatPerKWeight) (*wire.MsgTx, error)
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2016-04-13 06:36:41 +02:00
|
|
|
// ListUnspentWitness returns all unspent outputs which are version 0
|
2018-10-28 15:55:18 +01:00
|
|
|
// witness programs. The 'minconfirms' and 'maxconfirms' parameters
|
|
|
|
// indicate the minimum and maximum number of confirmations an output
|
|
|
|
// needs in order to be returned by this method. Passing -1 as
|
|
|
|
// 'minconfirms' indicates that even unconfirmed outputs should be
|
|
|
|
// returned. Using MaxInt32 as 'maxconfirms' implies returning all
|
|
|
|
// outputs with at least 'minconfirms'.
|
|
|
|
ListUnspentWitness(minconfirms, maxconfirms int32) ([]*Utxo, error)
|
2016-04-13 06:36:41 +02:00
|
|
|
|
2016-10-15 05:03:34 +02:00
|
|
|
// ListTransactionDetails returns a list of all transactions which are
|
|
|
|
// relevant to the wallet.
|
|
|
|
ListTransactionDetails() ([]*TransactionDetail, error)
|
|
|
|
|
2016-03-22 21:00:31 +01:00
|
|
|
// LockOutpoint marks an outpoint as locked meaning it will no longer
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// 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.
|
2016-03-22 21:00:31 +01:00
|
|
|
LockOutpoint(o wire.OutPoint)
|
|
|
|
|
2018-04-18 04:02:04 +02:00
|
|
|
// UnlockOutpoint unlocks a previously locked output, marking it
|
2016-12-22 21:34:51 +01:00
|
|
|
// eligible for coin selection.
|
2016-03-22 21:00:31 +01:00
|
|
|
UnlockOutpoint(o wire.OutPoint)
|
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// PublishTransaction performs cursory validation (dust checks, etc),
|
|
|
|
// then finally broadcasts the passed transaction to the Bitcoin network.
|
2018-01-15 23:26:35 +01:00
|
|
|
// If the transaction is rejected because it is conflicting with an
|
|
|
|
// already known transaction, ErrDoubleSpend is returned. If the
|
|
|
|
// transaction is already known (published already), no error will be
|
|
|
|
// returned. Other error returned depends on the currently active chain
|
|
|
|
// backend.
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
PublishTransaction(tx *wire.MsgTx) error
|
2016-03-22 21:00:31 +01:00
|
|
|
|
2016-10-15 23:07:05 +02:00
|
|
|
// 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.
|
|
|
|
//
|
2016-12-09 03:29:55 +01:00
|
|
|
// NOTE: a non-nil error should be returned if notifications aren't
|
2016-10-15 23:07:05 +02:00
|
|
|
// supported.
|
|
|
|
//
|
|
|
|
// TODO(roasbeef): make distinct interface?
|
|
|
|
SubscribeTransactions() (TransactionSubscription, error)
|
|
|
|
|
2016-12-09 03:29:55 +01:00
|
|
|
// 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.
|
2017-12-10 08:42:46 +01:00
|
|
|
// It also returns an int64 indicating the timestamp of the best block
|
|
|
|
// known to the wallet, expressed in Unix epoch time
|
|
|
|
IsSynced() (bool, int64, error)
|
2016-12-09 03:29:55 +01:00
|
|
|
|
|
|
|
// Start initializes the wallet, making any necessary connections,
|
2016-03-22 21:00:31 +01:00
|
|
|
// starting up required goroutines etc.
|
|
|
|
Start() error
|
|
|
|
|
|
|
|
// Stop signals the wallet for shutdown. Shutdown may entail closing
|
|
|
|
// any active sockets, database handles, stopping goroutines, etc.
|
|
|
|
Stop() error
|
2017-11-10 01:30:20 +01:00
|
|
|
|
|
|
|
// BackEnd returns a name for the wallet's backing chain service,
|
|
|
|
// which could be e.g. btcd, bitcoind, neutrino, or another consensus
|
|
|
|
// service.
|
|
|
|
BackEnd() string
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlockChainIO is a dedicated source which will be used to obtain queries
|
|
|
|
// related to the current state of the blockchain. The data returned by each of
|
|
|
|
// the defined methods within this interface should always return the most up
|
|
|
|
// to date data possible.
|
|
|
|
//
|
|
|
|
// TODO(roasbeef): move to diff package perhaps?
|
2016-09-12 21:33:22 +02:00
|
|
|
// TODO(roasbeef): move publish txn here?
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
type BlockChainIO interface {
|
2016-12-22 21:34:51 +01:00
|
|
|
// GetBestBlock returns the current height and block hash of the valid
|
|
|
|
// most-work chain the implementation is aware of.
|
2017-01-05 22:56:27 +01:00
|
|
|
GetBestBlock() (*chainhash.Hash, int32, error)
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
|
2017-05-11 01:37:14 +02:00
|
|
|
// GetUtxo attempts to return the passed outpoint if it's still a
|
|
|
|
// member of the utxo set. The passed height hint should be the "birth
|
2018-07-18 04:20:52 +02:00
|
|
|
// height" of the passed outpoint. The script passed should be the
|
2018-07-26 04:33:46 +02:00
|
|
|
// script that the outpoint creates. In the case that the output is in
|
2017-05-11 01:37:14 +02:00
|
|
|
// the UTXO set, then the output corresponding to that output is
|
|
|
|
// returned. Otherwise, a non-nil error will be returned.
|
2018-07-18 04:20:52 +02:00
|
|
|
GetUtxo(op *wire.OutPoint, pkScript []byte,
|
|
|
|
heightHint uint32) (*wire.TxOut, error)
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
|
2017-01-13 06:01:50 +01:00
|
|
|
// GetBlockHash returns the hash of the block in the best blockchain
|
2016-12-22 21:34:51 +01:00
|
|
|
// at the given height.
|
2017-01-05 22:56:27 +01:00
|
|
|
GetBlockHash(blockHeight int64) (*chainhash.Hash, error)
|
2016-12-07 16:49:58 +01:00
|
|
|
|
2016-12-22 21:34:51 +01:00
|
|
|
// GetBlock returns the block in the main chain identified by the given
|
|
|
|
// hash.
|
2017-01-05 22:56:27 +01:00
|
|
|
GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Signer represents an abstract object capable of generating raw signatures as
|
|
|
|
// well as full complete input scripts given a valid SignDescriptor and
|
|
|
|
// transaction. This interface fully abstracts away signing paving the way for
|
|
|
|
// Signer implementations such as hardware wallets, hardware tokens, HSM's, or
|
|
|
|
// simply a regular wallet.
|
|
|
|
type Signer interface {
|
|
|
|
// SignOutputRaw generates a signature for the passed transaction
|
|
|
|
// according to the data within the passed SignDescriptor.
|
|
|
|
//
|
|
|
|
// NOTE: The resulting signature should be void of a sighash byte.
|
|
|
|
SignOutputRaw(tx *wire.MsgTx, signDesc *SignDescriptor) ([]byte, error)
|
|
|
|
|
|
|
|
// ComputeInputScript generates a complete InputIndex for the passed
|
|
|
|
// transaction with the signature as defined within the passed
|
|
|
|
// SignDescriptor. This method should be capable of generating the
|
|
|
|
// proper input script for both regular p2wkh output and p2wkh outputs
|
2016-12-22 21:34:51 +01:00
|
|
|
// nested within a regular p2sh output.
|
2017-07-30 03:47:06 +02:00
|
|
|
//
|
|
|
|
// NOTE: This method will ignore any tweak parameters set within the
|
|
|
|
// passed SignDescriptor as it assumes a set of typical script
|
|
|
|
// templates (p2wkh, np2wkh, etc).
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
ComputeInputScript(tx *wire.MsgTx, signDesc *SignDescriptor) (*InputScript, error)
|
|
|
|
}
|
|
|
|
|
2017-04-14 19:59:13 +02:00
|
|
|
// MessageSigner represents an abstract object capable of signing arbitrary
|
|
|
|
// messages. The capabilities of this interface are used to sign announcements
|
|
|
|
// to the network, or just arbitrary messages that leverage the wallet's keys
|
|
|
|
// to attest to some message.
|
|
|
|
type MessageSigner interface {
|
|
|
|
// 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.
|
|
|
|
SignMessage(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error)
|
|
|
|
}
|
|
|
|
|
2018-01-17 03:04:07 +01:00
|
|
|
// PreimageCache is an interface that represents a global cache for preimages.
|
|
|
|
// We'll utilize this cache to communicate the discovery of new preimages
|
|
|
|
// across sub-systems.
|
|
|
|
type PreimageCache interface {
|
|
|
|
// LookupPreimage attempts to look up a preimage according to its hash.
|
|
|
|
// If found, the preimage is returned along with true for the second
|
|
|
|
// argument. Otherwise, it'll return false.
|
|
|
|
LookupPreimage(hash []byte) ([]byte, bool)
|
|
|
|
|
|
|
|
// AddPreimage attempts to add a new preimage to the global cache. If
|
|
|
|
// successful a nil error will be returned.
|
|
|
|
AddPreimage(preimage []byte) error
|
|
|
|
}
|
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// WalletDriver represents a "driver" for a particular concrete
|
2016-12-22 21:34:51 +01:00
|
|
|
// WalletController implementation. A driver is identified by a globally unique
|
|
|
|
// string identifier along with a 'New()' method which is responsible for
|
|
|
|
// initializing a particular WalletController concrete implementation.
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
type WalletDriver struct {
|
2018-01-17 03:04:07 +01:00
|
|
|
// WalletType is a string which uniquely identifies the
|
|
|
|
// WalletController that this driver, drives.
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
WalletType string
|
|
|
|
|
|
|
|
// New creates a new instance of a concrete WalletController
|
|
|
|
// implementation given a variadic set up arguments. The function takes
|
2017-12-18 03:40:05 +01:00
|
|
|
// a variadic number of interface parameters in order to provide
|
2016-12-22 21:34:51 +01:00
|
|
|
// initialization flexibility, thereby accommodating several potential
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// WalletController implementations.
|
|
|
|
New func(args ...interface{}) (WalletController, error)
|
2017-11-10 01:30:20 +01:00
|
|
|
|
|
|
|
// BackEnds returns a list of available chain service drivers for the
|
|
|
|
// wallet driver. This could be e.g. bitcoind, btcd, neutrino, etc.
|
|
|
|
BackEnds func() []string
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
wallets = make(map[string]*WalletDriver)
|
|
|
|
registerMtx sync.Mutex
|
|
|
|
)
|
|
|
|
|
|
|
|
// RegisteredWallets returns a slice of all currently registered notifiers.
|
|
|
|
//
|
|
|
|
// NOTE: This function is safe for concurrent access.
|
|
|
|
func RegisteredWallets() []*WalletDriver {
|
|
|
|
registerMtx.Lock()
|
|
|
|
defer registerMtx.Unlock()
|
|
|
|
|
|
|
|
registeredWallets := make([]*WalletDriver, 0, len(wallets))
|
|
|
|
for _, wallet := range wallets {
|
|
|
|
registeredWallets = append(registeredWallets, wallet)
|
|
|
|
}
|
|
|
|
|
|
|
|
return registeredWallets
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterWallet registers a WalletDriver which is capable of driving a
|
|
|
|
// concrete WalletController interface. In the case that this driver has
|
|
|
|
// already been registered, an error is returned.
|
|
|
|
//
|
|
|
|
// NOTE: This function is safe for concurrent access.
|
|
|
|
func RegisterWallet(driver *WalletDriver) error {
|
|
|
|
registerMtx.Lock()
|
|
|
|
defer registerMtx.Unlock()
|
|
|
|
|
|
|
|
if _, ok := wallets[driver.WalletType]; ok {
|
|
|
|
return fmt.Errorf("wallet already registered")
|
|
|
|
}
|
|
|
|
|
|
|
|
wallets[driver.WalletType] = driver
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:34:51 +01:00
|
|
|
// SupportedWallets returns a slice of strings that represents the wallet
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
// drivers that have been registered and are therefore supported.
|
|
|
|
//
|
|
|
|
// NOTE: This function is safe for concurrent access.
|
|
|
|
func SupportedWallets() []string {
|
|
|
|
registerMtx.Lock()
|
|
|
|
defer registerMtx.Unlock()
|
2016-03-22 21:00:31 +01:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
supportedWallets := make([]string, 0, len(wallets))
|
|
|
|
for walletName := range wallets {
|
|
|
|
supportedWallets = append(supportedWallets, walletName)
|
|
|
|
}
|
2016-03-22 21:00:31 +01:00
|
|
|
|
lnwallet: revamp interfaces, add BlockChainIO and Singer
This commit revamps the previous WalletController interface, edging it
closer to a more complete version.
Additionally, this commit also introduces two new interfaces:
BlockchainIO, and Singer along with a new factor driver struct, the
WalletDriver.
This BlockChainIO abstracts read-only access to the blockchain, while
the Singer interface abstracts the signing of inputs from the base
wallet paving the way to hardware wallets, air-gapped signing, etc.
Finally, in order to provide an easy method for selecting a particular
concrete implementation of a WalletController interface, the concept of
registering “WalletDriver”s has been introduced. A wallet driver is
essentially the encapsulation of a factory function capable of create a
new instance of a Wallet Controller.
2016-08-13 00:24:22 +02:00
|
|
|
return supportedWallets
|
2016-03-22 21:00:31 +01:00
|
|
|
}
|