lnwallet: expose required account parameter for WalletController methods

This commit is contained in:
Wilmer Paulino 2021-02-19 17:41:45 -08:00
parent a620ce3682
commit f38bf4d7fa
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
11 changed files with 239 additions and 96 deletions

@ -1372,7 +1372,10 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
shutdown, err := getUpfrontShutdownScript( shutdown, err := getUpfrontShutdownScript(
f.cfg.EnableUpfrontShutdown, peer, acceptorResp.UpfrontShutdown, f.cfg.EnableUpfrontShutdown, peer, acceptorResp.UpfrontShutdown,
func() (lnwire.DeliveryAddress, error) { func() (lnwire.DeliveryAddress, error) {
addr, err := f.cfg.Wallet.NewAddress(lnwallet.WitnessPubKey, false) addr, err := f.cfg.Wallet.NewAddress(
lnwallet.WitnessPubKey, false,
lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3153,6 +3156,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
func() (lnwire.DeliveryAddress, error) { func() (lnwire.DeliveryAddress, error) {
addr, err := f.cfg.Wallet.NewAddress( addr, err := f.cfg.Wallet.NewAddress(
lnwallet.WitnessPubKey, false, lnwallet.WitnessPubKey, false,
lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err

1
lnd.go

@ -676,6 +676,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
NewAddress: func() (btcutil.Address, error) { NewAddress: func() (btcutil.Address, error) {
return activeChainControl.Wallet.NewAddress( return activeChainControl.Wallet.NewAddress(
lnwallet.WitnessPubKey, false, lnwallet.WitnessPubKey, false,
lnwallet.DefaultAccountName,
) )
}, },
NodeKeyECDH: keychain.NewPubKeyECDH( NodeKeyECDH: keychain.NewPubKeyECDH(

@ -487,7 +487,9 @@ func (w *WalletKit) DeriveKey(ctx context.Context,
func (w *WalletKit) NextAddr(ctx context.Context, func (w *WalletKit) NextAddr(ctx context.Context,
req *AddrRequest) (*AddrResponse, error) { req *AddrRequest) (*AddrResponse, error) {
addr, err := w.cfg.Wallet.NewAddress(lnwallet.WitnessPubKey, false) addr, err := w.cfg.Wallet.NewAddress(
lnwallet.WitnessPubKey, false, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1073,7 +1075,9 @@ func (w *WalletKit) FundPsbt(_ context.Context,
// We can now ask the wallet to fund the TX. This will not yet // We can now ask the wallet to fund the TX. This will not yet
// lock any coins but might still change the wallet DB by // lock any coins but might still change the wallet DB by
// generating a new change address. // generating a new change address.
changeIndex, err = w.cfg.Wallet.FundPsbt(packet, feeSatPerKW) changeIndex, err = w.cfg.Wallet.FundPsbt(
packet, feeSatPerKW, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
return fmt.Errorf("wallet couldn't fund PSBT: %v", err) return fmt.Errorf("wallet couldn't fund PSBT: %v", err)
} }

@ -58,7 +58,7 @@ func (w *WalletController) ConfirmedBalance(confs int32) (btcutil.Amount, error)
// NewAddress is called to get new addresses for delivery, change etc. // NewAddress is called to get new addresses for delivery, change etc.
func (w *WalletController) NewAddress(addrType lnwallet.AddressType, func (w *WalletController) NewAddress(addrType lnwallet.AddressType,
change bool) (btcutil.Address, error) { change bool, _ string) (btcutil.Address, error) {
addr, _ := btcutil.NewAddressPubKey( addr, _ := btcutil.NewAddressPubKey(
w.RootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams, w.RootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams,
@ -67,8 +67,8 @@ func (w *WalletController) NewAddress(addrType lnwallet.AddressType,
} }
// LastUnusedAddress currently returns dummy values. // LastUnusedAddress currently returns dummy values.
func (w *WalletController) LastUnusedAddress(addrType lnwallet.AddressType) ( func (w *WalletController) LastUnusedAddress(addrType lnwallet.AddressType,
btcutil.Address, error) { _ string) (btcutil.Address, error) {
return nil, nil return nil, nil
} }
@ -148,13 +148,13 @@ func (w *WalletController) ListLeasedOutputs() ([]*wtxmgr.LockedOutput, error) {
// FundPsbt currently does nothing. // FundPsbt currently does nothing.
func (w *WalletController) FundPsbt(_ *psbt.Packet, func (w *WalletController) FundPsbt(_ *psbt.Packet,
_ chainfee.SatPerKWeight) (int32, error) { _ chainfee.SatPerKWeight, _ string) (int32, error) {
return 0, nil return 0, nil
} }
// FinalizePsbt currently does nothing. // FinalizePsbt currently does nothing.
func (w *WalletController) FinalizePsbt(_ *psbt.Packet) error { func (w *WalletController) FinalizePsbt(_ *psbt.Packet, _ string) error {
return nil return nil
} }

@ -3,6 +3,7 @@ package btcwallet
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"math" "math"
"sync" "sync"
@ -27,7 +28,8 @@ import (
) )
const ( const (
defaultAccount = uint32(waddrmgr.DefaultAccountNum) defaultAccount = uint32(waddrmgr.DefaultAccountNum)
importedAccount = uint32(waddrmgr.ImportedAddrAccount)
// UnconfirmedHeight is the special case end height that is used to // UnconfirmedHeight is the special case end height that is used to
// obtain unconfirmed transactions from ListTransactionDetails. // obtain unconfirmed transactions from ListTransactionDetails.
@ -46,6 +48,11 @@ var (
ExternalAddrType: waddrmgr.WitnessPubKey, ExternalAddrType: waddrmgr.WitnessPubKey,
InternalAddrType: waddrmgr.WitnessPubKey, InternalAddrType: waddrmgr.WitnessPubKey,
} }
// errNoImportedAddrGen is an error returned when a new address is
// requested for the default imported account within the wallet.
errNoImportedAddrGen = errors.New("addresses cannot be generated for " +
"the default imported account")
) )
// BtcWallet is an implementation of the lnwallet.WalletController interface // BtcWallet is an implementation of the lnwallet.WalletController interface
@ -237,26 +244,44 @@ func (b *BtcWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error) {
// NewAddress returns the next external or internal address for the wallet // NewAddress returns the next external or internal address for the wallet
// dictated by the value of the `change` parameter. If change is true, then an // dictated by the value of the `change` parameter. If change is true, then an
// internal address will be returned, otherwise an external address should be // internal address will be returned, otherwise an external address should be
// returned. // returned. The account parameter must be non-empty as it determines which
// account the address should be generated from.
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) NewAddress(t lnwallet.AddressType, change bool) (btcutil.Address, error) { func (b *BtcWallet) NewAddress(t lnwallet.AddressType, change bool,
var keyScope waddrmgr.KeyScope accountName string) (btcutil.Address, error) {
var (
keyScope waddrmgr.KeyScope
account uint32
)
switch accountName {
case waddrmgr.ImportedAddrAccountName:
return nil, errNoImportedAddrGen
case lnwallet.DefaultAccountName:
switch t {
case lnwallet.WitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0084
case lnwallet.NestedWitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0049Plus
default:
return nil, fmt.Errorf("unknown address type")
}
account = defaultAccount
switch t {
case lnwallet.WitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0084
case lnwallet.NestedWitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0049Plus
default: default:
return nil, fmt.Errorf("unknown address type") var err error
keyScope, account, err = b.wallet.LookupAccount(accountName)
if err != nil {
return nil, err
}
} }
if change { if change {
return b.wallet.NewChangeAddress(defaultAccount, keyScope) return b.wallet.NewChangeAddress(account, keyScope)
} }
return b.wallet.NewAddress(account, keyScope)
return b.wallet.NewAddress(defaultAccount, keyScope)
} }
// LastUnusedAddress returns the last *unused* address known by the wallet. An // LastUnusedAddress returns the last *unused* address known by the wallet. An
@ -264,22 +289,39 @@ func (b *BtcWallet) NewAddress(t lnwallet.AddressType, change bool) (btcutil.Add
// UIs in order to continually show the "freshest" address without having to // UIs in order to continually show the "freshest" address without having to
// worry about "address inflation" caused by continual refreshing. Similar to // worry about "address inflation" caused by continual refreshing. Similar to
// NewAddress it can derive a specified address type, and also optionally a // NewAddress it can derive a specified address type, and also optionally a
// change address. // change address. The account parameter must be non-empty as it determines
func (b *BtcWallet) LastUnusedAddress(addrType lnwallet.AddressType) ( // which account the address should be generated from.
btcutil.Address, error) { func (b *BtcWallet) LastUnusedAddress(addrType lnwallet.AddressType,
accountName string) (btcutil.Address, error) {
var keyScope waddrmgr.KeyScope var (
keyScope waddrmgr.KeyScope
account uint32
)
switch accountName {
case waddrmgr.ImportedAddrAccountName:
return nil, errNoImportedAddrGen
case lnwallet.DefaultAccountName:
switch addrType {
case lnwallet.WitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0084
case lnwallet.NestedWitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0049Plus
default:
return nil, fmt.Errorf("unknown address type")
}
account = defaultAccount
switch addrType {
case lnwallet.WitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0084
case lnwallet.NestedWitnessPubKey:
keyScope = waddrmgr.KeyScopeBIP0049Plus
default: default:
return nil, fmt.Errorf("unknown address type") var err error
keyScope, account, err = b.wallet.LookupAccount(accountName)
if err != nil {
return nil, err
}
} }
return b.wallet.CurrentAddress(defaultAccount, keyScope) return b.wallet.CurrentAddress(account, keyScope)
} }
// IsOurAddress checks if the passed address belongs to this wallet // IsOurAddress checks if the passed address belongs to this wallet
@ -698,49 +740,99 @@ func (b *BtcWallet) ListTransactionDetails(startHeight,
return txDetails, nil return txDetails, nil
} }
// FundPsbt creates a fully populated PSBT packet that contains enough // FundPsbt creates a fully populated PSBT packet that contains enough inputs to
// inputs to fund the outputs specified in the passed in packet with the // fund the outputs specified in the passed in packet with the specified fee
// specified fee rate. If there is change left, a change output from the // rate. If there is change left, a change output from the internal wallet is
// internal wallet is added and the index of the change output is returned. // added and the index of the change output is returned. Otherwise no additional
// Otherwise no additional output is created and the index -1 is returned. // output is created and the index -1 is returned.
// //
// NOTE: If the packet doesn't contain any inputs, coin selection is // NOTE: If the packet doesn't contain any inputs, coin selection is performed
// performed automatically. If the packet does contain any inputs, it is // automatically. The account parameter must be non-empty as it determines which
// assumed that full coin selection happened externally and no // set of coins are eligible for coin selection. If the packet does contain any
// additional inputs are added. If the specified inputs aren't enough to // inputs, it is assumed that full coin selection happened externally and no
// fund the outputs with the given fee rate, an error is returned. // additional inputs are added. If the specified inputs aren't enough to fund
// No lock lease is acquired for any of the selected/validated inputs. // the outputs with the given fee rate, an error is returned. No lock lease is
// It is in the caller's responsibility to lock the inputs before // acquired for any of the selected/validated inputs. It is in the caller's
// handing them out. // responsibility to lock the inputs before handing them out.
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) FundPsbt(packet *psbt.Packet, func (b *BtcWallet) FundPsbt(packet *psbt.Packet,
feeRate chainfee.SatPerKWeight) (int32, error) { feeRate chainfee.SatPerKWeight, accountName string) (int32, error) {
// The fee rate is passed in using units of sat/kw, so we'll convert // The fee rate is passed in using units of sat/kw, so we'll convert
// this to sat/KB as the CreateSimpleTx method requires this unit. // this to sat/KB as the CreateSimpleTx method requires this unit.
feeSatPerKB := btcutil.Amount(feeRate.FeePerKVByte()) feeSatPerKB := btcutil.Amount(feeRate.FeePerKVByte())
var (
keyScope *waddrmgr.KeyScope
accountNum uint32
)
switch accountName {
// If the default/imported account name was specified, we'll provide a
// nil key scope to FundPsbt, allowing it to select inputs from both key
// scopes (NP2WKH, P2WKH).
case lnwallet.DefaultAccountName:
accountNum = defaultAccount
case waddrmgr.ImportedAddrAccountName:
accountNum = importedAccount
// Otherwise, map the account name to its key scope and internal account
// number to only select inputs from said account.
default:
scope, account, err := b.wallet.LookupAccount(accountName)
if err != nil {
return 0, err
}
keyScope = &scope
accountNum = account
}
// Let the wallet handle coin selection and/or fee estimation based on // Let the wallet handle coin selection and/or fee estimation based on
// the partial TX information in the packet. // the partial TX information in the packet.
return b.wallet.FundPsbt(packet, nil, defaultAccount, feeSatPerKB) return b.wallet.FundPsbt(packet, keyScope, accountNum, feeSatPerKB)
} }
// FinalizePsbt expects a partial transaction with all inputs and // FinalizePsbt expects a partial transaction with all inputs and outputs fully
// outputs fully declared and tries to sign all inputs that belong to // declared and tries to sign all inputs that belong to the specified account.
// the wallet. Lnd must be the last signer of the transaction. That // Lnd must be the last signer of the transaction. That means, if there are any
// means, if there are any unsigned non-witness inputs or inputs without // unsigned non-witness inputs or inputs without UTXO information attached or
// UTXO information attached or inputs without witness data that do not // inputs without witness data that do not belong to lnd's wallet, this method
// belong to lnd's wallet, this method will fail. If no error is // will fail. If no error is returned, the PSBT is ready to be extracted and the
// returned, the PSBT is ready to be extracted and the final TX within // final TX within to be broadcast.
// to be broadcast.
// //
// NOTE: This method does NOT publish the transaction after it's been // NOTE: This method does NOT publish the transaction after it's been
// finalized successfully. // finalized successfully.
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) FinalizePsbt(packet *psbt.Packet) error { func (b *BtcWallet) FinalizePsbt(packet *psbt.Packet, accountName string) error {
return b.wallet.FinalizePsbt(nil, defaultAccount, packet) var (
keyScope *waddrmgr.KeyScope
accountNum uint32
)
switch accountName {
// If the default/imported account name was specified, we'll provide a
// nil key scope to FundPsbt, allowing it to sign inputs from both key
// scopes (NP2WKH, P2WKH).
case lnwallet.DefaultAccountName:
accountNum = defaultAccount
case waddrmgr.ImportedAddrAccountName:
accountNum = importedAccount
// Otherwise, map the account name to its key scope and internal account
// number to determine if the inputs belonging to this account should be
// signed.
default:
scope, account, err := b.wallet.LookupAccount(accountName)
if err != nil {
return err
}
keyScope = &scope
accountNum = account
}
return b.wallet.FinalizePsbt(keyScope, accountNum, packet)
} }
// txSubscriptionClient encapsulates the transaction notification client from // txSubscriptionClient encapsulates the transaction notification client from

@ -17,6 +17,12 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
) )
const (
// DefaultAccountName is the name for the default account used to manage
// on-chain funds within the wallet.
DefaultAccountName = "default"
)
// AddressType is an enum-like type which denotes the possible address types // AddressType is an enum-like type which denotes the possible address types
// WalletController supports. // WalletController supports.
type AddressType uint8 type AddressType uint8
@ -165,8 +171,10 @@ type WalletController interface {
// true, then an internal address should be used, otherwise an external // true, then an internal address should be used, otherwise an external
// address should be returned. The type of address returned is dictated // address should be returned. The type of address returned is dictated
// by the wallet's capabilities, and may be of type: p2sh, p2wkh, // by the wallet's capabilities, and may be of type: p2sh, p2wkh,
// p2wsh, etc. // p2wsh, etc. The account parameter must be non-empty as it determines
NewAddress(addrType AddressType, change bool) (btcutil.Address, error) // which account the address should be generated from.
NewAddress(addrType AddressType, change bool,
account string) (btcutil.Address, error)
// LastUnusedAddress returns the last *unused* address known by the // LastUnusedAddress returns the last *unused* address known by the
// wallet. An address is unused if it hasn't received any payments. // wallet. An address is unused if it hasn't received any payments.
@ -174,7 +182,10 @@ type WalletController interface {
// "freshest" address without having to worry about "address inflation" // "freshest" address without having to worry about "address inflation"
// caused by continual refreshing. Similar to NewAddress it can derive // caused by continual refreshing. Similar to NewAddress it can derive
// a specified address type. By default, this is a non-change address. // a specified address type. By default, this is a non-change address.
LastUnusedAddress(addrType AddressType) (btcutil.Address, error) // The account parameter must be non-empty as it determines which
// account the address should be generated from.
LastUnusedAddress(addrType AddressType,
account string) (btcutil.Address, error)
// IsOurAddress checks if the passed address belongs to this wallet // IsOurAddress checks if the passed address belongs to this wallet
IsOurAddress(a btcutil.Address) bool IsOurAddress(a btcutil.Address) bool
@ -286,28 +297,29 @@ type WalletController interface {
// is returned. // is returned.
// //
// NOTE: If the packet doesn't contain any inputs, coin selection is // NOTE: If the packet doesn't contain any inputs, coin selection is
// performed automatically. If the packet does contain any inputs, it is // performed automatically. The account parameter must be non-empty as
// assumed that full coin selection happened externally and no // it determines which set of coins are eligible for coin selection. If
// additional inputs are added. If the specified inputs aren't enough to // the packet does contain any inputs, it is assumed that full coin
// fund the outputs with the given fee rate, an error is returned. // selection happened externally and no additional inputs are added. If
// No lock lease is acquired for any of the selected/validated inputs. // the specified inputs aren't enough to fund the outputs with the given
// It is in the caller's responsibility to lock the inputs before // fee rate, an error is returned. No lock lease is acquired for any of
// handing them out. // the selected/validated inputs. It is in the caller's responsibility
FundPsbt(packet *psbt.Packet, feeRate chainfee.SatPerKWeight) (int32, // to lock the inputs before handing them out.
error) FundPsbt(packet *psbt.Packet, feeRate chainfee.SatPerKWeight,
account string) (int32, error)
// FinalizePsbt expects a partial transaction with all inputs and // FinalizePsbt expects a partial transaction with all inputs and
// outputs fully declared and tries to sign all inputs that belong to // outputs fully declared and tries to sign all inputs that belong to
// the wallet. Lnd must be the last signer of the transaction. That // the specified account. Lnd must be the last signer of the
// means, if there are any unsigned non-witness inputs or inputs without // transaction. That means, if there are any unsigned non-witness inputs
// UTXO information attached or inputs without witness data that do not // or inputs without UTXO information attached or inputs without witness
// belong to lnd's wallet, this method will fail. If no error is // data that do not belong to lnd's wallet, this method will fail. If no
// returned, the PSBT is ready to be extracted and the final TX within // error is returned, the PSBT is ready to be extracted and the final TX
// to be broadcast. // within to be broadcast.
// //
// NOTE: This method does NOT publish the transaction after it's been // NOTE: This method does NOT publish the transaction after it's been
// finalized successfully. // finalized successfully.
FinalizePsbt(packet *psbt.Packet) error FinalizePsbt(packet *psbt.Packet, account string) error
// SubscribeTransactions returns a TransactionSubscription client which // SubscribeTransactions returns a TransactionSubscription client which
// is capable of receiving async notifications as new transactions // is capable of receiving async notifications as new transactions

@ -157,7 +157,7 @@ func newPkScript(t *testing.T, w *lnwallet.LightningWallet,
t.Helper() t.Helper()
addr, err := w.NewAddress(addrType, false) addr, err := w.NewAddress(addrType, false, lnwallet.DefaultAccountName)
if err != nil { if err != nil {
t.Fatalf("unable to create new address: %v", err) t.Fatalf("unable to create new address: %v", err)
} }
@ -256,7 +256,10 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet,
addrs := make([]btcutil.Address, 0, numOutputs) addrs := make([]btcutil.Address, 0, numOutputs)
for i := 0; i < numOutputs; i++ { for i := 0; i < numOutputs; i++ {
// Grab a fresh address from the wallet to house this output. // Grab a fresh address from the wallet to house this output.
walletAddr, err := w.NewAddress(lnwallet.WitnessPubKey, false) walletAddr, err := w.NewAddress(
lnwallet.WitnessPubKey, false,
lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
return err return err
} }
@ -1138,7 +1141,10 @@ func testListTransactionDetails(miner *rpctest.Harness,
const outputAmt = btcutil.SatoshiPerBitcoin const outputAmt = btcutil.SatoshiPerBitcoin
txids := make(map[chainhash.Hash]struct{}) txids := make(map[chainhash.Hash]struct{})
for i := 0; i < numTxns; i++ { for i := 0; i < numTxns; i++ {
addr, err := alice.NewAddress(lnwallet.WitnessPubKey, false) addr, err := alice.NewAddress(
lnwallet.WitnessPubKey, false,
lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
t.Fatalf("unable to create new address: %v", err) t.Fatalf("unable to create new address: %v", err)
} }
@ -1465,7 +1471,10 @@ func testTransactionSubscriptions(miner *rpctest.Harness,
// Next, fetch a fresh address from the wallet, create 3 new outputs // Next, fetch a fresh address from the wallet, create 3 new outputs
// with the pkScript. // with the pkScript.
for i := 0; i < numTxns; i++ { for i := 0; i < numTxns; i++ {
addr, err := alice.NewAddress(lnwallet.WitnessPubKey, false) addr, err := alice.NewAddress(
lnwallet.WitnessPubKey, false,
lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
t.Fatalf("unable to create new address: %v", err) t.Fatalf("unable to create new address: %v", err)
} }
@ -2493,11 +2502,15 @@ func testLastUnusedAddr(miner *rpctest.Harness,
lnwallet.WitnessPubKey, lnwallet.NestedWitnessPubKey, lnwallet.WitnessPubKey, lnwallet.NestedWitnessPubKey,
} }
for _, addrType := range addrTypes { for _, addrType := range addrTypes {
addr1, err := alice.LastUnusedAddress(addrType) addr1, err := alice.LastUnusedAddress(
addrType, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
t.Fatalf("unable to get addr: %v", err) t.Fatalf("unable to get addr: %v", err)
} }
addr2, err := alice.LastUnusedAddress(addrType) addr2, err := alice.LastUnusedAddress(
addrType, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
t.Fatalf("unable to get addr: %v", err) t.Fatalf("unable to get addr: %v", err)
} }
@ -2523,7 +2536,9 @@ func testLastUnusedAddr(miner *rpctest.Harness,
// If we make a new address, then it should be brand new, as // If we make a new address, then it should be brand new, as
// the prior address has been used. // the prior address has been used.
addr3, err := alice.LastUnusedAddress(addrType) addr3, err := alice.LastUnusedAddress(
addrType, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
t.Fatalf("unable to get addr: %v", err) t.Fatalf("unable to get addr: %v", err)
} }
@ -2997,7 +3012,10 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
MinConfs: 1, MinConfs: 1,
FeeRate: 253, FeeRate: 253,
ChangeAddr: func() (btcutil.Address, error) { ChangeAddr: func() (btcutil.Address, error) {
return alice.NewAddress(lnwallet.WitnessPubKey, true) return alice.NewAddress(
lnwallet.WitnessPubKey, true,
lnwallet.DefaultAccountName,
)
}, },
}) })
if err != nil { if err != nil {
@ -3042,7 +3060,10 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
MinConfs: 1, MinConfs: 1,
FeeRate: 253, FeeRate: 253,
ChangeAddr: func() (btcutil.Address, error) { ChangeAddr: func() (btcutil.Address, error) {
return bob.NewAddress(lnwallet.WitnessPubKey, true) return bob.NewAddress(
lnwallet.WitnessPubKey, true,
lnwallet.DefaultAccountName,
)
}, },
}) })
if err != nil { if err != nil {

@ -722,7 +722,9 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
SubtractFees: req.SubtractFees, SubtractFees: req.SubtractFees,
FeeRate: req.FundingFeePerKw, FeeRate: req.FundingFeePerKw,
ChangeAddr: func() (btcutil.Address, error) { ChangeAddr: func() (btcutil.Address, error) {
return l.NewAddress(WitnessPubKey, true) return l.NewAddress(
WitnessPubKey, true, DefaultAccountName,
)
}, },
} }
fundingIntent, err = req.ChanFunder.ProvisionChannel( fundingIntent, err = req.ChanFunder.ProvisionChannel(

@ -2043,7 +2043,7 @@ func (p *Brontide) ChannelSnapshots() []*channeldb.ChannelSnapshot {
// the case of a cooperative channel close negotiation. // the case of a cooperative channel close negotiation.
func (p *Brontide) genDeliveryScript() ([]byte, error) { func (p *Brontide) genDeliveryScript() ([]byte, error) {
deliveryAddr, err := p.cfg.Wallet.NewAddress( deliveryAddr, err := p.cfg.Wallet.NewAddress(
lnwallet.WitnessPubKey, false, lnwallet.WitnessPubKey, false, lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -2333,10 +2333,14 @@ func (p *Brontide) fetchActiveChanCloser(chanID lnwire.ChannelID) (
"channel w/ active htlcs") "channel w/ active htlcs")
} }
// We'll create a valid closing state machine in order to respond to the // We'll create a valid closing state machine in order to
// initiated cooperative channel closure. First, we set the delivery // respond to the initiated cooperative channel closure. First,
// script that our funds will be paid out to. If an upfront shutdown script // we set the delivery script that our funds will be paid out
// was set, we will use it. Otherwise, we get a fresh delivery script. // to. If an upfront shutdown script was set, we will use it.
// Otherwise, we get a fresh delivery script.
//
// TODO: Expose option to allow upfront shutdown script from
// watch-only accounts.
deliveryScript := channel.LocalUpfrontShutdownScript() deliveryScript := channel.LocalUpfrontShutdownScript()
if len(deliveryScript) == 0 { if len(deliveryScript) == 0 {
var err error var err error

@ -1225,6 +1225,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
// allowing us to pass the reserved value check. // allowing us to pass the reserved value check.
changeAddr, err := r.server.cc.Wallet.NewAddress( changeAddr, err := r.server.cc.Wallet.NewAddress(
lnwallet.WitnessPubKey, true, lnwallet.WitnessPubKey, true,
lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -1381,7 +1382,7 @@ func (r *rpcServer) NewAddress(ctx context.Context,
switch in.Type { switch in.Type {
case lnrpc.AddressType_WITNESS_PUBKEY_HASH: case lnrpc.AddressType_WITNESS_PUBKEY_HASH:
addr, err = r.server.cc.Wallet.NewAddress( addr, err = r.server.cc.Wallet.NewAddress(
lnwallet.WitnessPubKey, false, lnwallet.WitnessPubKey, false, lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -1389,7 +1390,7 @@ func (r *rpcServer) NewAddress(ctx context.Context,
case lnrpc.AddressType_NESTED_PUBKEY_HASH: case lnrpc.AddressType_NESTED_PUBKEY_HASH:
addr, err = r.server.cc.Wallet.NewAddress( addr, err = r.server.cc.Wallet.NewAddress(
lnwallet.NestedWitnessPubKey, false, lnwallet.NestedWitnessPubKey, false, lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -1397,7 +1398,7 @@ func (r *rpcServer) NewAddress(ctx context.Context,
case lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH: case lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH:
addr, err = r.server.cc.Wallet.LastUnusedAddress( addr, err = r.server.cc.Wallet.LastUnusedAddress(
lnwallet.WitnessPubKey, lnwallet.WitnessPubKey, lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -1405,7 +1406,7 @@ func (r *rpcServer) NewAddress(ctx context.Context,
case lnrpc.AddressType_UNUSED_NESTED_PUBKEY_HASH: case lnrpc.AddressType_UNUSED_NESTED_PUBKEY_HASH:
addr, err = r.server.cc.Wallet.LastUnusedAddress( addr, err = r.server.cc.Wallet.LastUnusedAddress(
lnwallet.NestedWitnessPubKey, lnwallet.NestedWitnessPubKey, lnwallet.DefaultAccountName,
) )
if err != nil { if err != nil {
return nil, err return nil, err

@ -3809,7 +3809,9 @@ func newSweepPkScriptGen(
wallet lnwallet.WalletController) func() ([]byte, error) { wallet lnwallet.WalletController) func() ([]byte, error) {
return func() ([]byte, error) { return func() ([]byte, error) {
sweepAddr, err := wallet.NewAddress(lnwallet.WitnessPubKey, false) sweepAddr, err := wallet.NewAddress(
lnwallet.WitnessPubKey, false, lnwallet.DefaultAccountName,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }