diff --git a/packages/transport-http/src/subscribe/handlers/blocks.ts b/packages/transport-http/src/subscribe/handlers/blocks.ts index 41595263b..7d36255bc 100644 --- a/packages/transport-http/src/subscribe/handlers/blocks.ts +++ b/packages/transport-http/src/subscribe/handlers/blocks.ts @@ -1,7 +1,13 @@ import {SdkTransport} from "@onflow/typedefs" import {createSubscriptionHandler} from "./types" -type BlockDataModel = { +type BlocksArgs = + SdkTransport.SubscriptionArguments + +type BlocksData = + SdkTransport.SubscriptionData + +type BlocksDataDto = { block: { id: string parent_id: string @@ -18,7 +24,7 @@ type BlockDataModel = { } } -type BlockArgsModel = +type BlocksArgsDto = | { block_status?: number start_block_id?: string @@ -30,40 +36,38 @@ type BlockArgsModel = export const blocksHandler = createSubscriptionHandler<{ Topic: SdkTransport.SubscriptionTopic.BLOCKS - Args: SdkTransport.SubscriptionArguments - Data: SdkTransport.SubscriptionData - ArgsModel: BlockArgsModel - DataModel: BlockDataModel + Args: BlocksArgs + Data: BlocksData + ArgsDto: BlocksArgsDto + DataDto: BlocksDataDto }>({ topic: SdkTransport.SubscriptionTopic.BLOCKS, createSubscriber: (initialArgs, onData, onError) => { - let resumeArgs: SdkTransport.SubscriptionArguments = - { - ...initialArgs, - } + let resumeArgs: BlocksArgs = { + ...initialArgs, + } return { - sendData(data: BlockDataModel) { + sendData(data: BlocksDataDto) { // Parse the raw data - const parsedData: SdkTransport.SubscriptionData = - { - block: { - id: data.block.id, - parentId: data.block.parent_id, - height: data.block.height, - timestamp: data.block.timestamp, - collectionGuarantees: data.block.collection_guarantees.map( - guarantee => ({ - collectionId: guarantee.collection_id, - signerIds: guarantee.signer_ids, - }) - ), - blockSeals: data.block.block_seals.map(seal => ({ - blockId: seal.block_id, - executionReceiptId: seal.result_id, - })), - }, - } + const parsedData: BlocksData = { + block: { + id: data.block.id, + parentId: data.block.parent_id, + height: data.block.height, + timestamp: data.block.timestamp, + collectionGuarantees: data.block.collection_guarantees.map( + guarantee => ({ + collectionId: guarantee.collection_id, + signerIds: guarantee.signer_ids, + }) + ), + blockSeals: data.block.block_seals.map(seal => ({ + blockId: seal.block_id, + executionReceiptId: seal.result_id, + })), + }, + } // Update the resume args resumeArgs = { @@ -76,10 +80,8 @@ export const blocksHandler = createSubscriptionHandler<{ sendError(error: Error) { onError(error) }, - encodeArgs( - args: SdkTransport.SubscriptionArguments - ) { - let encodedArgs: BlockArgsModel = { + encodeArgs(args: BlocksArgs) { + let encodedArgs: BlocksArgsDto = { block_status: args.blockStatus, } diff --git a/packages/transport-http/src/subscribe/handlers/types.ts b/packages/transport-http/src/subscribe/handlers/types.ts index 1ab7048d5..df4a3ae9c 100644 --- a/packages/transport-http/src/subscribe/handlers/types.ts +++ b/packages/transport-http/src/subscribe/handlers/types.ts @@ -8,8 +8,8 @@ export interface SubscriptionHandler< Topic: string Args: any Data: any - DataModel: any - ArgsModel: any + ArgsDto: any + DataDto: any }, > { readonly topic: T["Topic"] @@ -17,7 +17,7 @@ export interface SubscriptionHandler< initialArgs: T["Args"], onData: (data: T["Data"]) => void, onError: (error: Error) => void - ): DataSubscriber + ): DataSubscriber } export interface DataSubscriber { @@ -47,8 +47,8 @@ export function createSubscriptionHandler< Topic: string Args: any Data: any - DataModel: any - ArgsModel: any + ArgsDto: any + DataDto: any }, >(handler: SubscriptionHandler): SubscriptionHandler { return handler