Skip to content

Commit

Permalink
multi-account: update createNewAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
roylee17 committed Sep 28, 2022
1 parent 03dd33f commit 531c461
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rpc/legacyrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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) {

cmd := icmd.(*btcjson.CreateNewAccountCmd)

// The wildcard * is reserved by the rpc server with the special meaning
Expand All @@ -800,15 +801,20 @@ func createNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
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) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCWalletUnlockNeeded,
Message: "Creating an account requires the wallet to be unlocked. " +
"Enter the wallet passphrase with walletpassphrase to unlock",
}
}
return nil, err

return nil, nil
}

// renameAccount handles a renameaccount request by renaming an account.
Expand Down

0 comments on commit 531c461

Please sign in to comment.