/
governance_proposals.go
128 lines (105 loc) · 3.13 KB
/
governance_proposals.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package types
import (
fmt "fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalTypeUnhaltBridge = "UnhaltBridge"
ProposalTypeAirdrop = "Airdrop"
ProposalTypeIBCMetadata = "IBCMetadata"
)
func (p *UnhaltBridgeProposal) GetTitle() string { return p.Title }
func (p *UnhaltBridgeProposal) GetDescription() string { return p.Description }
func (p *UnhaltBridgeProposal) ProposalRoute() string { return RouterKey }
func (p *UnhaltBridgeProposal) ProposalType() string {
return ProposalTypeUnhaltBridge
}
func (p *UnhaltBridgeProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
return nil
}
func (p UnhaltBridgeProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Unhalt Bridge Proposal:
Title: %s
Description: %s
target_nonce: %d
`, p.Title, p.Description, p.TargetNonce))
return b.String()
}
func (p *AirdropProposal) GetTitle() string { return p.Title }
func (p *AirdropProposal) GetDescription() string { return p.Description }
func (p *AirdropProposal) ProposalRoute() string { return RouterKey }
func (p *AirdropProposal) ProposalType() string {
return ProposalTypeAirdrop
}
func (p *AirdropProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
return nil
}
func (p AirdropProposal) String() string {
var b strings.Builder
total := uint64(0)
for _, v := range p.Amounts {
total += v
}
parsedRecipients := make([]sdk.AccAddress, len(p.Recipients)/20)
for i := 0; i < len(p.Recipients)/20; i++ {
indexStart := i * 20
indexEnd := indexStart + 20
addr := p.Recipients[indexStart:indexEnd]
parsedRecipients[i] = addr
}
recipients := ""
for i, a := range parsedRecipients {
recipients += fmt.Sprintf("Account: %s Amount: %d%s", a.String(), p.Amounts[i], p.Denom)
}
b.WriteString(fmt.Sprintf(`Airdrop Proposal:
Title: %s
Description: %s
Total Amount: %d%s
Recipients: %s
`, p.Title, p.Description, total, p.Denom, recipients))
return b.String()
}
func (p *IBCMetadataProposal) GetTitle() string { return p.Title }
func (p *IBCMetadataProposal) GetDescription() string { return p.Description }
func (p *IBCMetadataProposal) ProposalRoute() string { return RouterKey }
func (p *IBCMetadataProposal) ProposalType() string {
return ProposalTypeIBCMetadata
}
func (p *IBCMetadataProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
return nil
}
func (p IBCMetadataProposal) String() string {
decimals := uint32(0)
for _, denomUnit := range p.Metadata.DenomUnits {
if denomUnit.Denom == p.Metadata.Display {
decimals = denomUnit.Exponent
break
}
}
var b strings.Builder
b.WriteString(fmt.Sprintf(`IBC Metadata setting proposal:
Title: %s
Description: %s
Token Name: %s
Token Symbol: %s
Token Display: %s
Token Decimals: %d
Token Description: %s
`, p.Title, p.Description, p.Metadata.Name, p.Metadata.Symbol, p.Metadata.Display, decimals, p.Metadata.Description))
return b.String()
}