diff --git a/src/core/services/mirrornode/hedera-mirrornode-service.ts b/src/core/services/mirrornode/hedera-mirrornode-service.ts index f412e4652..1e411c693 100644 --- a/src/core/services/mirrornode/hedera-mirrornode-service.ts +++ b/src/core/services/mirrornode/hedera-mirrornode-service.ts @@ -36,6 +36,7 @@ import { handleMirrorNodeErrorResponse } from '@/core/utils/handle-mirror-node-e import { AccountAPIResponseSchema, + ContractInfoSchema, GetAccountsAPIResponseSchema, NftInfoSchema, TokenAirdropsResponseSchema, @@ -479,7 +480,11 @@ export class HederaMirrornodeServiceDefaultImpl implements HederaMirrornodeServi ); } - return (await response.json()) as ContractInfo; + return parseWithSchema( + ContractInfoSchema, + await response.json(), + `Mirror Node GET /contracts/${contractId}`, + ); } catch (error) { if (error instanceof CliError) throw error; throw new NetworkError( diff --git a/src/core/services/mirrornode/schemas.ts b/src/core/services/mirrornode/schemas.ts index 926f4f036..12b89e471 100644 --- a/src/core/services/mirrornode/schemas.ts +++ b/src/core/services/mirrornode/schemas.ts @@ -7,6 +7,7 @@ import { type AccountListItemAPIResponse, type AccountListItemBalance, type AccountListItemTokenBalance, + type ContractInfo, type GetAccountsAPIResponse, MirrorNodeKeyType, type NftInfo, @@ -209,6 +210,27 @@ export const TopicInfoSchema: z.ZodType = z.object({ deleted: z.boolean(), }); +export const ContractInfoSchema: z.ZodType = z.object({ + contract_id: z.string(), + account: z.string().optional(), + created_timestamp: z.string(), + deleted: z.boolean(), + memo: z.string(), + evm_address: z.string().optional(), + admin_key: optionalKeyRef, + auto_renew_account: nullableStringKey, + auto_renew_period: z.number(), + expiration_timestamp: nullableStringKey, + file_id: nullableStringKey, + max_automatic_token_associations: z.number(), + obtainer_id: nullableStringKey, + permanent_removal: z.union([z.boolean(), z.null()]).optional(), + proxy_account_id: nullableStringKey, + staked_account_id: nullableStringKey, + staked_node_id: z.union([z.number(), z.null()]).optional(), + stake_period_start: nullableStringKey, +}); + const transactionTransferItemSchema: z.ZodType = z.object({ account: z.string(), diff --git a/src/core/services/mirrornode/types.ts b/src/core/services/mirrornode/types.ts index 18484b063..5d2dc401a 100644 --- a/src/core/services/mirrornode/types.ts +++ b/src/core/services/mirrornode/types.ts @@ -209,26 +209,23 @@ export interface TransactionDetailsResponse { // Contract Info export interface ContractInfo { contract_id: string; - account: string; + account?: string; created_timestamp: string; deleted: boolean; memo: string; evm_address?: string; - admin_key?: { - _type: string; - key: string; - }; - auto_renew_account?: string; + admin_key?: MirrorNodeKey | null; + auto_renew_account?: string | null; auto_renew_period: number; - expiration_timestamp?: string; - file_id?: string; + expiration_timestamp?: string | null; + file_id?: string | null; max_automatic_token_associations: number; - obtainer_id?: string; - permanent_removal?: boolean; - proxy_account_id?: string; - staked_account_id?: string; - staked_node_id?: number; - stake_period_start?: string; + obtainer_id?: string | null; + permanent_removal?: boolean | null; + proxy_account_id?: string | null; + staked_account_id?: string | null; + staked_node_id?: number | null; + stake_period_start?: string | null; } // Token Airdrops