-
Notifications
You must be signed in to change notification settings - Fork 38
/
proposal.go
92 lines (74 loc) · 3.52 KB
/
proposal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
)
// constants
const (
ProposalContractRegistrationRequest string = "ProposalContractRegistrationRequest"
ProposalBatchContractRegistrationRequest string = "ProposalBatchContractRegistrationRequest"
)
func init() {
gov.RegisterProposalType(ProposalContractRegistrationRequest)
gov.RegisterProposalTypeCodec(&ContractRegistrationRequestProposal{}, "injective/ContractRegistrationRequestProposal")
gov.RegisterProposalType(ProposalBatchContractRegistrationRequest)
gov.RegisterProposalTypeCodec(&BatchContractRegistrationRequestProposal{}, "injective/BatchContractRegistrationRequestProposal")
}
// NewContractRegistrationRequestProposal returns new instance of ContractRegistrationRequestProposal
func NewContractRegistrationRequestProposal(title, description string, ContractRegistrationRequest ContractRegistrationRequest) *ContractRegistrationRequestProposal {
return &ContractRegistrationRequestProposal{
Title: title,
Description: description,
ContractRegistrationRequest: ContractRegistrationRequest,
}
}
// Implements Proposal Interface
var _ gov.Content = &ContractRegistrationRequestProposal{}
var _ gov.Content = &BatchContractRegistrationRequestProposal{}
// GetTitle returns the title of this proposal.
func (p *ContractRegistrationRequestProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *ContractRegistrationRequestProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *ContractRegistrationRequestProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *ContractRegistrationRequestProposal) ProposalType() string {
return ProposalContractRegistrationRequest
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *ContractRegistrationRequestProposal) ValidateBasic() error {
// Check if contract address is valid
if _, err := sdk.AccAddressFromBech32(p.ContractRegistrationRequest.ContractAddress); err != nil {
return sdkerrors.Wrapf(ErrInvalidContractAddress, "ContractRegistrationRequestProposal: Error parsing registry contract address %s", err.Error())
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *BatchContractRegistrationRequestProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *BatchContractRegistrationRequestProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *BatchContractRegistrationRequestProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *BatchContractRegistrationRequestProposal) ProposalType() string {
return ProposalBatchContractRegistrationRequest
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *BatchContractRegistrationRequestProposal) ValidateBasic() error {
for _, req := range p.ContractRegistrationRequests {
// Check if contract address is valid
if _, err := sdk.AccAddressFromBech32(req.ContractAddress); err != nil {
return sdkerrors.Wrapf(ErrInvalidContractAddress, "BatchContractRegistrationRequestProposal: Error parsing registry contract address %s", err.Error())
}
}
return gov.ValidateAbstract(p)
}