Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename juno_unsubsribe to starknet_unsubscribe #2348

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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

Check warning on line 498 in rpc/subscriptions.go

View check run for this annotation

Codecov / codecov/patch

rpc/subscriptions.go#L498

Added line #L498 was not covered by tests
}
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
Loading