This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
84 lines (68 loc) · 2.18 KB
/
utils.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
package utils
import (
"os"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/bianjieai/spartan-cosmos/module/node"
)
type (
ValidatorCreateProposalJSON struct {
Deposit string `json:"deposit"`
Content CreateValidatorProposalJSON `json:"content"`
}
CreateValidatorProposalJSON struct {
Title string `json:"title"`
Summary string `json:"summary"`
Name string `json:"name"`
Pubkey string `json:"pubkey"`
Power int64 `json:"power"`
Description string `json:"description"`
Operator string `json:"operator"`
}
ValidatorUpdateProposalJSON struct {
Deposit string `json:"deposit"`
Content node.UpdateValidatorProposal `json:"content"`
}
ValidatorRemoveProposalJSON struct {
Deposit string `json:"deposit"`
Content node.RemoveValidatorProposal `json:"content"`
}
)
// ParseValidatorCreateJSON reads and parses a ParamChangeProposalJSON from
// file.
func ParseValidatorCreateJSON(cdc *codec.LegacyAmino, proposalFile string) (ValidatorCreateProposalJSON, error) {
proposal := ValidatorCreateProposalJSON{}
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}
if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
return proposal, err
}
return proposal, nil
}
// ParseValidatorCreateJSON reads and parses a ParamChangeProposalJSON from
// file.
func ParseValidatorUpdateJSON(cdc *codec.LegacyAmino, proposalFile string) (ValidatorUpdateProposalJSON, error) {
proposal := ValidatorUpdateProposalJSON{}
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}
if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
return proposal, err
}
return proposal, nil
}
// ParseValidatorCreateJSON reads and parses a ParamChangeProposalJSON from
// file.
func ParseValidatorRemoveJSON(cdc *codec.LegacyAmino, proposalFile string) (ValidatorRemoveProposalJSON, error) {
proposal := ValidatorRemoveProposalJSON{}
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}
if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
return proposal, err
}
return proposal, nil
}