client: rename CliContext to Context (#6290)
* Refactor CliContext as Context * Fix lint issues * Fix goimports * Fix gov tests * Resolved ci-lint issues * Add changelog * Rename cliCtx to clientCtx * Fix mocks and routes * Add changelog * Update changelog * Apply suggestions from code review Co-authored-by: Alessio Treglia <alessio@tendermint.com> * merge client/rpc/ro{ot,utes}.go * Update docs * client/rpc: remove redundant client/rpc.RegisterRPCRoutes * regenerate mocks * Update ADRs Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Alessio Treglia
Federico Kunze
mergify[bot]
parent
654b2fdd10
commit
39f53ac22f
@@ -25,7 +25,7 @@ type AppModuleBasic interface {
|
||||
ValidateGenesis(json.RawMessage) error
|
||||
|
||||
// client functionality
|
||||
RegisterRESTRoutes(context.CLIContext, *mux.Router)
|
||||
RegisterRESTRoutes(client.Context, *mux.Router)
|
||||
GetTxCmd(*codec.Codec) *cobra.Command
|
||||
GetQueryCmd(*codec.Codec) *cobra.Command
|
||||
}
|
||||
|
||||
@@ -323,25 +323,25 @@ type TxBuilder interface {
|
||||
}
|
||||
```
|
||||
|
||||
We then update `CLIContext` to have new fields: `JSONMarshaler`, `TxGenerator`,
|
||||
We then update `Context` to have new fields: `JSONMarshaler`, `TxGenerator`,
|
||||
and `AccountRetriever`, and we update `AppModuleBasic.GetTxCmd` to take
|
||||
a `CLIContext` which should have all of these fields pre-populated.
|
||||
a `Context` which should have all of these fields pre-populated.
|
||||
|
||||
Each client method should then use one of the `Init` methods to re-initialize
|
||||
the pre-populated `CLIContext`. `tx.GenerateOrBroadcastTx` can be used to
|
||||
the pre-populated `Context`. `tx.GenerateOrBroadcastTx` can be used to
|
||||
generate or broadcast a transaction. For example:
|
||||
|
||||
```go
|
||||
import "github.com/spf13/cobra"
|
||||
import "github.com/cosmos/cosmos-sdk/client"
|
||||
import "github.com/cosmos/cosmos-sdk/client/tx"
|
||||
import "github.com/cosmos/cosmos-sdk/client/context"
|
||||
|
||||
func NewCmdDoSomething(ctx context.CLIContext) *cobra.Command {
|
||||
func NewCmdDoSomething(clientCtx client.Context) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := ctx.InitWithInput(cmd.InOrStdin())
|
||||
clientCtx := ctx.InitWithInput(cmd.InOrStdin())
|
||||
msg := NewSomeMsg{...}
|
||||
tx.GenerateOrBroadcastTx(cliCtx, msg)
|
||||
tx.GenerateOrBroadcastTx(clientCtx, msg)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,14 +211,14 @@ we have tweaked the grpc codegen to use an interface rather than concrete type
|
||||
for the generated client struct. This allows us to also reuse the GRPC infrastructure
|
||||
for ABCI client queries.
|
||||
|
||||
`CLIContext` will receive a new method `QueryConn` that returns a `ClientConn`
|
||||
1Context` will receive a new method `QueryConn` that returns a `ClientConn`
|
||||
that routes calls to ABCI queries
|
||||
|
||||
Clients (such as CLI methods) will then be able to call query methods like this:
|
||||
|
||||
```go
|
||||
cliCtx := context.NewCLIContext()
|
||||
queryClient := types.NewQueryClient(cliCtx.QueryConn())
|
||||
clientCtx := client.NewContext()
|
||||
queryClient := types.NewQueryClient(clientCtx.QueryConn())
|
||||
params := &types.QueryBalanceParams{addr, denom}
|
||||
result, err := queryClient.QueryBalance(gocontext.Background(), params)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user