github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/types/proposal.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "strings" 6 7 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 9 govtypes "github.com/fibonacci-chain/fbc/x/gov/types" 10 ) 11 12 const ( 13 // ProposalTypeCommunityPoolSpend defines the type for a CommunityPoolSpendProposal 14 ProposalTypeCommunityPoolSpend = "CommunityPoolSpend" 15 ) 16 17 // Assert CommunityPoolSpendProposal implements govtypes.Content at compile-time 18 var _ govtypes.Content = CommunityPoolSpendProposal{} 19 20 func init() { 21 govtypes.RegisterProposalType(ProposalTypeCommunityPoolSpend) 22 govtypes.RegisterProposalType(ProposalTypeChangeDistributionType) 23 govtypes.RegisterProposalType(ProposalTypeWithdrawRewardEnabled) 24 govtypes.RegisterProposalType(ProposalTypeRewardTruncatePrecision) 25 govtypes.RegisterProposalTypeCodec(CommunityPoolSpendProposal{}, "fbexchain/distribution/CommunityPoolSpendProposal") 26 govtypes.RegisterProposalTypeCodec(ChangeDistributionTypeProposal{}, "fbexchain/distribution/ChangeDistributionTypeProposal") 27 govtypes.RegisterProposalTypeCodec(WithdrawRewardEnabledProposal{}, "fbexchain/distribution/WithdrawRewardEnabledProposal") 28 govtypes.RegisterProposalTypeCodec(RewardTruncatePrecisionProposal{}, "fbexchain/distribution/RewardTruncatePrecisionProposal") 29 } 30 31 // CommunityPoolSpendProposal spends from the community pool 32 type CommunityPoolSpendProposal struct { 33 Title string `json:"title" yaml:"title"` 34 Description string `json:"description" yaml:"description"` 35 Recipient sdk.AccAddress `json:"recipient" yaml:"recipient"` 36 Amount sdk.SysCoins `json:"amount" yaml:"amount"` 37 } 38 39 // NewCommunityPoolSpendProposal creates a new community pool spned proposal. 40 func NewCommunityPoolSpendProposal(title, description string, recipient sdk.AccAddress, amount sdk.SysCoins) CommunityPoolSpendProposal { 41 return CommunityPoolSpendProposal{title, description, recipient, amount} 42 } 43 44 // GetTitle returns the title of a community pool spend proposal. 45 func (csp CommunityPoolSpendProposal) GetTitle() string { return csp.Title } 46 47 // GetDescription returns the description of a community pool spend proposal. 48 func (csp CommunityPoolSpendProposal) GetDescription() string { return csp.Description } 49 50 // GetDescription returns the routing key of a community pool spend proposal. 51 func (csp CommunityPoolSpendProposal) ProposalRoute() string { return RouterKey } 52 53 // ProposalType returns the type of a community pool spend proposal. 54 func (csp CommunityPoolSpendProposal) ProposalType() string { return ProposalTypeCommunityPoolSpend } 55 56 // ValidateBasic runs basic stateless validity checks 57 func (csp CommunityPoolSpendProposal) ValidateBasic() error { 58 err := govtypes.ValidateAbstract(ModuleName, csp) 59 if err != nil { 60 return err 61 } 62 if !csp.Amount.IsValid() { 63 return ErrInvalidProposalAmount() 64 } 65 if csp.Recipient.Empty() { 66 return ErrEmptyProposalRecipient() 67 } 68 return nil 69 } 70 71 // String implements the Stringer interface. 72 func (csp CommunityPoolSpendProposal) String() string { 73 var b strings.Builder 74 b.WriteString(fmt.Sprintf(`Community Pool Spend Proposal: 75 Title: %s 76 Description: %s 77 Recipient: %s 78 Amount: %s 79 `, csp.Title, csp.Description, csp.Recipient, csp.Amount)) 80 return b.String() 81 }