github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/client/cli/tx_distr_proposal.go (about)

     1  // nolint
     2  package cli
     3  
     4  import (
     5  	"bufio"
     6  	"fmt"
     7  	"strings"
     8  
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    11  	interfacetypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec/types"
    12  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    13  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/version"
    14  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth"
    15  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/utils"
    16  	"github.com/fibonacci-chain/fbc/x/distribution/types"
    17  	"github.com/fibonacci-chain/fbc/x/gov"
    18  	"github.com/spf13/cobra"
    19  )
    20  
    21  var (
    22  	flagCommission = "commission"
    23  )
    24  
    25  // GetCmdWithdrawAllRewards command to withdraw all rewards
    26  func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Command {
    27  	cmd := &cobra.Command{
    28  		Use:   "withdraw-all-rewards",
    29  		Short: "withdraw all delegations rewards for a delegator",
    30  		Long: strings.TrimSpace(
    31  			fmt.Sprintf(`Withdraw all rewards for a single delegator.
    32  
    33  Example:
    34  $ %s tx distr withdraw-all-rewards --from mykey
    35  `,
    36  				version.ClientName,
    37  			),
    38  		),
    39  		Args: cobra.NoArgs,
    40  		RunE: func(cmd *cobra.Command, args []string) error {
    41  			inBuf := bufio.NewReader(cmd.InOrStdin())
    42  			txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
    43  			cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)
    44  
    45  			delAddr := cliCtx.GetFromAddress()
    46  			msg := types.NewMsgWithdrawDelegatorAllRewards(delAddr)
    47  			return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
    48  		},
    49  	}
    50  
    51  	return cmd
    52  }
    53  
    54  // GetChangeDistributionTypeProposal implements the command to submit a change-distr-type proposal
    55  func GetChangeDistributionTypeProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    56  	cmd := &cobra.Command{
    57  		Use:   "change-distr-type [proposal-file]",
    58  		Args:  cobra.ExactArgs(1),
    59  		Short: "Submit a change distribution type proposal",
    60  		Long: strings.TrimSpace(
    61  			fmt.Sprintf(`Submit a change distribution type proposal with the specified value, 0: offchain model, 1:onchain model
    62  
    63  Example:
    64  $ %s tx gov submit-proposal change-distr-type <path/to/proposal.json> --from=<key_or_address>
    65  
    66  Where proposal.json contains:
    67  
    68  {
    69    "title": "Change Distribution Type",
    70    "description": "Will change the distribution type",
    71    "type": 0,
    72    "deposit": [
    73      {
    74        "denom": "%s",
    75        "amount": "100.000000000000000000"
    76      }
    77    ]
    78  }
    79  `,
    80  				version.ClientName, sdk.DefaultBondDenom,
    81  			),
    82  		),
    83  		RunE: func(cmd *cobra.Command, args []string) error {
    84  			cdc := cdcP.GetCdc()
    85  			inBuf := bufio.NewReader(cmd.InOrStdin())
    86  			txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
    87  			cliCtx := context.NewCLIContext().WithCodec(cdc)
    88  
    89  			proposal, err := ParseChangeDistributionTypeProposalJSON(cdc, args[0])
    90  			if err != nil {
    91  				return err
    92  			}
    93  
    94  			from := cliCtx.GetFromAddress()
    95  			content := types.NewChangeDistributionTypeProposal(proposal.Title, proposal.Description, proposal.Type)
    96  
    97  			msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from)
    98  
    99  			return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
   100  		},
   101  	}
   102  
   103  	return cmd
   104  }
   105  
   106  // GetWithdrawRewardEnabledProposal implements the command to submit a withdraw-reward-enabled proposal
   107  func GetWithdrawRewardEnabledProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
   108  	cmd := &cobra.Command{
   109  		Use:   "withdraw-reward-enabled [proposal-file]",
   110  		Args:  cobra.ExactArgs(1),
   111  		Short: "Submit a withdraw reward enabled or disabled proposal",
   112  		Long: strings.TrimSpace(
   113  			fmt.Sprintf(`Submit a withdraw reward enabled or disabled proposal with the specified value, true: enabled, false: disabled
   114  
   115  Example:
   116  $ %s tx gov submit-proposal withdraw-reward-enabled <path/to/proposal.json> --from=<key_or_address>
   117  
   118  Where proposal.json contains:
   119  
   120  {
   121    "title": "Withdraw Reward Enabled | Disabled",
   122    "description": "Will set withdraw reward enabled | disabled",
   123    "enabled": false,
   124    "deposit": [
   125      {
   126        "denom": "%s",
   127        "amount": "100.000000000000000000"
   128      }
   129    ]
   130  }
   131  `,
   132  				version.ClientName, sdk.DefaultBondDenom,
   133  			),
   134  		),
   135  		RunE: func(cmd *cobra.Command, args []string) error {
   136  			cdc := cdcP.GetCdc()
   137  			inBuf := bufio.NewReader(cmd.InOrStdin())
   138  			txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
   139  			cliCtx := context.NewCLIContext().WithCodec(cdc)
   140  
   141  			proposal, err := ParseWithdrawRewardEnabledProposalJSON(cdc, args[0])
   142  			if err != nil {
   143  				return err
   144  			}
   145  
   146  			from := cliCtx.GetFromAddress()
   147  			content := types.NewWithdrawRewardEnabledProposal(proposal.Title, proposal.Description, proposal.Enabled)
   148  
   149  			msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from)
   150  
   151  			return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
   152  		},
   153  	}
   154  
   155  	return cmd
   156  }
   157  
   158  // GetRewardTruncatePrecisionProposal implements the command to submit a reward-truncate-precision proposal
   159  func GetRewardTruncatePrecisionProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
   160  	cmd := &cobra.Command{
   161  		Use:   "reward-truncate-precision [proposal-file]",
   162  		Args:  cobra.ExactArgs(1),
   163  		Short: "Submit a reward truncated precision proposal",
   164  		Long: strings.TrimSpace(
   165  			fmt.Sprintf(`Submit a reward truncated precision proposal with the specified value,
   166  
   167  Example:
   168  $ %s tx gov submit-proposal reward-truncate-precision <path/to/proposal.json> --from=<key_or_address>
   169  
   170  Where proposal.json contains:
   171  
   172  {
   173  	"title": "Set reward truncated precision",
   174  	"description": "Set distribution reward truncated precision",
   175  	"deposit": [{
   176  		"denom": "%s",
   177  		"amount": "100.000000000000000000"
   178  	}],
   179  	"precision": "0"
   180  }
   181  `,
   182  				version.ClientName, sdk.DefaultBondDenom,
   183  			),
   184  		),
   185  		RunE: func(cmd *cobra.Command, args []string) error {
   186  			cdc := cdcP.GetCdc()
   187  			inBuf := bufio.NewReader(cmd.InOrStdin())
   188  			txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
   189  			cliCtx := context.NewCLIContext().WithCodec(cdc)
   190  
   191  			proposal, err := ParseRewardTruncatePrecisionProposalJSON(cdc, args[0])
   192  			if err != nil {
   193  				return err
   194  			}
   195  
   196  			from := cliCtx.GetFromAddress()
   197  			content := types.NewRewardTruncatePrecisionProposal(proposal.Title, proposal.Description, proposal.Precision)
   198  
   199  			msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from)
   200  
   201  			return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
   202  		},
   203  	}
   204  
   205  	return cmd
   206  }