Skip to content

Commit

Permalink
Cleanup client config (#1962)
Browse files Browse the repository at this point in the history
* Remove ReadFromClientConfig since we already do this, and move the sign mode textual after this logic.

* Update changelog.
  • Loading branch information
Taztingo authored and nullpointer0x00 committed May 15, 2024
1 parent b81138a commit e9db5cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Use fields of the SimulationState for the encoders needed for simulations [#1931](https://github.com/provenance-io/provenance/pull/1931).
* Removes sync-info code for sdk v0.50 [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Fix most of the failing unit tests [#1943](https://github.com/provenance-io/provenance/pull/1943)
* Clean up ReadFromClient [#1760](https://github.com/provenance-io/provenance/issues/1760).

### Dependencies

Expand Down
31 changes: 0 additions & 31 deletions cmd/provenanced/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
clientconfig "github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
Expand All @@ -39,10 +38,7 @@ import (
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -109,33 +105,6 @@ func NewRootCmd(sealConfig bool) (*cobra.Command, params.EncodingConfig) {
return err
}

// TODO[1760]: client: Check impact that this has on our custom client config.
initClientCtx, err = clientconfig.ReadFromClientConfig(initClientCtx)
if err != nil {
return err
}

// This needs to go after ReadFromClientConfig, as that function
// sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode
// is only available if the client is online.
if !initClientCtx.Offline {
enabledSignModes := tx.DefaultSignModes
enabledSignModes = append(enabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
}
txConfig, err := tx.NewTxConfigWithOptions(
initClientCtx.Codec,
txConfigOpts,
)
if err != nil {
return err
}

initClientCtx = initClientCtx.WithTxConfig(txConfig)
}

if err := client.SetCmdClientContext(cmd, initClientCtx); err != nil {
return err
}
Expand Down
24 changes: 24 additions & 0 deletions cmd/provenanced/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
)

// Default constants
Expand Down Expand Up @@ -92,5 +95,26 @@ func ApplyClientConfigToContext(ctx client.Context, config *ClientConfig) (clien
WithClient(clnt).
WithBroadcastMode(config.BroadcastMode)

// This needs to go after ReadFromClientConfig, as that function
// sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode
// is only available if the client is online.
if !ctx.Offline {
enabledSignModes := tx.DefaultSignModes
enabledSignModes = append(enabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(ctx),
}
txConfig, err := tx.NewTxConfigWithOptions(
ctx.Codec,
txConfigOpts,
)
if err != nil {
return ctx, err
}

ctx = ctx.WithTxConfig(txConfig)
}

return ctx, nil
}

0 comments on commit e9db5cd

Please sign in to comment.