Skip to content

Commit 0110f6f

Browse files
committed
chore: use PrincipalSchema in multiple areas
1 parent 2ec1338 commit 0110f6f

File tree

3 files changed

+14
-44
lines changed

3 files changed

+14
-44
lines changed

src/api/routes/address.ts

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ 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, UnanchoredParamSchema } from '../schemas/params';
26+
import { LimitParam, OffsetParam, PrincipalSchema, UnanchoredParamSchema } from '../schemas/params';
2727
import {
2828
AddressBalance,
2929
AddressBalanceSchema,
@@ -87,10 +87,7 @@ export const AddressRoutes: FastifyPluginAsync<
8787
description: `Retrieves STX token balance for a given Address or Contract Identifier.`,
8888
tags: ['Accounts'],
8989
params: Type.Object({
90-
principal: Type.String({
91-
description: 'Stacks address or a Contract identifier',
92-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
93-
}),
90+
principal: PrincipalSchema,
9491
}),
9592
querystring: Type.Object({
9693
unanchored: UnanchoredParamSchema,
@@ -155,10 +152,7 @@ export const AddressRoutes: FastifyPluginAsync<
155152
description: `Retrieves total account balance information for a given Address or Contract Identifier. This includes the balances of STX Tokens, Fungible Tokens and Non-Fungible Tokens for the account.`,
156153
tags: ['Accounts'],
157154
params: Type.Object({
158-
principal: Type.String({
159-
description: 'Stacks address or a Contract identifier',
160-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
161-
}),
155+
principal: PrincipalSchema,
162156
}),
163157
querystring: Type.Object({
164158
unanchored: UnanchoredParamSchema,
@@ -264,10 +258,7 @@ export const AddressRoutes: FastifyPluginAsync<
264258
If you need to actively monitor new transactions for an address or contract id, we highly recommend subscribing to [WebSockets or Socket.io](https://github.com/hirosystems/stacks-blockchain-api/tree/master/client) for real-time updates.`,
265259
tags: ['Accounts'],
266260
params: Type.Object({
267-
principal: Type.String({
268-
description: 'Stacks address or a Contract identifier',
269-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
270-
}),
261+
principal: PrincipalSchema,
271262
}),
272263
querystring: Type.Object({
273264
limit: LimitParam(ResourceType.Tx),
@@ -347,10 +338,7 @@ export const AddressRoutes: FastifyPluginAsync<
347338
Retrieves transaction details for a given Transaction Id \`tx_id\`, for a given account or contract Identifier.`,
348339
tags: ['Accounts'],
349340
params: Type.Object({
350-
principal: Type.String({
351-
description: 'Stacks address or a Contract identifier',
352-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
353-
}),
341+
principal: PrincipalSchema,
354342
tx_id: Type.String({
355343
description: 'Transaction ID',
356344
examples: ['0x34d79c7cfc2fe525438736733e501a4bf0308a5556e3e080d1e2c0858aad7448'],
@@ -414,10 +402,7 @@ export const AddressRoutes: FastifyPluginAsync<
414402
description: `Retrieve all transactions for an account or contract identifier including STX transfers for each transaction.`,
415403
tags: ['Accounts'],
416404
params: Type.Object({
417-
principal: Type.String({
418-
description: 'Stacks address or a Contract identifier',
419-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
420-
}),
405+
principal: PrincipalSchema,
421406
}),
422407
querystring: Type.Object({
423408
limit: LimitParam(ResourceType.Tx),
@@ -537,10 +522,7 @@ export const AddressRoutes: FastifyPluginAsync<
537522
description: `Retrieves a list of all assets events associated with an account or a Contract Identifier. This includes Transfers, Mints.`,
538523
tags: ['Accounts'],
539524
params: Type.Object({
540-
principal: Type.String({
541-
description: 'Stacks address or a Contract identifier',
542-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
543-
}),
525+
principal: PrincipalSchema,
544526
}),
545527
querystring: Type.Object({
546528
limit: LimitParam(ResourceType.Event),
@@ -598,10 +580,7 @@ export const AddressRoutes: FastifyPluginAsync<
598580
and transfers from contract-call transactions a the \`send-many-memo\` bulk sending contract.`,
599581
tags: ['Accounts'],
600582
params: Type.Object({
601-
principal: Type.String({
602-
description: 'Stacks address or a Contract identifier',
603-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
604-
}),
583+
principal: PrincipalSchema,
605584
}),
606585
querystring: Type.Object({
607586
limit: LimitParam(ResourceType.Tx),
@@ -700,10 +679,7 @@ export const AddressRoutes: FastifyPluginAsync<
700679
description: `Retrieves all transactions for a given address that are currently in mempool`,
701680
tags: ['Transactions'],
702681
params: Type.Object({
703-
principal: Type.String({
704-
description: 'Stacks address or a Contract identifier',
705-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
706-
}),
682+
principal: PrincipalSchema,
707683
}),
708684
querystring: Type.Object({
709685
limit: LimitParam(ResourceType.Tx),
@@ -750,10 +726,7 @@ export const AddressRoutes: FastifyPluginAsync<
750726
description: `Retrieves the latest nonce values used by an account by inspecting the mempool, microblock transactions, and anchored transactions.`,
751727
tags: ['Accounts'],
752728
params: Type.Object({
753-
principal: Type.String({
754-
description: 'Stacks address or a Contract identifier',
755-
examples: ['SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0'],
756-
}),
729+
principal: PrincipalSchema,
757730
}),
758731
querystring: Type.Object({
759732
block_height: Type.Optional(

src/api/routes/pox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { handleChainTipCache } from '../controllers/cache-controller';
55
import { FastifyPluginAsync } from 'fastify';
66
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
77
import { Server } from 'node:http';
8-
import { LimitParam, OffsetParam, UnanchoredParamSchema } from '../schemas/params';
8+
import { LimitParam, OffsetParam, PrincipalSchema, UnanchoredParamSchema } from '../schemas/params';
99
import { NotFoundError } from '../../errors';
1010
import { PaginatedResponse } from '../schemas/util';
1111
import { PoolDelegation, PoolDelegationSchema } from '../schemas/entities/pox';
@@ -119,7 +119,7 @@ export const PoxRoutes: FastifyPluginAsync<
119119
tags: ['Stacking'],
120120
params: Type.Object({
121121
pox: Type.Enum({ pox2: 'pox2', pox3: 'pox3', pox4: 'pox4' }),
122-
principal: Type.String(),
122+
principal: PrincipalSchema,
123123
}),
124124
},
125125
},

src/api/routes/tokens.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { InvalidRequestError, InvalidRequestErrorType } from '../../errors';
99
import { FastifyPluginAsync } from 'fastify';
1010
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
1111
import { Server } from 'node:http';
12-
import { LimitParam, OffsetParam, UnanchoredParamSchema } from '../schemas/params';
12+
import { LimitParam, OffsetParam, PrincipalSchema, UnanchoredParamSchema } from '../schemas/params';
1313
import { PaginatedResponse } from '../schemas/util';
1414
import {
1515
NonFungibleTokenHistoryEventWithTxIdSchema,
@@ -38,10 +38,7 @@ export const TokenRoutes: FastifyPluginAsync<
3838
More information on Non-Fungible Tokens on the Stacks blockchain can be found [here](https://docs.stacks.co/write-smart-contracts/tokens#non-fungible-tokens-nfts).`,
3939
tags: ['Non-Fungible Tokens'],
4040
querystring: Type.Object({
41-
principal: Type.String({
42-
description: `token owner's STX address or Smart Contract ID`,
43-
examples: ['SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.marketplace-v3'],
44-
}),
41+
principal: PrincipalSchema,
4542
asset_identifiers: Type.Optional(
4643
Type.Array(
4744
Type.String({

0 commit comments

Comments
 (0)