Skip to content

Commit 64b6bb5

Browse files
anilcsefedekunzeamaury1093
authored
rename RegisterCodec to RegisterLegacyAminoCodec (#7243)
* rename RegisterCodec to RegisterLegacyAminoCodec * Add changelog * gofmt * rename codec.New() to codec.NewLegacyAmino() * Add change log * Update CHANGELOG.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Fix Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
1 parent ebfb616 commit 64b6bb5

File tree

91 files changed

+256
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+256
-257
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3838
## [Unreleased]
3939

4040
### Client Breaking
41-
41+
* (modules) [\#7243](https://github.com/cosmos/cosmos-sdk/pull/7243) Rename `RegisterCodec` to `RegisterLegacyAminoCodec` and `codec.New()` is now renamed to `codec.NewLegacyAmino()`
4242
* (cli) [\#6651](https://github.com/cosmos/cosmos-sdk/pull/6651) The `gentx` command has been improved. No longer are `--from` and `--name` flags required. Instead, a single argument, `name`, is required which refers to the key pair in the Keyring. In addition, an optional
4343
`--moniker` flag can be provided to override the moniker found in `config.toml`.
4444
* (api) [\#6426](https://github.com/cosmos/cosmos-sdk/pull/6426) The ability to start an out-of-process API REST server has now been removed. Instead, the API server is now started in-process along with the application and Tendermint. Configuration options have been added to `app.toml` to enable/disable the API server along with additional HTTP server options.

baseapp/baseapp_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ func defaultLogger() log.Logger {
7575
func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp {
7676
logger := defaultLogger()
7777
db := dbm.NewMemDB()
78-
codec := codec.New()
78+
codec := codec.NewLegacyAmino()
7979
registerTestCodec(codec)
8080
return NewBaseApp(name, logger, db, testTxDecoder(codec), options...)
8181
}
8282

8383
func registerTestCodec(cdc *codec.LegacyAmino) {
8484
// register Tx, Msg
85-
sdk.RegisterCodec(cdc)
85+
sdk.RegisterLegacyAminoCodec(cdc)
8686

8787
// register test types
8888
cdc.RegisterConcrete(&txTest{}, "cosmos-sdk/baseapp/txTest", nil)
@@ -384,7 +384,7 @@ func testChangeNameHelper(name string) func(*BaseApp) {
384384
// Test that txs can be unmarshalled and read and that
385385
// correct error codes are returned when not
386386
func TestTxDecoder(t *testing.T) {
387-
codec := codec.New()
387+
codec := codec.NewLegacyAmino()
388388
registerTestCodec(codec)
389389

390390
app := newBaseApp(t.Name())
@@ -810,7 +810,7 @@ func TestCheckTx(t *testing.T) {
810810
app.InitChain(abci.RequestInitChain{})
811811

812812
// Create same codec used in txDecoder
813-
codec := codec.New()
813+
codec := codec.NewLegacyAmino()
814814
registerTestCodec(codec)
815815

816816
for i := int64(0); i < nTxs; i++ {
@@ -857,7 +857,7 @@ func TestDeliverTx(t *testing.T) {
857857
app.InitChain(abci.RequestInitChain{})
858858

859859
// Create same codec used in txDecoder
860-
codec := codec.New()
860+
codec := codec.NewLegacyAmino()
861861
registerTestCodec(codec)
862862

863863
nBlocks := 3
@@ -912,7 +912,7 @@ func TestMultiMsgDeliverTx(t *testing.T) {
912912
app := setupBaseApp(t, anteOpt, routerOpt)
913913

914914
// Create same codec used in txDecoder
915-
codec := codec.New()
915+
codec := codec.NewLegacyAmino()
916916
registerTestCodec(codec)
917917

918918
// run a multi-msg tx
@@ -993,7 +993,7 @@ func TestSimulateTx(t *testing.T) {
993993
app.InitChain(abci.RequestInitChain{})
994994

995995
// Create same codec used in txDecoder
996-
cdc := codec.New()
996+
cdc := codec.NewLegacyAmino()
997997
registerTestCodec(cdc)
998998

999999
nBlocks := 3
@@ -1128,7 +1128,7 @@ func TestRunInvalidTransaction(t *testing.T) {
11281128
tx.Msgs = append(tx.Msgs, msgNoDecode{})
11291129

11301130
// new codec so we can encode the tx, but we shouldn't be able to decode
1131-
newCdc := codec.New()
1131+
newCdc := codec.NewLegacyAmino()
11321132
registerTestCodec(newCdc)
11331133
newCdc.RegisterConcrete(&msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode", nil)
11341134

@@ -1385,7 +1385,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
13851385
bapp.Router().AddRoute(r)
13861386
}
13871387

1388-
cdc := codec.New()
1388+
cdc := codec.NewLegacyAmino()
13891389
app := setupBaseApp(t, anteOpt, routerOpt)
13901390

13911391
app.InitChain(abci.RequestInitChain{})
@@ -1485,7 +1485,7 @@ func TestGasConsumptionBadTx(t *testing.T) {
14851485
bapp.Router().AddRoute(r)
14861486
}
14871487

1488-
cdc := codec.New()
1488+
cdc := codec.NewLegacyAmino()
14891489
registerTestCodec(cdc)
14901490

14911491
app := setupBaseApp(t, anteOpt, routerOpt)
@@ -1698,7 +1698,7 @@ func TestWithRouter(t *testing.T) {
16981698
app.InitChain(abci.RequestInitChain{})
16991699

17001700
// Create same codec used in txDecoder
1701-
codec := codec.New()
1701+
codec := codec.NewLegacyAmino()
17021702
registerTestCodec(codec)
17031703

17041704
nBlocks := 3

client/keys/codec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
var KeysCdc *codec.LegacyAmino
1010

1111
func init() {
12-
KeysCdc = codec.New()
12+
KeysCdc = codec.NewLegacyAmino()
1313
cryptocodec.RegisterCrypto(KeysCdc)
1414
KeysCdc.Seal()
1515
}

codec/amino.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (cdc *LegacyAmino) Seal() {
2323
cdc.Amino.Seal()
2424
}
2525

26-
func New() *LegacyAmino {
26+
func NewLegacyAmino() *LegacyAmino {
2727
return &LegacyAmino{amino.NewCodec()}
2828
}
2929

codec/amino_codec_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func createTestCodec() *codec.LegacyAmino {
17-
cdc := codec.New()
17+
cdc := codec.NewLegacyAmino()
1818

1919
cdc.RegisterInterface((*testdata.Animal)(nil), nil)
2020
cdc.RegisterConcrete(testdata.Dog{}, "testdata/Dog", nil)

codec/legacy/codec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
var Cdc *codec.LegacyAmino
1313

1414
func init() {
15-
Cdc = codec.New()
15+
Cdc = codec.NewLegacyAmino()
1616
cryptocodec.RegisterCrypto(Cdc)
1717
codec.RegisterEvidences(Cdc)
1818
Cdc.Seal()

crypto/codec/amino.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
var amino *codec.LegacyAmino
1414

1515
func init() {
16-
amino = codec.New()
16+
amino = codec.NewLegacyAmino()
1717
RegisterCrypto(amino)
1818
}
1919

crypto/keyring/codec.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
var CryptoCdc *codec.LegacyAmino
1111

1212
func init() {
13-
CryptoCdc = codec.New()
13+
CryptoCdc = codec.NewLegacyAmino()
1414
cryptocodec.RegisterCrypto(CryptoCdc)
15-
RegisterCodec(CryptoCdc)
15+
RegisterLegacyAminoCodec(CryptoCdc)
1616
CryptoCdc.Seal()
1717
}
1818

19-
// RegisterCodec registers concrete types and interfaces on the given codec.
20-
func RegisterCodec(cdc *codec.LegacyAmino) {
19+
// RegisterLegacyAminoCodec registers concrete types and interfaces on the given codec.
20+
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
2121
cdc.RegisterInterface((*Info)(nil), nil)
2222
cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params", nil)
2323
cdc.RegisterConcrete(localInfo{}, "crypto/keys/localInfo", nil)

crypto/ledger/amino.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
66
)
77

8-
var cdc = codec.New()
8+
var cdc = codec.NewLegacyAmino()
99

1010
func init() {
1111
RegisterAmino(cdc)

crypto/types/multisig/threshold_pubkey_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestMultiSigMigration(t *testing.T) {
187187
multisigKey := multisig.NewPubKeyMultisigThreshold(2, pkSet)
188188
signBytesFn := func(mode signing.SignMode) ([]byte, error) { return msg, nil }
189189

190-
cdc := codec.New()
190+
cdc := codec.NewLegacyAmino()
191191

192192
err := multisig.AddSignatureFromPubKey(multisignature, sigs[0], pkSet[0], pkSet)
193193

docs/architecture/adr-011-generalize-genesis-accounts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The `auth` codec definition:
8080
var ModuleCdc *codec.LegacyAmino
8181

8282
func init() {
83-
ModuleCdc = codec.New()
83+
ModuleCdc = codec.NewLegacyAmino()
8484
// register module msg's and Account interface
8585
...
8686
// leave the codec unsealed

docs/basics/app-anatomy.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ See an example of `BeginBlocker` and `EndBlocker` functions from [`gaia`](https:
106106

107107
### Register Codec
108108

109-
The `MakeCodec` function is the last important function of the `app.go` file. The goal of this function is to instantiate a [codec `cdc`](../core/encoding.md) (e.g. amino) initialize the codec of the SDK and each of the application's modules using the `RegisterCodec` function.
109+
The `MakeCodec` function is the last important function of the `app.go` file. The goal of this function is to instantiate a [codec `cdc`](../core/encoding.md) (e.g. amino) initialize the codec of the SDK and each of the application's modules using the `RegisterLegacyAminoCodec` function.
110110

111-
To register the application's modules, the `MakeCodec` function calls `RegisterCodec` on `ModuleBasics`. `ModuleBasics` is a [basic manager](../building-modules/module-manager.md#basicmanager) which lists all of the application's modules. It is instanciated in the `init()` function, and only serves to easily register non-dependant elements of application's modules (such as codec). To learn more about the basic module manager, click [here](../building-modules/module-manager.md#basicmanager).
111+
To register the application's modules, the `MakeCodec` function calls `RegisterLegacyAminoCodec` on `ModuleBasics`. `ModuleBasics` is a [basic manager](../building-modules/module-manager.md#basicmanager) which lists all of the application's modules. It is instanciated in the `init()` function, and only serves to easily register non-dependant elements of application's modules (such as codec). To learn more about the basic module manager, click [here](../building-modules/module-manager.md#basicmanager).
112112

113113
See an example of a `MakeCodec` from [`gaia`](https://github.com/cosmos/gaia):
114114

docs/building-modules/module-manager.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The `AppModuleBasic` interface defines the independent methods modules need to i
3434
Let us go through the methods:
3535

3636
- `Name()`: Returns the name of the module as a `string`.
37-
- `RegisterCodec(*codec.LegacyAmino)`: Registers the `amino` codec for the module, which is used to marhsal and unmarshal structs to/from `[]byte` in order to persist them in the moduel's `KVStore`.
37+
- `RegisterLegacyAminoCodec(*codec.LegacyAmino)`: Registers the `amino` codec for the module, which is used to marhsal and unmarshal structs to/from `[]byte` in order to persist them in the moduel's `KVStore`.
3838
- `DefaultGenesis()`: Returns a default [`GenesisState`](./genesis.md#genesisstate) for the module, marshalled to `json.RawMessage`. The default `GenesisState` need to be defined by the module developer and is primarily used for testing.
3939
- `ValidateGenesis(json.RawMessage)`: Used to validate the `GenesisState` defined by a module, given in its `json.RawMessage` form. It will usually unmarshall the `json` before running a custom [`ValidateGenesis`](./genesis.md#validategenesis) function defined by the module developer.
4040
- `RegisterRESTRoutes(client.Context, *mux.Router)`: Registers the REST routes for the module. These routes will be used to map REST request to the module in order to process them. See [../interfaces/rest.md] for more.
@@ -108,7 +108,7 @@ The `BasicManager` is a structure that lists all the `AppModuleBasic` of an appl
108108
It implements the following methods:
109109

110110
- `NewBasicManager(modules ...AppModuleBasic)`: Constructor function. It takes a list of the application's `AppModuleBasic` and builds a new `BasicManager`. This function is generally called in the `init()` function of [`app.go`](../basics/app-anatomy.md#core-application-file) to quickly initialize the independent elements of the application's modules (click [here](https://github.com/cosmos/gaia/blob/master/app/app.go#L59-L74) to see an example).
111-
- `RegisterCodec(cdc *codec.LegacyAmino)`: Registers the [`codec`s](../core/encoding.md) of each of the application's `AppModuleBasic`. This function is usually called early on in the [application's construction](../basics/app-anatomy.md#constructor).
111+
- `RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)`: Registers the [`codec`s](../core/encoding.md) of each of the application's `AppModuleBasic`. This function is usually called early on in the [application's construction](../basics/app-anatomy.md#constructor).
112112
- `DefaultGenesis()`: Provides default genesis information for modules in the application by calling the [`DefaultGenesis()`](./genesis.md#defaultgenesis) function of each module. It is used to construct a default genesis file for the application.
113113
- `ValidateGenesis(genesis map[string]json.RawMessage)`: Validates the genesis information modules by calling the [`ValidateGenesis()`](./genesis.md#validategenesis) function of each module.
114114
- `RegisterRESTRoutes(ctx client.Context, rtr *mux.Router)`: Registers REST routes for modules by calling the [`RegisterRESTRoutes`](./module-interfaces.md#register-routes) function of each module. This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md).

docs/cn/basics/app-anatomy.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ See an example of an `InitChainer` from [`gaia`](https://github.com/cosmos/gaia)
104104

105105
### Register Codec
106106

107-
MakeCodec 函数是 app.go 文件的最后一个重要功能。 此函数的目的是使用 RegisterCodec 函数实例化 codec`cdc`,例如 amino 初始化 SDK 的编解码器以及每个应用程序的模块。
107+
MakeCodec 函数是 app.go 文件的最后一个重要功能。 此函数的目的是使用 RegisterLegacyAminoCodec 函数实例化 codec`cdc`,例如 amino 初始化 SDK 的编解码器以及每个应用程序的模块。
108108

109-
为了注册应用程序的模块,`MakeCodec` 函数在 `ModuleBasics` 上调用 `RegisterCodec``ModuleBasics` 是一个基本管理器,其中列出了应用程序的所有模块。 它在`init()`函数中得到实例化,仅用于注册应用程序模块的非依赖元素(例如编解码器)。 要了解有关基本模块管理器的更多信息,请点击[这里](https://docs.cosmos.network/master/building-modules/module-manager.html#basicmanager)
109+
为了注册应用程序的模块,`MakeCodec` 函数在 `ModuleBasics` 上调用 `RegisterLegacyAminoCodec``ModuleBasics` 是一个基本管理器,其中列出了应用程序的所有模块。 它在`init()`函数中得到实例化,仅用于注册应用程序模块的非依赖元素(例如编解码器)。 要了解有关基本模块管理器的更多信息,请点击[这里](https://docs.cosmos.network/master/building-modules/module-manager.html#basicmanager)
110110

111111
请参阅 [gaia](https://github.com/cosmos/gaia) 中的 `MakeCodec` 示例:
112112

docs/core/encoding.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ for their types, they may use an Amino codec directly.
5656

5757
Every module uses an Amino codec to serialize types and interfaces. This codec typically
5858
has types and interfaces registered in that module's domain only (e.g. messages),
59-
but there are exceptions like `x/gov`. Each module exposes a `RegisterCodec` function
59+
but there are exceptions like `x/gov`. Each module exposes a `RegisterLegacyAminoCodec` function
6060
that allows a user to provide a codec and have all the types registered. An application
6161
will call this method for each necessary module.
6262

server/tm_cmds.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ against which this app has been compiled.
130130
}
131131

132132
func printlnJSON(v interface{}) error {
133-
cdc := codec.New()
133+
cdc := codec.NewLegacyAmino()
134134
cryptocodec.RegisterCrypto(cdc)
135135

136136
marshalled, err := cdc.MarshalJSON(v)

simapp/encoding.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
// MakeEncodingConfig creates an EncodingConfig for testing
99
func MakeEncodingConfig() params.EncodingConfig {
1010
encodingConfig := params.MakeEncodingConfig()
11-
std.RegisterCodec(encodingConfig.Amino)
11+
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
1212
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
13-
ModuleBasics.RegisterCodec(encodingConfig.Amino)
13+
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
1414
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
1515
return encodingConfig
1616
}

simapp/params/amino.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
1212
func MakeEncodingConfig() EncodingConfig {
13-
cdc := codec.New()
13+
cdc := codec.NewLegacyAmino()
1414
interfaceRegistry := types.NewInterfaceRegistry()
1515
marshaler := codec.NewAminoCodec(cdc)
1616

simapp/params/proto.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
1313
func MakeEncodingConfig() EncodingConfig {
14-
amino := codec.New()
14+
amino := codec.NewLegacyAmino()
1515
interfaceRegistry := types.NewInterfaceRegistry()
1616
marshaler := codec.NewProtoCodec(interfaceRegistry)
1717
txCfg := tx.NewTxConfig(marshaler, std.DefaultPublicKeyCodec{}, tx.DefaultSignModes)

simapp/utils_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
)
1616

1717
func makeCodec(bm module.BasicManager) *codec.LegacyAmino {
18-
cdc := codec.New()
18+
cdc := codec.NewLegacyAmino()
1919

20-
bm.RegisterCodec(cdc)
21-
std.RegisterCodec(cdc)
20+
bm.RegisterLegacyAminoCodec(cdc)
21+
std.RegisterLegacyAminoCodec(cdc)
2222

2323
return cdc
2424
}

std/codec.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
99
)
1010

11-
func RegisterCodec(cdc *codec.LegacyAmino) {
12-
vesting.RegisterCodec(cdc)
13-
sdk.RegisterCodec(cdc)
11+
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
12+
vesting.RegisterLegacyAminoCodec(cdc)
13+
sdk.RegisterLegacyAminoCodec(cdc)
1414
cryptocodec.RegisterCrypto(cdc)
1515
}
1616

tests/mocks/types_module_module.go

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/codec.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"github.com/cosmos/cosmos-sdk/codec"
77
)
88

9-
// RegisterCodec registers the sdk message type.
10-
func RegisterCodec(cdc *codec.LegacyAmino) {
9+
// RegisterLegacyAminoCodec registers the sdk message type.
10+
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
1111
cdc.RegisterInterface((*Msg)(nil), nil)
1212
cdc.RegisterInterface((*Tx)(nil), nil)
1313
}

0 commit comments

Comments
 (0)