lnd.xprv/lnwallet/btcwallet/driver.go
Olaoluwa Osuntokun 6a1d8d0682
lnwallet: add a BtcWallet implementation of WalletController
This commit adds the first concrete implementation of the
WalletController interface: BtcWallet. This implementation is simply a
series of wrapper functions are the base btcwallet struct.

Additionally, for ease of use both the BlockChain IO and Signer
interface are also implemented by BtcWallet. Finally a new WalletDriver
implementation has been implemented, and will be register by the init()
method within this new package.
2016-09-08 12:25:32 -07:00

46 lines
1.2 KiB
Go

package btcwallet
import (
"fmt"
"github.com/lightningnetwork/lnd/lnwallet"
)
const (
walletType = "btcwallet"
)
// createNewWallet creates a new instance of BtcWallet given the proper list of
// initialization parameters. This function is the factory function required to
// properly create an instance of the lnwallet.WalletDriver struct for
// BtcWallet.
func createNewWallet(args ...interface{}) (lnwallet.WalletController, error) {
if len(args) != 1 {
return nil, fmt.Errorf("incorrect number of arguments to .New(...), "+
"expected 1, instead passed %v", len(args))
}
config, ok := args[0].(*Config)
if !ok {
return nil, fmt.Errorf("first argument to btcdnotifier.New is " +
"incorrect, expected a *btcrpcclient.ConnConfig")
}
return New(config)
}
// init registers a driver for the BtcWallet concrete implementation of the
// lnwallet.WalletController interface.
func init() {
// Register the driver.
driver := &lnwallet.WalletDriver{
WalletType: walletType,
New: createNewWallet,
}
if err := lnwallet.RegisterWallet(driver); err != nil {
panic(fmt.Sprintf("failed to register wallet driver '%s': %v",
walletType, err))
}
}