Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
|
)
|
|
|
|
type (
|
|
// ParamChangesJSON defines a slice of ParamChangeJSON objects which can be
|
|
// converted to a slice of ParamChange objects.
|
|
ParamChangesJSON []ParamChangeJSON
|
|
|
|
// ParamChangeJSON defines a parameter change used in JSON input. This
|
|
// allows values to be specified in raw JSON instead of being string encoded.
|
|
ParamChangeJSON struct {
|
|
Subspace string `json:"subspace" yaml:"subspace"`
|
|
Key string `json:"key" yaml:"key"`
|
|
Value json.RawMessage `json:"value" yaml:"value"`
|
|
}
|
|
|
|
// ParamChangeProposalJSON defines a ParameterChangeProposal with a deposit used
|
|
// to parse parameter change proposals from a JSON file.
|
|
ParamChangeProposalJSON struct {
|
|
Title string `json:"title" yaml:"title"`
|
|
Description string `json:"description" yaml:"description"`
|
|
Changes ParamChangesJSON `json:"changes" yaml:"changes"`
|
|
Deposit string `json:"deposit" yaml:"deposit"`
|
|
}
|
|
)
|
|
|
|
func NewParamChangeJSON(subspace, key string, value json.RawMessage) ParamChangeJSON {
|
|
return ParamChangeJSON{subspace, key, value}
|
|
}
|
|
|
|
// ToParamChange converts a ParamChangeJSON object to ParamChange.
|
|
func (pcj ParamChangeJSON) ToParamChange() proposal.ParamChange {
|
|
return proposal.NewParamChange(pcj.Subspace, pcj.Key, string(pcj.Value))
|
|
}
|
|
|
|
// ToParamChanges converts a slice of ParamChangeJSON objects to a slice of
|
|
// ParamChange.
|
|
func (pcj ParamChangesJSON) ToParamChanges() []proposal.ParamChange {
|
|
res := make([]proposal.ParamChange, len(pcj))
|
|
for i, pc := range pcj {
|
|
res[i] = pc.ToParamChange()
|
|
}
|
|
return res
|
|
}
|
|
|
|
// ParseParamChangeProposalJSON reads and parses a ParamChangeProposalJSON from
|
|
// file.
|
|
func ParseParamChangeProposalJSON(cdc *codec.LegacyAmino, proposalFile string) (ParamChangeProposalJSON, error) {
|
|
proposal := ParamChangeProposalJSON{}
|
|
|
|
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
|
|
}
|