diff --git a/packages/transport-http/src/subscribe/handlers/blocks.ts b/packages/transport-http/src/subscribe/handlers/blocks.ts index 76af1a309..eba1f9c52 100644 --- a/packages/transport-http/src/subscribe/handlers/blocks.ts +++ b/packages/transport-http/src/subscribe/handlers/blocks.ts @@ -1,30 +1,66 @@ import {SdkTransport} from "@onflow/typedefs" import {createSubscriptionHandler} from "./types" +type BlockDataModel = { + block: { + id: string + parent_id: string + height: number + timestamp: string + collection_guarantees: { + collection_id: string + signer_ids: string[] + }[] + block_seals: { + block_id: string + result_id: string + }[] + } +} + export const blocksHandler = createSubscriptionHandler<{ Topic: SdkTransport.SubscriptionTopic.BLOCKS Args: SdkTransport.SubscriptionArguments Data: SdkTransport.SubscriptionData - RawData: { - data: SdkTransport.SubscriptionData - } + RawData: BlockDataModel }>({ topic: SdkTransport.SubscriptionTopic.BLOCKS, createSubscriber: (initialArgs, onData, onError) => { let resumeArgs: SdkTransport.SubscriptionArguments = - initialArgs + { + ...initialArgs, + } return { - sendData(data: { - data: SdkTransport.SubscriptionData - }) { - const parsedData = data.data + sendData(data: BlockDataModel) { + // 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, + })), + }, + } + // Update the resume args resumeArgs = { - start: parsedData.placeholder.length, + block_status: resumeArgs.block_status, + start_block_id: data.block.id, } - onData(data.data) + onData(parsedData) }, sendError(error: Error) { onError(error) diff --git a/packages/typedefs/src/index.ts b/packages/typedefs/src/index.ts index b9d516de3..4f92c10f9 100644 --- a/packages/typedefs/src/index.ts +++ b/packages/typedefs/src/index.ts @@ -99,10 +99,6 @@ export type Block = { * - The details of which nodes executed and sealed the blocks */ blockSeals: Array - /** - * - The cryptographic signature of the block - */ - signatures: Array } export type CollectionGuarantee = { /** @@ -112,7 +108,7 @@ export type CollectionGuarantee = { /** * - The signer ids of the block */ - signerIds: Array + signerIds: Array } export type BlockSeal = { /** diff --git a/packages/typedefs/src/sdk-transport/subscriptions.ts b/packages/typedefs/src/sdk-transport/subscriptions.ts index 522073f4d..6b5ef8d02 100644 --- a/packages/typedefs/src/sdk-transport/subscriptions.ts +++ b/packages/typedefs/src/sdk-transport/subscriptions.ts @@ -1,9 +1,10 @@ +import {Block} from ".." + type SchemaItem = { args: TArgs data: TData } -// TODO: PLACEHOLDER - Replace with actual subscription topics export enum SubscriptionTopic { BLOCKS = "blocks", } @@ -11,10 +12,17 @@ export enum SubscriptionTopic { export type SubscriptionSchema = { [SubscriptionTopic.BLOCKS]: SchemaItem< { - start: number - }, + block_status?: number + } & ( + | { + start_block_id?: string + } + | { + start_block_height?: number + } + ), { - placeholder: string + block: Block } > }