diff --git a/waddrmgr/manager.go b/waddrmgr/manager.go index 6706703..2fcfbcd 100644 --- a/waddrmgr/manager.go +++ b/waddrmgr/manager.go @@ -1299,6 +1299,25 @@ func ValidateAccountName(name string) error { return nil } +// LookupAccount returns the corresponding key scope and account number for the +// account with the given name. +func (m *Manager) LookupAccount(ns walletdb.ReadBucket, name string) (KeyScope, + uint32, error) { + + m.mtx.RLock() + defer m.mtx.RUnlock() + + for keyScope, scopedMgr := range m.scopedManagers { + acct, err := scopedMgr.LookupAccount(ns, name) + if err == nil { + return keyScope, acct, nil + } + } + + str := fmt.Sprintf("account name '%s' not found", name) + return KeyScope{}, 0, managerError(ErrAccountNotFound, str, nil) +} + // selectCryptoKey selects the appropriate crypto key based on the key type. An // error is returned when an invalid key type is specified or the requested key // requires the manager to be unlocked when it isn't. diff --git a/wallet/wallet.go b/wallet/wallet.go index 9c0d8a4..c4d7d43 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -1762,6 +1762,22 @@ func (w *Wallet) AccountProperties(scope waddrmgr.KeyScope, acct uint32) (*waddr 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) { + var ( + keyScope waddrmgr.KeyScope + account uint32 + ) + err := walletdb.View(w.db, func(tx walletdb.ReadTx) error { + ns := tx.ReadBucket(waddrmgrNamespaceKey) + var err error + keyScope, account, err = w.Manager.LookupAccount(ns, name) + return err + }) + return keyScope, account, err +} + // RenameAccount sets the name for an account number to newName. func (w *Wallet) RenameAccount(scope waddrmgr.KeyScope, account uint32, newName string) error { manager, err := w.Manager.FetchScopedKeyManager(scope)