diff --git a/lntest/mock/walletcontroller.go b/lntest/mock/walletcontroller.go index c93b7030..50eddd1c 100644 --- a/lntest/mock/walletcontroller.go +++ b/lntest/mock/walletcontroller.go @@ -88,8 +88,9 @@ func (w *WalletController) ListAccounts(_ string, // ImportAccount currently returns a dummy value. func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey, - uint32, *waddrmgr.AddressType) error { - return nil + uint32, *waddrmgr.AddressType, bool) (*waddrmgr.AccountProperties, + []btcutil.Address, []btcutil.Address, error) { + return nil, nil, nil, nil } // ImportPublicKey currently returns a dummy value. diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index a94b56f7..bad28f92 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -36,6 +36,11 @@ const ( defaultAccount = uint32(waddrmgr.DefaultAccountNum) importedAccount = uint32(waddrmgr.ImportedAddrAccount) + // dryRunImportAccountNumAddrs represents the number of addresses we'll + // derive for an imported account's external and internal branch when a + // dry run is attempted. + dryRunImportAccountNumAddrs = 5 + // UnconfirmedHeight is the special case end height that is used to // obtain unconfirmed transactions from ListTransactionDetails. UnconfirmedHeight int32 = -1 @@ -566,12 +571,42 @@ func (b *BtcWallet) ListAccounts(name string, // // This is a part of the WalletController interface. func (b *BtcWallet) ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey, - masterKeyFingerprint uint32, addrType *waddrmgr.AddressType) error { + masterKeyFingerprint uint32, addrType *waddrmgr.AddressType, + dryRun bool) (*waddrmgr.AccountProperties, []btcutil.Address, + []btcutil.Address, error) { - _, err := b.wallet.ImportAccount( + if !dryRun { + accountProps, err := b.wallet.ImportAccount( + name, accountPubKey, masterKeyFingerprint, addrType, + ) + if err != nil { + return nil, nil, nil, err + } + return accountProps, nil, nil, nil + } + + // Derive addresses from both the external and internal branches of the + // account. There's no risk of address inflation as this is only done + // for dry runs. + accountProps, extAddrs, intAddrs, err := b.wallet.ImportAccountDryRun( name, accountPubKey, masterKeyFingerprint, addrType, + dryRunImportAccountNumAddrs, ) - return err + if err != nil { + return nil, nil, nil, err + } + + externalAddrs := make([]btcutil.Address, len(extAddrs)) + for i := 0; i < len(extAddrs); i++ { + externalAddrs[i] = extAddrs[i].Address() + } + + internalAddrs := make([]btcutil.Address, len(intAddrs)) + for i := 0; i < len(intAddrs); i++ { + internalAddrs[i] = intAddrs[i].Address() + } + + return accountProps, externalAddrs, internalAddrs, nil } // ImportPublicKey imports a single derived public key into the wallet. The diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 2e814a41..4a96cc87 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -219,7 +219,9 @@ type WalletController interface { // witness pubkeys everywhere) and our own BIP-0049Plus address schema // (nested pubkeys externally, witness pubkeys internally). ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey, - masterKeyFingerprint uint32, addrType *waddrmgr.AddressType) error + masterKeyFingerprint uint32, addrType *waddrmgr.AddressType, + dryRun bool) (*waddrmgr.AccountProperties, []btcutil.Address, + []btcutil.Address, error) // ImportPublicKey imports a single derived public key into the wallet. // The address type can usually be inferred from the key's version, but