Skip to content

Commit

Permalink
fixes errors in wallet/multisig/importParticipant (#5385)
Browse files Browse the repository at this point in the history
throws RPC errors with recognizable error codes

allows CLI to hadnle RPC errors more easily
  • Loading branch information
hughy authored Sep 19, 2024
1 parent a57ca30 commit 36deabb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ describe('Route wallet/multisig/importParticipant', () => {
).rejects.toThrow(
expect.objectContaining({
message: expect.stringContaining(
`Multisig participant already exists for the identity ${identity
.serialize()
.toString('hex')}`,
`Multisig identity ${identity.serialize().toString('hex')} already exists`,
),
status: 400,
}),
Expand Down
23 changes: 15 additions & 8 deletions ironfish/src/rpc/routes/wallet/multisig/importParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import * as yup from 'yup'
import {
DuplicateAccountNameError,
DuplicateIdentityError,
DuplicateIdentityNameError,
} from '../../../../wallet/errors'
import { RPC_ERROR_CODES, RpcValidationError } from '../../../adapters'
import { ApiNamespace } from '../../namespaces'
import { routes } from '../../router'
import { AssertHasRpcContext } from '../../rpcContext'
Expand Down Expand Up @@ -42,19 +38,30 @@ routes.register<typeof ImportParticipantRequestSchema, ImportParticipantResponse
AssertHasRpcContext(request, context, 'wallet')

if (await context.wallet.walletDb.hasMultisigSecretName(request.data.name)) {
throw new DuplicateIdentityNameError(request.data.name)
throw new RpcValidationError(
`Multisig identity already exists with the name ${request.data.name}`,
400,
RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME,
)
}

if (
await context.wallet.walletDb.getMultisigIdentity(
Buffer.from(request.data.identity, 'hex'),
)
) {
throw new DuplicateIdentityError(request.data.identity)
throw new RpcValidationError(
`Multisig identity ${request.data.identity} already exists`,
400,
)
}

if (context.wallet.getAccountByName(request.data.name)) {
throw new DuplicateAccountNameError(request.data.name)
throw new RpcValidationError(
`Account already exists with the name ${request.data.name}`,
400,
RPC_ERROR_CODES.DUPLICATE_ACCOUNT_NAME,
)
}

await context.wallet.walletDb.putMultisigIdentity(
Expand Down

0 comments on commit 36deabb

Please sign in to comment.