diff --git a/PENDING.md b/PENDING.md index 33b60198c..6d6754dc5 100644 --- a/PENDING.md +++ b/PENDING.md @@ -45,6 +45,7 @@ BREAKING CHANGES * [tools] Removed gocyclo [#2211](https://github.com/cosmos/cosmos-sdk/issues/2211) * [baseapp] Remove `SetTxDecoder` in favor of requiring the decoder be set in baseapp initialization. [#1441](https://github.com/cosmos/cosmos-sdk/issues/1441) * [store] Change storeInfo within the root multistore to use tmhash instead of ripemd160 \#2308 + * [codec] \#2324 All referrences to wire have been renamed to codec. Additionally, wire.NewCodec is now codec.New(). * Tendermint diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 10d9f55f7..1f9944014 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -14,10 +14,10 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/wire" ) // Key to store the header in the DB itself. @@ -331,7 +331,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc } // Encode with json - value := wire.Cdc.MustMarshalBinary(result) + value := codec.Cdc.MustMarshalBinary(result) return abci.ResponseQuery{ Code: uint32(sdk.ABCICodeOK), Value: value, diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index b87162786..8ce69f0a1 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -14,8 +14,8 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) var ( @@ -34,14 +34,14 @@ func defaultLogger() log.Logger { func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp { logger := defaultLogger() db := dbm.NewMemDB() - codec := wire.NewCodec() + codec := codec.New() registerTestCodec(codec) return NewBaseApp(name, logger, db, testTxDecoder(codec), options...) } -func registerTestCodec(cdc *wire.Codec) { +func registerTestCodec(cdc *codec.Codec) { // register Tx, Msg - sdk.RegisterWire(cdc) + sdk.RegisterCodec(cdc) // register test types cdc.RegisterConcrete(&txTest{}, "cosmos-sdk/baseapp/txTest", nil) @@ -350,7 +350,7 @@ func (msg msgCounter2) ValidateBasic() sdk.Error { } // amino decode -func testTxDecoder(cdc *wire.Codec) sdk.TxDecoder { +func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, sdk.Error) { var tx txTest if len(txBytes) == 0 { @@ -448,7 +448,7 @@ func TestCheckTx(t *testing.T) { app.InitChain(abci.RequestInitChain{}) // Create same codec used in txDecoder - codec := wire.NewCodec() + codec := codec.New() registerTestCodec(codec) for i := int64(0); i < nTxs; i++ { @@ -489,7 +489,7 @@ func TestDeliverTx(t *testing.T) { app := setupBaseApp(t, anteOpt, routerOpt) // Create same codec used in txDecoder - codec := wire.NewCodec() + codec := codec.New() registerTestCodec(codec) nBlocks := 3 @@ -532,7 +532,7 @@ func TestMultiMsgDeliverTx(t *testing.T) { app := setupBaseApp(t, anteOpt, routerOpt) // Create same codec used in txDecoder - codec := wire.NewCodec() + codec := codec.New() registerTestCodec(codec) // run a multi-msg tx @@ -613,8 +613,8 @@ func TestSimulateTx(t *testing.T) { app.InitChain(abci.RequestInitChain{}) // Create same codec used in txDecoder - codec := wire.NewCodec() - registerTestCodec(codec) + cdc := codec.New() + registerTestCodec(cdc) nBlocks := 3 for blockN := 0; blockN < nBlocks; blockN++ { @@ -634,7 +634,7 @@ func TestSimulateTx(t *testing.T) { require.Equal(t, gasConsumed, result.GasUsed) // simulate by calling Query with encoded tx - txBytes, err := codec.MarshalBinary(tx) + txBytes, err := cdc.MarshalBinary(tx) require.Nil(t, err) query := abci.RequestQuery{ Path: "/app/simulate", @@ -644,7 +644,7 @@ func TestSimulateTx(t *testing.T) { require.True(t, queryResult.IsOK(), queryResult.Log) var res sdk.Result - wire.Cdc.MustUnmarshalBinary(queryResult.Value, &res) + codec.Cdc.MustUnmarshalBinary(queryResult.Value, &res) require.Nil(t, err, "Result unmarshalling failed") require.True(t, res.IsOK(), res.Log) require.Equal(t, gasConsumed, res.GasUsed, res.Log) @@ -721,7 +721,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 := wire.NewCodec() + newCdc := codec.New() registerTestCodec(newCdc) newCdc.RegisterConcrete(&msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode", nil) diff --git a/client/context/context.go b/client/context/context.go index 3e785a28e..0983c970f 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -6,7 +6,7 @@ import ( "io" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/spf13/viper" @@ -22,7 +22,7 @@ const ctxAccStoreName = "acc" // CLIContext implements a typical CLI context created in SDK modules for // transaction handling and queries. type CLIContext struct { - Codec *wire.Codec + Codec *codec.Codec AccDecoder auth.AccountDecoder Client rpcclient.Client Logger io.Writer @@ -98,7 +98,7 @@ func createCertifier() tmlite.Certifier { } // WithCodec returns a copy of the context with an updated codec. -func (ctx CLIContext) WithCodec(cdc *wire.Codec) CLIContext { +func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext { ctx.Codec = cdc return ctx } diff --git a/client/context/query.go b/client/context/query.go index fc35e5351..30cd2db30 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -12,8 +12,8 @@ import ( "strings" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" - "github.com/cosmos/cosmos-sdk/wire" abci "github.com/tendermint/tendermint/abci/types" cmn "github.com/tendermint/tendermint/libs/common" tmliteProxy "github.com/tendermint/tendermint/lite/proxy" @@ -343,7 +343,7 @@ func (ctx CLIContext) verifyProof(path string, resp abci.ResponseQuery) error { } var multiStoreProof store.MultiStoreProof - cdc := wire.NewCodec() + cdc := codec.New() err = cdc.UnmarshalBinary(resp.Proof, &multiStoreProof) if err != nil { return errors.Wrap(err, "failed to unmarshalBinary rangeProof") diff --git a/client/keys/wire.go b/client/keys/codec.go similarity index 70% rename from client/keys/wire.go rename to client/keys/codec.go index a163f995a..6bbb16850 100644 --- a/client/keys/wire.go +++ b/client/keys/codec.go @@ -1,14 +1,14 @@ package keys import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) -var cdc *wire.Codec +var cdc *codec.Codec func init() { - cdc = wire.NewCodec() - wire.RegisterCrypto(cdc) + cdc = codec.New() + codec.RegisterCrypto(cdc) } // marshal keys diff --git a/client/lcd/wire.go b/client/lcd/codec.go similarity index 100% rename from client/lcd/wire.go rename to client/lcd/codec.go diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index b3c27bfba..312ac397b 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -22,9 +22,9 @@ import ( client "github.com/cosmos/cosmos-sdk/client" keys "github.com/cosmos/cosmos-sdk/client/keys" rpc "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" tests "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" "github.com/cosmos/cosmos-sdk/x/gov" @@ -61,7 +61,7 @@ func TestKeys(t *testing.T) { require.Equal(t, http.StatusOK, res.StatusCode, body) var resp keys.KeyOutput - err = wire.Cdc.UnmarshalJSON([]byte(body), &resp) + err = codec.Cdc.UnmarshalJSON([]byte(body), &resp) require.Nil(t, err, body) addr2Bech32 := resp.Address @@ -181,7 +181,7 @@ func TestBlock(t *testing.T) { res, body = Request(t, port, "GET", "/blocks/1", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - err = wire.Cdc.UnmarshalJSON([]byte(body), &resultBlock) + err = codec.Cdc.UnmarshalJSON([]byte(body), &resultBlock) require.Nil(t, err, "Couldn't parse block") require.NotEqual(t, ctypes.ResultBlock{}, resultBlock) diff --git a/client/lcd/root.go b/client/lcd/root.go index f18ee5dfd..088344b84 100644 --- a/client/lcd/root.go +++ b/client/lcd/root.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest" bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest" gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest" @@ -27,7 +27,7 @@ import ( // ServeCommand will generate a long-running rest server // (aka Light Client Daemon) that exposes functionality similar // to the cli, but over rest -func ServeCommand(cdc *wire.Codec) *cobra.Command { +func ServeCommand(cdc *codec.Codec) *cobra.Command { flagListenAddr := "laddr" flagCORS := "cors" flagMaxOpenConnections := "max-open" @@ -71,7 +71,7 @@ func ServeCommand(cdc *wire.Codec) *cobra.Command { return cmd } -func createHandler(cdc *wire.Codec) http.Handler { +func createHandler(cdc *codec.Codec) http.Handler { r := mux.NewRouter() kb, err := keys.GetKeyBase() //XXX diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 593690407..1075c078b 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -15,11 +15,11 @@ import ( "github.com/cosmos/cosmos-sdk/client" keys "github.com/cosmos/cosmos-sdk/client/keys" gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app" + "github.com/cosmos/cosmos-sdk/codec" crkeys "github.com/cosmos/cosmos-sdk/crypto/keys" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/spf13/viper" @@ -176,7 +176,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress genesisState.StakeData.Pool.LooseTokens = genesisState.StakeData.Pool.LooseTokens.Add(sdk.NewDec(100)) } - appState, err := wire.MarshalJSONIndent(cdc, genesisState) + appState, err := codec.MarshalJSONIndent(cdc, genesisState) require.NoError(t, err) genDoc.AppState = appState @@ -245,7 +245,7 @@ func startTM( // startLCD starts the LCD. // // NOTE: This causes the thread to block. -func startLCD(logger log.Logger, listenAddr string, cdc *wire.Codec) (net.Listener, error) { +func startLCD(logger log.Logger, listenAddr string, cdc *codec.Codec) (net.Listener, error) { return tmrpc.StartHTTPServer(listenAddr, createHandler(cdc), logger, tmrpc.Config{}) } diff --git a/client/rpc/block.go b/client/rpc/block.go index d16f38342..4e6ed0c5f 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -42,7 +42,7 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) { } // TODO move maarshalling into cmd/rest functions - // output, err := tmwire.MarshalJSON(res) + // output, err := tmcodec.MarshalJSON(res) output, err := cdc.MarshalJSON(res) if err != nil { return nil, err diff --git a/client/rpc/wire.go b/client/rpc/codec.go similarity index 100% rename from client/rpc/wire.go rename to client/rpc/codec.go diff --git a/client/tx/query.go b/client/tx/query.go index f95776b10..20a455d79 100644 --- a/client/tx/query.go +++ b/client/tx/query.go @@ -16,13 +16,13 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" ) // QueryTxCmd implements the default command for a tx query. -func QueryTxCmd(cdc *wire.Codec) *cobra.Command { +func QueryTxCmd(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "tx [hash]", Short: "Matches this txhash over all committed blocks", @@ -51,7 +51,7 @@ func QueryTxCmd(cdc *wire.Codec) *cobra.Command { return cmd } -func queryTx(cdc *wire.Codec, cliCtx context.CLIContext, hashHexStr string, trustNode bool) ([]byte, error) { +func queryTx(cdc *codec.Codec, cliCtx context.CLIContext, hashHexStr string, trustNode bool) ([]byte, error) { hash, err := hex.DecodeString(hashHexStr) if err != nil { return nil, err @@ -72,10 +72,10 @@ func queryTx(cdc *wire.Codec, cliCtx context.CLIContext, hashHexStr string, trus return nil, err } - return wire.MarshalJSONIndent(cdc, info) + return codec.MarshalJSONIndent(cdc, info) } -func formatTxResult(cdc *wire.Codec, res *ctypes.ResultTx) (Info, error) { +func formatTxResult(cdc *codec.Codec, res *ctypes.ResultTx) (Info, error) { // TODO: verify the proof if requested tx, err := parseTx(cdc, res.Tx) if err != nil { @@ -98,7 +98,7 @@ type Info struct { Result abci.ResponseDeliverTx `json:"result"` } -func parseTx(cdc *wire.Codec, txBytes []byte) (sdk.Tx, error) { +func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { var tx auth.StdTx err := cdc.UnmarshalBinary(txBytes, &tx) @@ -112,7 +112,7 @@ func parseTx(cdc *wire.Codec, txBytes []byte) (sdk.Tx, error) { // REST // transaction query REST handler -func QueryTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc { +func QueryTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) hashHexStr := vars["hash"] diff --git a/client/tx/root.go b/client/tx/root.go index 7e18d5aae..19376a25b 100644 --- a/client/tx/root.go +++ b/client/tx/root.go @@ -5,11 +5,11 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) // AddCommands adds a number of tx-query related subcommands -func AddCommands(cmd *cobra.Command, cdc *wire.Codec) { +func AddCommands(cmd *cobra.Command, cdc *codec.Codec) { cmd.AddCommand( SearchTxCmd(cdc), QueryTxCmd(cdc), @@ -17,7 +17,7 @@ func AddCommands(cmd *cobra.Command, cdc *wire.Codec) { } // register REST routes -func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET") r.HandleFunc("/txs", SearchTxRequestHandlerFn(cliCtx, cdc)).Methods("GET") // r.HandleFunc("/txs/sign", SignTxRequstHandler).Methods("POST") diff --git a/client/tx/search.go b/client/tx/search.go index 06b3c0972..000dc57eb 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -9,8 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -24,7 +24,7 @@ const ( ) // default client command to search through tagged transactions -func SearchTxCmd(cdc *wire.Codec) *cobra.Command { +func SearchTxCmd(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "txs", Short: "Search for all transactions that match the given tags.", @@ -70,7 +70,7 @@ $ gaiacli tendermint txs --tag test1,test2 --any return cmd } -func searchTxs(cliCtx context.CLIContext, cdc *wire.Codec, tags []string) ([]Info, error) { +func searchTxs(cliCtx context.CLIContext, cdc *codec.Codec, tags []string) ([]Info, error) { if len(tags) == 0 { return nil, errors.New("must declare at least one tag to search") } @@ -103,7 +103,7 @@ func searchTxs(cliCtx context.CLIContext, cdc *wire.Codec, tags []string) ([]Inf } // parse the indexed txs into an array of Info -func FormatTxResults(cdc *wire.Codec, res []*ctypes.ResultTx) ([]Info, error) { +func FormatTxResults(cdc *codec.Codec, res []*ctypes.ResultTx) ([]Info, error) { var err error out := make([]Info, len(res)) for i := range res { @@ -119,7 +119,7 @@ func FormatTxResults(cdc *wire.Codec, res []*ctypes.ResultTx) ([]Info, error) { // REST // Search Tx REST Handler -func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { tag := r.FormValue("tag") if tag == "" { diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 7cf235b16..627fb5987 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -12,8 +12,8 @@ import ( tmtypes "github.com/tendermint/tendermint/types" bam "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/gov" @@ -36,7 +36,7 @@ var ( // Extended ABCI application type GaiaApp struct { *bam.BaseApp - cdc *wire.Codec + cdc *codec.Codec // keys to access the substores keyMain *sdk.KVStoreKey @@ -128,16 +128,16 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio } // custom tx codec -func MakeCodec() *wire.Codec { - var cdc = wire.NewCodec() - ibc.RegisterWire(cdc) - bank.RegisterWire(cdc) - stake.RegisterWire(cdc) - slashing.RegisterWire(cdc) - gov.RegisterWire(cdc) - auth.RegisterWire(cdc) - sdk.RegisterWire(cdc) - wire.RegisterCrypto(cdc) +func MakeCodec() *codec.Codec { + var cdc = codec.New() + ibc.RegisterCodec(cdc) + bank.RegisterCodec(cdc) + stake.RegisterCodec(cdc) + slashing.RegisterCodec(cdc) + gov.RegisterCodec(cdc) + auth.RegisterCodec(cdc) + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) return cdc } @@ -222,7 +222,7 @@ func (app *GaiaApp) ExportAppStateAndValidators() (appState json.RawMessage, val StakeData: stake.WriteGenesis(ctx, app.stakeKeeper), GovData: gov.WriteGenesis(ctx, app.govKeeper), } - appState, err = wire.MarshalJSONIndent(app.cdc, genState) + appState, err = codec.MarshalJSONIndent(app.cdc, genState) if err != nil { return nil, nil, err } diff --git a/cmd/gaia/app/app_test.go b/cmd/gaia/app/app_test.go index 63d650cef..0fb45863c 100644 --- a/cmd/gaia/app/app_test.go +++ b/cmd/gaia/app/app_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/stake" "github.com/stretchr/testify/require" @@ -25,7 +25,7 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error { StakeData: stake.DefaultGenesisState(), } - stateBytes, err := wire.MarshalJSONIndent(gapp.cdc, genesisState) + stateBytes, err := codec.MarshalJSONIndent(gapp.cdc, genesisState) if err != nil { return err } diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 10c7e4126..e19ee616a 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -6,10 +6,10 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/stake" @@ -92,7 +92,7 @@ type GaiaGenTx struct { // GaiaAppGenTx generates a Gaia genesis transaction. func GaiaAppGenTx( - cdc *wire.Codec, pk crypto.PubKey, genTxConfig config.GenTx, + cdc *codec.Codec, pk crypto.PubKey, genTxConfig config.GenTx, ) (appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { if genTxConfig.Name == "" { return nil, nil, tmtypes.GenesisValidator{}, errors.New("Must specify --name (validator moniker)") @@ -136,7 +136,7 @@ func GaiaAppGenTx( } // Generate a gaia genesis transaction without flags -func GaiaAppGenTxNF(cdc *wire.Codec, pk crypto.PubKey, addr sdk.AccAddress, name string) ( +func GaiaAppGenTxNF(cdc *codec.Codec, pk crypto.PubKey, addr sdk.AccAddress, name string) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { var bz []byte @@ -145,7 +145,7 @@ func GaiaAppGenTxNF(cdc *wire.Codec, pk crypto.PubKey, addr sdk.AccAddress, name Address: addr, PubKey: sdk.MustBech32ifyConsPub(pk), } - bz, err = wire.MarshalJSONIndent(cdc, gaiaGenTx) + bz, err = codec.MarshalJSONIndent(cdc, gaiaGenTx) if err != nil { return } @@ -160,7 +160,7 @@ func GaiaAppGenTxNF(cdc *wire.Codec, pk crypto.PubKey, addr sdk.AccAddress, name // Create the core parameters for genesis initialization for gaia // note that the pubkey input is this machines pubkey -func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState GenesisState, err error) { +func GaiaAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (genesisState GenesisState, err error) { if len(appGenTxs) == 0 { err = errors.New("must provide at least genesis transaction") @@ -280,13 +280,13 @@ func validateGenesisStateAccounts(accs []GenesisAccount) (err error) { } // GaiaAppGenState but with JSON -func GaiaAppGenStateJSON(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { +func GaiaAppGenStateJSON(cdc *codec.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { // create the final app state genesisState, err := GaiaAppGenState(cdc, appGenTxs) if err != nil { return nil, err } - appState, err = wire.MarshalJSONIndent(cdc, genesisState) + appState, err = codec.MarshalJSONIndent(cdc, genesisState) return } diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 43f35925e..3d9f86789 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -18,10 +18,10 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/cmd/gaia/app" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/stake" @@ -549,8 +549,8 @@ func executeGetAccount(t *testing.T, cmdStr string) auth.BaseAccount { require.NoError(t, err, "out %v, err %v", out, err) value := initRes["value"] var acc auth.BaseAccount - cdc := wire.NewCodec() - wire.RegisterCrypto(cdc) + cdc := codec.New() + codec.RegisterCrypto(cdc) err = cdc.UnmarshalJSON(value, &acc) require.NoError(t, err, "value %v, err %v", string(value), err) return acc diff --git a/cmd/gaia/cmd/gaiadebug/hack.go b/cmd/gaia/cmd/gaiadebug/hack.go index d0a0ad9d7..3ff2730f4 100644 --- a/cmd/gaia/cmd/gaiadebug/hack.go +++ b/cmd/gaia/cmd/gaiadebug/hack.go @@ -21,7 +21,7 @@ import ( bam "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" @@ -127,7 +127,7 @@ var ( // Extended ABCI application type GaiaApp struct { *bam.BaseApp - cdc *wire.Codec + cdc *codec.Codec // keys to access the substores keyMain *sdk.KVStoreKey @@ -204,15 +204,15 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp } // custom tx codec -func MakeCodec() *wire.Codec { - var cdc = wire.NewCodec() - ibc.RegisterWire(cdc) - bank.RegisterWire(cdc) - stake.RegisterWire(cdc) - slashing.RegisterWire(cdc) - auth.RegisterWire(cdc) - sdk.RegisterWire(cdc) - wire.RegisterCrypto(cdc) +func MakeCodec() *codec.Codec { + var cdc = codec.New() + ibc.RegisterCodec(cdc) + bank.RegisterCodec(cdc) + stake.RegisterCodec(cdc) + slashing.RegisterCodec(cdc) + auth.RegisterCodec(cdc) + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) cdc.Seal() return cdc } diff --git a/wire/wire.go b/codec/codec.go similarity index 93% rename from wire/wire.go rename to codec/codec.go index 683149c99..175eb89c1 100644 --- a/wire/wire.go +++ b/codec/codec.go @@ -1,4 +1,4 @@ -package wire +package codec import ( "bytes" @@ -11,7 +11,7 @@ import ( // amino codec to marshal/unmarshal type Codec = amino.Codec -func NewCodec() *Codec { +func New() *Codec { cdc := amino.NewCodec() return cdc } @@ -42,7 +42,7 @@ func MarshalJSONIndent(cdc *Codec, obj interface{}) ([]byte, error) { var Cdc *Codec func init() { - cdc := NewCodec() + cdc := New() RegisterCrypto(cdc) Cdc = cdc.Seal() } diff --git a/crypto/keys/wire.go b/crypto/keys/codec.go similarity index 100% rename from crypto/keys/wire.go rename to crypto/keys/codec.go diff --git a/docs/sdk/core/app2.md b/docs/sdk/core/app2.md index 9a689cca6..6477617fb 100644 --- a/docs/sdk/core/app2.md +++ b/docs/sdk/core/app2.md @@ -139,8 +139,8 @@ Amino can also be used for persistent storage of interfaces. To use Amino, simply create a codec, and then register types: ``` -func NewCodec() *wire.Codec { - cdc := wire.NewCodec() +func NewCodec() *codec.Codec { + cdc := codec.New() cdc.RegisterInterface((*sdk.Msg)(nil), nil) cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil) cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil) @@ -175,7 +175,7 @@ func (tx app2Tx) GetMsgs() []sdk.Msg { } // Amino decode app2Tx. Capable of decoding both MsgSend and MsgIssue -func tx2Decoder(cdc *wire.Codec) sdk.TxDecoder { +func tx2Decoder(cdc *codec.Codec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, sdk.Error) { var tx app2Tx err := cdc.UnmarshalBinary(txBytes, &tx) diff --git a/docs/sdk/core/examples/app2.go b/docs/sdk/core/examples/app2.go index 5f23abe07..837c9f44f 100644 --- a/docs/sdk/core/examples/app2.go +++ b/docs/sdk/core/examples/app2.go @@ -13,8 +13,8 @@ import ( "github.com/tendermint/tendermint/libs/log" bapp "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) const ( @@ -25,8 +25,8 @@ var ( issuer = ed25519.GenPrivKey().PubKey().Address() ) -func NewCodec() *wire.Codec { - cdc := wire.NewCodec() +func NewCodec() *codec.Codec { + cdc := codec.New() cdc.RegisterInterface((*sdk.Msg)(nil), nil) cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil) cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil) @@ -196,7 +196,7 @@ func (tx app2Tx) GetSignature() []byte { } // Amino decode app2Tx. Capable of decoding both MsgSend and MsgIssue -func tx2Decoder(cdc *wire.Codec) sdk.TxDecoder { +func tx2Decoder(cdc *codec.Codec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, sdk.Error) { var tx app2Tx err := cdc.UnmarshalBinary(txBytes, &tx) diff --git a/docs/sdk/core/examples/app3.go b/docs/sdk/core/examples/app3.go index 787c75d96..9a101c281 100644 --- a/docs/sdk/core/examples/app3.go +++ b/docs/sdk/core/examples/app3.go @@ -7,8 +7,8 @@ import ( "github.com/tendermint/tendermint/libs/log" bapp "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -51,12 +51,12 @@ func NewApp3(logger log.Logger, db dbm.DB) *bapp.BaseApp { } // Update codec from app2 to register imported modules -func UpdatedCodec() *wire.Codec { - cdc := wire.NewCodec() +func UpdatedCodec() *codec.Codec { + cdc := codec.New() cdc.RegisterInterface((*sdk.Msg)(nil), nil) cdc.RegisterConcrete(MsgSend{}, "example/MsgSend", nil) cdc.RegisterConcrete(MsgIssue{}, "example/MsgIssue", nil) - auth.RegisterWire(cdc) + auth.RegisterCodec(cdc) cryptoAmino.RegisterAmino(cdc) return cdc } diff --git a/docs/sdk/core/examples/app4.go b/docs/sdk/core/examples/app4.go index 620913bb6..e4fa515ee 100644 --- a/docs/sdk/core/examples/app4.go +++ b/docs/sdk/core/examples/app4.go @@ -7,8 +7,8 @@ import ( "github.com/tendermint/tendermint/libs/log" bapp "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -76,7 +76,7 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount, err error) { // InitChainer will set initial balances for accounts as well as initial coin metadata // MsgIssue can no longer be used to create new coin -func NewInitChainer(cdc *wire.Codec, accountMapper auth.AccountMapper) sdk.InitChainer { +func NewInitChainer(cdc *codec.Codec, accountMapper auth.AccountMapper) sdk.InitChainer { return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { stateJSON := req.AppStateBytes diff --git a/docs/sdk/sdk-by-examples/simple-governance/app-codec.md b/docs/sdk/sdk-by-examples/simple-governance/app-codec.md index 9d35b4363..d994ba19c 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/app-codec.md +++ b/docs/sdk/sdk-by-examples/simple-governance/app-codec.md @@ -5,13 +5,13 @@ Finally, we need to define the `MakeCodec()` function and register the concrete types and interface from the various modules. ```go -func MakeCodec() *wire.Codec { - var cdc = wire.NewCodec() - wire.RegisterCrypto(cdc) // Register crypto. - sdk.RegisterWire(cdc) // Register Msgs - bank.RegisterWire(cdc) - simplestake.RegisterWire(cdc) - simpleGov.RegisterWire(cdc) +func MakeCodec() *codec.Codec { + var cdc = codec.New() + codec.RegisterCrypto(cdc) // Register crypto. + sdk.RegisterCodec(cdc) // Register Msgs + bank.RegisterCodec(cdc) + simplestake.RegisterCodec(cdc) + simpleGov.RegisterCodec(cdc) // Register AppAccount cdc.RegisterInterface((*auth.Account)(nil), nil) diff --git a/docs/sdk/sdk-by-examples/simple-governance/app-rest.md b/docs/sdk/sdk-by-examples/simple-governance/app-rest.md index 7e8469ad6..828d52c85 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/app-rest.md +++ b/docs/sdk/sdk-by-examples/simple-governance/app-rest.md @@ -13,7 +13,7 @@ var SimpleGovAppInit = server.AppInit{ } // SimpleGovAppGenState sets up the app_state and appends the simpleGov app state -func SimpleGovAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { +func SimpleGovAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { appState, err = server.SimpleAppGenState(cdc, appGenTxs) if err != nil { return diff --git a/docs/sdk/sdk-by-examples/simple-governance/app-structure.md b/docs/sdk/sdk-by-examples/simple-governance/app-structure.md index 7cec5aa5c..ce9ba5fef 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/app-structure.md +++ b/docs/sdk/sdk-by-examples/simple-governance/app-structure.md @@ -28,7 +28,7 @@ Then, let us define the structure of our application. // Extended ABCI application type SimpleGovApp struct { *bam.BaseApp - cdc *wire.Codec + cdc *codec.Codec // keys to access the substores capKeyMainStore *sdk.KVStoreKey diff --git a/docs/sdk/sdk-by-examples/simple-governance/intro.md b/docs/sdk/sdk-by-examples/simple-governance/intro.md index ab4b5b6a5..fe1c7639e 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/intro.md +++ b/docs/sdk/sdk-by-examples/simple-governance/intro.md @@ -28,7 +28,7 @@ Before getting in the bulk of the code, we will start by some introductory conte + [Types](module-types.md) + [Keeper](module-keeper.md) + [Handler](module-handler.md) - + [Wire](module-wire.md) + + [Wire](module-codec.md) + [Errors](module-errors.md) + Command-Line Interface and Rest API * [Command-Line Interface](module-cli.md) diff --git a/docs/sdk/sdk-by-examples/simple-governance/module-cli.md b/docs/sdk/sdk-by-examples/simple-governance/module-cli.md index b7e3143e3..4cdf331a9 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/module-cli.md +++ b/docs/sdk/sdk-by-examples/simple-governance/module-cli.md @@ -14,7 +14,7 @@ The CLI builds on top of [Cobra](https://github.com/spf13/cobra). Here is the sc ) // Main command function. One function for each command. - func Command(codec *wire.Codec) *cobra.Command { + func Command(codec *codec.Codec) *cobra.Command { // Create the command to return command := &cobra.Command{ Use: "actual command", diff --git a/docs/sdk/sdk-by-examples/simple-governance/module-codec.md b/docs/sdk/sdk-by-examples/simple-governance/module-codec.md new file mode 100644 index 000000000..68b03b936 --- /dev/null +++ b/docs/sdk/sdk-by-examples/simple-governance/module-codec.md @@ -0,0 +1,13 @@ +## Codec + +**File: [`x/simple_governance/codec.go`](https://github.com/cosmos/cosmos-sdk/blob/fedekunze/module_tutorial/examples/simpleGov/x/simple_governance/codec.go)** + +The `codec.go` file allows developers to register the concrete message types of their module into the codec. In our case, we have two messages to declare: + +```go +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(SubmitProposalMsg{}, "simple_governance/SubmitProposalMsg", nil) + cdc.RegisterConcrete(VoteMsg{}, "simple_governance/VoteMsg", nil) +} +``` +Don't forget to call this function in `app.go` (see [Application - Bridging it all together](app-structure.md)) for more). \ No newline at end of file diff --git a/docs/sdk/sdk-by-examples/simple-governance/module-init.md b/docs/sdk/sdk-by-examples/simple-governance/module-init.md index d018b512f..33bdfd500 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/module-init.md +++ b/docs/sdk/sdk-by-examples/simple-governance/module-init.md @@ -7,7 +7,7 @@ cd x/ mkdir simple_governance cd simple_governance mkdir -p client/cli client/rest -touch client/cli/simple_governance.go client/rest/simple_governance.go errors.go handler.go handler_test.go keeper_keys.go keeper_test.go keeper.go test_common.go test_types.go types.go wire.go +touch client/cli/simple_governance.go client/rest/simple_governance.go errors.go handler.go handler_test.go keeper_keys.go keeper_test.go keeper.go test_common.go test_types.go types.go codec.go ``` Let us start by adding the files we will need. Your module's folder should look something like that: @@ -25,7 +25,7 @@ x ├─── keeper_keys.go ├─── keeper.go ├─── types.go - └─── wire.go + └─── codec.go ``` Let us go into the detail of each of these files. \ No newline at end of file diff --git a/docs/sdk/sdk-by-examples/simple-governance/module-keeper.md b/docs/sdk/sdk-by-examples/simple-governance/module-keeper.md index 851593a78..99c7cd566 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/module-keeper.md +++ b/docs/sdk/sdk-by-examples/simple-governance/module-keeper.md @@ -47,7 +47,7 @@ With all that in mind, we can define the structure of our `Keeper`: ```go type Keeper struct { SimpleGov sdk.StoreKey // Key to our module's store - cdc *wire.Codec // Codec to encore/decode structs + cdc *codec.Codec // Codec to encore/decode structs ck bank.Keeper // Needed to handle deposits. This module onlyl requires read/writes to Atom balance sm stake.Keeper // Needed to compute voting power. This module only needs read access to the staking store. codespace sdk.CodespaceType // Reserves space for error codes diff --git a/docs/sdk/sdk-by-examples/simple-governance/module-wire.md b/docs/sdk/sdk-by-examples/simple-governance/module-wire.md deleted file mode 100644 index f889db91a..000000000 --- a/docs/sdk/sdk-by-examples/simple-governance/module-wire.md +++ /dev/null @@ -1,13 +0,0 @@ -## Wire - -**File: [`x/simple_governance/wire.go`](https://github.com/cosmos/cosmos-sdk/blob/fedekunze/module_tutorial/examples/simpleGov/x/simple_governance/wire.go)** - -The `wire.go` file allows developers to register the concrete message types of their module into the codec. In our case, we have two messages to declare: - -```go -func RegisterWire(cdc *wire.Codec) { - cdc.RegisterConcrete(SubmitProposalMsg{}, "simple_governance/SubmitProposalMsg", nil) - cdc.RegisterConcrete(VoteMsg{}, "simple_governance/VoteMsg", nil) -} -``` -Don't forget to call this function in `app.go` (see [Application - Bridging it all together](app-structure.md)) for more). \ No newline at end of file diff --git a/docs/spec/ibc/appendices.md b/docs/spec/ibc/appendices.md index 751924f46..a3d04960d 100644 --- a/docs/spec/ibc/appendices.md +++ b/docs/spec/ibc/appendices.md @@ -8,7 +8,7 @@ The specification has focused on semantics and functionality of the IBC protocol In defining a standard binary encoding for all the "universal" components, we wish to make use of a standardized library, with efficient serialization and support in multiple languages. We considered two main formats: Ethereum's RLP[[6](./references.md#6)] and Google's Protobuf[[7](./references.md#7)]. We decided for protobuf, as it is more widely supported, is more expressive for different data types, and supports code generation for very efficient (de)serialization codecs. It does have a learning curve and more setup to generate the code from the type specifications, but the ibc data types should not change often and this code generation setup only needs to happen once per language (and can be exposed in a common repo), so this is not a strong counter-argument. Efficiency, expressiveness, and wider support rule in its favor. It is also widely used in gRPC and in many microservice architectures. -The tendermint-specific data structures are encoded with go-wire[[8](./references.md#8)], the native binary encoding used inside of tendermint. Most blockchains define their own formats, and until some universal format for headers and signatures among blockchains emerge, it seems very premature to enforce any encoding here. These are defined as arbitrary byte slices in the protocol, to be parsed in an consensus engine-dependent manner. +The tendermint-specific data structures are encoded with go-amino[[8](./references.md#8)], the native binary encoding used inside of tendermint. Most blockchains define their own formats, and until some universal format for headers and signatures among blockchains emerge, it seems very premature to enforce any encoding here. These are defined as arbitrary byte slices in the protocol, to be parsed in an consensus engine-dependent manner. For the following appendixes, the data structure specifications will be in proto3[[9](./references.md#9)] format. @@ -61,7 +61,7 @@ The IBC protocol does not handle these kinds of errors. They must be handled ind **TODO: clean this all up** -This is a mess now, we need to figure out what formats we use, define go-wire, etc. or just point to the source???? Will do more later, need help here from the tendermint core team. +This is a mess now, we need to figure out what formats we use, define go-amino, etc. or just point to the source???? Will do more later, need help here from the tendermint core team. In order to prove a merkle root, we must fully define the headers, signatures, and validator information returned from the Tendermint consensus engine, as well as the rules by which to verify a header. We also define here the messages used for creating and removing connections to other blockchains as well as how to handle forks. diff --git a/docs/spec/ibc/channels-and-packets.md b/docs/spec/ibc/channels-and-packets.md index 0951ca657..56ea93b5a 100644 --- a/docs/spec/ibc/channels-and-packets.md +++ b/docs/spec/ibc/channels-and-packets.md @@ -28,7 +28,7 @@ Every transaction on the same chain already has a well-defined causality relatio For example, an application may wish to allow a single tokenized asset to be transferred between and held on multiple blockchains while preserving fungibility and conservation of supply. The application can mint asset vouchers on chain `B` when a particular IBC packet is committed to chain `B`, and require outgoing sends of that packet on chain `A` to escrow an equal amount of the asset on chain `A` until the vouchers are later redeemed back to chain `A` with an IBC packet in the reverse direction. This ordering guarantee along with correct application logic can ensure that total supply is preserved across both chains and that any vouchers minted on chain `B` can later be redeemed back to chain `A`. -This section provides definitions for packets and channels, a high-level specification of the queue interface, and a list of the necessary proofs. To implement wire-compatible IBC, chain `A` and chain `B` must also use a common encoding format. An example binary encoding format can be found in [Appendix C](appendices.md#appendix-c-merkle-proof-formats). +This section provides definitions for packets and channels, a high-level specification of the queue interface, and a list of the necessary proofs. To implement amino-compatible IBC, chain `A` and chain `B` must also use a common encoding format. An example binary encoding format can be found in [Appendix C](appendices.md#appendix-c-merkle-proof-formats). ### 3.2 Definitions diff --git a/docs/spec/ibc/conclusion.md b/docs/spec/ibc/conclusion.md index f85ae8599..0c4fae18e 100644 --- a/docs/spec/ibc/conclusion.md +++ b/docs/spec/ibc/conclusion.md @@ -6,4 +6,4 @@ We have demonstrated a secure, performant, and flexible protocol for cross-block This document defines solely a message queue protocol - not the application-level semantics which must sit on top of it to enable asset transfer between two chains. We will shortly release a separate paper on Cosmos IBC that defines the application logic used for direct value transfer as well as routing over the Cosmos hub. That paper builds upon the IBC protocol defined here and provides a first example of how to reason about application logic and global invariants in the context of IBC. -There is a reference implementation of the Cosmos IBC protocol as part of the Cosmos SDK, written in Golang and released under the Apache license. To facilitate implementations in other langauages which are wire-compatible with the Cosmos implementation, the following appendices define exact message and binary encoding formats. +There is a reference implementation of the Cosmos IBC protocol as part of the Cosmos SDK, written in Golang and released under the Apache license. To facilitate implementations in other langauages which are amino-compatible with the Cosmos implementation, the following appendices define exact message and binary encoding formats. diff --git a/docs/spec/ibc/references.md b/docs/spec/ibc/references.md index ba9fbee69..715086e1b 100644 --- a/docs/spec/ibc/references.md +++ b/docs/spec/ibc/references.md @@ -24,7 +24,7 @@ [https://developers.google.com/protocol-buffers/](https://developers.google.com/protocol-buffers/) ##### 8: -[https://github.com/tendermint/go-wire](https://github.com/tendermint/go-wire) +[https://github.com/tendermint/go-amino](https://github.com/tendermint/go-amino) ##### 9: [https://developers.google.com/protocol-buffers/docs/proto3](https://developers.google.com/protocol-buffers/docs/proto3) diff --git a/examples/basecoin/app/app.go b/examples/basecoin/app/app.go index 6330e9f31..657cbcf0f 100644 --- a/examples/basecoin/app/app.go +++ b/examples/basecoin/app/app.go @@ -4,9 +4,9 @@ import ( "encoding/json" bam "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/basecoin/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" @@ -27,7 +27,7 @@ const ( // integral app types. type BasecoinApp struct { *bam.BaseApp - cdc *wire.Codec + cdc *codec.Codec // keys to access the multistore keyMain *sdk.KVStoreKey @@ -93,16 +93,16 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba return app } -// MakeCodec creates a new wire codec and registers all the necessary types +// MakeCodec creates a new codec codec and registers all the necessary types // with the codec. -func MakeCodec() *wire.Codec { - cdc := wire.NewCodec() +func MakeCodec() *codec.Codec { + cdc := codec.New() - wire.RegisterCrypto(cdc) - sdk.RegisterWire(cdc) - bank.RegisterWire(cdc) - ibc.RegisterWire(cdc) - auth.RegisterWire(cdc) + codec.RegisterCrypto(cdc) + sdk.RegisterCodec(cdc) + bank.RegisterCodec(cdc) + ibc.RegisterCodec(cdc) + auth.RegisterCodec(cdc) // register custom type cdc.RegisterConcrete(&types.AppAccount{}, "basecoin/Account", nil) @@ -173,7 +173,7 @@ func (app *BasecoinApp) ExportAppStateAndValidators() (appState json.RawMessage, app.accountMapper.IterateAccounts(ctx, appendAccountsFn) genState := types.GenesisState{Accounts: accounts} - appState, err = wire.MarshalJSONIndent(app.cdc, genState) + appState, err = codec.MarshalJSONIndent(app.cdc, genState) if err != nil { return nil, nil, err } diff --git a/examples/basecoin/app/app_test.go b/examples/basecoin/app/app_test.go index dad8191b3..24237e602 100644 --- a/examples/basecoin/app/app_test.go +++ b/examples/basecoin/app/app_test.go @@ -4,9 +4,9 @@ import ( "os" "testing" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/basecoin/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -22,7 +22,7 @@ func setGenesis(baseApp *BasecoinApp, accounts ...*types.AppAccount) (types.Gene } genesisState := types.GenesisState{Accounts: genAccts} - stateBytes, err := wire.MarshalJSONIndent(baseApp.cdc, genesisState) + stateBytes, err := codec.MarshalJSONIndent(baseApp.cdc, genesisState) if err != nil { return types.GenesisState{}, err } @@ -67,7 +67,7 @@ func TestGenesis(t *testing.T) { // reload app and ensure the account is still there baseApp = NewBasecoinApp(logger, db) - stateBytes, err := wire.MarshalJSONIndent(baseApp.cdc, genState) + stateBytes, err := codec.MarshalJSONIndent(baseApp.cdc, genState) require.Nil(t, err) // initialize the chain with the expected genesis state diff --git a/examples/basecoin/types/account.go b/examples/basecoin/types/account.go index 45774ae43..04d3e371e 100644 --- a/examples/basecoin/types/account.go +++ b/examples/basecoin/types/account.go @@ -1,8 +1,8 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" ) @@ -30,7 +30,7 @@ func NewAppAccount(name string, baseAcct auth.BaseAccount) *AppAccount { // GetAccountDecoder returns the AccountDecoder function for the custom // AppAccount. -func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder { +func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder { return func(accBytes []byte) (auth.Account, error) { if len(accBytes) == 0 { return nil, sdk.ErrTxDecode("accBytes are empty") diff --git a/examples/democoin/app/app.go b/examples/democoin/app/app.go index e66dc0cb3..0449f6251 100644 --- a/examples/democoin/app/app.go +++ b/examples/democoin/app/app.go @@ -10,8 +10,8 @@ import ( tmtypes "github.com/tendermint/tendermint/types" bam "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" @@ -30,7 +30,7 @@ const ( // Extended ABCI application type DemocoinApp struct { *bam.BaseApp - cdc *wire.Codec + cdc *codec.Codec // keys to access the substores capKeyMainStore *sdk.KVStoreKey @@ -103,15 +103,15 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp { } // custom tx codec -func MakeCodec() *wire.Codec { - var cdc = wire.NewCodec() - wire.RegisterCrypto(cdc) // Register crypto. - sdk.RegisterWire(cdc) // Register Msgs - cool.RegisterWire(cdc) - pow.RegisterWire(cdc) - bank.RegisterWire(cdc) - ibc.RegisterWire(cdc) - simplestake.RegisterWire(cdc) +func MakeCodec() *codec.Codec { + var cdc = codec.New() + codec.RegisterCrypto(cdc) // Register crypto. + sdk.RegisterCodec(cdc) // Register Msgs + cool.RegisterCodec(cdc) + pow.RegisterCodec(cdc) + bank.RegisterCodec(cdc) + ibc.RegisterCodec(cdc) + simplestake.RegisterCodec(cdc) // Register AppAccount cdc.RegisterInterface((*auth.Account)(nil), nil) @@ -182,7 +182,7 @@ func (app *DemocoinApp) ExportAppStateAndValidators() (appState json.RawMessage, POWGenesis: pow.WriteGenesis(ctx, app.powKeeper), CoolGenesis: cool.WriteGenesis(ctx, app.coolKeeper), } - appState, err = wire.MarshalJSONIndent(app.cdc, genState) + appState, err = codec.MarshalJSONIndent(app.cdc, genState) if err != nil { return nil, nil, err } diff --git a/examples/democoin/app/app_test.go b/examples/democoin/app/app_test.go index e964dbad2..eeea84bd4 100644 --- a/examples/democoin/app/app_test.go +++ b/examples/democoin/app/app_test.go @@ -4,10 +4,10 @@ import ( "os" "testing" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/types" "github.com/cosmos/cosmos-sdk/examples/democoin/x/cool" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -27,7 +27,7 @@ func setGenesis(bapp *DemocoinApp, trend string, accs ...auth.BaseAccount) error CoolGenesis: cool.Genesis{trend}, } - stateBytes, err := wire.MarshalJSONIndent(bapp.cdc, genesisState) + stateBytes, err := codec.MarshalJSONIndent(bapp.cdc, genesisState) if err != nil { return err } diff --git a/examples/democoin/cmd/democoind/main.go b/examples/democoin/cmd/democoind/main.go index 528cafe1c..e22b0fc3e 100644 --- a/examples/democoin/cmd/democoind/main.go +++ b/examples/democoin/cmd/democoind/main.go @@ -13,9 +13,9 @@ import ( "github.com/tendermint/tendermint/libs/log" tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/app" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/wire" ) // init parameters @@ -25,7 +25,7 @@ var CoolAppInit = server.AppInit{ } // coolGenAppParams sets up the app_state and appends the cool app state -func CoolAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { +func CoolAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { appState, err = server.SimpleAppGenState(cdc, appGenTxs) if err != nil { return diff --git a/examples/democoin/types/account.go b/examples/democoin/types/account.go index 8eb9b0ae4..ad57c944d 100644 --- a/examples/democoin/types/account.go +++ b/examples/democoin/types/account.go @@ -1,8 +1,8 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/examples/democoin/x/cool" @@ -31,7 +31,7 @@ func (acc AppAccount) GetName() string { return acc.Name } func (acc *AppAccount) SetName(name string) { acc.Name = name } // Get the AccountDecoder function for the custom AppAccount -func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder { +func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder { return func(accBytes []byte) (res auth.Account, err error) { if len(accBytes) == 0 { return nil, sdk.ErrTxDecode("accBytes are empty") diff --git a/examples/democoin/x/assoc/validator_set.go b/examples/democoin/x/assoc/validator_set.go index 7515e1ad6..69b35501f 100644 --- a/examples/democoin/x/assoc/validator_set.go +++ b/examples/democoin/x/assoc/validator_set.go @@ -3,8 +3,8 @@ package assoc import ( "bytes" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // ValidatorSet defines @@ -12,7 +12,7 @@ type ValidatorSet struct { sdk.ValidatorSet store sdk.KVStore - cdc *wire.Codec + cdc *codec.Codec maxAssoc int addrLen int @@ -21,7 +21,7 @@ type ValidatorSet struct { var _ sdk.ValidatorSet = ValidatorSet{} // NewValidatorSet returns new ValidatorSet with underlying ValidatorSet -func NewValidatorSet(cdc *wire.Codec, store sdk.KVStore, valset sdk.ValidatorSet, maxAssoc int, addrLen int) ValidatorSet { +func NewValidatorSet(cdc *codec.Codec, store sdk.KVStore, valset sdk.ValidatorSet, maxAssoc int, addrLen int) ValidatorSet { if maxAssoc < 0 || addrLen < 0 { panic("Cannot use negative integer for NewValidatorSet") } diff --git a/examples/democoin/x/assoc/validator_set_test.go b/examples/democoin/x/assoc/validator_set_test.go index eac23b25e..9fc6526f8 100644 --- a/examples/democoin/x/assoc/validator_set_test.go +++ b/examples/democoin/x/assoc/validator_set_test.go @@ -9,10 +9,10 @@ import ( abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tendermint/libs/db" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/mock" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) func defaultContext(key sdk.StoreKey) sdk.Context { @@ -36,7 +36,7 @@ func TestValidatorSet(t *testing.T) { {addr2, sdk.NewDec(2)}, }} - valset := NewValidatorSet(wire.NewCodec(), ctx.KVStore(key).Prefix([]byte("assoc")), base, 1, 5) + valset := NewValidatorSet(codec.New(), ctx.KVStore(key).Prefix([]byte("assoc")), base, 1, 5) require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) diff --git a/examples/democoin/x/cool/app_test.go b/examples/democoin/x/cool/app_test.go index 3349928eb..35a656ceb 100644 --- a/examples/democoin/x/cool/app_test.go +++ b/examples/democoin/x/cool/app_test.go @@ -47,7 +47,7 @@ var ( func getMockApp(t *testing.T) *mock.App { mapp := mock.NewApp() - RegisterWire(mapp.Cdc) + RegisterCodec(mapp.Cdc) keyCool := sdk.NewKVStoreKey("cool") bankKeeper := bank.NewBaseKeeper(mapp.AccountMapper) keeper := NewKeeper(keyCool, bankKeeper, mapp.RegisterCodespace(DefaultCodespace)) diff --git a/examples/democoin/x/cool/client/cli/tx.go b/examples/democoin/x/cool/client/cli/tx.go index 1e41ff5b2..2f78bba46 100644 --- a/examples/democoin/x/cool/client/cli/tx.go +++ b/examples/democoin/x/cool/client/cli/tx.go @@ -7,15 +7,15 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/x/cool" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" ) // QuizTxCmd invokes the coolness quiz transaction. -func QuizTxCmd(cdc *wire.Codec) *cobra.Command { +func QuizTxCmd(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "cool [answer]", Short: "What's cooler than being cool?", @@ -40,7 +40,7 @@ func QuizTxCmd(cdc *wire.Codec) *cobra.Command { } // SetTrendTxCmd sends a new cool trend transaction. -func SetTrendTxCmd(cdc *wire.Codec) *cobra.Command { +func SetTrendTxCmd(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "setcool [answer]", Short: "You're so cool, tell us what is cool!", diff --git a/examples/democoin/x/cool/wire.go b/examples/democoin/x/cool/codec.go similarity index 53% rename from examples/democoin/x/cool/wire.go rename to examples/democoin/x/cool/codec.go index 63666888a..491c00617 100644 --- a/examples/democoin/x/cool/wire.go +++ b/examples/democoin/x/cool/codec.go @@ -1,11 +1,11 @@ package cool import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgQuiz{}, "cool/Quiz", nil) cdc.RegisterConcrete(MsgSetTrend{}, "cool/SetTrend", nil) } diff --git a/examples/democoin/x/cool/keeper_test.go b/examples/democoin/x/cool/keeper_test.go index 50b38fc3e..e3af7790e 100644 --- a/examples/democoin/x/cool/keeper_test.go +++ b/examples/democoin/x/cool/keeper_test.go @@ -8,9 +8,9 @@ import ( abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tendermint/libs/db" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" auth "github.com/cosmos/cosmos-sdk/x/auth" bank "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -26,7 +26,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) { func TestCoolKeeper(t *testing.T) { ms, capKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) am := auth.NewAccountMapper(cdc, capKey, auth.ProtoBaseAccount) diff --git a/examples/democoin/x/oracle/README.md b/examples/democoin/x/oracle/README.md index 0cfcb820d..b840dc0e8 100644 --- a/examples/democoin/x/oracle/README.md +++ b/examples/democoin/x/oracle/README.md @@ -38,7 +38,7 @@ func NewHandler(keeper Keeper) sdk.Handler { In the previous example, the keeper has an `oracle.Keeper`. `oracle.Keeper`s are generated by `NewKeeper`. ```go -func NewKeeper(key sdk.StoreKey, cdc *wire.Codec, valset sdk.ValidatorSet, supermaj sdk.Dec, timeout int64) Keeper { +func NewKeeper(key sdk.StoreKey, cdc *codec.Codec, valset sdk.ValidatorSet, supermaj sdk.Dec, timeout int64) Keeper { return Keeper { cdc: cdc, key: key, diff --git a/examples/democoin/x/oracle/keeper.go b/examples/democoin/x/oracle/keeper.go index 0406f560a..e55cd7083 100644 --- a/examples/democoin/x/oracle/keeper.go +++ b/examples/democoin/x/oracle/keeper.go @@ -1,7 +1,7 @@ package oracle import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -9,7 +9,7 @@ import ( // Keeper of the oracle store type Keeper struct { key sdk.StoreKey - cdc *wire.Codec + cdc *codec.Codec valset sdk.ValidatorSet @@ -18,7 +18,7 @@ type Keeper struct { } // NewKeeper constructs a new keeper -func NewKeeper(key sdk.StoreKey, cdc *wire.Codec, valset sdk.ValidatorSet, supermaj sdk.Dec, timeout int64) Keeper { +func NewKeeper(key sdk.StoreKey, cdc *codec.Codec, valset sdk.ValidatorSet, supermaj sdk.Dec, timeout int64) Keeper { if timeout < 0 { panic("Timeout should not be negative") } diff --git a/examples/democoin/x/oracle/keeper_keys.go b/examples/democoin/x/oracle/keeper_keys.go index f657e8027..9b71aeaa1 100644 --- a/examples/democoin/x/oracle/keeper_keys.go +++ b/examples/democoin/x/oracle/keeper_keys.go @@ -1,23 +1,23 @@ package oracle import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // GetInfoKey returns the key for OracleInfo -func GetInfoKey(p Payload, cdc *wire.Codec) []byte { +func GetInfoKey(p Payload, cdc *codec.Codec) []byte { bz := cdc.MustMarshalBinary(p) return append([]byte{0x00}, bz...) } // GetSignPrefix returns the prefix for signs -func GetSignPrefix(p Payload, cdc *wire.Codec) []byte { +func GetSignPrefix(p Payload, cdc *codec.Codec) []byte { bz := cdc.MustMarshalBinary(p) return append([]byte{0x01}, bz...) } // GetSignKey returns the key for sign -func GetSignKey(p Payload, signer sdk.AccAddress, cdc *wire.Codec) []byte { +func GetSignKey(p Payload, signer sdk.AccAddress, cdc *codec.Codec) []byte { return append(GetSignPrefix(p, cdc), signer...) } diff --git a/examples/democoin/x/oracle/oracle_test.go b/examples/democoin/x/oracle/oracle_test.go index f4971c8b1..416d933f2 100644 --- a/examples/democoin/x/oracle/oracle_test.go +++ b/examples/democoin/x/oracle/oracle_test.go @@ -9,10 +9,10 @@ import ( abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tendermint/libs/db" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/mock" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) func defaultContext(keys ...sdk.StoreKey) sdk.Context { @@ -39,8 +39,8 @@ func (o seqOracle) ValidateBasic() sdk.Error { return nil } -func makeCodec() *wire.Codec { - var cdc = wire.NewCodec() +func makeCodec() *codec.Codec { + var cdc = codec.New() cdc.RegisterInterface((*sdk.Msg)(nil), nil) cdc.RegisterConcrete(Msg{}, "test/Oracle", nil) @@ -79,7 +79,7 @@ func getSequence(ctx sdk.Context, key sdk.StoreKey) int { if seqbz == nil { seq = 0 } else { - wire.NewCodec().MustUnmarshalBinary(seqbz, &seq) + codec.New().MustUnmarshalBinary(seqbz, &seq) } return seq @@ -93,7 +93,7 @@ func handleSeqOracle(ctx sdk.Context, key sdk.StoreKey, o seqOracle) sdk.Error { return sdk.NewError(sdk.CodespaceRoot, 1, "") } - bz := wire.NewCodec().MustMarshalBinary(seq + 1) + bz := codec.New().MustMarshalBinary(seq + 1) store.Set([]byte("seq"), bz) return nil diff --git a/examples/democoin/x/pow/app_test.go b/examples/democoin/x/pow/app_test.go index 0a4f95cf1..6e6f07f77 100644 --- a/examples/democoin/x/pow/app_test.go +++ b/examples/democoin/x/pow/app_test.go @@ -23,7 +23,7 @@ var ( func getMockApp(t *testing.T) *mock.App { mapp := mock.NewApp() - RegisterWire(mapp.Cdc) + RegisterCodec(mapp.Cdc) keyPOW := sdk.NewKVStoreKey("pow") bankKeeper := bank.NewBaseKeeper(mapp.AccountMapper) config := Config{"pow", 1} diff --git a/examples/democoin/x/pow/client/cli/tx.go b/examples/democoin/x/pow/client/cli/tx.go index 15102b128..f1d708c89 100644 --- a/examples/democoin/x/pow/client/cli/tx.go +++ b/examples/democoin/x/pow/client/cli/tx.go @@ -6,9 +6,9 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/x/pow" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" @@ -16,7 +16,7 @@ import ( ) // command to mine some pow! -func MineCmd(cdc *wire.Codec) *cobra.Command { +func MineCmd(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "mine [difficulty] [count] [nonce] [solution]", Short: "Mine some coins with proof-of-work!", diff --git a/examples/democoin/x/pow/codec.go b/examples/democoin/x/pow/codec.go new file mode 100644 index 000000000..8f4296f17 --- /dev/null +++ b/examples/democoin/x/pow/codec.go @@ -0,0 +1,10 @@ +package pow + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(MsgMine{}, "pow/Mine", nil) +} diff --git a/examples/democoin/x/pow/handler_test.go b/examples/democoin/x/pow/handler_test.go index 03613f716..8166ddfc5 100644 --- a/examples/democoin/x/pow/handler_test.go +++ b/examples/democoin/x/pow/handler_test.go @@ -8,15 +8,15 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" auth "github.com/cosmos/cosmos-sdk/x/auth" bank "github.com/cosmos/cosmos-sdk/x/bank" ) func TestPowHandler(t *testing.T) { ms, capKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) am := auth.NewAccountMapper(cdc, capKey, auth.ProtoBaseAccount) diff --git a/examples/democoin/x/pow/keeper_test.go b/examples/democoin/x/pow/keeper_test.go index dbab3e617..dbd974c4d 100644 --- a/examples/democoin/x/pow/keeper_test.go +++ b/examples/democoin/x/pow/keeper_test.go @@ -9,9 +9,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" auth "github.com/cosmos/cosmos-sdk/x/auth" bank "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -29,7 +29,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) { func TestPowKeeperGetSet(t *testing.T) { ms, capKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) am := auth.NewAccountMapper(cdc, capKey, auth.ProtoBaseAccount) diff --git a/examples/democoin/x/pow/wire.go b/examples/democoin/x/pow/wire.go deleted file mode 100644 index 3d7f61486..000000000 --- a/examples/democoin/x/pow/wire.go +++ /dev/null @@ -1,10 +0,0 @@ -package pow - -import ( - "github.com/cosmos/cosmos-sdk/wire" -) - -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { - cdc.RegisterConcrete(MsgMine{}, "pow/Mine", nil) -} diff --git a/examples/democoin/x/simplestake/client/cli/commands.go b/examples/democoin/x/simplestake/client/cli/commands.go index 9f6eb40f7..d09bf64f3 100644 --- a/examples/democoin/x/simplestake/client/cli/commands.go +++ b/examples/democoin/x/simplestake/client/cli/commands.go @@ -7,9 +7,9 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/x/simplestake" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" @@ -25,7 +25,7 @@ const ( ) // simple bond tx -func BondTxCmd(cdc *wire.Codec) *cobra.Command { +func BondTxCmd(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "bond", Short: "Bond to a validator", @@ -79,7 +79,7 @@ func BondTxCmd(cdc *wire.Codec) *cobra.Command { } // simple unbond tx -func UnbondTxCmd(cdc *wire.Codec) *cobra.Command { +func UnbondTxCmd(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "unbond", Short: "Unbond from a validator", diff --git a/examples/democoin/x/simplestake/wire.go b/examples/democoin/x/simplestake/codec.go similarity index 57% rename from examples/democoin/x/simplestake/wire.go rename to examples/democoin/x/simplestake/codec.go index 4ef971b44..7813fd642 100644 --- a/examples/democoin/x/simplestake/wire.go +++ b/examples/democoin/x/simplestake/codec.go @@ -1,11 +1,11 @@ package simplestake import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgBond{}, "simplestake/BondMsg", nil) cdc.RegisterConcrete(MsgUnbond{}, "simplestake/UnbondMsg", nil) } diff --git a/examples/democoin/x/simplestake/keeper.go b/examples/democoin/x/simplestake/keeper.go index eb3f34079..7bdc17937 100644 --- a/examples/democoin/x/simplestake/keeper.go +++ b/examples/democoin/x/simplestake/keeper.go @@ -3,8 +3,8 @@ package simplestake import ( "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -17,13 +17,13 @@ type Keeper struct { ck bank.Keeper key sdk.StoreKey - cdc *wire.Codec + cdc *codec.Codec codespace sdk.CodespaceType } func NewKeeper(key sdk.StoreKey, bankKeeper bank.Keeper, codespace sdk.CodespaceType) Keeper { - cdc := wire.NewCodec() - wire.RegisterCrypto(cdc) + cdc := codec.New() + codec.RegisterCrypto(cdc) return Keeper{ key: key, cdc: cdc, diff --git a/examples/democoin/x/simplestake/keeper_test.go b/examples/democoin/x/simplestake/keeper_test.go index 417356f66..68f28bd91 100644 --- a/examples/democoin/x/simplestake/keeper_test.go +++ b/examples/democoin/x/simplestake/keeper_test.go @@ -12,9 +12,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -32,7 +32,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) { func TestKeeperGetSet(t *testing.T) { ms, authKey, capKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) accountMapper := auth.NewAccountMapper(cdc, authKey, auth.ProtoBaseAccount) @@ -60,7 +60,7 @@ func TestKeeperGetSet(t *testing.T) { func TestBonding(t *testing.T) { ms, authKey, capKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) diff --git a/examples/kvstore/kvstore b/examples/kvstore/kvstore index 5dd8b5eea..6de98cc56 100755 Binary files a/examples/kvstore/kvstore and b/examples/kvstore/kvstore differ diff --git a/server/export.go b/server/export.go index 1d0f760ce..c3d6b5283 100644 --- a/server/export.go +++ b/server/export.go @@ -7,14 +7,14 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" tmtypes "github.com/tendermint/tendermint/types" "io/ioutil" "path" ) // ExportCmd dumps app state to JSON. -func ExportCmd(ctx *Context, cdc *wire.Codec, appExporter AppExporter) *cobra.Command { +func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.Command { return &cobra.Command{ Use: "export", Short: "Export state to JSON", @@ -50,7 +50,7 @@ func ExportCmd(ctx *Context, cdc *wire.Codec, appExporter AppExporter) *cobra.Co doc.AppState = appState doc.Validators = validators - encoded, err := wire.MarshalJSONIndent(cdc, doc) + encoded, err := codec.MarshalJSONIndent(cdc, doc) if err != nil { return err } diff --git a/server/export_test.go b/server/export_test.go index 488c55bbf..999ba3c00 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -2,8 +2,8 @@ package server import ( "bytes" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/mock" - "github.com/cosmos/cosmos-sdk/wire" "github.com/stretchr/testify/require" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" "github.com/tendermint/tendermint/libs/log" @@ -18,7 +18,7 @@ func TestEmptyState(t *testing.T) { cfg, err := tcmd.ParseConfig() require.Nil(t, err) ctx := NewContext(cfg, logger) - cdc := wire.NewCodec() + cdc := codec.New() appInit := AppInit{ AppGenTx: mock.AppGenTx, AppGenState: mock.AppGenStateEmpty, diff --git a/server/init.go b/server/init.go index ffe2b6edd..adec4fba3 100644 --- a/server/init.go +++ b/server/init.go @@ -26,9 +26,9 @@ import ( tmtypes "github.com/tendermint/tendermint/types" clkeys "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/codec" serverconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) //Parameter names, for init gen-tx command @@ -63,7 +63,7 @@ type InitConfig struct { } // get cmd to initialize all files for tendermint and application -func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { +func GenTxCmd(ctx *Context, cdc *codec.Codec, appInit AppInit) *cobra.Command { cmd := &cobra.Command{ Use: "gen-tx", Short: "Create genesis transaction file (under [--home]/config/gentx/gentx-[nodeID].json)", @@ -99,7 +99,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { cliPrint, genTxFile, } - out, err := wire.MarshalJSONIndent(cdc, toPrint) + out, err := codec.MarshalJSONIndent(cdc, toPrint) if err != nil { return err } @@ -112,7 +112,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { return cmd } -func gentxWithConfig(cdc *wire.Codec, appInit AppInit, config *cfg.Config, genTxConfig serverconfig.GenTx) ( +func gentxWithConfig(cdc *codec.Codec, appInit AppInit, config *cfg.Config, genTxConfig serverconfig.GenTx) ( cliPrint json.RawMessage, genTxFile json.RawMessage, err error) { nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) if err != nil { @@ -132,7 +132,7 @@ func gentxWithConfig(cdc *wire.Codec, appInit AppInit, config *cfg.Config, genTx Validator: validator, AppGenTx: appGenTx, } - bz, err := wire.MarshalJSONIndent(cdc, tx) + bz, err := codec.MarshalJSONIndent(cdc, tx) if err != nil { return } @@ -158,7 +158,7 @@ func gentxWithConfig(cdc *wire.Codec, appInit AppInit, config *cfg.Config, genTx } // get cmd to initialize all files for tendermint and application -func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { +func InitCmd(ctx *Context, cdc *codec.Codec, appInit AppInit) *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Initialize genesis config, priv-validator file, and p2p-node file", @@ -188,7 +188,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { nodeID, appMessage, } - out, err := wire.MarshalJSONIndent(cdc, toPrint) + out, err := codec.MarshalJSONIndent(cdc, toPrint) if err != nil { return err } @@ -205,7 +205,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { return cmd } -func initWithConfig(cdc *wire.Codec, appInit AppInit, config *cfg.Config, initConfig InitConfig) ( +func initWithConfig(cdc *codec.Codec, appInit AppInit, config *cfg.Config, initConfig InitConfig) ( chainID string, nodeID string, appMessage json.RawMessage, err error) { nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) if err != nil { @@ -273,7 +273,7 @@ func initWithConfig(cdc *wire.Codec, appInit AppInit, config *cfg.Config, initCo } // append a genesis-piece -func processGenTxs(genTxsDir string, cdc *wire.Codec) ( +func processGenTxs(genTxsDir string, cdc *codec.Codec) ( validators []tmtypes.GenesisValidator, appGenTxs []json.RawMessage, persistentPeers string, err error) { var fos []os.FileInfo @@ -345,7 +345,7 @@ func readOrCreatePrivValidator(tmConfig *cfg.Config) crypto.PubKey { // writeGenesisFile creates and writes the genesis configuration to disk. An // error is returned if building or writing the configuration to file fails. // nolint: unparam -func writeGenesisFile(cdc *wire.Codec, genesisFile, chainID string, validators []tmtypes.GenesisValidator, appState json.RawMessage) error { +func writeGenesisFile(cdc *codec.Codec, genesisFile, chainID string, validators []tmtypes.GenesisValidator, appState json.RawMessage) error { genDoc := tmtypes.GenesisDoc{ ChainID: chainID, Validators: validators, @@ -369,12 +369,12 @@ type AppInit struct { FlagsAppGenTx *pflag.FlagSet // create the application genesis tx - AppGenTx func(cdc *wire.Codec, pk crypto.PubKey, genTxConfig serverconfig.GenTx) ( + AppGenTx func(cdc *codec.Codec, pk crypto.PubKey, genTxConfig serverconfig.GenTx) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) // AppGenState creates the core parameters initialization. It takes in a // pubkey meant to represent the pubkey of the validator of this machine. - AppGenState func(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) + AppGenState func(cdc *codec.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) } //_____________________________________________________________________ @@ -391,7 +391,7 @@ type SimpleGenTx struct { } // Generate a genesis transaction -func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey, genTxConfig serverconfig.GenTx) ( +func SimpleAppGenTx(cdc *codec.Codec, pk crypto.PubKey, genTxConfig serverconfig.GenTx) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { var addr sdk.AccAddress @@ -424,7 +424,7 @@ func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey, genTxConfig serverconfig. } // create the genesis app state -func SimpleAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { +func SimpleAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { if len(appGenTxs) != 1 { err = errors.New("must provide a single genesis transaction") diff --git a/server/init_test.go b/server/init_test.go index fb448bf5f..1913ac671 100644 --- a/server/init_test.go +++ b/server/init_test.go @@ -7,8 +7,8 @@ import ( "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/mock" - "github.com/cosmos/cosmos-sdk/wire" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" ) @@ -20,7 +20,7 @@ func TestInitCmd(t *testing.T) { cfg, err := tcmd.ParseConfig() require.Nil(t, err) ctx := NewContext(cfg, logger) - cdc := wire.NewCodec() + cdc := codec.New() appInit := AppInit{ AppGenState: mock.AppGenState, AppGenTx: mock.AppGenTx, diff --git a/server/mock/app.go b/server/mock/app.go index 3c6ad3ec2..abdec6be5 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -12,9 +12,9 @@ import ( tmtypes "github.com/tendermint/tendermint/types" bam "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" gc "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // NewApp creates a simple mock kvstore app for testing. It should work @@ -105,7 +105,7 @@ func InitChainer(key sdk.StoreKey) func(sdk.Context, abci.RequestInitChain) abci // AppGenState can be passed into InitCmd, returns a static string of a few // key-values that can be parsed by InitChainer -func AppGenState(_ *wire.Codec, _ []json.RawMessage) (appState json.RawMessage, err error) { +func AppGenState(_ *codec.Codec, _ []json.RawMessage) (appState json.RawMessage, err error) { appState = json.RawMessage(`{ "values": [ { @@ -122,13 +122,13 @@ func AppGenState(_ *wire.Codec, _ []json.RawMessage) (appState json.RawMessage, } // AppGenStateEmpty returns an empty transaction state for mocking. -func AppGenStateEmpty(_ *wire.Codec, _ []json.RawMessage) (appState json.RawMessage, err error) { +func AppGenStateEmpty(_ *codec.Codec, _ []json.RawMessage) (appState json.RawMessage, err error) { appState = json.RawMessage(``) return } // Return a validator, not much else -func AppGenTx(_ *wire.Codec, pk crypto.PubKey, genTxConfig gc.GenTx) ( +func AppGenTx(_ *codec.Codec, pk crypto.PubKey, genTxConfig gc.GenTx) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { validator = tmtypes.GenesisValidator{ diff --git a/server/start_test.go b/server/start_test.go index 570071e7b..db9fcd40f 100644 --- a/server/start_test.go +++ b/server/start_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/mock" - "github.com/cosmos/cosmos-sdk/wire" "github.com/tendermint/tendermint/abci/server" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" "github.com/tendermint/tendermint/libs/log" @@ -26,7 +26,7 @@ func TestStartStandAlone(t *testing.T) { cfg, err := tcmd.ParseConfig() require.Nil(t, err) ctx := NewContext(cfg, logger) - cdc := wire.NewCodec() + cdc := codec.New() appInit := AppInit{ AppGenState: mock.AppGenState, AppGenTx: mock.AppGenTx, diff --git a/server/testnet.go b/server/testnet.go index 951e378d1..e76263160 100644 --- a/server/testnet.go +++ b/server/testnet.go @@ -11,7 +11,7 @@ import ( "os" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/viper" cfg "github.com/tendermint/tendermint/config" cmn "github.com/tendermint/tendermint/libs/common" @@ -30,7 +30,7 @@ var ( const nodeDirPerm = 0755 // get cmd to initialize all files for tendermint testnet and application -func TestnetFilesCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { +func TestnetFilesCmd(ctx *Context, cdc *codec.Codec, appInit AppInit) *cobra.Command { cmd := &cobra.Command{ Use: "testnet", Short: "Initialize files for a Gaiad testnet", @@ -65,7 +65,7 @@ Example: return cmd } -func testnetWithConfig(config *cfg.Config, cdc *wire.Codec, appInit AppInit) error { +func testnetWithConfig(config *cfg.Config, cdc *codec.Codec, appInit AppInit) error { outDir := viper.GetString(outputDir) numValidators := viper.GetInt(nValidators) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index bf208a5be..82652bdec 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -3,7 +3,7 @@ package server import ( "fmt" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -83,8 +83,8 @@ func ShowAddressCmd(ctx *Context) *cobra.Command { } func printlnJSON(v interface{}) error { - cdc := wire.NewCodec() - wire.RegisterCrypto(cdc) + cdc := codec.New() + codec.RegisterCrypto(cdc) marshalled, err := cdc.MarshalJSON(v) if err != nil { return err diff --git a/server/util.go b/server/util.go index 6aff52965..22dbd7867 100644 --- a/server/util.go +++ b/server/util.go @@ -11,8 +11,8 @@ import ( "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/wire" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/cli" @@ -110,7 +110,7 @@ func validateConfig(conf *cfg.Config) error { // add server commands func AddCommands( - ctx *Context, cdc *wire.Codec, + ctx *Context, cdc *codec.Codec, rootCmd *cobra.Command, appInit AppInit, appCreator AppCreator, appExport AppExporter) { @@ -147,7 +147,7 @@ func AddCommands( // // NOTE: The ordering of the keys returned as the resulting JSON message is // non-deterministic, so the client should not rely on key ordering. -func InsertKeyJSON(cdc *wire.Codec, baseJSON []byte, key string, value json.RawMessage) ([]byte, error) { +func InsertKeyJSON(cdc *codec.Codec, baseJSON []byte, key string, value json.RawMessage) ([]byte, error) { var jsonMap map[string]json.RawMessage if err := cdc.UnmarshalJSON(baseJSON, &jsonMap); err != nil { @@ -155,7 +155,7 @@ func InsertKeyJSON(cdc *wire.Codec, baseJSON []byte, key string, value json.RawM } jsonMap[key] = value - bz, err := wire.MarshalJSONIndent(cdc, jsonMap) + bz, err := codec.MarshalJSONIndent(cdc, jsonMap) return json.RawMessage(bz), err } diff --git a/server/util_test.go b/server/util_test.go index 6082caa2c..2c16759c9 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -4,12 +4,12 @@ import ( "encoding/json" "testing" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/stretchr/testify/require" ) func TestInsertKeyJSON(t *testing.T) { - cdc := wire.NewCodec() + cdc := codec.New() foo := map[string]string{"foo": "foofoo"} bar := map[string]string{"barInner": "barbar"} diff --git a/store/types.go b/store/codec.go similarity index 100% rename from store/types.go rename to store/codec.go diff --git a/store/wire.go b/store/wire.go index 7befbdfcd..5724c8e54 100644 --- a/store/wire.go +++ b/store/wire.go @@ -1,7 +1,7 @@ package store import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) -var cdc = wire.NewCodec() +var cdc = codec.New() diff --git a/types/wire.go b/types/codec.go similarity index 60% rename from types/wire.go rename to types/codec.go index 2ef28820d..3d789afe9 100644 --- a/types/wire.go +++ b/types/codec.go @@ -1,9 +1,9 @@ package types -import wire "github.com/cosmos/cosmos-sdk/wire" +import "github.com/cosmos/cosmos-sdk/codec" // Register the sdk message type -func RegisterWire(cdc *wire.Codec) { +func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*Msg)(nil), nil) cdc.RegisterInterface((*Tx)(nil), nil) } diff --git a/types/decimal_test.go b/types/decimal_test.go index 115eeacb0..779460c25 100644 --- a/types/decimal_test.go +++ b/types/decimal_test.go @@ -4,7 +4,7 @@ import ( "math/big" "testing" - wire "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/stretchr/testify/require" ) @@ -220,7 +220,7 @@ func TestToLeftPadded(t *testing.T) { } } -var cdc = wire.NewCodec() +var cdc = codec.New() func TestZeroDeserializationJSON(t *testing.T) { d := Dec{new(big.Int)} @@ -242,7 +242,7 @@ func TestSerializationText(t *testing.T) { require.True(t, d.Equal(d2), "original: %v, unmarshalled: %v", d, d2) } -func TestSerializationGoWireJSON(t *testing.T) { +func TestSerializationGocodecJSON(t *testing.T) { d := mustNewDecFromStr(t, "0.333") bz, err := cdc.MarshalJSON(d) @@ -254,7 +254,7 @@ func TestSerializationGoWireJSON(t *testing.T) { require.True(t, d.Equal(d2), "original: %v, unmarshalled: %v", d, d2) } -func TestSerializationGoWireBinary(t *testing.T) { +func TestSerializationGocodecBinary(t *testing.T) { d := mustNewDecFromStr(t, "0.333") bz, err := cdc.MarshalBinary(d) @@ -273,7 +273,7 @@ type testDEmbedStruct struct { } // TODO make work for UnmarshalJSON -func TestEmbeddedStructSerializationGoWire(t *testing.T) { +func TestEmbeddedStructSerializationGocodec(t *testing.T) { obj := testDEmbedStruct{"foo", 10, NewDecWithPrec(1, 3)} bz, err := cdc.MarshalBinary(obj) require.Nil(t, err) diff --git a/types/errors.go b/types/errors.go index c72933d60..1d0de5eb4 100644 --- a/types/errors.go +++ b/types/errors.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" + "github.com/cosmos/cosmos-sdk/codec" cmn "github.com/tendermint/tendermint/libs/common" - "github.com/cosmos/cosmos-sdk/wire" abci "github.com/tendermint/tendermint/abci/types" ) @@ -252,7 +252,7 @@ func (err *sdkError) Code() CodeType { // Implements ABCIError. func (err *sdkError) ABCILog() string { - cdc := wire.NewCodec() + cdc := codec.New() parsedErrMsg := parseCmnError(err.cmnError.Error()) jsonErr := humanReadableError{ Codespace: err.codespace, diff --git a/types/lib/linear.go b/types/lib/linear.go index 5a311a01f..1c25f4eb4 100644 --- a/types/lib/linear.go +++ b/types/lib/linear.go @@ -4,13 +4,13 @@ import ( "fmt" "strconv" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) // Linear defines a primitive mapper type type Linear struct { - cdc *wire.Codec + cdc *codec.Codec store sdk.KVStore keys *LinearKeys } @@ -36,7 +36,7 @@ func DefaultLinearKeys() *LinearKeys { } // NewLinear constructs new Linear -func NewLinear(cdc *wire.Codec, store sdk.KVStore, keys *LinearKeys) Linear { +func NewLinear(cdc *codec.Codec, store sdk.KVStore, keys *LinearKeys) Linear { if keys == nil { keys = cachedDefaultLinearKeys } @@ -87,7 +87,7 @@ type List interface { } // NewList constructs new List -func NewList(cdc *wire.Codec, store sdk.KVStore, keys *LinearKeys) List { +func NewList(cdc *codec.Codec, store sdk.KVStore, keys *LinearKeys) List { return NewLinear(cdc, store, keys) } @@ -182,7 +182,7 @@ type Queue interface { } // NewQueue constructs new Queue -func NewQueue(cdc *wire.Codec, store sdk.KVStore, keys *LinearKeys) Queue { +func NewQueue(cdc *codec.Codec, store sdk.KVStore, keys *LinearKeys) Queue { return NewLinear(cdc, store, keys) } diff --git a/types/lib/linear_test.go b/types/lib/linear_test.go index 2b5a6c405..d19c04061 100644 --- a/types/lib/linear_test.go +++ b/types/lib/linear_test.go @@ -11,9 +11,9 @@ import ( abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) type S struct { @@ -21,18 +21,18 @@ type S struct { B bool } -func defaultComponents(key sdk.StoreKey) (sdk.Context, *wire.Codec) { +func defaultComponents(key sdk.StoreKey) (sdk.Context, *codec.Codec) { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) cms.LoadLatestVersion() ctx := sdk.NewContext(cms, abci.Header{}, false, log.NewNopLogger()) - cdc := wire.NewCodec() + cdc := codec.New() return ctx, cdc } func TestNewLinear(t *testing.T) { - cdc := wire.NewCodec() + cdc := codec.New() require.NotPanics(t, func() { NewLinear(cdc, nil, nil) }) require.NotPanics(t, func() { NewLinear(cdc, nil, DefaultLinearKeys()) }) require.NotPanics(t, func() { NewLinear(cdc, nil, &LinearKeys{[]byte{0xAA}, []byte{0xBB}, []byte{0xCC}}) }) diff --git a/x/auth/account.go b/x/auth/account.go index 3340c8bd5..ceadd3951 100644 --- a/x/auth/account.go +++ b/x/auth/account.go @@ -3,8 +3,8 @@ package auth import ( "errors" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/tendermint/tendermint/crypto" ) @@ -119,8 +119,8 @@ func (acc *BaseAccount) SetSequence(seq int64) error { // Wire // Most users shouldn't use this, but this comes handy for tests. -func RegisterBaseAccount(cdc *wire.Codec) { +func RegisterBaseAccount(cdc *codec.Codec) { cdc.RegisterInterface((*Account)(nil), nil) cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil) - wire.RegisterCrypto(cdc) + codec.RegisterCrypto(cdc) } diff --git a/x/auth/account_test.go b/x/auth/account_test.go index 17878ce6f..b7a78e2d2 100644 --- a/x/auth/account_test.go +++ b/x/auth/account_test.go @@ -8,8 +8,8 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { @@ -90,20 +90,19 @@ func TestBaseAccountMarshal(t *testing.T) { require.Nil(t, err) // need a codec for marshaling - codec := wire.NewCodec() - wire.RegisterCrypto(codec) + cdc := codec.New() + codec.RegisterCrypto(cdc) - b, err := codec.MarshalBinary(acc) + b, err := cdc.MarshalBinary(acc) require.Nil(t, err) acc2 := BaseAccount{} - err = codec.UnmarshalBinary(b, &acc2) + err = cdc.UnmarshalBinary(b, &acc2) require.Nil(t, err) require.Equal(t, acc, acc2) // error on bad bytes acc2 = BaseAccount{} - err = codec.UnmarshalBinary(b[:len(b)/2], &acc2) + err = cdc.UnmarshalBinary(b[:len(b)/2], &acc2) require.NotNil(t, err) - } diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index e13784512..75fd13043 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -110,7 +110,7 @@ func newTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []in func TestAnteHandlerSigErrors(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -163,7 +163,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { func TestAnteHandlerAccountNumbers(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -222,7 +222,7 @@ func TestAnteHandlerAccountNumbers(t *testing.T) { func TestAnteHandlerSequences(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -300,7 +300,7 @@ func TestAnteHandlerSequences(t *testing.T) { func TestAnteHandlerFees(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -342,7 +342,7 @@ func TestAnteHandlerFees(t *testing.T) { func TestAnteHandlerMemoGas(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -385,7 +385,7 @@ func TestAnteHandlerMemoGas(t *testing.T) { func TestAnteHandlerMultiSigner(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -436,7 +436,7 @@ func TestAnteHandlerMultiSigner(t *testing.T) { func TestAnteHandlerBadSignBytes(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -517,7 +517,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { func TestAnteHandlerSetPubKey(t *testing.T) { // setup ms, capKey, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) feeCollector := NewFeeCollectionKeeper(cdc, capKey2) @@ -570,7 +570,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) { func TestProcessPubKey(t *testing.T) { ms, capKey, _ := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount) ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, log.NewNopLogger()) diff --git a/x/auth/client/cli/account.go b/x/auth/client/cli/account.go index 6f6359288..13c3230cf 100644 --- a/x/auth/client/cli/account.go +++ b/x/auth/client/cli/account.go @@ -6,18 +6,18 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" ) // GetAccountCmdDefault invokes the GetAccountCmd for the auth.BaseAccount type. -func GetAccountCmdDefault(storeName string, cdc *wire.Codec) *cobra.Command { +func GetAccountCmdDefault(storeName string, cdc *codec.Codec) *cobra.Command { return GetAccountCmd(storeName, cdc, GetAccountDecoder(cdc)) } // GetAccountDecoder gets the account decoder for auth.DefaultAccount. -func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder { +func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder { return func(accBytes []byte) (acct auth.Account, err error) { err = cdc.UnmarshalBinaryBare(accBytes, &acct) if err != nil { @@ -31,7 +31,7 @@ func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder { // GetAccountCmd returns a query account that will display the state of the // account at a given address. // nolint: unparam -func GetAccountCmd(storeName string, cdc *wire.Codec, decoder auth.AccountDecoder) *cobra.Command { +func GetAccountCmd(storeName string, cdc *codec.Codec, decoder auth.AccountDecoder) *cobra.Command { return &cobra.Command{ Use: "account [address]", Short: "Query account balance", @@ -58,7 +58,7 @@ func GetAccountCmd(storeName string, cdc *wire.Codec, decoder auth.AccountDecode return err } - output, err := wire.MarshalJSONIndent(cdc, acc) + output, err := codec.MarshalJSONIndent(cdc, acc) if err != nil { return err } diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 9e5fc88b5..db11cedb9 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" @@ -15,7 +15,7 @@ import ( ) // register REST routes -func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, storeName string) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, storeName string) { r.HandleFunc( "/accounts/{address}", QueryAccountRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx), @@ -28,7 +28,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, s // query accountREST Handler func QueryAccountRequestHandlerFn( - storeName string, cdc *wire.Codec, + storeName string, cdc *codec.Codec, decoder auth.AccountDecoder, cliCtx context.CLIContext, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/x/auth/client/rest/sign.go b/x/auth/client/rest/sign.go index 5acde51c5..7ded69dc5 100644 --- a/x/auth/client/rest/sign.go +++ b/x/auth/client/rest/sign.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" ) @@ -23,7 +23,7 @@ type SignBody struct { } // sign tx REST handler -func SignTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc { +func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var m SignBody @@ -51,7 +51,7 @@ func SignTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.Han return } - output, err := wire.MarshalJSONIndent(cdc, signedTx) + output, err := codec.MarshalJSONIndent(cdc, signedTx) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/auth/client/txbuilder/txbuilder.go b/x/auth/client/txbuilder/txbuilder.go index 6daa75e12..030ddb72a 100644 --- a/x/auth/client/txbuilder/txbuilder.go +++ b/x/auth/client/txbuilder/txbuilder.go @@ -3,8 +3,8 @@ package context import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/pkg/errors" @@ -13,7 +13,7 @@ import ( // TxBuilder implements a transaction context created in SDK modules. type TxBuilder struct { - Codec *wire.Codec + Codec *codec.Codec AccountNumber int64 Sequence int64 Gas int64 // TODO: should this turn into uint64? requires further discussion - see #2173 @@ -49,7 +49,7 @@ func NewTxBuilderFromCLI() TxBuilder { } // WithCodec returns a copy of the context with an updated codec. -func (bldr TxBuilder) WithCodec(cdc *wire.Codec) TxBuilder { +func (bldr TxBuilder) WithCodec(cdc *codec.Codec) TxBuilder { bldr.Codec = cdc return bldr } diff --git a/x/auth/codec.go b/x/auth/codec.go new file mode 100644 index 000000000..624bdf428 --- /dev/null +++ b/x/auth/codec.go @@ -0,0 +1,19 @@ +package auth + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// Register concrete types on codec codec for default AppAccount +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterInterface((*Account)(nil), nil) + cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil) + cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil) +} + +var msgCdc = codec.New() + +func init() { + RegisterCodec(msgCdc) + codec.RegisterCrypto(msgCdc) +} diff --git a/x/auth/feekeeper.go b/x/auth/feekeeper.go index 3e03a81aa..d2cf7ce62 100644 --- a/x/auth/feekeeper.go +++ b/x/auth/feekeeper.go @@ -1,8 +1,8 @@ package auth import ( + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) var ( @@ -16,12 +16,12 @@ type FeeCollectionKeeper struct { // The (unexposed) key used to access the fee store from the Context. key sdk.StoreKey - // The wire codec for binary encoding/decoding of accounts. - cdc *wire.Codec + // The codec codec for binary encoding/decoding of accounts. + cdc *codec.Codec } // NewFeeKeeper returns a new FeeKeeper -func NewFeeCollectionKeeper(cdc *wire.Codec, key sdk.StoreKey) FeeCollectionKeeper { +func NewFeeCollectionKeeper(cdc *codec.Codec, key sdk.StoreKey) FeeCollectionKeeper { return FeeCollectionKeeper{ key: key, cdc: cdc, diff --git a/x/auth/feekeeper_test.go b/x/auth/feekeeper_test.go index 243293cc9..82bbe9c35 100644 --- a/x/auth/feekeeper_test.go +++ b/x/auth/feekeeper_test.go @@ -8,8 +8,8 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) var ( @@ -20,7 +20,7 @@ var ( func TestFeeCollectionKeeperGetSet(t *testing.T) { ms, _, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() // make context and keeper ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) @@ -39,7 +39,7 @@ func TestFeeCollectionKeeperGetSet(t *testing.T) { func TestFeeCollectionKeeperAdd(t *testing.T) { ms, _, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() // make context and keeper ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) @@ -59,7 +59,7 @@ func TestFeeCollectionKeeperAdd(t *testing.T) { func TestFeeCollectionKeeperClear(t *testing.T) { ms, _, capKey2 := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() // make context and keeper ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) diff --git a/x/auth/mapper.go b/x/auth/mapper.go index c8bf94a21..51565c0c9 100644 --- a/x/auth/mapper.go +++ b/x/auth/mapper.go @@ -1,8 +1,8 @@ package auth import ( + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" "github.com/tendermint/tendermint/crypto" ) @@ -18,14 +18,14 @@ type AccountMapper struct { // The prototypical Account constructor. proto func() Account - // The wire codec for binary encoding/decoding of accounts. - cdc *wire.Codec + // The codec codec for binary encoding/decoding of accounts. + cdc *codec.Codec } // NewAccountMapper returns a new sdk.AccountMapper that // uses go-amino to (binary) encode and decode concrete sdk.Accounts. // nolint -func NewAccountMapper(cdc *wire.Codec, key sdk.StoreKey, proto func() Account) AccountMapper { +func NewAccountMapper(cdc *codec.Codec, key sdk.StoreKey, proto func() Account) AccountMapper { return AccountMapper{ key: key, proto: proto, diff --git a/x/auth/mapper_test.go b/x/auth/mapper_test.go index 679ee12cd..96dc57b79 100644 --- a/x/auth/mapper_test.go +++ b/x/auth/mapper_test.go @@ -9,9 +9,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + codec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) { @@ -27,7 +27,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) { func TestAccountMapperGetSet(t *testing.T) { ms, capKey, _ := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() RegisterBaseAccount(cdc) // make context and mapper diff --git a/x/auth/stdtx.go b/x/auth/stdtx.go index 69627b31a..e38dc0c7e 100644 --- a/x/auth/stdtx.go +++ b/x/auth/stdtx.go @@ -3,8 +3,8 @@ package auth import ( "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/tendermint/tendermint/crypto" ) @@ -165,7 +165,7 @@ type StdSignature struct { } // logic for standard transaction decoding -func DefaultTxDecoder(cdc *wire.Codec) sdk.TxDecoder { +func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, sdk.Error) { var tx = StdTx{} diff --git a/x/auth/wire.go b/x/auth/wire.go deleted file mode 100644 index e22151101..000000000 --- a/x/auth/wire.go +++ /dev/null @@ -1,19 +0,0 @@ -package auth - -import ( - "github.com/cosmos/cosmos-sdk/wire" -) - -// Register concrete types on wire codec for default AppAccount -func RegisterWire(cdc *wire.Codec) { - cdc.RegisterInterface((*Account)(nil), nil) - cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil) - cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil) -} - -var msgCdc = wire.NewCodec() - -func init() { - RegisterWire(msgCdc) - wire.RegisterCrypto(msgCdc) -} diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index 2a3cd5e66..a29a25b99 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -15,7 +15,7 @@ import ( func getBenchmarkMockApp() (*mock.App, error) { mapp := mock.NewApp() - RegisterWire(mapp.Cdc) + RegisterCodec(mapp.Cdc) bankKeeper := NewBaseKeeper(mapp.AccountMapper) mapp.Router().AddRoute("bank", NewHandler(bankKeeper)) diff --git a/x/bank/client/cli/sendtx.go b/x/bank/client/cli/sendtx.go index 6c49fa4f0..31fe18299 100644 --- a/x/bank/client/cli/sendtx.go +++ b/x/bank/client/cli/sendtx.go @@ -5,8 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/bank/client" @@ -22,7 +22,7 @@ const ( ) // SendTxCmd will create a send tx and sign it with the given key. -func SendTxCmd(cdc *wire.Codec) *cobra.Command { +func SendTxCmd(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "send", Short: "Create and sign a send tx", diff --git a/x/bank/client/rest/broadcast.go b/x/bank/client/rest/broadcast.go index 5124b791b..6e34acdaa 100644 --- a/x/bank/client/rest/broadcast.go +++ b/x/bank/client/rest/broadcast.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth" ) @@ -15,7 +15,7 @@ type broadcastBody struct { } // BroadcastTxRequestHandlerFn returns the broadcast tx REST handler -func BroadcastTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc { +func BroadcastTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var m broadcastBody if ok := unmarshalBodyOrReturnBadRequest(cliCtx, w, r, &m); !ok { @@ -33,7 +33,7 @@ func BroadcastTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) htt return } - output, err := wire.MarshalJSONIndent(cdc, res) + output, err := codec.MarshalJSONIndent(cdc, res) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/bank/client/rest/sendtx.go b/x/bank/client/rest/sendtx.go index 02a66f2b9..242614d11 100644 --- a/x/bank/client/rest/sendtx.go +++ b/x/bank/client/rest/sendtx.go @@ -7,9 +7,9 @@ import ( cliclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/bank/client" @@ -18,7 +18,7 @@ import ( ) // RegisterRoutes - Central function to define routes that get registered by the main application -func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc("/accounts/{address}/send", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST") r.HandleFunc("/tx/broadcast", BroadcastTxRequestHandlerFn(cdc, cliCtx)).Methods("POST") } @@ -36,15 +36,15 @@ type sendBody struct { GasAdjustment string `json:"gas_adjustment"` } -var msgCdc = wire.NewCodec() +var msgCdc = codec.New() func init() { - bank.RegisterWire(msgCdc) + bank.RegisterCodec(msgCdc) } // SendRequestHandlerFn - http request handler to send coins to a address // nolint: gocyclo -func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { +func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // collect data vars := mux.Vars(r) @@ -131,7 +131,7 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo return } - output, err := wire.MarshalJSONIndent(cdc, res) + output, err := codec.MarshalJSONIndent(cdc, res) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/bank/codec.go b/x/bank/codec.go new file mode 100644 index 000000000..bcc2cbdda --- /dev/null +++ b/x/bank/codec.go @@ -0,0 +1,17 @@ +package bank + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil) + cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil) +} + +var msgCdc = codec.New() + +func init() { + RegisterCodec(msgCdc) +} diff --git a/x/bank/keeper_test.go b/x/bank/keeper_test.go index ee45ae1ca..c48410c15 100644 --- a/x/bank/keeper_test.go +++ b/x/bank/keeper_test.go @@ -10,9 +10,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + codec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" ) @@ -29,7 +29,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) { func TestKeeper(t *testing.T) { ms, authKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) @@ -114,7 +114,7 @@ func TestKeeper(t *testing.T) { func TestSendKeeper(t *testing.T) { ms, authKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) @@ -183,7 +183,7 @@ func TestSendKeeper(t *testing.T) { func TestViewKeeper(t *testing.T) { ms, authKey := setupMultiStore() - cdc := wire.NewCodec() + cdc := codec.New() auth.RegisterBaseAccount(cdc) ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) diff --git a/x/bank/simulation/sim_test.go b/x/bank/simulation/sim_test.go index cd2353c6e..811535507 100644 --- a/x/bank/simulation/sim_test.go +++ b/x/bank/simulation/sim_test.go @@ -16,7 +16,7 @@ import ( func TestBankWithRandomMessages(t *testing.T) { mapp := mock.NewApp() - bank.RegisterWire(mapp.Cdc) + bank.RegisterCodec(mapp.Cdc) mapper := mapp.AccountMapper bankKeeper := bank.NewBaseKeeper(mapper) mapp.Router().AddRoute("bank", bank.NewHandler(bankKeeper)) diff --git a/x/bank/wire.go b/x/bank/wire.go deleted file mode 100644 index f468d3e53..000000000 --- a/x/bank/wire.go +++ /dev/null @@ -1,17 +0,0 @@ -package bank - -import ( - "github.com/cosmos/cosmos-sdk/wire" -) - -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { - cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil) - cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil) -} - -var msgCdc = wire.NewCodec() - -func init() { - RegisterWire(msgCdc) -} diff --git a/x/distribution/keeper.go b/x/distribution/keeper.go index 858632f2a..937a4674c 100644 --- a/x/distribution/keeper.go +++ b/x/distribution/keeper.go @@ -3,14 +3,14 @@ package stake //// keeper of the staking store //type Keeper struct { //storeKey sdk.StoreKey -//cdc *wire.Codec +//cdc *codec.Codec //bankKeeper bank.Keeper //// codespace //codespace sdk.CodespaceType //} -//func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper { +//func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper { //keeper := Keeper{ //storeKey: key, //cdc: cdc, diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 4ac461c0a..77364665a 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/gov" @@ -49,7 +49,7 @@ var proposalFlags = []string{ } // GetCmdSubmitProposal implements submitting a proposal transaction command. -func GetCmdSubmitProposal(cdc *wire.Codec) *cobra.Command { +func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "submit-proposal", Short: "Submit a proposal along with an initial deposit", @@ -156,7 +156,7 @@ func parseSubmitProposalFlags() (*proposal, error) { } // GetCmdDeposit implements depositing tokens for an active proposal. -func GetCmdDeposit(cdc *wire.Codec) *cobra.Command { +func GetCmdDeposit(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "deposit", Short: "deposit tokens for activing proposal", @@ -202,7 +202,7 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command { } // GetCmdVote implements creating a new vote command. -func GetCmdVote(cdc *wire.Codec) *cobra.Command { +func GetCmdVote(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "vote", Short: "vote for an active proposal, options: Yes/No/NoWithVeto/Abstain", @@ -253,7 +253,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command { } // GetCmdQueryProposal implements the query proposal command. -func GetCmdQueryProposal(queryRoute string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "query-proposal", Short: "query proposal details", @@ -287,7 +287,7 @@ func GetCmdQueryProposal(queryRoute string, cdc *wire.Codec) *cobra.Command { // nolint: gocyclo // GetCmdQueryProposals implements a query proposals command. -func GetCmdQueryProposals(queryRoute string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "query-proposals", Short: "query proposals with optional filters", @@ -366,7 +366,7 @@ func GetCmdQueryProposals(queryRoute string, cdc *wire.Codec) *cobra.Command { // Command to Get a Proposal Information // GetCmdQueryVote implements the query proposal vote command. -func GetCmdQueryVote(queryRoute string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "query-vote", Short: "query vote", @@ -405,7 +405,7 @@ func GetCmdQueryVote(queryRoute string, cdc *wire.Codec) *cobra.Command { } // GetCmdQueryVotes implements the command to query for proposal votes. -func GetCmdQueryVotes(queryRoute string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "query-votes", Short: "query votes on a proposal", @@ -438,7 +438,7 @@ func GetCmdQueryVotes(queryRoute string, cdc *wire.Codec) *cobra.Command { // Command to Get a specific Deposit Information // GetCmdQueryDeposit implements the query proposal deposit command. -func GetCmdQueryDeposit(queryRoute string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "query-deposit", Short: "query deposit", @@ -477,7 +477,7 @@ func GetCmdQueryDeposit(queryRoute string, cdc *wire.Codec) *cobra.Command { } // GetCmdQueryDeposits implements the command to query for proposal deposits. -func GetCmdQueryDeposits(queryRoute string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "query-deposits", Short: "query deposits on a proposal", @@ -509,7 +509,7 @@ func GetCmdQueryDeposits(queryRoute string, cdc *wire.Codec) *cobra.Command { } // GetCmdQueryDeposits implements the command to query for proposal deposits. -func GetCmdQueryTally(queryRoute string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "query-tally", Short: "get the tally of a proposal vote", diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 8bf675b02..059c0bb1c 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/gorilla/mux" @@ -26,7 +26,7 @@ const ( ) // RegisterRoutes - Central function to define routes that get registered by the main application -func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc("/gov/proposals", postProposalHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST") @@ -61,7 +61,7 @@ type voteReq struct { Option gov.VoteOption `json:"option"` // option from OptionSet chosen by the voter } -func postProposalHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc { +func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req postProposalReq err := buildReq(w, r, cdc, &req) @@ -85,7 +85,7 @@ func postProposalHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.Hand } } -func depositHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc { +func depositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -122,7 +122,7 @@ func depositHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFu } } -func voteHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc { +func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -159,7 +159,7 @@ func voteHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc } } -func queryProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc { +func queryProposalHandlerFn(cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -197,7 +197,7 @@ func queryProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc { } } -func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc { +func queryDepositHandlerFn(cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -264,7 +264,7 @@ func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc { } } -func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc { +func queryVoteHandlerFn(cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -336,7 +336,7 @@ func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc { // nolint: gocyclo // todo: Split this functionality into helper functions to remove the above -func queryVotesOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc { +func queryVotesOnProposalHandlerFn(cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -375,7 +375,7 @@ func queryVotesOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc { // nolint: gocyclo // todo: Split this functionality into helper functions to remove the above -func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc { +func queryProposalsWithParameterFn(cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { bechVoterAddr := r.URL.Query().Get(RestVoter) bechDepositerAddr := r.URL.Query().Get(RestDepositer) @@ -441,7 +441,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc { // nolint: gocyclo // todo: Split this functionality into helper functions to remove the above -func queryTallyOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc { +func queryTallyOnProposalHandlerFn(cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/gov/client/rest/util.go b/x/gov/client/rest/util.go index b152cb20b..0bc1a8804 100644 --- a/x/gov/client/rest/util.go +++ b/x/gov/client/rest/util.go @@ -9,8 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" ) @@ -24,7 +24,7 @@ type baseReq struct { GasAdjustment string `json:"gas_adjustment"` } -func buildReq(w http.ResponseWriter, r *http.Request, cdc *wire.Codec, req interface{}) error { +func buildReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) error { body, err := ioutil.ReadAll(r.Body) if err != nil { utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) @@ -68,7 +68,7 @@ func (req baseReq) baseReqValidate(w http.ResponseWriter) bool { // TODO: Build this function out into a more generic base-request // (probably should live in client/lcd). -func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLIContext, baseReq baseReq, msg sdk.Msg, cdc *wire.Codec) { +func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLIContext, baseReq baseReq, msg sdk.Msg, cdc *codec.Codec) { simulateGas, gas, err := client.ReadGasFlag(baseReq.Gas) if err != nil { utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) @@ -119,7 +119,7 @@ func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLICont return } - output, err := wire.MarshalJSONIndent(cdc, res) + output, err := codec.MarshalJSONIndent(cdc, res) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/gov/wire.go b/x/gov/codec.go similarity index 70% rename from x/gov/wire.go rename to x/gov/codec.go index 405ee464e..6df535449 100644 --- a/x/gov/wire.go +++ b/x/gov/codec.go @@ -1,11 +1,11 @@ package gov import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil) cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil) @@ -15,4 +15,4 @@ func RegisterWire(cdc *wire.Codec) { cdc.RegisterConcrete(&TextProposal{}, "gov/TextProposal", nil) } -var msgCdc = wire.NewCodec() +var msgCdc = codec.New() diff --git a/x/gov/keeper.go b/x/gov/keeper.go index 576d2cc22..bebcf51e7 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -1,8 +1,8 @@ package gov import ( + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/params" ) @@ -31,15 +31,15 @@ type Keeper struct { // The (unexposed) keys used to access the stores from the Context. storeKey sdk.StoreKey - // The wire codec for binary encoding/decoding. - cdc *wire.Codec + // The codec codec for binary encoding/decoding. + cdc *codec.Codec // Reserved codespace codespace sdk.CodespaceType } -// NewGovernanceMapper returns a mapper that uses go-wire to (binary) encode and decode gov types. -func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ps params.Setter, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { +// NewGovernanceMapper returns a mapper that uses go-codec to (binary) encode and decode gov types. +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ps params.Setter, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { return Keeper{ storeKey: key, ps: ps, @@ -51,8 +51,8 @@ func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ps params.Setter, ck bank.Keep } } -// Returns the go-wire codec. -func (keeper Keeper) WireCodec() *wire.Codec { +// Returns the go-codec codec. +func (keeper Keeper) WireCodec() *codec.Codec { return keeper.cdc } diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 6aa0c9884..f20bb46f7 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -3,8 +3,8 @@ package gov import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" abci "github.com/tendermint/tendermint/abci/types" ) @@ -60,7 +60,7 @@ func queryProposal(ctx sdk.Context, path []string, req abci.RequestQuery, keeper return []byte{}, ErrUnknownProposal(DefaultCodespace, params.ProposalID) } - bz, err2 := wire.MarshalJSONIndent(keeper.cdc, proposal) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, proposal) if err2 != nil { panic("could not marshal result to JSON") } @@ -82,7 +82,7 @@ func queryDeposit(ctx sdk.Context, path []string, req abci.RequestQuery, keeper } deposit, _ := keeper.GetDeposit(ctx, params.ProposalID, params.Depositer) - bz, err2 := wire.MarshalJSONIndent(keeper.cdc, deposit) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, deposit) if err2 != nil { panic("could not marshal result to JSON") } @@ -104,7 +104,7 @@ func queryVote(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Kee } vote, _ := keeper.GetVote(ctx, params.ProposalID, params.Voter) - bz, err2 := wire.MarshalJSONIndent(keeper.cdc, vote) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, vote) if err2 != nil { panic("could not marshal result to JSON") } @@ -132,7 +132,7 @@ func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper deposits = append(deposits, deposit) } - bz, err2 := wire.MarshalJSONIndent(keeper.cdc, deposits) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, deposits) if err2 != nil { panic("could not marshal result to JSON") } @@ -161,7 +161,7 @@ func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke votes = append(votes, vote) } - bz, err2 := wire.MarshalJSONIndent(keeper.cdc, votes) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, votes) if err2 != nil { panic("could not marshal result to JSON") } @@ -186,7 +186,7 @@ func queryProposals(ctx sdk.Context, path []string, req abci.RequestQuery, keepe proposals := keeper.GetProposalsFiltered(ctx, params.Voter, params.Depositer, params.ProposalStatus, params.NumLatestProposals) - bz, err2 := wire.MarshalJSONIndent(keeper.cdc, proposals) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, proposals) if err2 != nil { panic("could not marshal result to JSON") } @@ -223,7 +223,7 @@ func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke _, tallyResult, _ = tally(ctx, keeper, proposal) } - bz, err2 := wire.MarshalJSONIndent(keeper.cdc, tallyResult) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, tallyResult) if err2 != nil { panic("could not marshal result to JSON") } diff --git a/x/gov/simulation/msgs.go b/x/gov/simulation/msgs.go index 3eb21b79a..478b4be0f 100644 --- a/x/gov/simulation/msgs.go +++ b/x/gov/simulation/msgs.go @@ -156,7 +156,6 @@ func SimulateMsgVote(k gov.Keeper, sk stake.Keeper) simulation.Operation { return operationSimulateMsgVote(k, sk, nil, -1) } - // nolint: unparam func operationSimulateMsgVote(k gov.Keeper, sk stake.Keeper, key crypto.PrivKey, proposalID int64) simulation.Operation { return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, event func(string)) (action string, fOp []simulation.FutureOperation, err error) { diff --git a/x/gov/simulation/sim_test.go b/x/gov/simulation/sim_test.go index 841b4c0f7..35a11fb07 100644 --- a/x/gov/simulation/sim_test.go +++ b/x/gov/simulation/sim_test.go @@ -21,8 +21,8 @@ import ( func TestGovWithRandomMessages(t *testing.T) { mapp := mock.NewApp() - bank.RegisterWire(mapp.Cdc) - gov.RegisterWire(mapp.Cdc) + bank.RegisterCodec(mapp.Cdc) + gov.RegisterCodec(mapp.Cdc) mapper := mapp.AccountMapper bankKeeper := bank.NewBaseKeeper(mapper) stakeKey := sdk.NewKVStoreKey("stake") diff --git a/x/gov/test_common.go b/x/gov/test_common.go index f2f3625e6..fdede91eb 100644 --- a/x/gov/test_common.go +++ b/x/gov/test_common.go @@ -23,8 +23,8 @@ import ( func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper, []sdk.AccAddress, []crypto.PubKey, []crypto.PrivKey) { mapp := mock.NewApp() - stake.RegisterWire(mapp.Cdc) - RegisterWire(mapp.Cdc) + stake.RegisterCodec(mapp.Cdc) + RegisterCodec(mapp.Cdc) keyGlobalParams := sdk.NewKVStoreKey("params") keyStake := sdk.NewKVStoreKey("stake") diff --git a/x/ibc/app_test.go b/x/ibc/app_test.go index e92e71a8c..6806d9779 100644 --- a/x/ibc/app_test.go +++ b/x/ibc/app_test.go @@ -18,7 +18,7 @@ import ( func getMockApp(t *testing.T) *mock.App { mapp := mock.NewApp() - RegisterWire(mapp.Cdc) + RegisterCodec(mapp.Cdc) keyIBC := sdk.NewKVStoreKey("ibc") ibcMapper := NewMapper(mapp.Cdc, keyIBC, mapp.RegisterCodespace(DefaultCodespace)) bankKeeper := bank.NewBaseKeeper(mapp.AccountMapper) diff --git a/x/ibc/client/cli/ibctx.go b/x/ibc/client/cli/ibctx.go index 49494a218..d34d6687b 100644 --- a/x/ibc/client/cli/ibctx.go +++ b/x/ibc/client/cli/ibctx.go @@ -7,8 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/ibc" @@ -24,7 +24,7 @@ const ( ) // IBCTransferCmd implements the IBC transfer command. -func IBCTransferCmd(cdc *wire.Codec) *cobra.Command { +func IBCTransferCmd(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "transfer", RunE: func(cmd *cobra.Command, args []string) error { diff --git a/x/ibc/client/cli/relay.go b/x/ibc/client/cli/relay.go index e93806974..a2b626b2c 100644 --- a/x/ibc/client/cli/relay.go +++ b/x/ibc/client/cli/relay.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/keys" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" @@ -28,7 +28,7 @@ const ( ) type relayCommander struct { - cdc *wire.Codec + cdc *codec.Codec address sdk.AccAddress decoder auth.AccountDecoder mainStore string @@ -39,7 +39,7 @@ type relayCommander struct { } // IBCRelayCmd implements the IBC relay command. -func IBCRelayCmd(cdc *wire.Codec) *cobra.Command { +func IBCRelayCmd(cdc *codec.Codec) *cobra.Command { cmdr := relayCommander{ cdc: cdc, decoder: authcmd.GetAccountDecoder(cdc), diff --git a/x/ibc/client/rest/transfer.go b/x/ibc/client/rest/transfer.go index 5a7b632e8..e44ea240b 100644 --- a/x/ibc/client/rest/transfer.go +++ b/x/ibc/client/rest/transfer.go @@ -7,9 +7,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/ibc" @@ -17,7 +17,7 @@ import ( ) // RegisterRoutes - Central function to define routes that get registered by the main application -func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc("/ibc/{destchain}/{address}/send", TransferRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST") } @@ -36,7 +36,7 @@ type transferBody struct { // TransferRequestHandler - http request handler to transfer coins to a address // on a different chain via IBC // nolint: gocyclo -func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { +func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) destChainID := vars["destchain"] diff --git a/x/ibc/wire.go b/x/ibc/codec.go similarity index 59% rename from x/ibc/wire.go rename to x/ibc/codec.go index f5644acc5..43ffeb519 100644 --- a/x/ibc/wire.go +++ b/x/ibc/codec.go @@ -1,11 +1,11 @@ package ibc import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(IBCTransferMsg{}, "cosmos-sdk/IBCTransferMsg", nil) cdc.RegisterConcrete(IBCReceiveMsg{}, "cosmos-sdk/IBCReceiveMsg", nil) } diff --git a/x/ibc/ibc_test.go b/x/ibc/ibc_test.go index acc484e0a..c8e7492be 100644 --- a/x/ibc/ibc_test.go +++ b/x/ibc/ibc_test.go @@ -10,9 +10,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -38,8 +38,8 @@ func getCoins(ck bank.Keeper, ctx sdk.Context, addr sdk.AccAddress) (sdk.Coins, return coins, err } -func makeCodec() *wire.Codec { - var cdc = wire.NewCodec() +func makeCodec() *codec.Codec { + var cdc = codec.New() // Register Msgs cdc.RegisterInterface((*sdk.Msg)(nil), nil) @@ -51,7 +51,7 @@ func makeCodec() *wire.Codec { // Register AppAccount cdc.RegisterInterface((*auth.Account)(nil), nil) cdc.RegisterConcrete(&auth.BaseAccount{}, "test/ibc/Account", nil) - wire.RegisterCrypto(cdc) + codec.RegisterCrypto(cdc) cdc.Seal() diff --git a/x/ibc/mapper.go b/x/ibc/mapper.go index 251699617..95c88b62f 100644 --- a/x/ibc/mapper.go +++ b/x/ibc/mapper.go @@ -3,20 +3,20 @@ package ibc import ( "fmt" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) // IBC Mapper type Mapper struct { key sdk.StoreKey - cdc *wire.Codec + cdc *codec.Codec codespace sdk.CodespaceType } // XXX: The Mapper should not take a CoinKeeper. Rather have the CoinKeeper // take an Mapper. -func NewMapper(cdc *wire.Codec, key sdk.StoreKey, codespace sdk.CodespaceType) Mapper { +func NewMapper(cdc *codec.Codec, key sdk.StoreKey, codespace sdk.CodespaceType) Mapper { // XXX: How are these codecs supposed to work? return Mapper{ key: key, @@ -60,7 +60,7 @@ func (ibcm Mapper) ReceiveIBCPacket(ctx sdk.Context, packet IBCPacket) sdk.Error // -------------------------- // Functions for accessing the underlying KVStore. -func marshalBinaryPanic(cdc *wire.Codec, value interface{}) []byte { +func marshalBinaryPanic(cdc *codec.Codec, value interface{}) []byte { res, err := cdc.MarshalBinary(value) if err != nil { panic(err) @@ -68,7 +68,7 @@ func marshalBinaryPanic(cdc *wire.Codec, value interface{}) []byte { return res } -func unmarshalBinaryPanic(cdc *wire.Codec, bz []byte, ptr interface{}) { +func unmarshalBinaryPanic(cdc *codec.Codec, bz []byte, ptr interface{}) { err := cdc.UnmarshalBinary(bz, ptr) if err != nil { panic(err) diff --git a/x/ibc/types.go b/x/ibc/types.go index b3fe6fc39..0dcc0813d 100644 --- a/x/ibc/types.go +++ b/x/ibc/types.go @@ -3,16 +3,16 @@ package ibc import ( "encoding/json" + codec "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - wire "github.com/cosmos/cosmos-sdk/wire" ) var ( - msgCdc *wire.Codec + msgCdc *codec.Codec ) func init() { - msgCdc = wire.NewCodec() + msgCdc = codec.New() } // ------------------------------ diff --git a/x/mock/app.go b/x/mock/app.go index ebfb97ae5..1fe411fbc 100644 --- a/x/mock/app.go +++ b/x/mock/app.go @@ -6,8 +6,8 @@ import ( "os" bam "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -24,7 +24,7 @@ const chainID = "" // capabilities aren't needed for testing. type App struct { *bam.BaseApp - Cdc *wire.Codec // Cdc is public since the codec is passed into the module anyways + Cdc *codec.Codec // Cdc is public since the codec is passed into the module anyways KeyMain *sdk.KVStoreKey KeyAccount *sdk.KVStoreKey @@ -43,10 +43,10 @@ func NewApp() *App { db := dbm.NewMemDB() // Create the cdc with some standard codecs - cdc := wire.NewCodec() - sdk.RegisterWire(cdc) - wire.RegisterCrypto(cdc) - auth.RegisterWire(cdc) + cdc := codec.New() + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + auth.RegisterCodec(cdc) // Create your application object app := &App{ diff --git a/x/params/keeper.go b/x/params/keeper.go index 7fd9bb3c9..ca158ad42 100644 --- a/x/params/keeper.go +++ b/x/params/keeper.go @@ -4,18 +4,18 @@ import ( "fmt" "reflect" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // Keeper manages global parameter store type Keeper struct { - cdc *wire.Codec + cdc *codec.Codec key sdk.StoreKey } // NewKeeper constructs a new Keeper -func NewKeeper(cdc *wire.Codec, key sdk.StoreKey) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey) Keeper { return Keeper{ cdc: cdc, key: key, @@ -24,7 +24,7 @@ func NewKeeper(cdc *wire.Codec, key sdk.StoreKey) Keeper { // InitKeeper constructs a new Keeper with initial parameters // nolint: errcheck -func InitKeeper(ctx sdk.Context, cdc *wire.Codec, key sdk.StoreKey, params ...interface{}) Keeper { +func InitKeeper(ctx sdk.Context, cdc *codec.Codec, key sdk.StoreKey, params ...interface{}) Keeper { if len(params)%2 != 0 { panic("Odd params list length for InitKeeper") } diff --git a/x/params/keeper_test.go b/x/params/keeper_test.go index 626d68c7d..7eac7319f 100644 --- a/x/params/keeper_test.go +++ b/x/params/keeper_test.go @@ -9,9 +9,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) func defaultContext(key sdk.StoreKey) sdk.Context { @@ -37,7 +37,7 @@ func TestKeeper(t *testing.T) { skey := sdk.NewKVStoreKey("test") ctx := defaultContext(skey) - setter := NewKeeper(wire.NewCodec(), skey).Setter() + setter := NewKeeper(codec.New(), skey).Setter() for _, kv := range kvs { err := setter.Set(ctx, kv.key, kv.param) @@ -51,7 +51,7 @@ func TestKeeper(t *testing.T) { assert.Equal(t, kv.param, param) } - cdc := wire.NewCodec() + cdc := codec.New() for _, kv := range kvs { var param int64 bz := setter.GetRaw(ctx, kv.key) @@ -75,7 +75,7 @@ func TestKeeper(t *testing.T) { func TestGetter(t *testing.T) { key := sdk.NewKVStoreKey("test") ctx := defaultContext(key) - keeper := NewKeeper(wire.NewCodec(), key) + keeper := NewKeeper(codec.New(), key) g := keeper.Getter() s := keeper.Setter() diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 90e8137e2..497440a08 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -24,7 +24,7 @@ var ( func getMockApp(t *testing.T) (*mock.App, stake.Keeper, Keeper) { mapp := mock.NewApp() - RegisterWire(mapp.Cdc) + RegisterCodec(mapp.Cdc) keyStake := sdk.NewKVStoreKey("stake") tkeyStake := sdk.NewTransientStoreKey("transient_stake") keySlashing := sdk.NewKVStoreKey("slashing") diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index 87d0ad41d..50ccc6c0e 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -8,13 +8,13 @@ import ( "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" // XXX fix sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" // XXX fix "github.com/cosmos/cosmos-sdk/x/slashing" ) // GetCmdQuerySigningInfo implements the command to query signing info. -func GetCmdQuerySigningInfo(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "signing-info [validator-pubkey]", Short: "Query a validator's signing information", @@ -44,7 +44,7 @@ func GetCmdQuerySigningInfo(storeName string, cdc *wire.Codec) *cobra.Command { case "json": // parse out the signing info - output, err := wire.MarshalJSONIndent(cdc, signingInfo) + output, err := codec.MarshalJSONIndent(cdc, signingInfo) if err != nil { return err } diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index 1810ffeed..9d7e46578 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -5,8 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -15,7 +15,7 @@ import ( ) // GetCmdUnjail implements the create unjail validator command. -func GetCmdUnjail(cdc *wire.Codec) *cobra.Command { +func GetCmdUnjail(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "unjail", Args: cobra.NoArgs, diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 0ebe13250..e83f1a235 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -5,13 +5,13 @@ import ( "net/http" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/gorilla/mux" ) -func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec) { +func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc( "/slashing/signing_info/{validator}", signingInfoHandlerFn(cliCtx, "slashing", cdc), @@ -20,7 +20,7 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Cod // http request handler to query signing info // nolint: unparam -func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *wire.Codec) http.HandlerFunc { +func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/x/slashing/client/rest/rest.go b/x/slashing/client/rest/rest.go index 7c2fdf905..507fcb517 100644 --- a/x/slashing/client/rest/rest.go +++ b/x/slashing/client/rest/rest.go @@ -2,14 +2,14 @@ package rest import ( "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys" - "github.com/cosmos/cosmos-sdk/wire" "github.com/gorilla/mux" ) // RegisterRoutes registers staking-related REST handlers to a router -func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { registerQueryRoutes(cliCtx, r, cdc) registerTxRoutes(cliCtx, r, cdc, kb) } diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 969cdcce0..45b1b6471 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -10,16 +10,16 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/gorilla/mux" ) -func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { +func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc( "/slashing/unjail", unjailRequestHandlerFn(cdc, kb, cliCtx), @@ -39,7 +39,7 @@ type UnjailBody struct { } // nolint: gocyclo -func unjailRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { +func unjailRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var m UnjailBody body, err := ioutil.ReadAll(r.Body) diff --git a/x/slashing/codec.go b/x/slashing/codec.go new file mode 100644 index 000000000..ebe08428c --- /dev/null +++ b/x/slashing/codec.go @@ -0,0 +1,12 @@ +package slashing + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) +} + +var cdcEmpty = codec.New() diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index 272516585..5a008ccec 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -6,8 +6,8 @@ import ( tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/params" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -16,7 +16,7 @@ import ( // Keeper of the slashing store type Keeper struct { storeKey sdk.StoreKey - cdc *wire.Codec + cdc *codec.Codec validatorSet sdk.ValidatorSet params params.Getter // codespace @@ -24,7 +24,7 @@ type Keeper struct { } // NewKeeper creates a slashing keeper -func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, params params.Getter, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, params params.Getter, codespace sdk.CodespaceType) Keeper { keeper := Keeper{ storeKey: key, cdc: cdc, diff --git a/x/slashing/msg.go b/x/slashing/msg.go index 3d2bdedca..58aae2498 100644 --- a/x/slashing/msg.go +++ b/x/slashing/msg.go @@ -1,11 +1,11 @@ package slashing import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) -var cdc = wire.NewCodec() +var cdc = codec.New() // name to identify transaction types const MsgType = "slashing" diff --git a/x/slashing/test_common.go b/x/slashing/test_common.go index a21930ad9..db2293a2f 100644 --- a/x/slashing/test_common.go +++ b/x/slashing/test_common.go @@ -14,9 +14,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/params" @@ -39,13 +39,13 @@ var ( initCoins = sdk.NewInt(200) ) -func createTestCodec() *wire.Codec { - cdc := wire.NewCodec() - sdk.RegisterWire(cdc) - auth.RegisterWire(cdc) - bank.RegisterWire(cdc) - stake.RegisterWire(cdc) - wire.RegisterCrypto(cdc) +func createTestCodec() *codec.Codec { + cdc := codec.New() + sdk.RegisterCodec(cdc) + auth.RegisterCodec(cdc) + bank.RegisterCodec(cdc) + stake.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) return cdc } diff --git a/x/slashing/wire.go b/x/slashing/wire.go deleted file mode 100644 index 208acda06..000000000 --- a/x/slashing/wire.go +++ /dev/null @@ -1,12 +0,0 @@ -package slashing - -import ( - "github.com/cosmos/cosmos-sdk/wire" -) - -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { - cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) -} - -var cdcEmpty = wire.NewCodec() diff --git a/x/stake/app_test.go b/x/stake/app_test.go index a787e5e4d..6542fb196 100644 --- a/x/stake/app_test.go +++ b/x/stake/app_test.go @@ -31,7 +31,7 @@ var ( func getMockApp(t *testing.T) (*mock.App, Keeper) { mApp := mock.NewApp() - RegisterWire(mApp.Cdc) + RegisterCodec(mApp.Cdc) keyStake := sdk.NewKVStoreKey("stake") tkeyStake := sdk.NewTransientStoreKey("transient_stake") diff --git a/x/stake/client/cli/query.go b/x/stake/client/cli/query.go index 9a017fb59..26b57c2a6 100644 --- a/x/stake/client/cli/query.go +++ b/x/stake/client/cli/query.go @@ -8,14 +8,14 @@ import ( "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/stake" "github.com/cosmos/cosmos-sdk/x/stake/types" ) // GetCmdQueryValidator implements the validator query command. -func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryValidator(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "validator [operator-addr]", Short: "Query a validator", @@ -48,7 +48,7 @@ func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command { case "json": // parse out the validator - output, err := wire.MarshalJSONIndent(cdc, validator) + output, err := codec.MarshalJSONIndent(cdc, validator) if err != nil { return err } @@ -65,7 +65,7 @@ func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command { } // GetCmdQueryValidators implements the query all validators command. -func GetCmdQueryValidators(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "validators", Short: "Query for all validators", @@ -97,7 +97,7 @@ func GetCmdQueryValidators(storeName string, cdc *wire.Codec) *cobra.Command { fmt.Println(resp) } case "json": - output, err := wire.MarshalJSONIndent(cdc, validators) + output, err := codec.MarshalJSONIndent(cdc, validators) if err != nil { return err } @@ -115,7 +115,7 @@ func GetCmdQueryValidators(storeName string, cdc *wire.Codec) *cobra.Command { } // GetCmdQueryDelegation the query delegation command. -func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "delegation", Short: "Query a delegation based on address and validator address", @@ -153,7 +153,7 @@ func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command { fmt.Println(resp) case "json": - output, err := wire.MarshalJSONIndent(cdc, delegation) + output, err := codec.MarshalJSONIndent(cdc, delegation) if err != nil { return err } @@ -174,7 +174,7 @@ func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command { // GetCmdQueryDelegations implements the command to query all the delegations // made from one delegator. -func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryDelegations(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "delegations [delegator-addr]", Short: "Query all delegations made from one delegator", @@ -200,7 +200,7 @@ func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command { delegations = append(delegations, delegation) } - output, err := wire.MarshalJSONIndent(cdc, delegations) + output, err := codec.MarshalJSONIndent(cdc, delegations) if err != nil { return err } @@ -217,7 +217,7 @@ func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command { // GetCmdQueryUnbondingDelegation implements the command to query a single // unbonding-delegation record. -func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "unbonding-delegation", Short: "Query an unbonding-delegation record based on delegator and validator address", @@ -252,7 +252,7 @@ func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Co fmt.Println(resp) case "json": - output, err := wire.MarshalJSONIndent(cdc, ubd) + output, err := codec.MarshalJSONIndent(cdc, ubd) if err != nil { return err } @@ -273,7 +273,7 @@ func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Co // GetCmdQueryUnbondingDelegations implements the command to query all the // unbonding-delegation records for a delegator. -func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryUnbondingDelegations(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "unbonding-delegations [delegator-addr]", Short: "Query all unbonding-delegations records for one delegator", @@ -299,7 +299,7 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.C ubds = append(ubds, ubd) } - output, err := wire.MarshalJSONIndent(cdc, ubds) + output, err := codec.MarshalJSONIndent(cdc, ubds) if err != nil { return err } @@ -316,7 +316,7 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.C // GetCmdQueryRedelegation implements the command to query a single // redelegation record. -func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryRedelegation(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "redelegation", Short: "Query a redelegation record based on delegator and a source and destination validator address", @@ -356,7 +356,7 @@ func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command { fmt.Println(resp) case "json": - output, err := wire.MarshalJSONIndent(cdc, red) + output, err := codec.MarshalJSONIndent(cdc, red) if err != nil { return err } @@ -377,7 +377,7 @@ func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command { // GetCmdQueryRedelegations implements the command to query all the // redelegation records for a delegator. -func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryRedelegations(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "redelegations [delegator-addr]", Short: "Query all redelegations records for one delegator", @@ -403,7 +403,7 @@ func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command reds = append(reds, red) } - output, err := wire.MarshalJSONIndent(cdc, reds) + output, err := codec.MarshalJSONIndent(cdc, reds) if err != nil { return err } @@ -419,7 +419,7 @@ func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command } // GetCmdQueryPool implements the pool query command. -func GetCmdQueryPool(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryPool(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "pool", Short: "Query the current staking pool values", @@ -443,7 +443,7 @@ func GetCmdQueryPool(storeName string, cdc *wire.Codec) *cobra.Command { case "json": // parse out the pool - output, err := wire.MarshalJSONIndent(cdc, pool) + output, err := codec.MarshalJSONIndent(cdc, pool) if err != nil { return err } @@ -458,7 +458,7 @@ func GetCmdQueryPool(storeName string, cdc *wire.Codec) *cobra.Command { } // GetCmdQueryPool implements the params query command. -func GetCmdQueryParams(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdQueryParams(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "parameters", Short: "Query the current staking parameters information", @@ -482,7 +482,7 @@ func GetCmdQueryParams(storeName string, cdc *wire.Codec) *cobra.Command { case "json": // parse out the params - output, err := wire.MarshalJSONIndent(cdc, params) + output, err := codec.MarshalJSONIndent(cdc, params) if err != nil { return err } diff --git a/x/stake/client/cli/tx.go b/x/stake/client/cli/tx.go index fad881803..f91717328 100644 --- a/x/stake/client/cli/tx.go +++ b/x/stake/client/cli/tx.go @@ -7,8 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/stake" @@ -20,7 +20,7 @@ import ( ) // GetCmdCreateValidator implements the create validator command handler. -func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command { +func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "create-validator", Short: "create new validator initialized with a self-delegation to it", @@ -94,7 +94,7 @@ func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command { } // GetCmdEditValidator implements the create edit validator command. -func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command { +func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "edit-validator", Short: "edit and existing validator account", @@ -133,7 +133,7 @@ func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command { } // GetCmdDelegate implements the delegate command. -func GetCmdDelegate(cdc *wire.Codec) *cobra.Command { +func GetCmdDelegate(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "delegate", Short: "delegate liquid tokens to an validator", @@ -176,7 +176,7 @@ func GetCmdDelegate(cdc *wire.Codec) *cobra.Command { } // GetCmdRedelegate implements the redelegate validator command. -func GetCmdRedelegate(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "redelegate", Short: "redelegate illiquid tokens from one validator to another", @@ -192,7 +192,7 @@ func GetCmdRedelegate(storeName string, cdc *wire.Codec) *cobra.Command { } // GetCmdBeginRedelegate the begin redelegation command. -func GetCmdBeginRedelegate(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdBeginRedelegate(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "begin", Short: "begin redelegation", @@ -250,7 +250,7 @@ func GetCmdBeginRedelegate(storeName string, cdc *wire.Codec) *cobra.Command { // nolint: gocyclo // TODO: Make this pass gocyclo linting func getShares( - storeName string, cdc *wire.Codec, sharesAmountStr, + storeName string, cdc *codec.Codec, sharesAmountStr, sharesPercentStr string, delAddr sdk.AccAddress, valAddr sdk.ValAddress, ) (sharesAmount sdk.Dec, err error) { switch { @@ -296,7 +296,7 @@ func getShares( } // GetCmdCompleteRedelegate implements the complete redelegation command. -func GetCmdCompleteRedelegate(cdc *wire.Codec) *cobra.Command { +func GetCmdCompleteRedelegate(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "complete", Short: "complete redelegation", @@ -338,7 +338,7 @@ func GetCmdCompleteRedelegate(cdc *wire.Codec) *cobra.Command { } // GetCmdUnbond implements the unbond validator command. -func GetCmdUnbond(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "unbond", Short: "begin or complete unbonding shares from a validator", @@ -354,7 +354,7 @@ func GetCmdUnbond(storeName string, cdc *wire.Codec) *cobra.Command { } // GetCmdBeginUnbonding implements the begin unbonding validator command. -func GetCmdBeginUnbonding(storeName string, cdc *wire.Codec) *cobra.Command { +func GetCmdBeginUnbonding(storeName string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "begin", Short: "begin unbonding", @@ -403,7 +403,7 @@ func GetCmdBeginUnbonding(storeName string, cdc *wire.Codec) *cobra.Command { } // GetCmdCompleteUnbonding implements the complete unbonding validator command. -func GetCmdCompleteUnbonding(cdc *wire.Codec) *cobra.Command { +func GetCmdCompleteUnbonding(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "complete", Short: "complete unbonding", diff --git a/x/stake/client/rest/query.go b/x/stake/client/rest/query.go index 7a0602ee2..ca1d71b9a 100644 --- a/x/stake/client/rest/query.go +++ b/x/stake/client/rest/query.go @@ -7,8 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/stake" "github.com/cosmos/cosmos-sdk/x/stake/tags" "github.com/cosmos/cosmos-sdk/x/stake/types" @@ -18,7 +18,7 @@ import ( const storeName = "stake" -func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec) { +func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { // Get all delegations (delegation, undelegation and redelegation) from a delegator r.HandleFunc( @@ -100,7 +100,7 @@ type DelegationSummary struct { } // HTTP request handler to query a delegator delegations -func delegatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func delegatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var valAddr sdk.ValAddress @@ -177,7 +177,7 @@ func delegatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Handler // nolint gocyclo // HTTP request handler to query all staking txs (msgs) from a delegator -func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var output []byte var typesQuerySlice []string @@ -253,7 +253,7 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Hand } // HTTP request handler to query an unbonding-delegation -func unbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func unbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) bech32delegator := vars["delegatorAddr"] @@ -310,7 +310,7 @@ func unbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) h } // HTTP request handler to query a bonded validator -func delegationHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func delegationHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // read parameters vars := mux.Vars(r) @@ -372,7 +372,7 @@ func delegationHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Handle } // HTTP request handler to query all delegator bonded validators -func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var valAddr sdk.ValAddress @@ -434,7 +434,7 @@ func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) ht } // HTTP request handler to get information from a currently bonded validator -func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // read parameters var output []byte @@ -473,7 +473,7 @@ func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) htt // TODO bech32 // http request handler to query list of validators -func validatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { kvs, err := cliCtx.QuerySubspace(stake.ValidatorsKey, storeName) if err != nil { @@ -507,7 +507,7 @@ func validatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Handle } // HTTP request handler to query the validator information from a given validator address -func validatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func validatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var output []byte @@ -560,7 +560,7 @@ func validatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Handler } // HTTP request handler to query the pool information -func poolHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func poolHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { key := stake.PoolKey @@ -590,7 +590,7 @@ func poolHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc } // HTTP request handler to query the staking params values -func paramsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc { +func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { key := stake.ParamKey diff --git a/x/stake/client/rest/rest.go b/x/stake/client/rest/rest.go index 7c2fdf905..507fcb517 100644 --- a/x/stake/client/rest/rest.go +++ b/x/stake/client/rest/rest.go @@ -2,14 +2,14 @@ package rest import ( "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys" - "github.com/cosmos/cosmos-sdk/wire" "github.com/gorilla/mux" ) // RegisterRoutes registers staking-related REST handlers to a router -func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { +func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { registerQueryRoutes(cliCtx, r, cdc) registerTxRoutes(cliCtx, r, cdc, kb) } diff --git a/x/stake/client/rest/tx.go b/x/stake/client/rest/tx.go index fda92f85a..b71684360 100644 --- a/x/stake/client/rest/tx.go +++ b/x/stake/client/rest/tx.go @@ -9,9 +9,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/utils" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/stake" @@ -20,7 +20,7 @@ import ( ctypes "github.com/tendermint/tendermint/rpc/core/types" ) -func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { +func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) { r.HandleFunc( "/stake/delegators/{delegatorAddr}/delegations", delegationsRequestHandlerFn(cdc, kb, cliCtx), @@ -72,7 +72,7 @@ type EditDelegationsBody struct { // nolint: gocyclo // TODO: Split this up into several smaller functions, and remove the above nolint // TODO: use sdk.ValAddress instead of sdk.AccAddress for validators in messages -func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { +func delegationsRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var m EditDelegationsBody @@ -329,7 +329,7 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex results[i] = res } - output, err := wire.MarshalJSONIndent(cdc, results[:]) + output, err := codec.MarshalJSONIndent(cdc, results[:]) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/stake/client/rest/utils.go b/x/stake/client/rest/utils.go index 13f3abb74..6bd91e740 100644 --- a/x/stake/client/rest/utils.go +++ b/x/stake/client/rest/utils.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/stake" "github.com/cosmos/cosmos-sdk/x/stake/tags" "github.com/cosmos/cosmos-sdk/x/stake/types" @@ -24,7 +24,7 @@ func contains(stringSlice []string, txType string) bool { return false } -func getDelegatorValidator(cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( +func getDelegatorValidator(cliCtx context.CLIContext, cdc *codec.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( validator types.Validator, httpStatusCode int, errMsg string, err error) { key := stake.GetDelegationKey(delAddr, valAddr) @@ -53,7 +53,7 @@ func getDelegatorValidator(cliCtx context.CLIContext, cdc *wire.Codec, delAddr s } func getDelegatorDelegations( - cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( + cliCtx context.CLIContext, cdc *codec.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( outputDelegation DelegationWithoutRat, httpStatusCode int, errMsg string, err error) { delegationKey := stake.GetDelegationKey(delAddr, valAddr) @@ -82,7 +82,7 @@ func getDelegatorDelegations( } func getDelegatorUndelegations( - cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( + cliCtx context.CLIContext, cdc *codec.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( unbonds types.UnbondingDelegation, httpStatusCode int, errMsg string, err error) { undelegationKey := stake.GetUBDKey(delAddr, valAddr) @@ -103,7 +103,7 @@ func getDelegatorUndelegations( } func getDelegatorRedelegations( - cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( + cliCtx context.CLIContext, cdc *codec.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( regelegations types.Redelegation, httpStatusCode int, errMsg string, err error) { key := stake.GetREDsByDelToValDstIndexKey(delAddr, valAddr) @@ -125,7 +125,7 @@ func getDelegatorRedelegations( } // queries staking txs -func queryTxs(node rpcclient.Client, cdc *wire.Codec, tag string, delegatorAddr string) ([]tx.Info, error) { +func queryTxs(node rpcclient.Client, cdc *codec.Codec, tag string, delegatorAddr string) ([]tx.Info, error) { page := 0 perPage := 100 prove := false @@ -139,7 +139,7 @@ func queryTxs(node rpcclient.Client, cdc *wire.Codec, tag string, delegatorAddr } // gets all validators -func getValidators(validatorKVs []sdk.KVPair, cdc *wire.Codec) ([]types.Validator, error) { +func getValidators(validatorKVs []sdk.KVPair, cdc *codec.Codec) ([]types.Validator, error) { validators := make([]types.Validator, len(validatorKVs)) for i, kv := range validatorKVs { @@ -156,7 +156,7 @@ func getValidators(validatorKVs []sdk.KVPair, cdc *wire.Codec) ([]types.Validato // gets all Bech32 validators from a key // nolint: unparam -func getBech32Validators(storeName string, cliCtx context.CLIContext, cdc *wire.Codec) ( +func getBech32Validators(storeName string, cliCtx context.CLIContext, cdc *codec.Codec) ( validators []types.Validator, httpStatusCode int, errMsg string, err error) { // Get all validators using key diff --git a/x/stake/keeper/keeper.go b/x/stake/keeper/keeper.go index cbf6e39e4..a3754f750 100644 --- a/x/stake/keeper/keeper.go +++ b/x/stake/keeper/keeper.go @@ -1,8 +1,8 @@ package keeper import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/stake/types" @@ -12,7 +12,7 @@ import ( type Keeper struct { storeKey sdk.StoreKey storeTKey sdk.StoreKey - cdc *wire.Codec + cdc *codec.Codec bankKeeper bank.Keeper validatorHooks sdk.ValidatorHooks @@ -20,7 +20,7 @@ type Keeper struct { codespace sdk.CodespaceType } -func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper { keeper := Keeper{ storeKey: key, storeTKey: tkey, diff --git a/x/stake/keeper/test_common.go b/x/stake/keeper/test_common.go index 8ebded7bf..03d4642b6 100644 --- a/x/stake/keeper/test_common.go +++ b/x/stake/keeper/test_common.go @@ -14,9 +14,9 @@ import ( dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/stake/types" @@ -52,8 +52,8 @@ func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, ty //_______________________________________________________________________________________ // create a codec used only for testing -func MakeTestCodec() *wire.Codec { - var cdc = wire.NewCodec() +func MakeTestCodec() *codec.Codec { + var cdc = codec.New() // Register Msgs cdc.RegisterInterface((*sdk.Msg)(nil), nil) @@ -69,7 +69,7 @@ func MakeTestCodec() *wire.Codec { // Register AppAccount cdc.RegisterInterface((*auth.Account)(nil), nil) cdc.RegisterConcrete(&auth.BaseAccount{}, "test/stake/Account", nil) - wire.RegisterCrypto(cdc) + codec.RegisterCrypto(cdc) return cdc } diff --git a/x/stake/simulation/sim_test.go b/x/stake/simulation/sim_test.go index 3bfd665f4..53b9d826c 100644 --- a/x/stake/simulation/sim_test.go +++ b/x/stake/simulation/sim_test.go @@ -19,7 +19,7 @@ import ( func TestStakeWithRandomMessages(t *testing.T) { mapp := mock.NewApp() - bank.RegisterWire(mapp.Cdc) + bank.RegisterCodec(mapp.Cdc) mapper := mapp.AccountMapper bankKeeper := bank.NewBaseKeeper(mapper) stakeKey := sdk.NewKVStoreKey("stake") diff --git a/x/stake/stake.go b/x/stake/stake.go index 767169f9c..74be3a702 100644 --- a/x/stake/stake.go +++ b/x/stake/stake.go @@ -65,7 +65,7 @@ var ( NewDescription = types.NewDescription NewGenesisState = types.NewGenesisState DefaultGenesisState = types.DefaultGenesisState - RegisterWire = types.RegisterWire + RegisterCodec = types.RegisterCodec NewMsgCreateValidator = types.NewMsgCreateValidator NewMsgCreateValidatorOnBehalfOf = types.NewMsgCreateValidatorOnBehalfOf diff --git a/x/stake/types/wire.go b/x/stake/types/codec.go similarity index 77% rename from x/stake/types/wire.go rename to x/stake/types/codec.go index 86f9f5f09..aa4f64f8a 100644 --- a/x/stake/types/wire.go +++ b/x/stake/types/codec.go @@ -1,11 +1,11 @@ package types import ( - "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/codec" ) -// Register concrete types on wire codec -func RegisterWire(cdc *wire.Codec) { +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) @@ -16,12 +16,12 @@ func RegisterWire(cdc *wire.Codec) { } // generic sealed codec to be used throughout sdk -var MsgCdc *wire.Codec +var MsgCdc *codec.Codec func init() { - cdc := wire.NewCodec() - RegisterWire(cdc) - wire.RegisterCrypto(cdc) + cdc := codec.New() + RegisterCodec(cdc) + codec.RegisterCrypto(cdc) MsgCdc = cdc //MsgCdc = cdc.Seal() //TODO use when upgraded to go-amino 0.9.10 } diff --git a/x/stake/types/delegation.go b/x/stake/types/delegation.go index 5a2274c3a..e6bf11e73 100644 --- a/x/stake/types/delegation.go +++ b/x/stake/types/delegation.go @@ -5,8 +5,8 @@ import ( "fmt" "time" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // Delegation represents the bond with tokens held by an account. It is @@ -25,7 +25,7 @@ type delegationValue struct { } // return the delegation without fields contained within the key for the store -func MustMarshalDelegation(cdc *wire.Codec, delegation Delegation) []byte { +func MustMarshalDelegation(cdc *codec.Codec, delegation Delegation) []byte { val := delegationValue{ delegation.Shares, delegation.Height, @@ -34,7 +34,7 @@ func MustMarshalDelegation(cdc *wire.Codec, delegation Delegation) []byte { } // return the delegation without fields contained within the key for the store -func MustUnmarshalDelegation(cdc *wire.Codec, key, value []byte) Delegation { +func MustUnmarshalDelegation(cdc *codec.Codec, key, value []byte) Delegation { delegation, err := UnmarshalDelegation(cdc, key, value) if err != nil { panic(err) @@ -43,7 +43,7 @@ func MustUnmarshalDelegation(cdc *wire.Codec, key, value []byte) Delegation { } // return the delegation without fields contained within the key for the store -func UnmarshalDelegation(cdc *wire.Codec, key, value []byte) (delegation Delegation, err error) { +func UnmarshalDelegation(cdc *codec.Codec, key, value []byte) (delegation Delegation, err error) { var storeValue delegationValue err = cdc.UnmarshalBinary(value, &storeValue) if err != nil { @@ -115,7 +115,7 @@ type ubdValue struct { } // return the unbonding delegation without fields contained within the key for the store -func MustMarshalUBD(cdc *wire.Codec, ubd UnbondingDelegation) []byte { +func MustMarshalUBD(cdc *codec.Codec, ubd UnbondingDelegation) []byte { val := ubdValue{ ubd.CreationHeight, ubd.MinTime, @@ -126,7 +126,7 @@ func MustMarshalUBD(cdc *wire.Codec, ubd UnbondingDelegation) []byte { } // unmarshal a unbonding delegation from a store key and value -func MustUnmarshalUBD(cdc *wire.Codec, key, value []byte) UnbondingDelegation { +func MustUnmarshalUBD(cdc *codec.Codec, key, value []byte) UnbondingDelegation { ubd, err := UnmarshalUBD(cdc, key, value) if err != nil { panic(err) @@ -135,7 +135,7 @@ func MustUnmarshalUBD(cdc *wire.Codec, key, value []byte) UnbondingDelegation { } // unmarshal a unbonding delegation from a store key and value -func UnmarshalUBD(cdc *wire.Codec, key, value []byte) (ubd UnbondingDelegation, err error) { +func UnmarshalUBD(cdc *codec.Codec, key, value []byte) (ubd UnbondingDelegation, err error) { var storeValue ubdValue err = cdc.UnmarshalBinary(value, &storeValue) if err != nil { @@ -205,7 +205,7 @@ type redValue struct { } // return the redelegation without fields contained within the key for the store -func MustMarshalRED(cdc *wire.Codec, red Redelegation) []byte { +func MustMarshalRED(cdc *codec.Codec, red Redelegation) []byte { val := redValue{ red.CreationHeight, red.MinTime, @@ -218,7 +218,7 @@ func MustMarshalRED(cdc *wire.Codec, red Redelegation) []byte { } // unmarshal a redelegation from a store key and value -func MustUnmarshalRED(cdc *wire.Codec, key, value []byte) Redelegation { +func MustUnmarshalRED(cdc *codec.Codec, key, value []byte) Redelegation { red, err := UnmarshalRED(cdc, key, value) if err != nil { panic(err) @@ -227,7 +227,7 @@ func MustUnmarshalRED(cdc *wire.Codec, key, value []byte) Redelegation { } // unmarshal a redelegation from a store key and value -func UnmarshalRED(cdc *wire.Codec, key, value []byte) (red Redelegation, err error) { +func UnmarshalRED(cdc *codec.Codec, key, value []byte) (red Redelegation, err error) { var storeValue redValue err = cdc.UnmarshalBinary(value, &storeValue) if err != nil { diff --git a/x/stake/types/params.go b/x/stake/types/params.go index bad4251cb..4dcc3782a 100644 --- a/x/stake/types/params.go +++ b/x/stake/types/params.go @@ -5,8 +5,8 @@ import ( "fmt" "time" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // defaultUnbondingTime reflects three weeks in seconds as the default @@ -62,7 +62,7 @@ func (p Params) HumanReadableString() string { } // unmarshal the current staking params value from store key or panic -func MustUnmarshalParams(cdc *wire.Codec, value []byte) Params { +func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params { params, err := UnmarshalParams(cdc, value) if err != nil { panic(err) @@ -71,7 +71,7 @@ func MustUnmarshalParams(cdc *wire.Codec, value []byte) Params { } // unmarshal the current staking params value from store key -func UnmarshalParams(cdc *wire.Codec, value []byte) (params Params, err error) { +func UnmarshalParams(cdc *codec.Codec, value []byte) (params Params, err error) { err = cdc.UnmarshalBinary(value, ¶ms) if err != nil { return diff --git a/x/stake/types/pool.go b/x/stake/types/pool.go index b01ed8e9a..c7cb69748 100644 --- a/x/stake/types/pool.go +++ b/x/stake/types/pool.go @@ -5,8 +5,8 @@ import ( "fmt" "time" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // Pool - dynamic parameters of the current state @@ -142,7 +142,7 @@ func (p Pool) HumanReadableString() string { } // unmarshal the current pool value from store key or panics -func MustUnmarshalPool(cdc *wire.Codec, value []byte) Pool { +func MustUnmarshalPool(cdc *codec.Codec, value []byte) Pool { pool, err := UnmarshalPool(cdc, value) if err != nil { panic(err) @@ -151,7 +151,7 @@ func MustUnmarshalPool(cdc *wire.Codec, value []byte) Pool { } // unmarshal the current pool value from store key -func UnmarshalPool(cdc *wire.Codec, value []byte) (pool Pool, err error) { +func UnmarshalPool(cdc *codec.Codec, value []byte) (pool Pool, err error) { err = cdc.UnmarshalBinary(value, &pool) if err != nil { return diff --git a/x/stake/types/validator.go b/x/stake/types/validator.go index 31af4daaa..6c5066a78 100644 --- a/x/stake/types/validator.go +++ b/x/stake/types/validator.go @@ -9,8 +9,8 @@ import ( "github.com/tendermint/tendermint/crypto" tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" ) // Validator defines the total amount of bond shares and their exchange rate to @@ -82,7 +82,7 @@ type validatorValue struct { } // return the redelegation without fields contained within the key for the store -func MustMarshalValidator(cdc *wire.Codec, validator Validator) []byte { +func MustMarshalValidator(cdc *codec.Codec, validator Validator) []byte { val := validatorValue{ ConsPubKey: validator.ConsPubKey, Jailed: validator.Jailed, @@ -103,7 +103,7 @@ func MustMarshalValidator(cdc *wire.Codec, validator Validator) []byte { } // unmarshal a redelegation from a store key and value -func MustUnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) Validator { +func MustUnmarshalValidator(cdc *codec.Codec, operatorAddr, value []byte) Validator { validator, err := UnmarshalValidator(cdc, operatorAddr, value) if err != nil { panic(err) @@ -112,7 +112,7 @@ func MustUnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) Validat } // unmarshal a redelegation from a store key and value -func UnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) (validator Validator, err error) { +func UnmarshalValidator(cdc *codec.Codec, operatorAddr, value []byte) (validator Validator, err error) { if len(operatorAddr) != sdk.AddrLen { err = fmt.Errorf("%v", ErrBadValidatorAddr(DefaultCodespace).Data()) return @@ -202,7 +202,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { return nil, err } - return wire.Cdc.MarshalJSON(bechValidator{ + return codec.Cdc.MarshalJSON(bechValidator{ OperatorAddr: v.OperatorAddr, ConsPubKey: bechConsPubKey, Jailed: v.Jailed, @@ -224,7 +224,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the validator from JSON using Bech32 func (v *Validator) UnmarshalJSON(data []byte) error { bv := &bechValidator{} - if err := wire.Cdc.UnmarshalJSON(data, bv); err != nil { + if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil { return err } consPubKey, err := sdk.GetConsPubKeyBech32(bv.ConsPubKey) diff --git a/x/stake/types/validator_test.go b/x/stake/types/validator_test.go index 70ab5f105..eceffbad3 100644 --- a/x/stake/types/validator_test.go +++ b/x/stake/types/validator_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -265,12 +265,12 @@ func TestHumanReadableString(t *testing.T) { func TestValidatorMarshalUnmarshalJSON(t *testing.T) { validator := NewValidator(addr1, pk1, Description{}) - js, err := wire.Cdc.MarshalJSON(validator) + js, err := codec.Cdc.MarshalJSON(validator) require.NoError(t, err) require.NotEmpty(t, js) require.Contains(t, string(js), "\"consensus_pubkey\":\"cosmosvalconspu") got := &Validator{} - err = wire.Cdc.UnmarshalJSON(js, got) + err = codec.Cdc.UnmarshalJSON(js, got) assert.NoError(t, err) assert.Equal(t, validator, *got) }