2016-08-13 01:29:38 +03:00
|
|
|
package btcwallet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-06-05 04:34:16 +03:00
|
|
|
"github.com/btcsuite/btcwallet/chain"
|
2021-03-18 15:08:53 +03:00
|
|
|
"github.com/lightningnetwork/lnd/blockcache"
|
2018-07-31 10:17:17 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
2016-08-13 01:29:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2021-03-18 15:08:53 +03:00
|
|
|
if len(args) != 2 {
|
2016-08-13 01:29:38 +03:00
|
|
|
return nil, fmt.Errorf("incorrect number of arguments to .New(...), "+
|
2021-03-18 15:08:53 +03:00
|
|
|
"expected 2, instead passed %v", len(args))
|
2016-08-13 01:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
config, ok := args[0].(*Config)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("first argument to btcdnotifier.New is " +
|
2017-08-25 04:54:17 +03:00
|
|
|
"incorrect, expected a *rpcclient.ConnConfig")
|
2016-08-13 01:29:38 +03:00
|
|
|
}
|
|
|
|
|
2021-03-18 15:08:53 +03:00
|
|
|
blockCache, ok := args[1].(*blockcache.BlockCache)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("second argument to btcdnotifier.New is " +
|
|
|
|
"incorrect, expected a *blockcache.BlockCache")
|
|
|
|
}
|
|
|
|
|
|
|
|
return New(*config, blockCache)
|
2016-08-13 01:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2017-11-10 03:30:20 +03:00
|
|
|
BackEnds: chain.BackEnds,
|
2016-08-13 01:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := lnwallet.RegisterWallet(driver); err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to register wallet driver '%s': %v",
|
|
|
|
walletType, err))
|
|
|
|
}
|
|
|
|
}
|