1
1
package utils
2
2
3
3
import (
4
+ "encoding/json"
4
5
"io/ioutil"
5
6
6
7
"github.com/cosmos/cosmos-sdk/codec"
@@ -9,24 +10,58 @@ import (
9
10
"github.com/cosmos/cosmos-sdk/x/params"
10
11
)
11
12
12
- // ParamChangeProposalJSON defines a ParameterChangeProposal with a deposit used
13
- // to parse parameter change proposals from a JSON file.
14
- type ParamChangeProposalJSON struct {
15
- Title string `json:"title"`
16
- Description string `json:"description"`
17
- Changes []params.ParamChange `json:"changes"`
18
- Deposit sdk.Coins `json:"deposit"`
13
+ type (
14
+ // ParamChangesJSON defines a slice of ParamChangeJSON objects which can be
15
+ // converted to a slice of ParamChange objects.
16
+ ParamChangesJSON []ParamChangeJSON
17
+
18
+ // ParamChangeJSON defines a parameter change used in JSON input. This
19
+ // allows values to be specified in raw JSON instead of being string encoded.
20
+ ParamChangeJSON struct {
21
+ Subspace string `json:"subspace"`
22
+ Key string `json:"key"`
23
+ Subkey string `json:"subkey,omitempty"`
24
+ Value json.RawMessage `json:"value"`
25
+ }
26
+
27
+ // ParamChangeProposalJSON defines a ParameterChangeProposal with a deposit used
28
+ // to parse parameter change proposals from a JSON file.
29
+ ParamChangeProposalJSON struct {
30
+ Title string `json:"title"`
31
+ Description string `json:"description"`
32
+ Changes ParamChangesJSON `json:"changes"`
33
+ Deposit sdk.Coins `json:"deposit"`
34
+ }
35
+
36
+ // ParamChangeProposalReq defines a parameter change proposal request body.
37
+ ParamChangeProposalReq struct {
38
+ BaseReq rest.BaseReq `json:"base_req"`
39
+
40
+ Title string `json:"title"`
41
+ Description string `json:"description"`
42
+ Changes ParamChangesJSON `json:"changes"`
43
+ Proposer sdk.AccAddress `json:"proposer"`
44
+ Deposit sdk.Coins `json:"deposit"`
45
+ }
46
+ )
47
+
48
+ func NewParamChangeJSON (subspace , key , subkey string , value json.RawMessage ) ParamChangeJSON {
49
+ return ParamChangeJSON {subspace , key , subkey , value }
19
50
}
20
51
21
- // ParamChangeProposalReq defines a parameter change proposal request body.
22
- type ParamChangeProposalReq struct {
23
- BaseReq rest.BaseReq `json:"base_req"`
52
+ // ToParamChange converts a ParamChangeJSON object to ParamChange.
53
+ func (pcj ParamChangeJSON ) ToParamChange () params.ParamChange {
54
+ return params .NewParamChange (pcj .Subspace , pcj .Key , pcj .Subkey , string (pcj .Value ))
55
+ }
24
56
25
- Title string `json:"title"`
26
- Description string `json:"description"`
27
- Changes []params.ParamChange `json:"changes"`
28
- Proposer sdk.AccAddress `json:"proposer"`
29
- Deposit sdk.Coins `json:"deposit"`
57
+ // ToParamChanges converts a slice of ParamChangeJSON objects to a slice of
58
+ // ParamChange.
59
+ func (pcj ParamChangesJSON ) ToParamChanges () []params.ParamChange {
60
+ res := make ([]params.ParamChange , len (pcj ))
61
+ for i , pc := range pcj {
62
+ res [i ] = pc .ToParamChange ()
63
+ }
64
+ return res
30
65
}
31
66
32
67
// ParseParamChangeProposalJSON reads and parses a ParamChangeProposalJSON from
0 commit comments