From ddbe5ecee4b90cebe9113a59dc866db30a6ff9b3 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 17 Feb 2021 16:24:25 -0800 Subject: [PATCH] wallet: expose AccountPropertiesByName --- wallet/wallet.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/wallet/wallet.go b/wallet/wallet.go index c4d7d43..549199f 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -1762,6 +1762,30 @@ func (w *Wallet) AccountProperties(scope waddrmgr.KeyScope, acct uint32) (*waddr return props, err } +// AccountPropertiesByName returns the properties of an account by its name. It +// first fetches the desynced information from the address manager, then updates +// the indexes based on the address pools. +func (w *Wallet) AccountPropertiesByName(scope waddrmgr.KeyScope, + name string) (*waddrmgr.AccountProperties, error) { + + manager, err := w.Manager.FetchScopedKeyManager(scope) + if err != nil { + return nil, err + } + + var props *waddrmgr.AccountProperties + err = walletdb.View(w.db, func(tx walletdb.ReadTx) error { + waddrmgrNs := tx.ReadBucket(waddrmgrNamespaceKey) + acct, err := manager.LookupAccount(waddrmgrNs, name) + if err != nil { + return err + } + props, err = manager.AccountProperties(waddrmgrNs, acct) + return err + }) + return props, err +} + // LookupAccount returns the corresponding key scope and account number for the // account with the given name. func (w *Wallet) LookupAccount(name string) (waddrmgr.KeyScope, uint32, error) {