From 4ba933fa240c3e9cf0e0ab80d9b4843b43e293d2 Mon Sep 17 00:00:00 2001 From: Ng Wei Han <47109095+weiihann@users.noreply.github.com> Date: Tue, 24 Dec 2024 21:21:38 +0800 Subject: [PATCH] Rename `juno_unsubsribe` to `starknet_unsubscribe` (#2348) --- docs/docs/websocket.md | 4 ++-- rpc/handlers.go | 8 +++----- rpc/subscriptions.go | 2 +- rpc/subscriptions_test.go | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/docs/websocket.md b/docs/docs/websocket.md index 4614caedc0..f31e369811 100644 --- a/docs/docs/websocket.md +++ b/docs/docs/websocket.md @@ -155,7 +155,7 @@ 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: @@ -163,7 +163,7 @@ Use the `juno_unsubscribe` method with the `result` value from the subscription ```json { "jsonrpc": "2.0", - "method": "juno_unsubscribe", + "method": "starknet_unsubscribe", "params": { "id": 16570962336122680234 }, diff --git a/rpc/handlers.go b/rpc/handlers.go index 7657d021a8..83795b666f 100644 --- a/rpc/handlers.go +++ b/rpc/handlers.go @@ -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 ( @@ -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, }, @@ -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, }, diff --git a/rpc/subscriptions.go b/rpc/subscriptions.go index 371219f165..7a57981261 100644 --- a/rpc/subscriptions.go +++ b/rpc/subscriptions.go @@ -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. diff --git a/rpc/subscriptions_test.go b/rpc/subscriptions_test.go index 9ca3f2d4fb..4757ab73d8 100644 --- a/rpc/subscriptions_test.go +++ b/rpc/subscriptions_test.go @@ -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)))) }