Some checks are pending
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
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"git.cw.tr/mukan-network/mukan-sdk/client"
|
|
"git.cw.tr/mukan-network/mukan-sdk/server"
|
|
"git.cw.tr/mukan-network/mukan-sdk/types/module"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/genutil/types"
|
|
)
|
|
|
|
const chainUpgradeGuide = "https://git.cw.tr/mukan-network/mukan-sdk/blob/main/UPGRADING.md"
|
|
|
|
// ValidateGenesisCmd takes a genesis file, and makes sure that it is valid.
|
|
func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "validate [file]",
|
|
Aliases: []string{"validate-genesis"},
|
|
Args: cobra.RangeArgs(0, 1),
|
|
Short: "Validates the genesis file at the default location or at the location passed as an arg",
|
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|
serverCtx := server.GetServerContextFromCmd(cmd)
|
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
|
|
|
cdc := clientCtx.Codec
|
|
|
|
// Load default if passed no args, otherwise load passed file
|
|
var genesis string
|
|
if len(args) == 0 {
|
|
genesis = serverCtx.Config.GenesisFile()
|
|
} else {
|
|
genesis = args[0]
|
|
}
|
|
|
|
appGenesis, err := types.AppGenesisFromFile(genesis)
|
|
if err != nil {
|
|
return enrichUnmarshalError(err)
|
|
}
|
|
|
|
if err := appGenesis.ValidateAndComplete(); err != nil {
|
|
return fmt.Errorf("make sure that you have correctly migrated all CometBFT consensus params. Refer the UPGRADING.md (%s): %w", chainUpgradeGuide, err)
|
|
}
|
|
|
|
var genState map[string]json.RawMessage
|
|
if err := json.Unmarshal(appGenesis.AppState, &genState); err != nil {
|
|
if strings.Contains(err.Error(), "unexpected end of JSON input") {
|
|
return fmt.Errorf("app_state is missing in the genesis file: %s", err.Error())
|
|
}
|
|
return fmt.Errorf("error unmarshalling genesis doc %s: %w", genesis, err)
|
|
}
|
|
|
|
if err = mbm.ValidateGenesis(cdc, clientCtx.TxConfig, genState); err != nil {
|
|
errStr := fmt.Sprintf("error validating genesis file %s: %s", genesis, err.Error())
|
|
if errors.Is(err, io.EOF) {
|
|
errStr = fmt.Sprintf("%s: section is missing in the app_state", errStr)
|
|
}
|
|
return fmt.Errorf("%s", errStr)
|
|
}
|
|
|
|
fmt.Fprintf(cmd.OutOrStdout(), "File at %s is a valid genesis file\n", genesis)
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
func enrichUnmarshalError(err error) error {
|
|
var syntaxErr *json.SyntaxError
|
|
if errors.As(err, &syntaxErr) {
|
|
return fmt.Errorf("error at offset %d: %s", syntaxErr.Offset, syntaxErr.Error())
|
|
}
|
|
return err
|
|
}
|