-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parse home flag earlier (#20771)
(cherry picked from commit 5aaff21) # Conflicts: # CHANGELOG.md # client/config/config.go # client/v2/CHANGELOG.md # scripts/simapp-v2-init.sh # server/v2/cometbft/flags/flags.go # server/v2/commands.go # simapp/CHANGELOG.md # simapp/app.go # simapp/app_v2.go # simapp/simd/cmd/root.go # simapp/simd/cmd/root_v2.go # simapp/v2/app_di.go # simapp/v2/simdv2/cmd/commands.go # simapp/v2/simdv2/cmd/root_di.go # x/upgrade/CHANGELOG.md # x/upgrade/depinject.go # x/upgrade/go.mod
- Loading branch information
1 parent
0e6db14
commit 0a3ba38
Showing
22 changed files
with
1,210 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package helpers | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// GetNodeHomeDirectory gets the home directory of the node (where the config is located). | ||
// It parses the home flag if set if the `NODE_HOME` environment variable if set (and ignores name). | ||
// Otherwise, it returns the default home directory given its name. | ||
func GetNodeHomeDirectory(name string) (string, error) { | ||
// get the home directory from the flag | ||
args := os.Args | ||
for i := 0; i < len(args); i++ { | ||
if args[i] == "--home" && i+1 < len(args) { | ||
return filepath.Clean(args[i+1]), nil | ||
} else if strings.HasPrefix(args[i], "--home=") { | ||
return filepath.Clean(args[i][7:]), nil | ||
} | ||
} | ||
|
||
// get the home directory from the environment variable | ||
homeDir := os.Getenv("NODE_HOME") | ||
if homeDir != "" { | ||
return filepath.Clean(homeDir), nil | ||
} | ||
|
||
// return the default home directory | ||
userHomeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return filepath.Join(userHomeDir, name), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -x | ||
|
||
ROOT=$PWD | ||
|
||
SIMD="$ROOT/build/simdv2" | ||
CONFIG="${CONFIG:-$HOME/.simappv2/config}" | ||
|
||
COSMOS_BUILD_OPTIONS=v2 make build | ||
|
||
if [ -d "$($SIMD config home)" ]; then rm -rv $($SIMD config home); fi | ||
|
||
$SIMD init simapp-v2-node --chain-id simapp-v2-chain | ||
|
||
cd "$CONFIG" | ||
|
||
# to change the voting_period | ||
jq '.app_state.gov.voting_params.voting_period = "600s"' genesis.json > temp.json && mv temp.json genesis.json | ||
|
||
# to change the inflation | ||
jq '.app_state.mint.minter.inflation = "0.300000000000000000"' genesis.json > temp.json && mv temp.json genesis.json | ||
|
||
# change the initial height to 2 to work around store/v2 and iavl limitations with a genesis block | ||
jq '.initial_height = 2' genesis.json > temp.json && mv temp.json genesis.json | ||
|
||
$SIMD config set client chain-id simapp-v2-chain | ||
$SIMD keys add test_validator --indiscreet | ||
VALIDATOR_ADDRESS=$($SIMD keys show test_validator -a --keyring-backend test) | ||
|
||
$SIMD genesis add-genesis-account "$VALIDATOR_ADDRESS" 1000000000stake | ||
$SIMD genesis gentx test_validator 1000000000stake --keyring-backend test | ||
$SIMD genesis collect-gentxs | ||
|
||
$SIMD start & | ||
SIMD_PID=$! | ||
|
||
cnt=0 | ||
while ! $SIMD query block --type=height 5; do | ||
cnt=$((cnt + 1)) | ||
if [ $cnt -gt 30 ]; then | ||
kill -9 "$SIMD_PID" | ||
exit 1 | ||
fi | ||
sleep 1 | ||
done | ||
|
||
kill -9 "$SIMD_PID" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package flags | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
const ( | ||
FlagQuery = "query" | ||
FlagType = "type" | ||
FlagOrderBy = "order_by" | ||
) | ||
|
||
const ( | ||
FlagChainID = "chain-id" | ||
FlagNode = "node" | ||
FlagGRPC = "grpc-addr" | ||
FlagGRPCInsecure = "grpc-insecure" | ||
FlagHeight = "height" | ||
FlagGasAdjustment = "gas-adjustment" | ||
FlagFrom = "from" | ||
FlagName = "name" | ||
FlagAccountNumber = "account-number" | ||
FlagSequence = "sequence" | ||
FlagNote = "note" | ||
FlagFees = "fees" | ||
FlagGas = "gas" | ||
FlagGasPrices = "gas-prices" | ||
FlagBroadcastMode = "broadcast-mode" | ||
FlagDryRun = "dry-run" | ||
FlagGenerateOnly = "generate-only" | ||
FlagOffline = "offline" | ||
FlagOutputDocument = "output-document" // inspired by wget -O | ||
FlagSkipConfirmation = "yes" | ||
FlagProve = "prove" | ||
FlagKeyringBackend = "keyring-backend" | ||
FlagPage = "page" | ||
FlagLimit = "limit" | ||
FlagSignMode = "sign-mode" | ||
FlagPageKey = "page-key" | ||
FlagOffset = "offset" | ||
FlagCountTotal = "count-total" | ||
FlagTimeoutHeight = "timeout-height" | ||
FlagUnordered = "unordered" | ||
FlagKeyAlgorithm = "algo" | ||
FlagKeyType = "key-type" | ||
FlagFeePayer = "fee-payer" | ||
FlagFeeGranter = "fee-granter" | ||
FlagReverse = "reverse" | ||
FlagTip = "tip" | ||
FlagAux = "aux" | ||
FlagInitHeight = "initial-height" | ||
// FlagOutput is the flag to set the output format. | ||
// This differs from FlagOutputDocument that is used to set the output file. | ||
FlagOutput = "output" | ||
// Logging flags | ||
FlagLogLevel = "log_level" | ||
FlagLogFormat = "log_format" | ||
FlagLogNoColor = "log_no_color" | ||
) | ||
|
||
// List of supported output formats | ||
const ( | ||
OutputFormatJSON = "json" | ||
OutputFormatText = "text" | ||
) | ||
|
||
// AddQueryFlagsToCmd adds common flags to a module query command. | ||
func AddQueryFlagsToCmd(cmd *cobra.Command) { | ||
cmd.Flags().String(FlagNode, "tcp://localhost:26657", "<host>:<port> to CometBFT RPC interface for this chain") | ||
cmd.Flags().String(FlagGRPC, "", "the gRPC endpoint to use for this chain") | ||
cmd.Flags().Bool(FlagGRPCInsecure, false, "allow gRPC over insecure channels, if not the server must use TLS") | ||
cmd.Flags().Int64(FlagHeight, 0, "Use a specific height to query state at (this can error if the node is pruning state)") | ||
cmd.Flags().StringP(FlagOutput, "o", "text", "Output format (text|json)") | ||
|
||
// some base commands does not require chainID e.g `simd testnet` while subcommands do | ||
// hence the flag should not be required for those commands | ||
_ = cmd.MarkFlagRequired(FlagChainID) | ||
} |
Oops, something went wrong.