lnwallet/btcwallet: update btcwallet config to be aware of new chain interface

This commit is contained in:
Olaoluwa Osuntokun 2017-05-24 17:34:03 -07:00
parent 392a8180dd
commit aca729abfe
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 23 additions and 43 deletions

@ -39,8 +39,7 @@ type BtcWallet struct {
// wallet is an active instance of btcwallet. // wallet is an active instance of btcwallet.
wallet *base.Wallet wallet *base.Wallet
// rpc is an an active RPC connection to btcd full-node. chain chain.Interface
rpc *chain.RPCClient
db walletdb.DB db walletdb.DB
@ -94,14 +93,6 @@ func New(cfg Config) (*BtcWallet, error) {
} }
} }
// Create a special websockets rpc client for btcd which will be used
// by the wallet for notifications, calls, etc.
rpcc, err := chain.NewRPCClient(cfg.NetParams, cfg.RPCHost,
cfg.RPCUser, cfg.RPCPass, cfg.CACert, false, 20)
if err != nil {
return nil, err
}
// Create a bucket within the wallet's database dedicated to storing // Create a bucket within the wallet's database dedicated to storing
// our LN specific data. // our LN specific data.
db := wallet.Database() db := wallet.Database()
@ -121,7 +112,7 @@ func New(cfg Config) (*BtcWallet, error) {
cfg: &cfg, cfg: &cfg,
wallet: wallet, wallet: wallet,
db: db, db: db,
rpc: rpcc, chain: cfg.ChainSource,
netParams: cfg.NetParams, netParams: cfg.NetParams,
utxoCache: make(map[wire.OutPoint]*wire.TxOut), utxoCache: make(map[wire.OutPoint]*wire.TxOut),
}, nil }, nil
@ -134,7 +125,7 @@ func New(cfg Config) (*BtcWallet, error) {
func (b *BtcWallet) Start() error { func (b *BtcWallet) Start() error {
// Establish an RPC connection in additino to starting the goroutines // Establish an RPC connection in additino to starting the goroutines
// in the underlying wallet. // in the underlying wallet.
if err := b.rpc.Start(); err != nil { if err := b.chain.Start(); err != nil {
return err return err
} }
@ -143,7 +134,7 @@ func (b *BtcWallet) Start() error {
// Pass the rpc client into the wallet so it can sync up to the // Pass the rpc client into the wallet so it can sync up to the
// current main chain. // current main chain.
b.wallet.SynchronizeRPC(b.rpc) b.wallet.SynchronizeRPC(b.chain)
if err := b.wallet.Unlock(b.cfg.PrivatePass, nil); err != nil { if err := b.wallet.Unlock(b.cfg.PrivatePass, nil); err != nil {
return err return err
@ -161,7 +152,7 @@ func (b *BtcWallet) Stop() error {
b.wallet.WaitForShutdown() b.wallet.WaitForShutdown()
b.rpc.Shutdown() b.chain.Stop()
return nil return nil
} }

@ -11,6 +11,7 @@ import (
// init function of the package, it registers itself. The import is used // init function of the package, it registers itself. The import is used
// to activate the side effects w/o actually binding the package name to // to activate the side effects w/o actually binding the package name to
// a file-level variable. // a file-level variable.
"github.com/roasbeef/btcwallet/chain"
_ "github.com/roasbeef/btcwallet/walletdb/bdb" _ "github.com/roasbeef/btcwallet/walletdb/bdb"
) )
@ -47,37 +48,25 @@ type Config struct {
// generated log files. // generated log files.
LogDir string LogDir string
// DebugLevel is a string representing the level of verbosity the // PrivatePass is the private password to the underlying btcwallet
// logger should use. // instance. Without this, the wallet cannot be decrypted and operated.
DebugLevel string
// RPCHost is the host and port to use to reach the rpc sever.
RPCHost string // localhost:18334
// RPCUser is the username which should be used to authentiate with the
// rpc server.
RPCUser string
// RPCPass is the password which should be used to authenticate the
// connection with the RPC server.
RPCPass string
// RPCNoTLS denotes if a TLS connection should be attempted when
// connecting to the RPC server.
RPCNoTLS bool
// RPCCert directory where the TLS certificate of the RPC sever is
// stored. If the RPCNoTLS is false, then this value will be unused.
RPCCert string
RPCKey string
// CACert is the raw RPC cert for btcd.
CACert []byte
PrivatePass []byte 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 PublicPass []byte
// HdSeed is an optional seed to feed into the wallet. If this is
// unspecified, a new seed will be generated.
HdSeed []byte HdSeed []byte
// 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
// NetParams is the net parameters for the target chain.
NetParams *chaincfg.Params NetParams *chaincfg.Params
} }