Skip to content

Commit

Permalink
change naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Dec 2, 2024
1 parent aaf89ca commit b150d6b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
70 changes: 36 additions & 34 deletions packages/transport-http/src/subscribe/handlers/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import {SdkTransport} from "@onflow/typedefs"
import {createSubscriptionHandler} from "./types"

type BlockDataModel = {
type BlocksArgs =
SdkTransport.SubscriptionArguments<SdkTransport.SubscriptionTopic.BLOCKS>

type BlocksData =
SdkTransport.SubscriptionData<SdkTransport.SubscriptionTopic.BLOCKS>

type BlocksDataDto = {
block: {
id: string
parent_id: string
Expand All @@ -18,7 +24,7 @@ type BlockDataModel = {
}
}

type BlockArgsModel =
type BlocksArgsDto =
| {
block_status?: number
start_block_id?: string
Expand All @@ -30,40 +36,38 @@ type BlockArgsModel =

export const blocksHandler = createSubscriptionHandler<{
Topic: SdkTransport.SubscriptionTopic.BLOCKS
Args: SdkTransport.SubscriptionArguments<SdkTransport.SubscriptionTopic.BLOCKS>
Data: SdkTransport.SubscriptionData<SdkTransport.SubscriptionTopic.BLOCKS>
ArgsModel: BlockArgsModel
DataModel: BlockDataModel
Args: BlocksArgs
Data: BlocksData
ArgsDto: BlocksArgsDto
DataDto: BlocksDataDto
}>({
topic: SdkTransport.SubscriptionTopic.BLOCKS,
createSubscriber: (initialArgs, onData, onError) => {
let resumeArgs: SdkTransport.SubscriptionArguments<SdkTransport.SubscriptionTopic.BLOCKS> =
{
...initialArgs,
}
let resumeArgs: BlocksArgs = {
...initialArgs,
}

return {
sendData(data: BlockDataModel) {
sendData(data: BlocksDataDto) {
// Parse the raw data
const parsedData: SdkTransport.SubscriptionData<SdkTransport.SubscriptionTopic.BLOCKS> =
{
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 = {
Expand All @@ -76,10 +80,8 @@ export const blocksHandler = createSubscriptionHandler<{
sendError(error: Error) {
onError(error)
},
encodeArgs(
args: SdkTransport.SubscriptionArguments<SdkTransport.SubscriptionTopic.BLOCKS>
) {
let encodedArgs: BlockArgsModel = {
encodeArgs(args: BlocksArgs) {
let encodedArgs: BlocksArgsDto = {
block_status: args.blockStatus,
}

Expand Down
10 changes: 5 additions & 5 deletions packages/transport-http/src/subscribe/handlers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export interface SubscriptionHandler<
Topic: string
Args: any
Data: any
DataModel: any
ArgsModel: any
ArgsDto: any
DataDto: any
},
> {
readonly topic: T["Topic"]
createSubscriber(
initialArgs: T["Args"],
onData: (data: T["Data"]) => void,
onError: (error: Error) => void
): DataSubscriber<T["Args"], T["ArgsModel"], T["DataModel"]>
): DataSubscriber<T["Args"], T["ArgsDto"], T["DataDto"]>
}

export interface DataSubscriber<Args, ArgsModel, Data> {
Expand Down Expand Up @@ -47,8 +47,8 @@ export function createSubscriptionHandler<
Topic: string
Args: any
Data: any
DataModel: any
ArgsModel: any
ArgsDto: any
DataDto: any
},
>(handler: SubscriptionHandler<T>): SubscriptionHandler<T> {
return handler
Expand Down

0 comments on commit b150d6b

Please sign in to comment.