Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

rename wire to codec #2324

Merged
merged 3 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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++ {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++ {
Expand All @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions client/keys/wire.go → client/keys/codec.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions client/lcd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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{})
}

Expand Down
2 changes: 1 addition & 1 deletion client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions client/tx/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions client/tx/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ 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),
)
}

// 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")
Expand Down
Loading