Skip to content

Commit 4ba933f

Browse files
authored
Rename juno_unsubsribe to starknet_unsubscribe (#2348)
1 parent dfeb41a commit 4ba933f

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

docs/docs/websocket.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ When a new block is added, you will receive a message like this:
155155

156156
## Unsubscribe from newly created blocks
157157

158-
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:
158+
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:
159159

160160
<Tabs>
161161
<TabItem value="request" label="Request">
162162

163163
```json
164164
{
165165
"jsonrpc": "2.0",
166-
"method": "juno_unsubscribe",
166+
"method": "starknet_unsubscribe",
167167
"params": {
168168
"id": 16570962336122680234
169169
},

rpc/handlers.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ var (
6666
ErrUnsupportedTxVersion = &jsonrpc.Error{Code: 61, Message: "the transaction version is not supported"}
6767
ErrUnsupportedContractClassVersion = &jsonrpc.Error{Code: 62, Message: "the contract class version is not supported"}
6868
ErrUnexpectedError = &jsonrpc.Error{Code: 63, Message: "An unexpected error occurred"}
69+
ErrInvalidSubscriptionID = &jsonrpc.Error{Code: 66, Message: "Invalid subscription id"}
6970
ErrTooManyAddressesInFilter = &jsonrpc.Error{Code: 67, Message: "Too many addresses in filter sender_address filter"}
7071
ErrTooManyBlocksBack = &jsonrpc.Error{Code: 68, Message: fmt.Sprintf("Cannot go back more than %v blocks", maxBlocksBack)}
7172
ErrCallOnPending = &jsonrpc.Error{Code: 69, Message: "This method does not support being called on the pending block"}
72-
73-
// These errors can be only be returned by Juno-specific methods.
74-
ErrSubscriptionNotFound = &jsonrpc.Error{Code: 100, Message: "Subscription not found"}
7573
)
7674

7775
const (
@@ -366,7 +364,7 @@ func (h *Handler) Methods() ([]jsonrpc.Method, string) { //nolint: funlen
366364
Handler: h.SubscribePendingTxs,
367365
},
368366
{
369-
Name: "juno_unsubscribe",
367+
Name: "starknet_unsubscribe",
370368
Params: []jsonrpc.Parameter{{Name: "id"}},
371369
Handler: h.Unsubscribe,
372370
},
@@ -535,7 +533,7 @@ func (h *Handler) MethodsV0_7() ([]jsonrpc.Method, string) { //nolint: funlen
535533
Handler: h.SubscribeNewHeads,
536534
},
537535
{
538-
Name: "juno_unsubscribe",
536+
Name: "starknet_unsubscribe",
539537
Params: []jsonrpc.Parameter{{Name: "id"}},
540538
Handler: h.Unsubscribe,
541539
},

rpc/subscriptions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func (h *Handler) Unsubscribe(ctx context.Context, id uint64) (bool, *jsonrpc.Er
495495
sub, ok := h.subscriptions[id]
496496
h.mu.Unlock() // Don't defer since h.unsubscribe acquires the lock.
497497
if !ok || !sub.conn.Equal(w) {
498-
return false, ErrSubscriptionNotFound
498+
return false, ErrInvalidSubscriptionID
499499
}
500500
sub.cancel()
501501
sub.wg.Wait() // Let the subscription finish before responding.

rpc/subscriptions_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
571571
require.Equal(t, newHeadsResponse(secondID), string(secondHeaderGot))
572572

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

0 commit comments

Comments
 (0)