Skip to content

Commit

Permalink
feat!: update PSS cli (#1708)
Browse files Browse the repository at this point in the history
finalize PSS CLI cmds
  • Loading branch information
sainoe authored Mar 26, 2024
1 parent b251141 commit 72f5f66
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
45 changes: 45 additions & 0 deletions x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,48 @@ func NewOptOutCmd() *cobra.Command {

return cmd
}

func NewSetConsumerCommissionRate() *cobra.Command {
cmd := &cobra.Command{
Use: "set-consumer-commission-rate [consumer-chain-id] [commission-rate]",
Short: "set a per-consumer chain commission",
Long: strings.TrimSpace(
fmt.Sprintf(`Note that the "commission-rate" argument is a fraction and should be in the range [0,1].
Example:
%s set-consumer-commission-rate consumer-1 0.5 --from node0 --home ../node0`,
version.AppName),
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags())
if err != nil {
return err
}
txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

providerValAddr := clientCtx.GetFromAddress()

commission, err := sdk.NewDecFromStr(args[1])
if err != nil {
return err
}
msg := types.NewMsgSetConsumerCommissionRate(args[0], commission, sdk.ValAddress(providerValAddr))
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}

flags.AddTxFlagsToCmd(cmd)

_ = cmd.MarkFlagRequired(flags.FlagFrom)

return cmd
}
10 changes: 8 additions & 2 deletions x/ccv/provider/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ func NewHandler(k *keeper.Keeper) sdk.Handler {
case *types.MsgSubmitConsumerMisbehaviour:
res, err := msgServer.SubmitConsumerMisbehaviour(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgSubmitConsumerDoubleVoting:
res, err := msgServer.SubmitConsumerDoubleVoting(sdk.WrapSDKContext(ctx), msg)
case *types.MsgOptIn:
res, err := msgServer.OptIn(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgOptOut:
res, err := msgServer.OptOut(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgSetConsumerCommissionRate:
res, err := msgServer.SetConsumerCommissionRate(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
Expand Down
9 changes: 9 additions & 0 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ func (msg MsgOptOut) ValidateBasic() error {
return nil
}

// NewMsgSetConsumerCommissionRate creates a new MsgSetConsumerCommissionRate msg instance.
func NewMsgSetConsumerCommissionRate(chainID string, commission sdk.Dec, providerValidatorAddress sdk.ValAddress) *MsgSetConsumerCommissionRate {
return &MsgSetConsumerCommissionRate{
ChainId: chainID,
Rate: commission,
ProviderAddr: providerValidatorAddress.String(),
}
}

// Type implements the sdk.Msg interface.
func (msg MsgOptOut) Type() string {
return TypeMsgOptOut
Expand Down

0 comments on commit 72f5f66

Please sign in to comment.