-
Notifications
You must be signed in to change notification settings - Fork 16
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
proposed additional QueryKeys API method to support getting events of different types in log index order #944
base: main
Are you sure you want to change the base?
Conversation
… types in index order
@@ -65,6 +65,9 @@ type ContractReader interface { | |||
// QueryKey provides fetching chain agnostic events (Sequence) with general querying capability. | |||
QueryKey(ctx context.Context, contract BoundContract, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]Sequence, error) | |||
|
|||
// QueryKeys provides fetching chain agnostic events of different types (SequenceWithKey) with general querying capability. | |||
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]SequenceWithKey, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a map of Key -> Sequence?
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]SequenceWithKey, error) | |
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) (map[string]Sequence, error) |
If you are worried about ordering, could consider a sequence:
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]SequenceWithKey, error) | |
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) (iter.Seq2[string, Sequence], error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with map[string]Sequence is it would lose the order, the key thing is that the order across the various event types needs to be maintained.
no strong feelings on using iter, however the result isn't streamed so no strong advantage to using iter either as far as I can see, and I think it would add a bit of complexity to the loop implementation. On balance my pref would be for []SequenceWithKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Streaming is not the only reason to use an iter.Seq
, and this API is a layer above the GRPC protos. The advantage is that we can express what we need naturally and directly without declaring extra hyper-specific types. Another similar approach could be a generic entry/pair/etc.:
type Entry[K comparable, V any] struct {
K K
V V
}
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]SequenceWithKey, error) | |
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]Entry[string, Sequence], error) |
Could also consider documenting via a type:
// SortedEntries is a slice of [Entry]s sorted by ascending keys.
type SortedEntries[K comparable, V any] []Entry[K, V]
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]SequenceWithKey, error) | |
QueryKeys(ctx context.Context, contract BoundContract, filters []query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) (SortedEntries[string, Sequence], error) |
Required to correctly replicate state from on chain contract that publishes multiple event types to offchain state.
For comment, tentatively agreed with @ilija42 pending inspiration from above.