From 197954c5be35b536952f721b32d8d1951fe46b55 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 24 Mar 2023 15:12:18 -0700 Subject: [PATCH 1/4] typed BondProvider event --- proto/arkeo/arkeo/events.proto | 19 +++++++++++++++++++ x/arkeo/keeper/events.go | 16 +++++++++++----- x/arkeo/keeper/msg_server_bond_provider.go | 4 ++-- 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 proto/arkeo/arkeo/events.proto diff --git a/proto/arkeo/arkeo/events.proto b/proto/arkeo/arkeo/events.proto new file mode 100644 index 00000000..999f6dba --- /dev/null +++ b/proto/arkeo/arkeo/events.proto @@ -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/events"; + +message EventBondProvider { + string creator = 1; + string provider = 2 [ (gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ]; + string service = 3; + int64 bond = 4 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/x/arkeo/keeper/events.go b/x/arkeo/keeper/events.go index 16b8d684..a81f83f5 100644 --- a/x/arkeo/keeper/events.go +++ b/x/arkeo/keeper/events.go @@ -2,17 +2,23 @@ package keeper import ( "github.com/arkeonetwork/arkeo/common/cosmos" + "github.com/arkeonetwork/arkeo/x/arkeo/events" "github.com/arkeonetwork/arkeo/x/arkeo/types" 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) { + if err := ctx.EventManager().EmitTypedEvent( + &events.EventBondProvider{ + Provider: msg.Provider, + Creator: msg.Creator, + Service: msg.Service, + Bond: msg.Bond, }, - ) + ); err != nil { + panic(err) + } } func (k msgServer) CloseContractEvent(ctx cosmos.Context, contract *types.Contract) { diff --git a/x/arkeo/keeper/msg_server_bond_provider.go b/x/arkeo/keeper/msg_server_bond_provider.go index 06f5e307..eaee6aa8 100644 --- a/x/arkeo/keeper/msg_server_bond_provider.go +++ b/x/arkeo/keeper/msg_server_bond_provider.go @@ -89,7 +89,7 @@ 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) + k.EmitBondProviderEvent(ctx, provider.Bond, msg) return nil } @@ -97,7 +97,7 @@ func (k msgServer) BondProviderHandle(ctx cosmos.Context, msg *types.MsgBondProv err = k.SetProvider(ctx, provider) if err == nil { - k.BondProviderEvent(ctx, provider.Bond, msg) + k.EmitBondProviderEvent(ctx, provider.Bond, msg) } return err } From e5bb7282ef7aa0fe15847a0bce0f5a49d65e1eb5 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 24 Mar 2023 15:31:13 -0700 Subject: [PATCH 2/4] fix event bond proto def --- proto/arkeo/arkeo/events.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/arkeo/arkeo/events.proto b/proto/arkeo/arkeo/events.proto index 999f6dba..5a17e72a 100644 --- a/proto/arkeo/arkeo/events.proto +++ b/proto/arkeo/arkeo/events.proto @@ -11,9 +11,9 @@ message EventBondProvider { string creator = 1; string provider = 2 [ (gogoproto.casttype) = "github.com/arkeonetwork/arkeo/common.PubKey" ]; string service = 3; - int64 bond = 4 [ + string bond = 4 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; -} \ No newline at end of file +} From 00513eca5f27b055f0b8cccb01cc041fa8f0c883 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 24 Mar 2023 15:32:52 -0700 Subject: [PATCH 3/4] EmitBondProviderEvent return error --- x/arkeo/keeper/events.go | 8 +++----- x/arkeo/keeper/msg_server_bond_provider.go | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/x/arkeo/keeper/events.go b/x/arkeo/keeper/events.go index a81f83f5..0145e8e6 100644 --- a/x/arkeo/keeper/events.go +++ b/x/arkeo/keeper/events.go @@ -8,17 +8,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -func (k msgServer) EmitBondProviderEvent(ctx cosmos.Context, bond cosmos.Int, msg *types.MsgBondProvider) { - if err := ctx.EventManager().EmitTypedEvent( +func (k msgServer) EmitBondProviderEvent(ctx cosmos.Context, bond cosmos.Int, msg *types.MsgBondProvider) error { + return ctx.EventManager().EmitTypedEvent( &events.EventBondProvider{ Provider: msg.Provider, Creator: msg.Creator, Service: msg.Service, Bond: msg.Bond, }, - ); err != nil { - panic(err) - } + ) } func (k msgServer) CloseContractEvent(ctx cosmos.Context, contract *types.Contract) { diff --git a/x/arkeo/keeper/msg_server_bond_provider.go b/x/arkeo/keeper/msg_server_bond_provider.go index eaee6aa8..6f5da9e1 100644 --- a/x/arkeo/keeper/msg_server_bond_provider.go +++ b/x/arkeo/keeper/msg_server_bond_provider.go @@ -97,7 +97,7 @@ func (k msgServer) BondProviderHandle(ctx cosmos.Context, msg *types.MsgBondProv err = k.SetProvider(ctx, provider) if err == nil { - k.EmitBondProviderEvent(ctx, provider.Bond, msg) + return k.EmitBondProviderEvent(ctx, provider.Bond, msg) } return err } From f86d3f9893527ff1b8da7570f9eea52aac01171a Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 24 Mar 2023 15:50:57 -0700 Subject: [PATCH 4/4] BondProvider event typed --- proto/arkeo/arkeo/events.proto | 2 +- x/arkeo/keeper/events.go | 3 +-- x/arkeo/keeper/msg_server_bond_provider.go | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/proto/arkeo/arkeo/events.proto b/proto/arkeo/arkeo/events.proto index 5a17e72a..055fe6eb 100644 --- a/proto/arkeo/arkeo/events.proto +++ b/proto/arkeo/arkeo/events.proto @@ -5,7 +5,7 @@ package arkeo.arkeo; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; -option go_package = "github.com/arkeonetwork/arkeo/x/arkeo/events"; +option go_package = "github.com/arkeonetwork/arkeo/x/arkeo/types"; message EventBondProvider { string creator = 1; diff --git a/x/arkeo/keeper/events.go b/x/arkeo/keeper/events.go index 0145e8e6..fab0012e 100644 --- a/x/arkeo/keeper/events.go +++ b/x/arkeo/keeper/events.go @@ -2,7 +2,6 @@ package keeper import ( "github.com/arkeonetwork/arkeo/common/cosmos" - "github.com/arkeonetwork/arkeo/x/arkeo/events" "github.com/arkeonetwork/arkeo/x/arkeo/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -10,7 +9,7 @@ import ( func (k msgServer) EmitBondProviderEvent(ctx cosmos.Context, bond cosmos.Int, msg *types.MsgBondProvider) error { return ctx.EventManager().EmitTypedEvent( - &events.EventBondProvider{ + &types.EventBondProvider{ Provider: msg.Provider, Creator: msg.Creator, Service: msg.Service, diff --git a/x/arkeo/keeper/msg_server_bond_provider.go b/x/arkeo/keeper/msg_server_bond_provider.go index 6f5da9e1..6c8e7261 100644 --- a/x/arkeo/keeper/msg_server_bond_provider.go +++ b/x/arkeo/keeper/msg_server_bond_provider.go @@ -89,8 +89,7 @@ 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.EmitBondProviderEvent(ctx, provider.Bond, msg) - return nil + return k.EmitBondProviderEvent(ctx, provider.Bond, msg) } provider.LastUpdate = ctx.BlockHeight()