Skip to content

Commit

Permalink
Rename juno_unsubsribe to starknet_unsubscribe (#2348)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann authored Dec 24, 2024
1 parent dfeb41a commit 4ba933f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/docs/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ When a new block is added, you will receive a message like this:

## Unsubscribe from newly created blocks

Use the `juno_unsubscribe` method with the `result` value from the subscription response or the `subscription` field from any new block event to stop receiving updates for new blocks:
Use the `starknet_unsubscribe` method with the `result` value from the subscription response or the `subscription` field from any new block event to stop receiving updates for new blocks:

<Tabs>
<TabItem value="request" label="Request">

```json
{
"jsonrpc": "2.0",
"method": "juno_unsubscribe",
"method": "starknet_unsubscribe",
"params": {
"id": 16570962336122680234
},
Expand Down
8 changes: 3 additions & 5 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ var (
ErrUnsupportedTxVersion = &jsonrpc.Error{Code: 61, Message: "the transaction version is not supported"}
ErrUnsupportedContractClassVersion = &jsonrpc.Error{Code: 62, Message: "the contract class version is not supported"}
ErrUnexpectedError = &jsonrpc.Error{Code: 63, Message: "An unexpected error occurred"}
ErrInvalidSubscriptionID = &jsonrpc.Error{Code: 66, Message: "Invalid subscription id"}
ErrTooManyAddressesInFilter = &jsonrpc.Error{Code: 67, Message: "Too many addresses in filter sender_address filter"}
ErrTooManyBlocksBack = &jsonrpc.Error{Code: 68, Message: fmt.Sprintf("Cannot go back more than %v blocks", maxBlocksBack)}
ErrCallOnPending = &jsonrpc.Error{Code: 69, Message: "This method does not support being called on the pending block"}

// These errors can be only be returned by Juno-specific methods.
ErrSubscriptionNotFound = &jsonrpc.Error{Code: 100, Message: "Subscription not found"}
)

const (
Expand Down Expand Up @@ -366,7 +364,7 @@ func (h *Handler) Methods() ([]jsonrpc.Method, string) { //nolint: funlen
Handler: h.SubscribePendingTxs,
},
{
Name: "juno_unsubscribe",
Name: "starknet_unsubscribe",
Params: []jsonrpc.Parameter{{Name: "id"}},
Handler: h.Unsubscribe,
},
Expand Down Expand Up @@ -535,7 +533,7 @@ func (h *Handler) MethodsV0_7() ([]jsonrpc.Method, string) { //nolint: funlen
Handler: h.SubscribeNewHeads,
},
{
Name: "juno_unsubscribe",
Name: "starknet_unsubscribe",
Params: []jsonrpc.Parameter{{Name: "id"}},
Handler: h.Unsubscribe,
},
Expand Down
2 changes: 1 addition & 1 deletion rpc/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func (h *Handler) Unsubscribe(ctx context.Context, id uint64) (bool, *jsonrpc.Er
sub, ok := h.subscriptions[id]
h.mu.Unlock() // Don't defer since h.unsubscribe acquires the lock.
if !ok || !sub.conn.Equal(w) {
return false, ErrSubscriptionNotFound
return false, ErrInvalidSubscriptionID
}
sub.cancel()
sub.wg.Wait() // Let the subscription finish before responding.
Expand Down
2 changes: 1 addition & 1 deletion rpc/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
require.Equal(t, newHeadsResponse(secondID), string(secondHeaderGot))

// Unsubscribe
unsubMsg := `{"jsonrpc":"2.0","id":1,"method":"juno_unsubscribe","params":[%d]}`
unsubMsg := `{"jsonrpc":"2.0","id":1,"method":"starknet_unsubscribe","params":[%d]}`
require.NoError(t, conn1.Write(ctx, websocket.MessageBinary, []byte(fmt.Sprintf(unsubMsg, firstID))))
require.NoError(t, conn2.Write(ctx, websocket.MessageBinary, []byte(fmt.Sprintf(unsubMsg, secondID))))
}
Expand Down

0 comments on commit 4ba933f

Please sign in to comment.