From 8745cf03c1502a687e240e51cd705d20e9137601 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 25 May 2021 16:08:23 -0700 Subject: [PATCH] lnwallet: check if requested address type is compatible with account --- lnwallet/btcwallet/btcwallet.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 141b2878..09ffb77b 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -71,7 +71,8 @@ var ( errNoImportedAddrGen = errors.New("addresses cannot be generated for " + "the default imported account") - // errIncompatibleAccountAddr + // errIncompatibleAccountAddr is an error returned when the type of a + // new address being requested is incompatible with the account. errIncompatibleAccountAddr = errors.New("incompatible address type " + "for account") ) @@ -392,12 +393,17 @@ func (b *BtcWallet) keyScopeForAccountAddr(accountName string, return addrKeyScope, defaultAccount, nil } - // Otherwise, look up the account's key scope. + // Otherwise, look up the account's key scope and check that it supports + // the requested address type. keyScope, account, err := b.wallet.LookupAccount(accountName) if err != nil { return waddrmgr.KeyScope{}, 0, err } + if keyScope != addrKeyScope { + return waddrmgr.KeyScope{}, 0, errIncompatibleAccountAddr + } + return keyScope, account, nil }