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

feat: add event core api to runtime #15547

Merged
merged 14 commits into from
Mar 30, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/groups) [#14879](https://github.com/cosmos/cosmos-sdk/pull/14879) Add `Query/Groups` query to get all the groups.
* (x/genutil,cli) [#15147](https://github.com/cosmos/cosmos-sdk/pull/15147) Add `--initial-height` flag to cli init cmd to provide `genesis.json` with user defined initial block height
* (x/gov) [#15151](https://github.com/cosmos/cosmos-sdk/pull/15151) Add `burn_vote_quorum`, `burn_proposal_deposit_prevote` and `burn_vote_veto` params to allow applications to decide if they would like to burn deposits
* (runtime) [#15547](https://github.com/cosmos/cosmos-sdk/pull/15547) Allow runtime to pass event core api service to modules

### Improvements

Expand Down
3 changes: 2 additions & 1 deletion client/v2/autocli/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func testExecCommon(t *testing.T, buildModuleCommand func(string, *Builder) (*co
Builder: flag.Builder{
GetClientConn: func() (grpc.ClientConnInterface, error) {
return conn, nil
}},
},
},
GetClientConn: func(*cobra.Command) (grpc.ClientConnInterface, error) {
return conn, nil
},
Expand Down
1 change: 0 additions & 1 deletion client/v2/autocli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func TestJSONParsing(t *testing.T) {
"-u", "27", // shorthand
)
assert.DeepEqual(t, conn.lastRequest, conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform())

}

func TestOptions(t *testing.T) {
Expand Down
59 changes: 59 additions & 0 deletions runtime/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package runtime
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"

"cosmossdk.io/core/event"
"google.golang.org/protobuf/runtime/protoiface"

sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ event.Service = (*EventService)(nil)

type EventService struct {
Events
}

func (es EventService) EventManager(ctx context.Context) event.Manager {
sdkCtx := sdk.UnwrapSDKContext(ctx)
return &Events{sdkCtx.EventManager()}
}

var _ event.Manager = (*Events)(nil)

type Events struct {
sdk.EventManagerI
}

func NewEventManager(ctx context.Context) event.Manager {
sdkCtx := sdk.UnwrapSDKContext(ctx)
return &Events{sdkCtx.EventManager()}
}

// Emit emits an typed event that is defined in the protobuf file.
// In the future these events will be added to consensus
func (e Events) Emit(ctx context.Context, event protoiface.MessageV1) error {
return e.EventManagerI.EmitTypedEvent(event)
}

// EmitKV emits a key value pair event
func (e Events) EmitKV(ctx context.Context, eventType string, attrs ...event.Attribute) error {
attributes := make([]sdk.Attribute, 0, len(attrs))

for _, attr := range attrs {
attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value))
}

events := sdk.Events{
sdk.NewEvent(eventType, attributes...),
}
e.EventManagerI.EmitEvents(events)
return nil
}

// Emit emits an typed event that is defined in the protobuf file.
// In the future these events will be added to consensus
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
func (e Events) EmitNonConsensus(ctx context.Context, event protoiface.MessageV1) error {
return e.EventManagerI.EmitTypedEvent(event)
}
7 changes: 7 additions & 0 deletions runtime/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package runtime

import (
"context"
"fmt"
"os"

Expand All @@ -13,6 +14,7 @@ import (
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
"cosmossdk.io/depinject"

storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -63,6 +65,7 @@ func init() {
ProvideKVStoreService,
ProvideMemoryStoreService,
ProvideTransientStoreService,
ProvideEventService,
),
appmodule.Invoke(SetupAppBuilder),
)
Expand Down Expand Up @@ -202,3 +205,7 @@ func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) stor
storeKey := ProvideTransientStoreKey(key, app)
return transientStoreService{key: storeKey}
}

func ProvideEventService(ctx context.Context, app *AppBuilder) event.Service {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
return EventService{}
}
1 change: 0 additions & 1 deletion x/feegrant/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func NewMsgRevokeAllowance(granter sdk.AccAddress, grantee sdk.AccAddress) MsgRe

// ValidateBasic implements the sdk.Msg interface.
func (msg MsgRevokeAllowance) ValidateBasic() error {

return nil
}

Expand Down