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!: update PSS cli #1708

Merged
merged 1 commit into from
Mar 26, 2024
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
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 @@ -289,3 +289,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
Loading