diff --git a/packages/sdk/src/subscribe/subscription-manager.test.ts b/packages/sdk/src/subscribe/subscription-manager.test.ts deleted file mode 100644 index 9c31e341c..000000000 --- a/packages/sdk/src/subscribe/subscription-manager.test.ts +++ /dev/null @@ -1 +0,0 @@ -describe("SubscriptionManager", () => {}) diff --git a/packages/sdk/src/subscribe/subscription-manager.ts b/packages/sdk/src/subscribe/subscription-manager.ts deleted file mode 100644 index 736d605eb..000000000 --- a/packages/sdk/src/subscribe/subscription-manager.ts +++ /dev/null @@ -1,70 +0,0 @@ -//subscriptionmanager - -enum SubscriptionTopic { - EVENTS = "events", - BLOCKS = "blocks", -} - -type SubscriptionTypes = { - [SubscriptionTopic.EVENTS]: { - args: { - startBlock: number - endBlock: number - } - response: { - type: string - data: any - } - } - [SubscriptionTopic.BLOCKS]: { - args: { - startBlock: number - endBlock: number - } - response: { - type: string - data: any - } - } -} - -type Subscription = { - unsubscribe: () => void -} - -type SubscriptionTransport = { - subscribe: (topic: string, args: any, callback: (data: any) => void) => string - unsubscribe: (subscriptionId: string) => void -} - -export class SubscriptionManager { - private subscriptions: Subscription[] = [] - - constructor(private readonly transport: SubscriptionTransport) {} - - subscribe( - topic: T, - args: SubscriptionTypes[T]["args"], - callback: (data: any) => void - ): () => void { - const subscription = this.transport.subscribe(topic, args, data => { - const decodedData = this.decode(topic, data) - callback(decodedData) - }) - - return () => { - const index = this.subscriptions.indexOf(subscription) - if (index !== -1) { - this.subscriptions.splice(index, 1) - subscription.unsubscribe() - } - } - } - - decode( - topic: T, - data: any - ): SubscriptionTypes[T]["response"] { - return data - } -}