multi-account: set DefaultScope to KeyScopeBIP0044

By design, all scopes shared the same account name/number space.
This commit is contained in:
Roy Lee 2022-08-22 10:25:18 -07:00
parent 5a0c010688
commit 47e8dbda55
2 changed files with 15 additions and 4 deletions

View file

@ -168,6 +168,9 @@ var (
Coin: 140,
}
// Set Default Scope to BIP0044 (legacy address type).
DefaultKeyScope = KeyScopeBIP0044
// DefaultKeyScopes is the set of default key scopes that will be
// created by the root manager upon initial creation.
DefaultKeyScopes = []KeyScope{

View file

@ -1689,7 +1689,12 @@ func (w *Wallet) AddressInfo(a btcutil.Address) (waddrmgr.ManagedAddress, error)
// AccountNumber returns the account number for an account name under a
// particular key scope.
func (w *Wallet) AccountNumber(scope waddrmgr.KeyScope, accountName string) (uint32, error) {
func (w *Wallet) AccountNumber(accountName string) (uint32, error) {
// By design, the same account number is shared across all scopes.
return w.accountNumber(waddrmgr.DefaultKeyScope, accountName)
}
func (w *Wallet) accountNumber(scope waddrmgr.KeyScope, accountName string) (uint32, error) {
manager, err := w.Manager.FetchScopedKeyManager(scope)
if err != nil {
return 0, err
@ -1698,7 +1703,6 @@ func (w *Wallet) AccountNumber(scope waddrmgr.KeyScope, accountName string) (uin
var account uint32
err = walletdb.View(w.db, func(tx walletdb.ReadTx) error {
addrmgrNs := tx.ReadBucket(waddrmgrNamespaceKey)
var err error
account, err = manager.LookupAccount(addrmgrNs, accountName)
return err
})
@ -1706,7 +1710,12 @@ func (w *Wallet) AccountNumber(scope waddrmgr.KeyScope, accountName string) (uin
}
// AccountName returns the name of an account.
func (w *Wallet) AccountName(scope waddrmgr.KeyScope, accountNumber uint32) (string, error) {
func (w *Wallet) AccountName(accountNumber uint32) (string, error) {
// By design, the same account name is shared across all scopes.
return w.accountName(waddrmgr.DefaultKeyScope, accountNumber)
}
func (w *Wallet) accountName(scope waddrmgr.KeyScope, accountNumber uint32) (string, error) {
manager, err := w.Manager.FetchScopedKeyManager(scope)
if err != nil {
return "", err
@ -1715,7 +1724,6 @@ func (w *Wallet) AccountName(scope waddrmgr.KeyScope, accountNumber uint32) (str
var accountName string
err = walletdb.View(w.db, func(tx walletdb.ReadTx) error {
addrmgrNs := tx.ReadBucket(waddrmgrNamespaceKey)
var err error
accountName, err = manager.AccountName(addrmgrNs, accountNumber)
return err
})