lnwallet: expose dry run support for ImportAccount

This commit is contained in:
Wilmer Paulino 2021-05-04 15:56:26 -07:00
parent 64699d8538
commit 994405709a
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
3 changed files with 44 additions and 6 deletions

@ -88,8 +88,9 @@ func (w *WalletController) ListAccounts(_ string,
// ImportAccount currently returns a dummy value. // ImportAccount currently returns a dummy value.
func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey, func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey,
uint32, *waddrmgr.AddressType) error { uint32, *waddrmgr.AddressType, bool) (*waddrmgr.AccountProperties,
return nil []btcutil.Address, []btcutil.Address, error) {
return nil, nil, nil, nil
} }
// ImportPublicKey currently returns a dummy value. // ImportPublicKey currently returns a dummy value.

@ -36,6 +36,11 @@ const (
defaultAccount = uint32(waddrmgr.DefaultAccountNum) defaultAccount = uint32(waddrmgr.DefaultAccountNum)
importedAccount = uint32(waddrmgr.ImportedAddrAccount) 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 // UnconfirmedHeight is the special case end height that is used to
// obtain unconfirmed transactions from ListTransactionDetails. // obtain unconfirmed transactions from ListTransactionDetails.
UnconfirmedHeight int32 = -1 UnconfirmedHeight int32 = -1
@ -566,12 +571,42 @@ func (b *BtcWallet) ListAccounts(name string,
// //
// This is a part of the WalletController interface. // This is a part of the WalletController interface.
func (b *BtcWallet) ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey, 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, 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 // ImportPublicKey imports a single derived public key into the wallet. The

@ -219,7 +219,9 @@ type WalletController interface {
// witness pubkeys everywhere) and our own BIP-0049Plus address schema // witness pubkeys everywhere) and our own BIP-0049Plus address schema
// (nested pubkeys externally, witness pubkeys internally). // (nested pubkeys externally, witness pubkeys internally).
ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKey, 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. // ImportPublicKey imports a single derived public key into the wallet.
// The address type can usually be inferred from the key's version, but // The address type can usually be inferred from the key's version, but