Skip to content

Commit be17c4f

Browse files
authored
feat(1716): mirror node pending and outstanding airdrops response validation (#1744)
Signed-off-by: rozekmichal <michal.rozek@blockydevs.com>
1 parent cdd2810 commit be17c4f

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/core/services/mirrornode/hedera-mirrornode-service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { handleMirrorNodeErrorResponse } from '@/core/utils/handle-mirror-node-e
3838
import {
3939
AccountAPIResponseSchema,
4040
GetAccountsAPIResponseSchema,
41+
TokenAirdropsResponseSchema,
4142
TokenBalancesResponseSchema,
4243
TokenInfoSchema,
4344
TopicInfoSchema,
@@ -493,7 +494,11 @@ export class HederaMirrornodeServiceDefaultImpl implements HederaMirrornodeServi
493494
);
494495
}
495496

496-
return (await response.json()) as TokenAirdropsResponse;
497+
return parseWithSchema(
498+
TokenAirdropsResponseSchema,
499+
await response.json(),
500+
`Mirror Node GET /accounts/${accountId}/airdrops/pending`,
501+
);
497502
} catch (error) {
498503
if (error instanceof CliError) throw error;
499504
throw new NetworkError(
@@ -519,7 +524,11 @@ export class HederaMirrornodeServiceDefaultImpl implements HederaMirrornodeServi
519524
);
520525
}
521526

522-
return (await response.json()) as TokenAirdropsResponse;
527+
return parseWithSchema(
528+
TokenAirdropsResponseSchema,
529+
await response.json(),
530+
`Mirror Node GET /accounts/${accountId}/airdrops/outstanding`,
531+
);
523532
} catch (error) {
524533
if (error instanceof CliError) throw error;
525534
throw new NetworkError(

src/core/services/mirrornode/schemas.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type {
66
AccountListItemBalance,
77
AccountListItemTokenBalance,
88
GetAccountsAPIResponse,
9+
TokenAirdropItem,
10+
TokenAirdropsResponse,
911
TokenBalanceInfo,
1012
TokenBalancesResponse,
1113
TokenInfo,
@@ -158,6 +160,18 @@ export const TokenBalancesResponseSchema: z.ZodType<TokenBalancesResponse> =
158160
.optional(),
159161
});
160162

163+
const TokenAirdropItemSchema: z.ZodType<TokenAirdropItem> = z.object({
164+
account_id: z.string(),
165+
amount: z.number(),
166+
token_id: z.string(),
167+
timestamp: z.string(),
168+
});
169+
170+
export const TokenAirdropsResponseSchema: z.ZodType<TokenAirdropsResponse> =
171+
z.object({
172+
airdrops: z.array(TokenAirdropItemSchema),
173+
});
174+
161175
export const TopicInfoSchema: z.ZodType<TopicInfo> = z.object({
162176
topic_id: z.string(),
163177
admin_key: optionalKeyRef,

src/core/services/mirrornode/types.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,15 @@ export interface ContractInfo {
216216
}
217217

218218
// Token Airdrops
219+
export interface TokenAirdropItem {
220+
account_id: string;
221+
amount: number;
222+
token_id: string;
223+
timestamp: string;
224+
}
225+
219226
export interface TokenAirdropsResponse {
220-
airdrops: Array<{
221-
account_id: string;
222-
amount: number;
223-
token_id: string;
224-
timestamp: string;
225-
}>;
227+
airdrops: TokenAirdropItem[];
226228
}
227229

228230
// Exchange Rate

0 commit comments

Comments
 (0)