waddrmgr+wallet: expose LookupAccount
This exposes a mapping of account name to its corresponding key scope and internal account number to facilitate the use of external APIs by users.
This commit is contained in:
parent
a180b0fcaa
commit
bbd7f8f887
2 changed files with 35 additions and 0 deletions
|
@ -1299,6 +1299,25 @@ func ValidateAccountName(name string) error {
|
||||||
return nil
|
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
|
// 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
|
// error is returned when an invalid key type is specified or the requested key
|
||||||
// requires the manager to be unlocked when it isn't.
|
// requires the manager to be unlocked when it isn't.
|
||||||
|
|
|
@ -1762,6 +1762,22 @@ func (w *Wallet) AccountProperties(scope waddrmgr.KeyScope, acct uint32) (*waddr
|
||||||
return props, 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) {
|
||||||
|
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.
|
// RenameAccount sets the name for an account number to newName.
|
||||||
func (w *Wallet) RenameAccount(scope waddrmgr.KeyScope, account uint32, newName string) error {
|
func (w *Wallet) RenameAccount(scope waddrmgr.KeyScope, account uint32, newName string) error {
|
||||||
manager, err := w.Manager.FetchScopedKeyManager(scope)
|
manager, err := w.Manager.FetchScopedKeyManager(scope)
|
||||||
|
|
Loading…
Reference in a new issue