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(profile): events #742

Merged
merged 8 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
25 changes: 25 additions & 0 deletions proto/profile/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package tendermint.spn.profile;

import "gogoproto/gogo.proto";
import "profile/coordinator.proto";
import "profile/validator.proto";


option go_package = "github.com/tendermint/spn/x/profile/types";

message EventCoordinatorCreated {
giunatale marked this conversation as resolved.
Show resolved Hide resolved
Coordinator coordinator = 1 [(gogoproto.nullable) = false];
}

message EventCoordinatorUpdated {
Coordinator coordinator = 1 [(gogoproto.nullable) = false];
}

message EventValidatorCreated {
Validator validator = 1 [(gogoproto.nullable) = false];
}

message EventValidatorUpdated {
Validator validator = 1 [(gogoproto.nullable) = false];
}
18 changes: 15 additions & 3 deletions x/profile/keeper/msg_add_validator_operator_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ func (k msgServer) AddValidatorOperatorAddress(
Description: types.ValidatorDescription{},
}

// get the current validator to eventually overwrite description and remove existing operator address
if validatorStore, found := k.GetValidator(ctx, valAddr); found {
// get the current validator to eventually overwrite description and add opAddr
validatorStore, valFound := k.GetValidator(ctx, valAddr)
if valFound {
validator.Description = validatorStore.Description
validator = validatorStore.AddValidatorOperatorAddress(opAddr)
}
Expand All @@ -35,5 +36,16 @@ func (k msgServer) AddValidatorOperatorAddress(
ValidatorAddress: valAddr,
})

return &types.MsgAddValidatorOperatorAddressResponse{}, nil
var err error
if valFound {
err = ctx.EventManager().EmitTypedEvent(
&types.EventValidatorUpdated{
Validator: validator})
} else {
err = ctx.EventManager().EmitTypedEvent(
&types.EventValidatorCreated{
Validator: validator})
}

return &types.MsgAddValidatorOperatorAddressResponse{}, err
}
11 changes: 8 additions & 3 deletions x/profile/keeper/msg_create_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func (k msgServer) CreateCoordinator(
ctx := sdk.UnwrapSDKContext(goCtx)

// Check if the coordinator address is already in the store
coord, found := k.getCoordinatorByAddress(ctx, msg.Address)
coordByAddr, found := k.getCoordinatorByAddress(ctx, msg.Address)
if found {
return &types.MsgCreateCoordinatorResponse{},
sdkerrors.Wrap(types.ErrCoordAlreadyExist,
fmt.Sprintf("coordinatorId: %d", coord.CoordinatorID))
fmt.Sprintf("coordinatorId: %d", coordByAddr.CoordinatorID))
}

coordID := k.AppendCoordinator(ctx, types.Coordinator{
Expand All @@ -34,7 +34,12 @@ func (k msgServer) CreateCoordinator(
CoordinatorID: coordID,
})

coord, _ := k.GetCoordinator(ctx, coordID)
err := ctx.EventManager().EmitTypedEvent(
&types.EventCoordinatorCreated{
Coordinator: coord})

return &types.MsgCreateCoordinatorResponse{
CoordinatorID: coordID,
}, nil
}, err
}
5 changes: 4 additions & 1 deletion x/profile/keeper/msg_disable_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ func (k msgServer) DisableCoordinator(
coord.Active = false
k.SetCoordinator(ctx, coord)
k.RemoveCoordinatorByAddress(ctx, msg.Address)
err := ctx.EventManager().EmitTypedEvent(
&types.EventCoordinatorUpdated{
Coordinator: coord})

return &types.MsgDisableCoordinatorResponse{
CoordinatorID: coord.CoordinatorID,
}, nil
}, err
}
5 changes: 4 additions & 1 deletion x/profile/keeper/msg_update_coordinator_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (k msgServer) UpdateCoordinatorAddress(
CoordinatorID: coord.CoordinatorID,
})
k.SetCoordinator(ctx, coord)
err := ctx.EventManager().EmitTypedEvent(
&types.EventCoordinatorUpdated{
Coordinator: coord})

return &types.MsgUpdateCoordinatorAddressResponse{}, nil
return &types.MsgUpdateCoordinatorAddressResponse{}, err
}
6 changes: 5 additions & 1 deletion x/profile/keeper/msg_update_coordinator_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ func (k msgServer) UpdateCoordinatorDescription(
}

k.SetCoordinator(ctx, coord)
return &types.MsgUpdateCoordinatorDescriptionResponse{}, nil
err := ctx.EventManager().EmitTypedEvent(
&types.EventCoordinatorUpdated{
Coordinator: coord})

return &types.MsgUpdateCoordinatorDescriptionResponse{}, err
}
16 changes: 13 additions & 3 deletions x/profile/keeper/msg_update_validator_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func (k msgServer) UpdateValidatorDescription(
ctx := sdk.UnwrapSDKContext(goCtx)

// Check if the validator address is already in the store
validator, found := k.GetValidator(ctx, msg.Address)
if !found {
validator, valfound := k.GetValidator(ctx, msg.Address)
if !valfound {
validator = types.Validator{
Address: msg.Address,
Description: types.ValidatorDescription{},
Expand All @@ -40,6 +40,16 @@ func (k msgServer) UpdateValidatorDescription(
}

k.SetValidator(ctx, validator)
var err error
if valfound {
err = ctx.EventManager().EmitTypedEvent(
&types.EventValidatorUpdated{
Validator: validator})
} else {
err = ctx.EventManager().EmitTypedEvent(
&types.EventValidatorCreated{
Validator: validator})
}

return &types.MsgUpdateValidatorDescriptionResponse{}, nil
return &types.MsgUpdateValidatorDescriptionResponse{}, err
}
Loading