refactor(client): add client/Context.Codec and deprecate JSONCodec (#9498)
* chore(types): add sdk.Context.Codec and deprecate JSONCodec * Use clientContext.Codec rather than JSONCodec everywhere * update tests to use clientContext.Codec * added a note that EncodingConfig.Marshaler will be renamed to Codec * update changelog * fix tests to use clientCtx.WithCodec instead of WithJSONCodec * fix genutil build * Update simapp/params/encoding.go Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,8 @@ import (
|
||||
// This is provided for compatibility between protobuf and amino implementations.
|
||||
type EncodingConfig struct {
|
||||
InterfaceRegistry types.InterfaceRegistry
|
||||
Marshaler codec.Codec
|
||||
TxConfig client.TxConfig
|
||||
Amino *codec.LegacyAmino
|
||||
// NOTE: this field will be renamed to Codec
|
||||
Marshaler codec.Codec
|
||||
TxConfig client.TxConfig
|
||||
Amino *codec.LegacyAmino
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
depCdc := clientCtx.JSONCodec
|
||||
depCdc := clientCtx.Codec
|
||||
cdc := depCdc.(codec.Codec)
|
||||
|
||||
serverCtx := server.GetServerContextFromCmd(cmd)
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestAddGenesisAccountCmd(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
serverCtx := server.NewContext(viper.New(), cfg, logger)
|
||||
clientCtx := client.Context{}.WithJSONCodec(appCodec).WithHomeDir(home)
|
||||
clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
|
||||
@@ -39,7 +39,7 @@ import (
|
||||
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
initClientCtx := client.Context{}.
|
||||
WithJSONCodec(encodingConfig.Marshaler).
|
||||
WithCodec(encodingConfig.Marshaler).
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
WithLegacyAmino(encodingConfig.Amino).
|
||||
|
||||
@@ -271,11 +271,11 @@ func initGenFiles(
|
||||
genFiles []string, numValidators int,
|
||||
) error {
|
||||
|
||||
appGenState := mbm.DefaultGenesis(clientCtx.JSONCodec)
|
||||
appGenState := mbm.DefaultGenesis(clientCtx.Codec)
|
||||
|
||||
// set the accounts in the genesis state
|
||||
var authGenState authtypes.GenesisState
|
||||
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState)
|
||||
clientCtx.Codec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState)
|
||||
|
||||
accounts, err := authtypes.PackAccounts(genAccounts)
|
||||
if err != nil {
|
||||
@@ -283,14 +283,14 @@ func initGenFiles(
|
||||
}
|
||||
|
||||
authGenState.Accounts = accounts
|
||||
appGenState[authtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&authGenState)
|
||||
appGenState[authtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&authGenState)
|
||||
|
||||
// set the balances in the genesis state
|
||||
var bankGenState banktypes.GenesisState
|
||||
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState)
|
||||
clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState)
|
||||
|
||||
bankGenState.Balances = genBalances
|
||||
appGenState[banktypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&bankGenState)
|
||||
appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState)
|
||||
|
||||
appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ")
|
||||
if err != nil {
|
||||
@@ -337,7 +337,7 @@ func collectGenFiles(
|
||||
return err
|
||||
}
|
||||
|
||||
nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.JSONCodec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator)
|
||||
nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user