feat(client): Add cobra's context to clientCtx (#15458)
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
This commit is contained in:
@@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
### Features
|
||||
|
||||
* (x/bank) [#15265](https://github.com/cosmos/cosmos-sdk/pull/15265) Update keeper interface to include `GetAllDenomMetaData`.
|
||||
* (client) [#15458](https://github.com/cosmos/cosmos-sdk/pull/15458) Add a `CmdContext` field to client.Context initialized to cobra command's context.
|
||||
* (core) [#15133](https://github.com/cosmos/cosmos-sdk/pull/15133) Implement RegisterServices in the module manager.
|
||||
* (x/gov) [#14373](https://github.com/cosmos/cosmos-sdk/pull/14373) Add new proto field `constitution` of type `string` to gov module genesis state, which allows chain builders to lay a strong foundation by specifying purpose.
|
||||
* (x/genutil) [#15301](https://github.com/cosmos/cosmos-sdk/pull/15031) Add application genesis. The genesis is now entirely managed by the application and passed to CometBFT at note instantiation. Functions that were taking a `cmttypes.GenesisDoc{}` now takes a `genutiltypes.AppGenesis{}`.
|
||||
|
||||
@@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -61,6 +62,16 @@ type Context struct {
|
||||
|
||||
// TODO: Deprecated (remove).
|
||||
LegacyAmino *codec.LegacyAmino
|
||||
|
||||
// CmdContext is the context.Context from the Cobra command.
|
||||
CmdContext context.Context
|
||||
}
|
||||
|
||||
// WithCmdContext returns a copy of the context with an updated context.Context,
|
||||
// usually set to the cobra cmd context.
|
||||
func (ctx Context) WithCmdContext(c context.Context) Context {
|
||||
ctx.CmdContext = c
|
||||
return ctx
|
||||
}
|
||||
|
||||
// WithKeyring returns a copy of the context with an updated keyring.
|
||||
|
||||
+1
-2
@@ -116,8 +116,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
|
||||
}
|
||||
}
|
||||
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
err = Sign(context.TODO(), txf, clientCtx.GetFromName(), tx, true)
|
||||
err = Sign(clientCtx.CmdContext, txf, clientCtx.GetFromName(), tx, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ func NewRootCmd() *cobra.Command {
|
||||
cmd.SetOut(cmd.OutOrStdout())
|
||||
cmd.SetErr(cmd.ErrOrStderr())
|
||||
|
||||
initClientCtx = initClientCtx.WithCmdContext(cmd.Context())
|
||||
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -2,7 +2,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -324,8 +323,7 @@ func initTestnetFiles(
|
||||
WithKeybase(kb).
|
||||
WithTxConfig(clientCtx.TxConfig)
|
||||
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
if err := tx.Sign(context.TODO(), txFactory, nodeDirName, txBuilder, true); err != nil {
|
||||
if err := tx.Sign(cmd.Context(), txFactory, nodeDirName, txBuilder, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -546,8 +546,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
|
||||
WithKeybase(kb).
|
||||
WithTxConfig(cfg.TxConfig)
|
||||
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
err = tx.Sign(context.TODO(), txFactory, nodeDirName, txBuilder, true)
|
||||
err = tx.Sign(context.Background(), txFactory, nodeDirName, txBuilder, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package sims
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -61,9 +62,8 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee
|
||||
Sequence: accSeqs[i],
|
||||
PubKey: p.PubKey(),
|
||||
}
|
||||
// When Textual is wired up, use GetSignBytesWithContext
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/13747
|
||||
signBytes, err := txConfig.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx())
|
||||
|
||||
signBytes, err := authsign.GetSignBytesWithContext(txConfig.SignModeHandler(), context.Background(), signMode, signerData, tx.GetTx())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -133,8 +132,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {
|
||||
PubKey: sig.PubKey,
|
||||
}
|
||||
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
err = signing.VerifySignature(context.TODO(), sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx())
|
||||
err = signing.VerifySignature(cmd.Context(), sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx())
|
||||
if err != nil {
|
||||
addr, _ := sdk.AccAddressFromHexUnsafe(sig.PubKey.Address().String())
|
||||
return fmt.Errorf("couldn't verify signature for address %s", addr)
|
||||
@@ -306,8 +304,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
for _, sig := range signatureBatch {
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
err = signing.VerifySignature(context.TODO(), sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx())
|
||||
err = signing.VerifySignature(cmd.Context(), sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx())
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't verify signature: %w %v", err, sig)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -112,8 +111,8 @@ func printAndValidateSigs(
|
||||
Sequence: accSeq,
|
||||
PubKey: pubKey,
|
||||
}
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
err = authsigning.VerifySignature(context.TODO(), pubKey, signingData, sig.Data, signModeHandler, sigTx)
|
||||
|
||||
err = authsigning.VerifySignature(cmd.Context(), pubKey, signingData, sig.Data, signModeHandler, sigTx)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
+2
-5
@@ -3,7 +3,6 @@ package client
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -59,8 +58,7 @@ func SignTx(txFactory tx.Factory, clientCtx client.Context, name string, txBuild
|
||||
}
|
||||
}
|
||||
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
return tx.Sign(context.TODO(), txFactory, name, txBuilder, overwriteSig)
|
||||
return tx.Sign(clientCtx.CmdContext, txFactory, name, txBuilder, overwriteSig)
|
||||
}
|
||||
|
||||
// SignTxWithSignerAddress attaches a signature to a transaction.
|
||||
@@ -88,8 +86,7 @@ func SignTxWithSignerAddress(txFactory tx.Factory, clientCtx client.Context, add
|
||||
}
|
||||
}
|
||||
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
return tx.Sign(context.TODO(), txFactory, name, txBuilder, overwrite)
|
||||
return tx.Sign(clientCtx.CmdContext, txFactory, name, txBuilder, overwrite)
|
||||
}
|
||||
|
||||
// Read and decode a StdTx from the given filename. Can pass "-" to read from stdin.
|
||||
|
||||
Reference in New Issue
Block a user