Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/core/services/mirrornode/__tests__/unit/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ export const createMockTransactionDetailsResponse = (
transaction_hash: 'hash123',
name: 'CRYPTOTRANSFER',
node: '0.0.3',
transaction_fee: 100000,
scheduled: false,
transfers: [
{ account: '0.0.1234', amount: -1000000 },
Expand Down
7 changes: 6 additions & 1 deletion src/core/services/mirrornode/hedera-mirrornode-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
TopicInfoSchema,
TopicMessagesAPIResponseSchema,
TopicMessageSchema,
TransactionDetailsResponseSchema,
} from './schemas';
import { MirrorNodeKeyType, NetworkToBaseUrl } from './types';

Expand Down Expand Up @@ -450,7 +451,11 @@ export class HederaMirrornodeServiceDefaultImpl implements HederaMirrornodeServi
);
}

return (await response.json()) as TransactionDetailsResponse;
return parseWithSchema(
TransactionDetailsResponseSchema,
await response.json(),
`Mirror Node GET /transactions/${transactionId}`,
);
} catch (error) {
if (error instanceof CliError) throw error;
throw new NetworkError(
Expand Down
63 changes: 63 additions & 0 deletions src/core/services/mirrornode/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import {
type TopicMessage,
type TopicMessageChunkInfo,
type TopicMessagesAPIResponse,
type TransactionAssessedCustomFeeItem,
type TransactionDetailItem,
type TransactionDetailsResponse,
type TransactionNftTransferItem,
type TransactionTokenTransferItem,
type TransactionTransferItem,
} from './types';

const mirrorKeyObject = z.object({
Expand Down Expand Up @@ -202,3 +208,60 @@ export const TopicInfoSchema: z.ZodType<TopicInfo> = z.object({
created_timestamp: z.string(),
deleted: z.boolean(),
});

const transactionTransferItemSchema: z.ZodType<TransactionTransferItem> =
z.object({
account: z.string(),
amount: z.number(),
is_approval: z.boolean().optional(),
});

const transactionTokenTransferItemSchema: z.ZodType<TransactionTokenTransferItem> =
z.object({
token_id: z.string(),
account: z.string(),
amount: z.number(),
is_approval: z.boolean().optional(),
});

const transactionNftTransferItemSchema: z.ZodType<TransactionNftTransferItem> =
z.object({
is_approval: z.boolean(),
receiver_account_id: z.string(),
sender_account_id: z.string(),
serial_number: z.number(),
token_id: z.string(),
});

const transactionAssessedCustomFeeItemSchema: z.ZodType<TransactionAssessedCustomFeeItem> =
z.object({
amount: z.number(),
collector_account_id: z.string(),
token_id: z.string().nullable().optional(),
effective_payer_account_ids: z.array(z.string()).optional(),
});

export const TransactionDetailItemSchema: z.ZodType<TransactionDetailItem> =
z.object({
transaction_id: z.string(),
consensus_timestamp: z.string(),
valid_start_timestamp: z.string(),
charged_tx_fee: z.number(),
memo_base64: z.union([z.string(), z.null()]).optional(),
result: z.string(),
transaction_hash: z.string(),
name: z.string(),
node: z.string(),
scheduled: z.boolean(),
transfers: z.array(transactionTransferItemSchema),
token_transfers: z.array(transactionTokenTransferItemSchema).optional(),
nft_transfers: z.array(transactionNftTransferItemSchema).optional(),
assessed_custom_fees: z
.array(transactionAssessedCustomFeeItemSchema)
.optional(),
});

export const TransactionDetailsResponseSchema: z.ZodType<TransactionDetailsResponse> =
z.object({
transactions: z.array(TransactionDetailItemSchema),
});
79 changes: 46 additions & 33 deletions src/core/services/mirrornode/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,40 +157,53 @@ export interface TopicMessagesResponse {
}

// Transaction Details
export interface TransactionTransferItem {
account: string;
amount: number;
is_approval?: boolean;
}

export interface TransactionTokenTransferItem {
token_id: string;
account: string;
amount: number;
is_approval?: boolean;
}

export interface TransactionNftTransferItem {
is_approval: boolean;
receiver_account_id: string;
sender_account_id: string;
serial_number: number;
token_id: string;
}

export interface TransactionAssessedCustomFeeItem {
amount: number;
collector_account_id: string;
token_id?: string | null;
effective_payer_account_ids?: string[];
}

export interface TransactionDetailItem {
transaction_id: string;
consensus_timestamp: string;
valid_start_timestamp: string;
charged_tx_fee: number;
memo_base64?: string | null;
result: string;
transaction_hash: string;
name: string;
node: string;
scheduled: boolean;
transfers: TransactionTransferItem[];
token_transfers?: TransactionTokenTransferItem[];
nft_transfers?: TransactionNftTransferItem[];
assessed_custom_fees?: TransactionAssessedCustomFeeItem[];
}

export interface TransactionDetailsResponse {
transactions: Array<{
transaction_id: string;
consensus_timestamp: string;
valid_start_timestamp: string;
charged_tx_fee: number;
memo_base64?: string;
result: string;
transaction_hash: string;
name: string;
node: string;
transaction_fee: number;
scheduled: boolean;
transfers: Array<{
account: string;
amount: number;
}>;
token_transfers?: Array<{
account: string;
amount: number;
token_id: string;
}>;
nft_transfers?: Array<{
account: string;
amount: number;
token_id: string;
serial_number: number;
}>;
assessed_custom_fees?: Array<{
amount: number;
collector_account_id: string;
token_id?: string;
}>;
}>;
transactions: TransactionDetailItem[];
}

// Contract Info
Expand Down
Loading