Skip to content

Commit

Permalink
refactor: better zod
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso committed Feb 25, 2025
1 parent 7b55ca6 commit 26c92d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions packages/hathor-rpc-handler/src/rpcMethods/getAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ const baseSchema = {
};

const getAddressSchema = z.discriminatedUnion("type", [
z.object({
z.object(baseSchema).merge(z.object({
type: z.literal('first_empty'),
...baseSchema,
}),
z.object({
})),
z.object(baseSchema).merge(z.object({
type: z.literal('full_path'),
full_path: z.string().min(1),
...baseSchema,
}),
})),
z.object({
type: z.literal('index'),
index: z.number().int().nonnegative(),
Expand Down
8 changes: 4 additions & 4 deletions packages/hathor-rpc-handler/src/rpcMethods/getUtxos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const getUtxosSchema = z.object({
maxUtxos: z.number().default(255),
token: z.string().default('HTR'),
filterAddress: z.string(),
authorities: z.number().nullish().optional(),
amountSmallerThan: z.number().min(0).nullish().optional(),
amountBiggerThan: z.number().min(0).nullish().optional(),
maximumAmount: z.number().nullish().optional(),
authorities: z.number().default(0),
amountSmallerThan: z.number().min(0).default(0),
amountBiggerThan: z.number().min(0).default(0),
maximumAmount: z.number().default(0),
onlyAvailableUtxos: z.boolean().default(true),
}).transform(data => ({
...data,
Expand Down

0 comments on commit 26c92d6

Please sign in to comment.