github.com/Finschia/finschia-sdk@v0.48.1/x/distribution/types/proposal.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "strings" 6 7 sdk "github.com/Finschia/finschia-sdk/types" 8 govtypes "github.com/Finschia/finschia-sdk/x/gov/types" 9 ) 10 11 const ( 12 // ProposalTypeCommunityPoolSpend defines the type for a CommunityPoolSpendProposal 13 ProposalTypeCommunityPoolSpend = "CommunityPoolSpend" 14 ) 15 16 // Assert CommunityPoolSpendProposal implements govtypes.Content at compile-time 17 var _ govtypes.Content = &CommunityPoolSpendProposal{} 18 19 func init() { 20 govtypes.RegisterProposalType(ProposalTypeCommunityPoolSpend) 21 } 22 23 // NewCommunityPoolSpendProposal creates a new community pool spned proposal. 24 // 25 //nolint:interfacer 26 func NewCommunityPoolSpendProposal(title, description string, recipient sdk.AccAddress, amount sdk.Coins) *CommunityPoolSpendProposal { 27 return &CommunityPoolSpendProposal{title, description, recipient.String(), amount} 28 } 29 30 // GetTitle returns the title of a community pool spend proposal. 31 func (csp *CommunityPoolSpendProposal) GetTitle() string { return csp.Title } 32 33 // GetDescription returns the description of a community pool spend proposal. 34 func (csp *CommunityPoolSpendProposal) GetDescription() string { return csp.Description } 35 36 // GetDescription returns the routing key of a community pool spend proposal. 37 func (csp *CommunityPoolSpendProposal) ProposalRoute() string { return RouterKey } 38 39 // ProposalType returns the type of a community pool spend proposal. 40 func (csp *CommunityPoolSpendProposal) ProposalType() string { return ProposalTypeCommunityPoolSpend } 41 42 // ValidateBasic runs basic stateless validity checks 43 func (csp *CommunityPoolSpendProposal) ValidateBasic() error { 44 err := govtypes.ValidateAbstract(csp) 45 if err != nil { 46 return err 47 } 48 if !csp.Amount.IsValid() { 49 return ErrInvalidProposalAmount 50 } 51 if csp.Recipient == "" { 52 return ErrEmptyProposalRecipient 53 } 54 55 return nil 56 } 57 58 // String implements the Stringer interface. 59 func (csp CommunityPoolSpendProposal) String() string { 60 var b strings.Builder 61 b.WriteString(fmt.Sprintf(`Community Pool Spend Proposal: 62 Title: %s 63 Description: %s 64 Recipient: %s 65 Amount: %s 66 `, csp.Title, csp.Description, csp.Recipient, csp.Amount)) 67 return b.String() 68 }