Skip to content

Commit

Permalink
Added message handlers for new proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Nov 7, 2023
1 parent 4b04069 commit 275ae80
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
25 changes: 17 additions & 8 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ func (k msgServer) ConsumerAddition(goCtx context.Context, msg *types.MsgConsume
return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer)
}

// TODO: Call keeper implementation !

ctx := sdk.UnwrapSDKContext(goCtx)
err := k.Keeper.HandleNewConsumerAdditionProposal(ctx, msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed handling ConsumerAddition proposal")
}
return &types.MsgConsumerAdditionResponse{}, nil
}

Expand All @@ -130,20 +133,26 @@ func (k msgServer) ConsumerRemoval(
return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer)
}

// TODO: Call keeper implementation !
ctx := sdk.UnwrapSDKContext(goCtx)
err := k.Keeper.HandleNewConsumerRemovalProposal(ctx, msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed handling ConsumerAddition proposal")
}

return &types.MsgConsumerRemovalResponse{}, nil
}

// ConsumerRemoval defines a rpc handler method for MsgConsumerRemoval
func (k msgServer) ChangeRewardDenoms(
goCtx context.Context,
msg *types.MsgChangeRewardDenoms) (*types.MsgChangeRewardDenomsResponse, error) {
// ChangeRewardDenoms defines a rpc handler method for MsgChangeRewardDenoms
func (k msgServer) ChangeRewardDenoms(goCtx context.Context, msg *types.MsgChangeRewardDenoms) (*types.MsgChangeRewardDenomsResponse, error) {
if k.GetAuthority() != msg.Signer {
return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer)
}

// TODO: Call keeper implementation !
sdkCtx := sdk.UnwrapSDKContext(goCtx)
err := k.Keeper.HandleNewConsumerRewardDenomProposal(sdkCtx, msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed handling Change Reward Denoms proposal")
}

return &types.MsgChangeRewardDenomsResponse{}, nil
}
44 changes: 44 additions & 0 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@ import (
ccv "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

// Wrapper for the new proposal messages MsgConsumerAddition.
// Will replace legacy handler HandleConsumerAdditionProposal
func (k Keeper) HandleNewConsumerAdditionProposal(ctx sdk.Context, proposal *types.MsgConsumerAddition) error {
p := types.ConsumerAdditionProposal{
Title: "New ConsumerAddition Proposal",
ChainId: proposal.ChainId,
InitialHeight: proposal.InitialHeight,
GenesisHash: proposal.GenesisHash,
BinaryHash: proposal.BinaryHash,
SpawnTime: proposal.SpawnTime,
UnbondingPeriod: proposal.UnbondingPeriod,
CcvTimeoutPeriod: proposal.CcvTimeoutPeriod,
TransferTimeoutPeriod: proposal.TransferTimeoutPeriod,
ConsumerRedistributionFraction: proposal.ConsumerRedistributionFraction,
BlocksPerDistributionTransmission: proposal.BlocksPerDistributionTransmission,
HistoricalEntries: proposal.HistoricalEntries,
DistributionTransmissionChannel: proposal.DistributionTransmissionChannel,
}
return k.HandleConsumerAdditionProposal(ctx, &p)

}

// Wrapper for the new proposal messages MsgConsumerRemoval.
// Will replace legacy handler HandleConsumerRemovalProposal
func (k Keeper) HandleNewConsumerRemovalProposal(ctx sdk.Context, proposal *types.MsgConsumerRemoval) error {
p := types.ConsumerRemovalProposal{
ChainId: proposal.ChainId,
StopTime: proposal.StopTime,
}
return k.HandleConsumerRemovalProposal(ctx, &p)

}

// Wrapper for the new proposal messages MsgChangeRewardDenoms.
// Will replace legacy handler HandleConsumerRewardDenomProposal
func (k Keeper) HandleNewConsumerRewardDenomProposal(ctx sdk.Context, proposal *types.MsgChangeRewardDenoms) error {
p := types.ChangeRewardDenomsProposal{
Title: "New ChangeRewardDenomsProposal",
DenomsToAdd: proposal.DenomsToAdd,
DenomsToRemove: proposal.DenomsToRemove,
}
return k.HandleConsumerRewardDenomProposal(ctx, &p)
}

// HandleConsumerAdditionProposal will receive the consumer chain's client state from the proposal.
// If the client can be successfully created in a cached context, it stores the proposal as a pending proposal.
//
Expand Down

0 comments on commit 275ae80

Please sign in to comment.