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.
This commit is contained in:
CirroStorm 2018-09-27 23:58:46 -04:00 committed by Olaoluwa Osuntokun
parent 6afee3d099
commit f594a57c94
4 changed files with 9 additions and 19 deletions

@ -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

@ -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

@ -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,

@ -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{