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

init: Implement ADR 032 typed events #7564

Merged
merged 20 commits into from
Oct 28, 2020
Merged

Conversation

akhilkumarpilli
Copy link
Contributor

Description

Implement EmitTypedEvent, EmitTypedEvents and ParseTypedEvent functions.

ref: #7563


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Oct 15, 2020

Codecov Report

Merging #7564 into master will increase coverage by 0.01%.
The diff coverage is 63.26%.

@@            Coverage Diff             @@
##           master    #7564      +/-   ##
==========================================
+ Coverage   54.11%   54.12%   +0.01%     
==========================================
  Files         611      611              
  Lines       38571    38620      +49     
==========================================
+ Hits        20871    20902      +31     
- Misses      15573    15582       +9     
- Partials     2127     2136       +9     

@anilcse anilcse changed the title Implement ADR 032 typed event functions Implement ADR 032 typed events base Oct 16, 2020
@anilcse anilcse changed the title Implement ADR 032 typed events base Implement ADR 032 typed events init Oct 16, 2020
@anilcse anilcse changed the title Implement ADR 032 typed events init init: Implement ADR 032 typed events Oct 16, 2020
@akhilkumarpilli akhilkumarpilli marked this pull request as ready for review October 16, 2020 14:08
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me overall, would like to see an Any test.

types/events_test.go Outdated Show resolved Hide resolved
types/events.go Show resolved Hide resolved
coin2 := sdk.NewCoin("fakedenom2", sdk.NewInt(1999999))

s.Require().NoError(em.EmitTypedEvents(&coin1))
s.Require().NoError(em.EmitTypedEvent(&coin2))
Copy link
Contributor

@amaury1093 amaury1093 Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't cross my mind while reading the ADR, but does now. It seems weird that we can send an event that is a Coin.

Maybe we should create some convention, like the type name should be Event... or Msg...Response? (can be for another PR of course)

// TypedEventToEvent takes typed event and converts to Event object
func TypedEventToEvent(tev proto.Message) (Event, error) {
evtType := proto.MessageName(tev)
evtJSON, err := codec.ProtoMarshalJSON(tev, nil)
Copy link
Contributor

@amaury1093 amaury1093 Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the nil argument won't work if tev contains an Any... or maybe it will. Just to be sure, would you mind adding a test with Any in TestEventManagerTypedEvents?

Copy link
Member

@jackzampolin jackzampolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, great work @akhilkumarpilli

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK, nice!

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Oct 28, 2020
@mergify mergify bot merged commit c3638ad into cosmos:master Oct 28, 2020
clevinson pushed a commit that referenced this pull request Oct 29, 2020
* Add EmitTypedEvent in events

* Add parseTypedEvent method

* Use jsonpb

* Modify unmarshal proto in events

* Add a test for typed events

* Fix reflect  issue in parseTypedEvent

* Modify event tests and add comments

* Add EmitTypedEvents and refactor other methods

* Fix golangci-lint issues

* Update ProtoMarshalJSON params

* Address PR comments

Co-authored-by: anilCSE <anil@vitwit.com>
Co-authored-by: Jack Zampolin <jack.zampolin@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants