Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename RegisterCodec to RegisterLegacyAminoCodec #7243

Merged
merged 11 commits into from
Sep 7, 2020
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]

### Client Breaking

* (modules) [\#7243](https://github.com/cosmos/cosmos-sdk/pull/7243) Rename `RegisterCodec` to `RegisterLegacyAminoCodec` and `codec.New()` is now renamed to `codec.NewLegacyAmino()`
* (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
`--moniker` flag can be provided to override the moniker found in `config.toml`.
* (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.
Expand Down
22 changes: 11 additions & 11 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func defaultLogger() log.Logger {
func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp {
logger := defaultLogger()
db := dbm.NewMemDB()
codec := codec.New()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)
return NewBaseApp(name, logger, db, testTxDecoder(codec), options...)
}

func registerTestCodec(cdc *codec.LegacyAmino) {
// register Tx, Msg
sdk.RegisterCodec(cdc)
sdk.RegisterLegacyAminoCodec(cdc)

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

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

// Create same codec used in txDecoder
codec := codec.New()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)

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

// Create same codec used in txDecoder
codec := codec.New()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)

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

// Create same codec used in txDecoder
codec := codec.New()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)

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

// Create same codec used in txDecoder
cdc := codec.New()
cdc := codec.NewLegacyAmino()
registerTestCodec(cdc)

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

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

Expand Down Expand Up @@ -1385,7 +1385,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
bapp.Router().AddRoute(r)
}

cdc := codec.New()
cdc := codec.NewLegacyAmino()
app := setupBaseApp(t, anteOpt, routerOpt)

app.InitChain(abci.RequestInitChain{})
Expand Down Expand Up @@ -1485,7 +1485,7 @@ func TestGasConsumptionBadTx(t *testing.T) {
bapp.Router().AddRoute(r)
}

cdc := codec.New()
cdc := codec.NewLegacyAmino()
registerTestCodec(cdc)

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

// Create same codec used in txDecoder
codec := codec.New()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)

nBlocks := 3
Expand Down
2 changes: 1 addition & 1 deletion client/keys/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
var KeysCdc *codec.LegacyAmino

func init() {
KeysCdc = codec.New()
KeysCdc = codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(KeysCdc)
KeysCdc.Seal()
}
Expand Down
2 changes: 1 addition & 1 deletion codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (cdc *LegacyAmino) Seal() {
cdc.Amino.Seal()
}

func New() *LegacyAmino {
func NewLegacyAmino() *LegacyAmino {
return &LegacyAmino{amino.NewCodec()}
}

Expand Down
2 changes: 1 addition & 1 deletion codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func createTestCodec() *codec.LegacyAmino {
cdc := codec.New()
cdc := codec.NewLegacyAmino()

cdc.RegisterInterface((*testdata.Animal)(nil), nil)
cdc.RegisterConcrete(testdata.Dog{}, "testdata/Dog", nil)
Expand Down
2 changes: 1 addition & 1 deletion codec/legacy/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Cdc *codec.LegacyAmino

func init() {
Cdc = codec.New()
Cdc = codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(Cdc)
codec.RegisterEvidences(Cdc)
Cdc.Seal()
Expand Down
2 changes: 1 addition & 1 deletion crypto/codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var amino *codec.LegacyAmino

func init() {
amino = codec.New()
amino = codec.NewLegacyAmino()
RegisterCrypto(amino)
}

Expand Down
8 changes: 4 additions & 4 deletions crypto/keyring/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
var CryptoCdc *codec.LegacyAmino

func init() {
CryptoCdc = codec.New()
CryptoCdc = codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(CryptoCdc)
RegisterCodec(CryptoCdc)
RegisterLegacyAminoCodec(CryptoCdc)
CryptoCdc.Seal()
}

// RegisterCodec registers concrete types and interfaces on the given codec.
func RegisterCodec(cdc *codec.LegacyAmino) {
// RegisterLegacyAminoCodec registers concrete types and interfaces on the given codec.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterInterface((*Info)(nil), nil)
cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params", nil)
cdc.RegisterConcrete(localInfo{}, "crypto/keys/localInfo", nil)
Expand Down
2 changes: 1 addition & 1 deletion crypto/ledger/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
)

var cdc = codec.New()
var cdc = codec.NewLegacyAmino()

func init() {
RegisterAmino(cdc)
Expand Down
2 changes: 1 addition & 1 deletion crypto/types/multisig/threshold_pubkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestMultiSigMigration(t *testing.T) {
multisigKey := multisig.NewPubKeyMultisigThreshold(2, pkSet)
signBytesFn := func(mode signing.SignMode) ([]byte, error) { return msg, nil }

cdc := codec.New()
cdc := codec.NewLegacyAmino()

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

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/adr-011-generalize-genesis-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The `auth` codec definition:
var ModuleCdc *codec.LegacyAmino

func init() {
ModuleCdc = codec.New()
ModuleCdc = codec.NewLegacyAmino()
// register module msg's and Account interface
...
// leave the codec unsealed
Expand Down
4 changes: 2 additions & 2 deletions docs/basics/app-anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ See an example of `BeginBlocker` and `EndBlocker` functions from [`gaia`](https:

### Register Codec

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.
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.

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).
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).

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

Expand Down
4 changes: 2 additions & 2 deletions docs/building-modules/module-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The `AppModuleBasic` interface defines the independent methods modules need to i
Let us go through the methods:

- `Name()`: Returns the name of the module as a `string`.
- `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`.
- `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`.
- `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.
- `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.
- `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.
Expand Down Expand Up @@ -108,7 +108,7 @@ The `BasicManager` is a structure that lists all the `AppModuleBasic` of an appl
It implements the following methods:

- `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).
- `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).
- `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).
- `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.
- `ValidateGenesis(genesis map[string]json.RawMessage)`: Validates the genesis information modules by calling the [`ValidateGenesis()`](./genesis.md#validategenesis) function of each module.
- `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).
Expand Down
4 changes: 2 additions & 2 deletions docs/cn/basics/app-anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ See an example of an `InitChainer` from [`gaia`](https://github.com/cosmos/gaia)

### Register Codec

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/core/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for their types, they may use an Amino codec directly.

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

Expand Down
2 changes: 1 addition & 1 deletion server/tm_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ against which this app has been compiled.
}

func printlnJSON(v interface{}) error {
cdc := codec.New()
cdc := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(cdc)

marshalled, err := cdc.MarshalJSON(v)
Expand Down
4 changes: 2 additions & 2 deletions simapp/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterCodec(encodingConfig.Amino)
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterCodec(encodingConfig.Amino)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
2 changes: 1 addition & 1 deletion simapp/params/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
cdc := codec.New()
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewAminoCodec(cdc)

Expand Down
2 changes: 1 addition & 1 deletion simapp/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.New()
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, std.DefaultPublicKeyCodec{}, tx.DefaultSignModes)
Expand Down
6 changes: 3 additions & 3 deletions simapp/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

func makeCodec(bm module.BasicManager) *codec.LegacyAmino {
cdc := codec.New()
cdc := codec.NewLegacyAmino()

bm.RegisterCodec(cdc)
std.RegisterCodec(cdc)
bm.RegisterLegacyAminoCodec(cdc)
std.RegisterLegacyAminoCodec(cdc)

return cdc
}
Expand Down
6 changes: 3 additions & 3 deletions std/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

func RegisterCodec(cdc *codec.LegacyAmino) {
vesting.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
vesting.RegisterLegacyAminoCodec(cdc)
sdk.RegisterLegacyAminoCodec(cdc)
cryptocodec.RegisterCrypto(cdc)
}

Expand Down
36 changes: 18 additions & 18 deletions tests/mocks/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
)

// RegisterCodec registers the sdk message type.
func RegisterCodec(cdc *codec.LegacyAmino) {
// RegisterLegacyAminoCodec registers the sdk message type.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterInterface((*Msg)(nil), nil)
cdc.RegisterInterface((*Tx)(nil), nil)
}
Expand Down
Loading