Skip to content

Commit

Permalink
feat: onReorg
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Nov 27, 2024
1 parent 8fcf1a5 commit ecf6290
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/channel/ws_0_8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
SubscriptionEventsResponse,
SubscriptionNewHeadsResponse,
SubscriptionPendingTransactionsResponse,
SubscriptionReorgResponse,
SubscriptionTransactionsStatusResponse,
WebSocketEvents,
} from 'starknet-types-08';
Expand Down Expand Up @@ -72,6 +73,17 @@ export class WebSocketChannel {
*/
public websocket: WebSocket;

/**
* Assign implementation method to get 'on reorg event data'
* @example
* ```typescript
* webSocketChannel.onReorg = async function (data) {
* // ... do something when reorg happens
* }
* ```
*/
public onReorg: (this: WebSocketChannel, data: SubscriptionReorgResponse) => any = () => {};

/**
* Assign implementation method to get 'starknet block heads'
* @example
Expand Down Expand Up @@ -375,7 +387,8 @@ export class WebSocketChannel {

switch (eventName) {
case 'starknet_subscriptionReorg':
throw Error('Reorg'); // todo: implement what to do
this.onReorg(message.params as SubscriptionReorgResponse);
break;
case 'starknet_subscriptionNewHeads':
this.onNewHeads(message.params as SubscriptionNewHeadsResponse);
break;
Expand Down

0 comments on commit ecf6290

Please sign in to comment.