From f594a57c940d57c41dad4632f2994a3315d844cf Mon Sep 17 00:00:00 2001 From: CirroStorm Date: Thu, 27 Sep 2018 23:58:46 -0400 Subject: [PATCH] lnwallet: remove need for lnwallet to have access to the private key This paves the way for lnd to work with hardware wallets, in which case it will not have access to the private key. --- lnwallet/btcwallet/btcwallet.go | 12 ++++-------- lnwallet/interface.go | 7 ++----- mock.go | 4 ++-- server.go | 5 +---- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 3fb7665c..40d7f4e9 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -9,7 +9,6 @@ import ( "sync" "time" - "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" @@ -255,15 +254,12 @@ func (b *BtcWallet) NewAddress(t lnwallet.AddressType, change bool) (btcutil.Add return b.wallet.NewAddress(defaultAccount, keyScope) } -// GetPrivKey retrieves the underlying private key associated with the passed -// address. If the we're unable to locate the proper private key, then a -// non-nil error will be returned. +// IsOurAddress checks if the passed address belongs to this wallet // // This is a part of the WalletController interface. -func (b *BtcWallet) GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error) { - // Using the ID address, request the private key corresponding to the - // address from the wallet's address manager. - return b.wallet.PrivKeyForAddress(a) +func (b *BtcWallet) IsOurAddress(a btcutil.Address) bool { + result, err := b.wallet.HaveAddress(a) + return result && (err == nil) } // SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying out to diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 073cd913..81bff102 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -148,11 +148,8 @@ type WalletController interface { // p2wsh, etc. NewAddress(addrType AddressType, change bool) (btcutil.Address, error) - // GetPrivKey retrieves the underlying private key associated with the - // passed address. If the wallet is unable to locate this private key - // due to the address not being under control of the wallet, then an - // error should be returned. - GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error) + // IsOurAddress checks if the passed address belongs to this wallet + IsOurAddress(a btcutil.Address) bool // SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying // out to the specified outputs. In the case the wallet has insufficient diff --git a/mock.go b/mock.go index b2d4d89a..6fd7e9f3 100644 --- a/mock.go +++ b/mock.go @@ -222,8 +222,8 @@ func (m *mockWalletController) NewAddress(addrType lnwallet.AddressType, m.rootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams) return addr, nil } -func (*mockWalletController) GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error) { - return nil, nil +func (*mockWalletController) IsOurAddress(a btcutil.Address) bool { + return false } func (*mockWalletController) SendOutputs(outputs []*wire.TxOut, diff --git a/server.go b/server.go index b448b391..9fb002bb 100644 --- a/server.go +++ b/server.go @@ -658,10 +658,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, s.htlcSwitch.RemoveLink(chanID) return nil }, - IsOurAddress: func(addr btcutil.Address) bool { - _, err := cc.wallet.GetPrivKey(addr) - return err == nil - }, + IsOurAddress: cc.wallet.IsOurAddress, ContractBreach: func(chanPoint wire.OutPoint, breachRet *lnwallet.BreachRetribution) error { event := &ContractBreachEvent{