multi-account: update createNewAccount

This commit is contained in:
Roy Lee 2022-08-22 13:48:01 -07:00
parent 03dd33f8c9
commit 531c461383

View file

@ -792,6 +792,7 @@ func keypoolRefill(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
// returning a new account. If the last account has no transaction history // returning a new account. If the last account has no transaction history
// as per BIP 0044 a new account cannot be created so an error will be returned. // as per BIP 0044 a new account cannot be created so an error will be returned.
func createNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func createNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.CreateNewAccountCmd) cmd := icmd.(*btcjson.CreateNewAccountCmd)
// The wildcard * is reserved by the rpc server with the special meaning // The wildcard * is reserved by the rpc server with the special meaning
@ -800,7 +801,11 @@ func createNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return nil, &ErrReservedAccountName return nil, &ErrReservedAccountName
} }
_, err := w.NextAccount(waddrmgr.KeyScopeBIP0044, cmd.Account) fn := func(scope waddrmgr.KeyScope) error {
_, err := w.NextAccount(scope, cmd.Account)
return err
}
err := forEachKeyScope(fn)
if waddrmgr.IsError(err, waddrmgr.ErrLocked) { if waddrmgr.IsError(err, waddrmgr.ErrLocked) {
return nil, &btcjson.RPCError{ return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCWalletUnlockNeeded, Code: btcjson.ErrRPCWalletUnlockNeeded,
@ -808,7 +813,8 @@ func createNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
"Enter the wallet passphrase with walletpassphrase to unlock", "Enter the wallet passphrase with walletpassphrase to unlock",
} }
} }
return nil, err
return nil, nil
} }
// renameAccount handles a renameaccount request by renaming an account. // renameAccount handles a renameaccount request by renaming an account.