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:
parent
6afee3d099
commit
f594a57c94
@ -9,7 +9,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"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)
|
return b.wallet.NewAddress(defaultAccount, keyScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPrivKey retrieves the underlying private key associated with the passed
|
// IsOurAddress checks if the passed address belongs to this wallet
|
||||||
// address. If the we're unable to locate the proper private key, then a
|
|
||||||
// non-nil error will be returned.
|
|
||||||
//
|
//
|
||||||
// This is a part of the WalletController interface.
|
// This is a part of the WalletController interface.
|
||||||
func (b *BtcWallet) GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error) {
|
func (b *BtcWallet) IsOurAddress(a btcutil.Address) bool {
|
||||||
// Using the ID address, request the private key corresponding to the
|
result, err := b.wallet.HaveAddress(a)
|
||||||
// address from the wallet's address manager.
|
return result && (err == nil)
|
||||||
return b.wallet.PrivKeyForAddress(a)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying out to
|
// SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying out to
|
||||||
|
@ -148,11 +148,8 @@ type WalletController interface {
|
|||||||
// p2wsh, etc.
|
// p2wsh, etc.
|
||||||
NewAddress(addrType AddressType, change bool) (btcutil.Address, error)
|
NewAddress(addrType AddressType, change bool) (btcutil.Address, error)
|
||||||
|
|
||||||
// GetPrivKey retrieves the underlying private key associated with the
|
// IsOurAddress checks if the passed address belongs to this wallet
|
||||||
// passed address. If the wallet is unable to locate this private key
|
IsOurAddress(a btcutil.Address) bool
|
||||||
// due to the address not being under control of the wallet, then an
|
|
||||||
// error should be returned.
|
|
||||||
GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error)
|
|
||||||
|
|
||||||
// SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying
|
// SendOutputs funds, signs, and broadcasts a Bitcoin transaction paying
|
||||||
// out to the specified outputs. In the case the wallet has insufficient
|
// out to the specified outputs. In the case the wallet has insufficient
|
||||||
|
4
mock.go
4
mock.go
@ -222,8 +222,8 @@ func (m *mockWalletController) NewAddress(addrType lnwallet.AddressType,
|
|||||||
m.rootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams)
|
m.rootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams)
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
func (*mockWalletController) GetPrivKey(a btcutil.Address) (*btcec.PrivateKey, error) {
|
func (*mockWalletController) IsOurAddress(a btcutil.Address) bool {
|
||||||
return nil, nil
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*mockWalletController) SendOutputs(outputs []*wire.TxOut,
|
func (*mockWalletController) SendOutputs(outputs []*wire.TxOut,
|
||||||
|
@ -658,10 +658,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
|
|||||||
s.htlcSwitch.RemoveLink(chanID)
|
s.htlcSwitch.RemoveLink(chanID)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
IsOurAddress: func(addr btcutil.Address) bool {
|
IsOurAddress: cc.wallet.IsOurAddress,
|
||||||
_, err := cc.wallet.GetPrivKey(addr)
|
|
||||||
return err == nil
|
|
||||||
},
|
|
||||||
ContractBreach: func(chanPoint wire.OutPoint,
|
ContractBreach: func(chanPoint wire.OutPoint,
|
||||||
breachRet *lnwallet.BreachRetribution) error {
|
breachRet *lnwallet.BreachRetribution) error {
|
||||||
event := &ContractBreachEvent{
|
event := &ContractBreachEvent{
|
||||||
|
Loading…
Reference in New Issue
Block a user