Fix panic in context when setting nodeURI (#7699)
* Fix panic in context Move URI parsing outside of context. WithNodeURI will only set the nodeURI. To set the Client in the context, WithClient must be called. * add changelog * add deleted space back
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -131,6 +132,13 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont
|
||||
rpcURI, _ := flagSet.GetString(flags.FlagNode)
|
||||
if rpcURI != "" {
|
||||
clientCtx = clientCtx.WithNodeURI(rpcURI)
|
||||
|
||||
client, err := rpchttp.New(rpcURI, "/websocket")
|
||||
if err != nil {
|
||||
return clientCtx, err
|
||||
}
|
||||
|
||||
clientCtx = clientCtx.WithClient(client)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
@@ -95,12 +94,6 @@ func (ctx Context) WithOutputFormat(format string) Context {
|
||||
// WithNodeURI returns a copy of the context with an updated node URI.
|
||||
func (ctx Context) WithNodeURI(nodeURI string) Context {
|
||||
ctx.NodeURI = nodeURI
|
||||
client, err := rpchttp.New(nodeURI, "/websocket")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx.Client = client
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user