Skip to content

Commit

Permalink
Add SubscriptionResponse
Browse files Browse the repository at this point in the history
Using jsonrpc.Request for subscription response is misleading and by
adding a separate struct for returning responses to subscription events
is more appropriate
  • Loading branch information
IronGauntlets committed Nov 25, 2024
1 parent 25a389e commit f7579fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion rpc/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import (

const subscribeEventsChunkSize = 1024

type SubscriptionResponse struct {
Version string `json:"jsonrpc"`
Method string `json:"method"`
Params any `json:"params"`
}

func (h *Handler) SubscribeEvents(ctx context.Context, fromAddr *felt.Felt, keys [][]felt.Felt,
blockID *BlockID,
) (*SubscriptionID, *jsonrpc.Error) {
Expand Down Expand Up @@ -158,7 +164,7 @@ func sendEvents(ctx context.Context, w jsonrpc.Conn, events []*blockchain.Filter
},
}

resp, err := json.Marshal(jsonrpc.Request{
resp, err := json.Marshal(SubscriptionResponse{
Version: "2.0",
Method: "starknet_subscriptionEvents",
Params: map[string]any{
Expand Down
2 changes: 1 addition & 1 deletion rpc/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestSubscribeEvents(t *testing.T) {
}

func marshalSubscriptionResponse(e *EmittedEvent, id uint64) ([]byte, error) {
return json.Marshal(jsonrpc.Request{
return json.Marshal(SubscriptionResponse{
Version: "2.0",
Method: "starknet_subscriptionEvents",
Params: map[string]any{
Expand Down

0 comments on commit f7579fe

Please sign in to comment.