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

     1  package cli
     2  
     3  import (
     4  	"io/ioutil"
     5  
     6  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
     7  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  )
     9  
    10  type (
    11  	// ChangeDistributionTypeProposalJSON defines a ChangeDistributionTypeProposal with a deposit
    12  	ChangeDistributionTypeProposalJSON struct {
    13  		Title       string       `json:"title" yaml:"title"`
    14  		Description string       `json:"description" yaml:"description"`
    15  		Type        uint32       `json:"type" yaml:"type"`
    16  		Deposit     sdk.SysCoins `json:"deposit" yaml:"deposit"`
    17  	}
    18  
    19  	// WithdrawRewardEnabledProposalJSON defines a WithdrawRewardEnabledProposal with a deposit
    20  	WithdrawRewardEnabledProposalJSON struct {
    21  		Title       string       `json:"title" yaml:"title"`
    22  		Description string       `json:"description" yaml:"description"`
    23  		Enabled     bool         `json:"enabled" yaml:"enabled"`
    24  		Deposit     sdk.SysCoins `json:"deposit" yaml:"deposit"`
    25  	}
    26  
    27  	// RewardTruncatePrecisonProposalJSON defines a RewardTruncatePrecisionProposal with a deposit
    28  	RewardTruncatePrecisonProposalJSON struct {
    29  		Title       string       `json:"title" yaml:"title"`
    30  		Description string       `json:"description" yaml:"description"`
    31  		Deposit     sdk.SysCoins `json:"deposit" yaml:"deposit"`
    32  		Precision   int64        `json:"precision" yaml:"precision"`
    33  	}
    34  )
    35  
    36  // ParseChangeDistributionTypeProposalJSON reads and parses a ChangeDistributionTypeProposalJSON from a file.
    37  func ParseChangeDistributionTypeProposalJSON(cdc *codec.Codec, proposalFile string) (ChangeDistributionTypeProposalJSON, error) {
    38  	proposal := ChangeDistributionTypeProposalJSON{}
    39  
    40  	contents, err := ioutil.ReadFile(proposalFile)
    41  	if err != nil {
    42  		return proposal, err
    43  	}
    44  
    45  	if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
    46  		return proposal, err
    47  	}
    48  
    49  	return proposal, nil
    50  }
    51  
    52  // ParseWithdrawRewardEnabledProposalJSON reads and parses a WithdrawRewardEnabledProposalJSON from a file.
    53  func ParseWithdrawRewardEnabledProposalJSON(cdc *codec.Codec, proposalFile string) (WithdrawRewardEnabledProposalJSON, error) {
    54  	proposal := WithdrawRewardEnabledProposalJSON{}
    55  
    56  	contents, err := ioutil.ReadFile(proposalFile)
    57  	if err != nil {
    58  		return proposal, err
    59  	}
    60  
    61  	if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
    62  		return proposal, err
    63  	}
    64  
    65  	return proposal, nil
    66  }
    67  
    68  // ParseRewardTruncatePrecisionProposalJSON reads and parses a RewardTruncatePrecisonProposalJSON from a file.
    69  func ParseRewardTruncatePrecisionProposalJSON(cdc *codec.Codec, proposalFile string) (RewardTruncatePrecisonProposalJSON, error) {
    70  	proposal := RewardTruncatePrecisonProposalJSON{}
    71  
    72  	contents, err := ioutil.ReadFile(proposalFile)
    73  	if err != nil {
    74  		return proposal, err
    75  	}
    76  
    77  	if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
    78  		return proposal, err
    79  	}
    80  
    81  	return proposal, nil
    82  }