Skip to content

Commit

Permalink
Update events keys filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Nov 19, 2024
1 parent ccecb7a commit 37d8c2a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
17 changes: 12 additions & 5 deletions api/eventsopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ type EventsOpts struct {
// If empty then events there is no address filter on returned events.
Address *types.Address

// Keys
// Keys.
// Each list corresponds to matching keys for a given location.
// For example, [[a,b],[c,d] will return any event with either a or b in the first key field, and either c or d in the second
// key field. [[],[c,d]] will return any event with either c or d in the second key field regardless of what is in the first.
// If empty then there is no key filter on returned events.
Keys []types.FieldElement
Keys [][]types.FieldElement

// Limit is the maximum number of events to return.
// This value must be provided.
Expand All @@ -55,9 +58,13 @@ func (o *EventsOpts) MarshalJSON() ([]byte, error) {
filter["address"] = o.Address.String()
}
if len(o.Keys) > 0 {
keys := make([]string, 0, len(o.Keys))
for _, key := range o.Keys {
keys = append(keys, key.String())
keys := make([][]string, 0, len(o.Keys))
for _, keySet := range o.Keys {
set := make([]string, 0, len(keySet))
for _, key := range keySet {
set = append(set, key.String())
}
keys = append(keys, set)
}
filter["keys"] = keys
}
Expand Down
17 changes: 17 additions & 0 deletions jsonrpc/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/attestantio/go-starknet-client/api"
"github.com/attestantio/go-starknet-client/jsonrpc"
"github.com/attestantio/go-starknet-client/types"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
)
Expand All @@ -42,4 +43,20 @@ func TestEvents(t *testing.T) {
})
require.NoError(t, err)
require.NotNil(t, response.Data)

response2, err := s.Events(ctx, &api.EventsOpts{
FromBlock: "300000",
ToBlock: "330000",
Keys: [][]types.FieldElement{
{
strToFieldElement("0xc4a5eb3afec3e38cbe8f43f66c46bb0ca74ae6f10bfbd7c7f0f461d5cdb9f4"),
},
{
strToFieldElement("0x6478e774beb00cd6b0714b0ad3ed3f80949b7e52b84f8f5792099d8990b7e26"),
},
},
Limit: 10,
})
require.NoError(t, err)
require.NotNil(t, response2.Data)
}
14 changes: 8 additions & 6 deletions jsonrpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,14 @@ func (s *Service) CheckConnectionState(ctx context.Context) {
// // Switched from synced to not synced.
// }

log.Trace().
Bool("was_active", wasActive).
Bool("active", active).
Bool("was_synced", wasSynced).
Bool("synced", synced).
Msg("Updated connection state")
if (wasActive != active) || (wasSynced != synced) {
log.Trace().
Bool("was_active", wasActive).
Bool("active", active).
Bool("was_synced", wasSynced).
Bool("synced", synced).
Msg("Updated connection state")
}

s.connectionMu.Lock()
s.connectionActive = active
Expand Down

0 comments on commit 37d8c2a

Please sign in to comment.