From 98bbd314a7dc90bb2c297142a5aec1b3cc6f459b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 2 Feb 2016 19:09:54 -0800 Subject: [PATCH] lnwallet: add active Bitcoin network to config --- lnwallet/config.go | 4 ++++ lnwallet/wallet.go | 10 +++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lnwallet/config.go b/lnwallet/config.go index 1cacad31..56f70897 100644 --- a/lnwallet/config.go +++ b/lnwallet/config.go @@ -3,6 +3,7 @@ package lnwallet import ( "path/filepath" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcutil" ) @@ -48,6 +49,9 @@ type Config struct { PrivatePass []byte PublicPass []byte HdSeed []byte + + // Which bitcoin network are we using? + NetParams *chaincfg.Params } // setDefaults... diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 178db855..ea3aa971 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -18,7 +18,6 @@ import ( "github.com/lightningnetwork/lnd/shachain" "github.com/btcsuite/btcd/btcec" - "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" @@ -41,9 +40,6 @@ var ( ErrInsufficientFunds = errors.New("not enough available outputs to " + "create funding transaction") - // Which bitcoin network are we using? - // TODO(roasbeef): config - ActiveNetParams = &chaincfg.TestNet3Params // Namespace bucket keys. lightningNamespaceKey = []byte("ln-wallet") waddrmgrNamespaceKey = []byte("waddrmgr") @@ -253,7 +249,7 @@ type LightningWallet struct { // TODO(roasbeef): fin...add config func NewLightningWallet(config *Config) (*LightningWallet, walletdb.DB, error) { // Ensure the wallet exists or create it when the create flag is set. - netDir := networkDir(config.DataDir, ActiveNetParams) + netDir := networkDir(config.DataDir, config.NetParams) dbPath := filepath.Join(netDir, walletDbName) var pubPass []byte @@ -348,7 +344,7 @@ func (l *LightningWallet) Startup() error { } // TODO(roasbeef): config... - rpcc, err := chain.NewRPCClient(ActiveNetParams, l.cfg.RpcHost, + rpcc, err := chain.NewRPCClient(l.cfg.NetParams, l.cfg.RpcHost, l.cfg.RpcUser, l.cfg.RpcPass, l.cfg.CACert, false, 20) if err != nil { return err @@ -750,7 +746,7 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) { // Is this our txin? TODO(roasbeef): assumes all inputs are P2PKH... prevIndex := txIn.PreviousOutPoint.Index prevOut := txDetail.TxRecord.MsgTx.TxOut[prevIndex] - _, addrs, _, _ := txscript.ExtractPkScriptAddrs(prevOut.PkScript, ActiveNetParams) + _, addrs, _, _ := txscript.ExtractPkScriptAddrs(prevOut.PkScript, l.cfg.NetParams) apkh, ok := addrs[0].(*btcutil.AddressPubKeyHash) if !ok { req.err <- btcwallet.ErrUnsupportedTransactionType