(serverv2/cometbft) Read config from commands & handle FlagNode (#20621)
This commit is contained in:
parent
c36edbddbd
commit
8d205afbb3
@ -21,6 +21,7 @@ import (
|
||||
"cosmossdk.io/server/v2/cometbft/client/rpc"
|
||||
"cosmossdk.io/server/v2/cometbft/flags"
|
||||
auth "cosmossdk.io/x/auth/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -28,15 +29,25 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
)
|
||||
|
||||
func (s *CometBFTServer[T]) rpcClient() (rpc.CometRPC, error) {
|
||||
func (s *CometBFTServer[T]) rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) {
|
||||
if s.config.Standalone {
|
||||
client, err := rpchttp.New(s.config.CmtConfig.RPC.ListenAddress)
|
||||
client, err := rpchttp.New(client.GetConfigFromCmd(cmd).RPC.ListenAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
if s.Node == nil || cmd.Flags().Changed(flags.FlagNode) {
|
||||
rpcURI, err := cmd.Flags().GetString(flags.FlagNode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rpcURI != "" {
|
||||
return rpchttp.New(rpcURI)
|
||||
}
|
||||
}
|
||||
|
||||
return local.New(s.Node), nil
|
||||
}
|
||||
|
||||
@ -46,7 +57,7 @@ func (s *CometBFTServer[T]) StatusCommand() *cobra.Command {
|
||||
Use: "status",
|
||||
Short: "Query remote node for status",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
rpcclient, err := s.rpcClient()
|
||||
rpcclient, err := s.rpcClient(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -80,7 +91,8 @@ func (s *CometBFTServer[T]) ShowNodeIDCmd() *cobra.Command {
|
||||
Use: "show-node-id",
|
||||
Short: "Show this node's ID",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
nodeKey, err := p2p.LoadNodeKey(s.config.CmtConfig.NodeKeyFile())
|
||||
cmtConfig := client.GetConfigFromCmd(cmd)
|
||||
nodeKey, err := p2p.LoadNodeKey(cmtConfig.NodeKeyFile())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -97,7 +109,7 @@ func (s *CometBFTServer[T]) ShowValidatorCmd() *cobra.Command {
|
||||
Use: "show-validator",
|
||||
Short: "Show this node's CometBFT validator info",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg := s.config.CmtConfig
|
||||
cfg := client.GetConfigFromCmd(cmd)
|
||||
privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
|
||||
pk, err := privValidator.GetPubKey()
|
||||
if err != nil {
|
||||
@ -131,7 +143,7 @@ func (s *CometBFTServer[T]) ShowAddressCmd() *cobra.Command {
|
||||
Use: "show-address",
|
||||
Short: "Shows this node's CometBFT validator consensus address",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg := s.config.CmtConfig
|
||||
cfg := client.GetConfigFromCmd(cmd)
|
||||
privValidator := pvm.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
|
||||
// TODO: use address codec?
|
||||
valConsAddr := (sdk.ConsAddress)(privValidator.GetAddress())
|
||||
@ -188,7 +200,7 @@ for. Each module documents its respective events under 'xx_events.md'.
|
||||
version.AppName,
|
||||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
rpcclient, err := s.rpcClient()
|
||||
rpcclient, err := s.rpcClient(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -241,7 +253,7 @@ $ %s query block --%s=%s <hash>
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
typ, _ := cmd.Flags().GetString(auth.FlagType)
|
||||
|
||||
rpcclient, err := s.rpcClient()
|
||||
rpcclient, err := s.rpcClient(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -332,7 +344,7 @@ func (s *CometBFTServer[T]) QueryBlockResultsCmd() *cobra.Command {
|
||||
|
||||
// TODO: we should be able to do this without using client context
|
||||
|
||||
node, err := s.rpcClient()
|
||||
node, err := s.rpcClient(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -392,6 +404,7 @@ func (s *CometBFTServer[T]) BootstrapStateCmd() *cobra.Command {
|
||||
Short: "Bootstrap CometBFT state at an arbitrary block height using a light client",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg := client.GetConfigFromCmd(cmd)
|
||||
height, err := cmd.Flags().GetUint64("height")
|
||||
if err != nil {
|
||||
return err
|
||||
@ -404,7 +417,7 @@ func (s *CometBFTServer[T]) BootstrapStateCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
// TODO genensis doc provider and apphash
|
||||
return node.BootstrapState(cmd.Context(), s.config.CmtConfig, cmtcfg.DefaultDBProvider, nil, height, nil)
|
||||
return node.BootstrapState(cmd.Context(), cfg, cmtcfg.DefaultDBProvider, nil, height, nil)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user