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

typed BondProvider event #158

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions proto/arkeo/arkeo/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";

package arkeo.arkeo;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/arkeonetwork/arkeo/x/arkeo/types";

message EventBondProvider {
string creator = 1;
string provider = 2 [ (gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ];
string service = 3;
string bond = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
11 changes: 7 additions & 4 deletions x/arkeo/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k msgServer) BondProviderEvent(ctx cosmos.Context, bond cosmos.Int, msg *types.MsgBondProvider) {
ctx.EventManager().EmitEvents(
sdk.Events{
types.NewBondProviderEvent(bond, msg),
func (k msgServer) EmitBondProviderEvent(ctx cosmos.Context, bond cosmos.Int, msg *types.MsgBondProvider) error {
return ctx.EventManager().EmitTypedEvent(
&types.EventBondProvider{
Provider: msg.Provider,
Creator: msg.Creator,
Service: msg.Service,
Bond: msg.Bond,
},
)
}
Expand Down
5 changes: 2 additions & 3 deletions x/arkeo/keeper/msg_server_bond_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ func (k msgServer) BondProviderHandle(ctx cosmos.Context, msg *types.MsgBondProv
provider.Bond = provider.Bond.Add(msg.Bond)
if provider.Bond.IsZero() {
k.RemoveProvider(ctx, provider.PubKey, provider.Service)
k.BondProviderEvent(ctx, provider.Bond, msg)
return nil
return k.EmitBondProviderEvent(ctx, provider.Bond, msg)
}

provider.LastUpdate = ctx.BlockHeight()

err = k.SetProvider(ctx, provider)
if err == nil {
k.BondProviderEvent(ctx, provider.Bond, msg)
return k.EmitBondProviderEvent(ctx, provider.Bond, msg)
}
return err
}