-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat(server/v2): refactor the server/v2 events #21785
Changes from 5 commits
895cf04
8596f3d
7bc777b
9b221e8
dc2ab6d
4ca72d0
715bad1
466d799
1232713
dd9b219
e59ee1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ require ( | |
) | ||
|
||
replace cosmossdk.io/core/testing => ../core/testing | ||
|
||
replace cosmossdk.io/schema => ../schema | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this in a separate PR? I'm pretty sure this replace has a global effect on all go.mod's in the SDK. Instead if needed we can tag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we need a new tag of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure let's have alpha.3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, you can now remove all the replaces and use https://github.com/cosmos/cosmos-sdk/releases/tag/schema%2Fv0.3.0 and https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv1.0.0-alpha.3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for tagging schema @julienrbrt ! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ | |
collectionLookup *btree.Map[string, *collectionSchemaCodec] | ||
} | ||
|
||
func (m moduleDecoder) decodeKV(update schema.KVPairUpdate) ([]schema.ObjectUpdate, error) { | ||
func (m moduleDecoder) decodeKV(update schema.KVPairUpdate) ([]schema.StateObjectUpdate, error) { | ||
Check failure on line 70 in collections/indexing.go GitHub Actions / dependency-review
Check failure on line 70 in collections/indexing.go GitHub Actions / tests (02)
Check failure on line 70 in collections/indexing.go GitHub Actions / tests (00)
Check failure on line 70 in collections/indexing.go GitHub Actions / tests (03)
Check failure on line 70 in collections/indexing.go GitHub Actions / golangci-lint
|
||
key := update.Key | ||
ks := string(key) | ||
var cd *collectionSchemaCodec | ||
|
@@ -87,32 +87,32 @@ | |
return cd.decodeKVPair(update) | ||
} | ||
|
||
func (c collectionSchemaCodec) decodeKVPair(update schema.KVPairUpdate) ([]schema.ObjectUpdate, error) { | ||
func (c collectionSchemaCodec) decodeKVPair(update schema.KVPairUpdate) ([]schema.StateObjectUpdate, error) { | ||
Check failure on line 90 in collections/indexing.go GitHub Actions / dependency-review
Check failure on line 90 in collections/indexing.go GitHub Actions / tests (02)
Check failure on line 90 in collections/indexing.go GitHub Actions / tests (00)
Check failure on line 90 in collections/indexing.go GitHub Actions / tests (03)
Check failure on line 90 in collections/indexing.go GitHub Actions / golangci-lint
|
||
// strip prefix | ||
key := update.Key | ||
key = key[len(c.coll.GetPrefix()):] | ||
|
||
k, err := c.keyDecoder(key) | ||
if err != nil { | ||
return []schema.ObjectUpdate{ | ||
return []schema.StateObjectUpdate{ | ||
Check failure on line 97 in collections/indexing.go GitHub Actions / dependency-review
Check failure on line 97 in collections/indexing.go GitHub Actions / tests (02)
Check failure on line 97 in collections/indexing.go GitHub Actions / tests (00)
Check failure on line 97 in collections/indexing.go GitHub Actions / tests (03)
Check failure on line 97 in collections/indexing.go GitHub Actions / golangci-lint
|
||
{TypeName: c.coll.GetName()}, | ||
}, err | ||
Comment on lines
+97
to
99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the compilation error due to undefined type The static analysis hints indicate that the type ToolsGitHub Check: tests (03)
GitHub Check: tests (02)
GitHub Check: tests (01)
GitHub Check: tests (00)
GitHub Check: dependency-review
GitHub Check: golangci-lint
|
||
} | ||
|
||
if update.Remove { | ||
return []schema.ObjectUpdate{ | ||
return []schema.StateObjectUpdate{ | ||
Check failure on line 103 in collections/indexing.go GitHub Actions / dependency-review
Check failure on line 103 in collections/indexing.go GitHub Actions / tests (02)
Check failure on line 103 in collections/indexing.go GitHub Actions / tests (00)
Check failure on line 103 in collections/indexing.go GitHub Actions / tests (03)
Check failure on line 103 in collections/indexing.go GitHub Actions / golangci-lint
|
||
{TypeName: c.coll.GetName(), Key: k, Delete: true}, | ||
}, nil | ||
Comment on lines
+103
to
105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the compilation error due to undefined type The static analysis hints indicate that the type ToolsGitHub Check: tests (03)
GitHub Check: tests (02)
GitHub Check: tests (01)
GitHub Check: tests (00)
GitHub Check: dependency-review
GitHub Check: golangci-lint
|
||
} | ||
|
||
v, err := c.valueDecoder(update.Value) | ||
if err != nil { | ||
return []schema.ObjectUpdate{ | ||
return []schema.StateObjectUpdate{ | ||
Check failure on line 110 in collections/indexing.go GitHub Actions / dependency-review
Check failure on line 110 in collections/indexing.go GitHub Actions / tests (02)
Check failure on line 110 in collections/indexing.go GitHub Actions / tests (00)
Check failure on line 110 in collections/indexing.go GitHub Actions / tests (03)
Check failure on line 110 in collections/indexing.go GitHub Actions / golangci-lint
|
||
{TypeName: c.coll.GetName(), Key: k}, | ||
}, err | ||
Comment on lines
+110
to
112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the compilation error due to undefined type The static analysis hints indicate that the type ToolsGitHub Check: tests (03)
GitHub Check: tests (02)
GitHub Check: tests (01)
GitHub Check: tests (00)
GitHub Check: dependency-review
GitHub Check: golangci-lint
|
||
} | ||
|
||
return []schema.ObjectUpdate{ | ||
return []schema.StateObjectUpdate{ | ||
Check failure on line 115 in collections/indexing.go GitHub Actions / dependency-review
Check failure on line 115 in collections/indexing.go GitHub Actions / tests (02)
Check failure on line 115 in collections/indexing.go GitHub Actions / tests (00)
Check failure on line 115 in collections/indexing.go GitHub Actions / tests (03)
Check failure on line 115 in collections/indexing.go GitHub Actions / golangci-lint
|
||
{TypeName: c.coll.GetName(), Key: k, Value: v}, | ||
}, nil | ||
Comment on lines
+115
to
117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the compilation error due to undefined type The static analysis hints indicate that the type ToolsGitHub Check: tests (03)
GitHub Check: tests (02)
GitHub Check: tests (01)
GitHub Check: tests (00)
GitHub Check: dependency-review
GitHub Check: golangci-lint
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,6 @@ func TypedEventToEvent(tev transaction.Msg) (event.Event, error) { | |
|
||
return event.Event{ | ||
Type: evtType, | ||
Attributes: attrs, | ||
Attributes: func() ([]event.Attribute, error) { return attrs, nil }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider enhancing the attributes closure for more robust error handling and validation. The introduction of a closure to encapsulate the attributes allows for deferred execution and the addition of logic without altering the function signature. This is a good approach to make the handling of attributes more flexible. However, the current implementation doesn't fully leverage the potential benefits of the closure. Consider adding error handling or validation logic within the closure to ensure the attributes are valid and to handle any potential errors gracefully. For example: Attributes: func() ([]event.Attribute, error) {
if err := validateAttributes(attrs); err != nil {
return nil, err
}
return attrs, nil
}, This way, the closure can serve as a centralized point to handle attribute-related errors and validations, making the code more robust and maintainable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can actually wrap all the logic in |
||
}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,11 @@ func IntoStreamingEvents(events []event.Event) []*Event { | |
strEvent := &Event{ | ||
Type: event.Type, | ||
} | ||
|
||
for _, eventValue := range event.Attributes { | ||
attrs, err := event.Attributes() | ||
if err != nil { | ||
panic(err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid panicking on errors. Return an error instead to allow graceful error handling. Panicking on an error is not an ideal error handling strategy as it can lead to unexpected program crashes. Instead of panicking, the function should return an error to allow the caller to handle the error gracefully. Consider applying this diff to improve the error handling: - attrs, err := event.Attributes()
- if err != nil {
- panic(err)
- }
+ attrs, err := event.Attributes()
+ if err != nil {
+ return nil, err
+ } Also, update the function signature to return an error: -func IntoStreamingEvents(events []event.Event) []*Event {
+func IntoStreamingEvents(events []event.Event) ([]*Event, error) {
|
||
for _, eventValue := range attrs { | ||
strEvent.Attributes = append(strEvent.Attributes, &EventAttribute{ | ||
Key: eventValue.Key, | ||
Value: eventValue.Value, | ||
|
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.
Fix the undefined type
schema.StateObjectType
.The static analysis tools indicate that
schema.StateObjectType
is undefined. This change would cause compilation errors.Please ensure that
schema.StateObjectType
is properly defined and imported before using it as the type for theobjectType
field.Tools
GitHub Check: tests (03)
GitHub Check: tests (02)
GitHub Check: tests (01)
GitHub Check: tests (00)
GitHub Check: dependency-review
GitHub Check: golangci-lint