Skip to content

Commit a0df9fb

Browse files
committed
chore: use UntilBlockSchema in multiple areas
1 parent 0110f6f commit a0df9fb

File tree

2 files changed

+21
-61
lines changed

2 files changed

+21
-61
lines changed

src/api/routes/address.ts

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ import { has0xPrefix } from '@hirosystems/api-toolkit';
2323
import { FastifyPluginAsync } from 'fastify';
2424
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
2525
import { Server } from 'node:http';
26-
import { LimitParam, OffsetParam, PrincipalSchema, UnanchoredParamSchema } from '../schemas/params';
26+
import {
27+
LimitParam,
28+
OffsetParam,
29+
PrincipalSchema,
30+
UnanchoredParamSchema,
31+
UntilBlockSchema,
32+
} from '../schemas/params';
2733
import {
2834
AddressBalance,
2935
AddressBalanceSchema,
@@ -91,16 +97,7 @@ export const AddressRoutes: FastifyPluginAsync<
9197
}),
9298
querystring: Type.Object({
9399
unanchored: UnanchoredParamSchema,
94-
until_block: Type.Optional(
95-
Type.String({
96-
description:
97-
'Block hash or block height. Return data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.',
98-
examples: [
99-
'60000',
100-
'0x4839a8b01cfb39ffcc0d07d3db31e848d5adf5279d529ed5062300b9f353ff79',
101-
],
102-
})
103-
),
100+
until_block: UntilBlockSchema,
104101
}),
105102
response: {
106103
200: AddressStxBalanceSchema,
@@ -156,16 +153,7 @@ export const AddressRoutes: FastifyPluginAsync<
156153
}),
157154
querystring: Type.Object({
158155
unanchored: UnanchoredParamSchema,
159-
until_block: Type.Optional(
160-
Type.String({
161-
description:
162-
'Block hash or block height. Return data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.',
163-
examples: [
164-
'60000',
165-
'0x4839a8b01cfb39ffcc0d07d3db31e848d5adf5279d529ed5062300b9f353ff79',
166-
],
167-
})
168-
),
156+
until_block: UntilBlockSchema,
169157
}),
170158
response: {
171159
200: AddressBalanceSchema,
@@ -267,16 +255,7 @@ export const AddressRoutes: FastifyPluginAsync<
267255
Type.Integer({ description: 'Filter for transactions only at this given block height' })
268256
),
269257
unanchored: UnanchoredParamSchema,
270-
until_block: Type.Optional(
271-
Type.String({
272-
description:
273-
'Block hash or block height. Return data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.',
274-
examples: [
275-
'60000',
276-
'0x4839a8b01cfb39ffcc0d07d3db31e848d5adf5279d529ed5062300b9f353ff79',
277-
],
278-
})
279-
),
258+
until_block: UntilBlockSchema,
280259
}),
281260
response: {
282261
200: AddressTransactionsListResponseSchema,
@@ -411,16 +390,7 @@ export const AddressRoutes: FastifyPluginAsync<
411390
Type.Integer({ description: 'Filter for transactions only at this given block height' })
412391
),
413392
unanchored: UnanchoredParamSchema,
414-
until_block: Type.Optional(
415-
Type.String({
416-
description:
417-
'Block hash or block height. Return data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.',
418-
examples: [
419-
'60000',
420-
'0x4839a8b01cfb39ffcc0d07d3db31e848d5adf5279d529ed5062300b9f353ff79',
421-
],
422-
})
423-
),
393+
until_block: UntilBlockSchema,
424394
}),
425395
response: {
426396
200: AddressTransactionsWithTransfersListResponseSchema,
@@ -528,16 +498,7 @@ export const AddressRoutes: FastifyPluginAsync<
528498
limit: LimitParam(ResourceType.Event),
529499
offset: OffsetParam(),
530500
unanchored: UnanchoredParamSchema,
531-
until_block: Type.Optional(
532-
Type.String({
533-
description:
534-
'Block hash or block height. Return data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.',
535-
examples: [
536-
'60000',
537-
'0x4839a8b01cfb39ffcc0d07d3db31e848d5adf5279d529ed5062300b9f353ff79',
538-
],
539-
})
540-
),
501+
until_block: UntilBlockSchema,
541502
}),
542503
response: {
543504
200: PaginatedResponse(TransactionEventSchema, { title: 'AddressAssetsListResponse' }),
@@ -589,16 +550,7 @@ export const AddressRoutes: FastifyPluginAsync<
589550
Type.Integer({ description: 'Filter for transactions only at this given block height' })
590551
),
591552
unanchored: UnanchoredParamSchema,
592-
until_block: Type.Optional(
593-
Type.String({
594-
description:
595-
'Block hash or block height. Return data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.',
596-
examples: [
597-
'60000',
598-
'0x4839a8b01cfb39ffcc0d07d3db31e848d5adf5279d529ed5062300b9f353ff79',
599-
],
600-
})
601-
),
553+
until_block: UntilBlockSchema,
602554
}),
603555
response: {
604556
200: AddressStxInboundListResponseSchema,

src/api/schemas/params.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ export const UnanchoredParamSchema = Type.Optional(
3636
})
3737
);
3838

39+
export const UntilBlockSchema = Type.Optional(
40+
Type.String({
41+
description:
42+
'Block hash or block height. Return data representing the state up until that point in time, rather than the current block. Note - Use either of the query parameters but not both at a time.',
43+
examples: ['60000', '0x4839a8b01cfb39ffcc0d07d3db31e848d5adf5279d529ed5062300b9f353ff79'],
44+
})
45+
);
46+
3947
export const TransactionIdParamSchema = Type.String({
4048
pattern: isTestEnv ? undefined : '^(0x)?[a-fA-F0-9]{64}$',
4149
title: 'Transaction ID',

0 commit comments

Comments
 (0)