diff --git a/app/app_test.go b/app/app_test.go index ac5b1b890990..6c4d88dd5211 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -118,7 +118,7 @@ func (at *appTest) reset() { at.initAccount(at.acctOut) resabci := at.app.Commit() - require.True(at.t, resabci.Code.IsOK(), resabci) + require.True(at.t, resabci.IsOK(), resabci) } func getBalance(key sdk.Actor, store state.SimpleDB) (coin.Coins, error) { @@ -145,7 +145,7 @@ func (at *appTest) execDeliver(t *testing.T, tx sdk.Tx) (res abci.ResponseDelive res = at.app.DeliverTx(txBytes) // check the tags - if res.Code.IsOK() { + if res.IsOK() { tags := res.Tags require.NotEmpty(tags) require.Equal("height", tags[0].Key) @@ -270,13 +270,13 @@ func TestTx(t *testing.T) { //Regular CheckTx at.reset() cres, _, _ = at.execCheck(t, at.getTx(coin.Coins{{"mycoin", 5}}, 1)) - assert.True(cres.Code.IsOK(), "ExecTx/Good CheckTx: Expected OK return from ExecTx, Error: %v", cres) + assert.True(cres.IsOK(), "ExecTx/Good CheckTx: Expected OK return from ExecTx, Error: %v", cres) //Regular DeliverTx at.reset() amt := coin.Coins{{"mycoin", 3}} dres, diffIn, diffOut = at.execDeliver(t, at.getTx(amt, 1)) - assert.True(dres.Code.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres) + assert.True(dres.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres) assert.Equal(amt.Negative(), diffIn) assert.Equal(amt, diffOut) @@ -285,7 +285,7 @@ func TestTx(t *testing.T) { amt = coin.Coins{{"mycoin", 4}} toll := coin.Coin{"mycoin", 1} dres, diffIn, diffOut = at.execDeliver(t, at.feeTx(amt, toll, 1)) - assert.True(dres.Code.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres) + assert.True(dres.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", dres) payment := amt.Plus(coin.Coins{toll}).Negative() assert.Equal(payment, diffIn) assert.Equal(amt, diffOut) @@ -297,7 +297,7 @@ func TestQuery(t *testing.T) { at := newAppTest(t) dres, _, _ := at.execDeliver(t, at.getTx(coin.Coins{{"mycoin", 5}}, 1)) - assert.True(dres.Code.IsOK(), "Commit, DeliverTx: Expected OK return from DeliverTx, Error: %v", dres) + assert.True(dres.IsOK(), "Commit, DeliverTx: Expected OK return from DeliverTx, Error: %v", dres) resQueryPreCommit := at.app.Query(abci.RequestQuery{ Path: "/account", @@ -305,7 +305,7 @@ func TestQuery(t *testing.T) { }) cres := at.app.Commit() - assert.True(cres.Code.IsOK(), cres) + assert.True(cres.IsOK(), cres) key := stack.PrefixedKey(coin.NameCoin, at.acctIn.Address()) resQueryPostCommit := at.app.Query(abci.RequestQuery{ diff --git a/app/store.go b/app/store.go index 3b523f3e5cc0..6ea079b7bc14 100644 --- a/app/store.go +++ b/app/store.go @@ -135,7 +135,7 @@ func (app *StoreApp) SetOption(res abci.RequestSetOption) abci.ResponseSetOption func (app *StoreApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) { if len(reqQuery.Data) == 0 { resQuery.Log = "Query cannot be zero length" - resQuery.Code = abci.CodeType_EncodingError + resQuery.Code = errors.CodeTypeEncodingErr return } @@ -150,7 +150,7 @@ func (app *StoreApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQu // is not yet in the blockchain withProof := app.CommittedHeight() - 1 - if tree.Tree.VersionExists(withProof) { + if tree.Tree.VersionExists(uint64(withProof)) { height = withProof } else { height = app.CommittedHeight() @@ -176,7 +176,7 @@ func (app *StoreApp) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQu } default: - resQuery.Code = abci.CodeType_UnknownRequest + resQuery.Code = errors.CodeTypeUnknownRequest resQuery.Log = cmn.Fmt("Unexpected Query path: %v", reqQuery.Path) } return diff --git a/app/val_test.go b/app/val_test.go index 677a903ea9d6..5c976806740e 100644 --- a/app/val_test.go +++ b/app/val_test.go @@ -79,7 +79,7 @@ func TestEndBlock(t *testing.T) { tx := base.ValChangeTx{c}.Wrap() txBytes := wire.BinaryBytes(tx) res := app.DeliverTx(txBytes) - require.True(res.Code.IsOK(), "%#v", res) + require.True(res.IsOK(), "%#v", res) } diff := app.EndBlock(abci.RequestEndBlock{app.height}) // TODO: don't care about order here... diff --git a/client/query_test.go b/client/query_test.go index 8f93ff40044d..f6e049a7a532 100644 --- a/client/query_test.go +++ b/client/query_test.go @@ -55,7 +55,7 @@ func TestAppProofs(t *testing.T) { require.NoError(err, "%+v", err) require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx) require.EqualValues(0, br.DeliverTx.Code) - brh := int(br.Height) + brh := br.Height // This sets up our trust on the node based on some past point. source := certclient.NewProvider(cl) @@ -119,7 +119,7 @@ func TestTxProofs(t *testing.T) { require.NoError(err, "%+v", err) require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx) require.EqualValues(0, br.DeliverTx.Code) - brh := int(br.Height) + brh := br.Height source := certclient.NewProvider(cl) seed, err := source.GetByHeight(brh - 2) diff --git a/errors/code.go b/errors/code.go index ec9a24cf35d7..c49223898f80 100644 --- a/errors/code.go +++ b/errors/code.go @@ -1,15 +1,14 @@ package errors const ( - defaultErrCode uint32 = 0x1 + CodeTypeInternalErr uint32 = 1 + CodeTypeEncodingErr uint32 = 2 + CodeTypeUnauthorized uint32 = 3 + CodeTypeUnknownRequest uint32 = 4 + CodeTypeUnknownAddress uint32 = 5 + CodeTypeBaseUnknownAddress uint32 = 5 // lol fuck it + CodeTypeBadNonce uint32 = 6 - CodeTypeInternalErr uint32 = 0 - CodeTypeEncodingErr uint32 = 1 - CodeTypeUnauthorized uint32 = 2 - CodeTypeUnknownRequest uint32 = 3 - CodeTypeUnknownAddress uint32 = 4 - CodeTypeBaseUnknownAddress uint32 = 4 // lol fuck it - CodeTypeBadNonce uint32 = 5 - CodeTypeBaseInvalidInput uint32 = 20 - CodeTypeBaseInvalidOutput uint32 = 21 + CodeTypeBaseInvalidInput uint32 = 20 + CodeTypeBaseInvalidOutput uint32 = 21 ) diff --git a/errors/main.go b/errors/main.go index 9cfbe61978dc..6fd8c176f638 100644 --- a/errors/main.go +++ b/errors/main.go @@ -95,7 +95,7 @@ func Wrap(err error) TMError { return tm } - return WithCode(err, defaultErrCode) + return WithCode(err, CodeTypeInternalErr) } // WithCode adds a stacktrace if necessary and sets the code and msg, @@ -145,5 +145,5 @@ func HasErrorCode(err error, code uint32) bool { if tm, ok := err.(TMError); ok { return tm.ErrorCode() == code } - return code == defaultErrCode + return code == CodeTypeInternalErr } diff --git a/errors/main_test.go b/errors/main_test.go index f8f60845d25b..b9393c881d03 100644 --- a/errors/main_test.go +++ b/errors/main_test.go @@ -7,8 +7,6 @@ import ( pkerr "github.com/pkg/errors" "github.com/stretchr/testify/assert" - - abci "github.com/tendermint/abci/types" ) func TestCreateResult(t *testing.T) { @@ -17,15 +15,15 @@ func TestCreateResult(t *testing.T) { cases := []struct { err error msg string - code abci.CodeType + code uint32 }{ - {stderr.New("base"), "base", defaultErrCode}, - {pkerr.New("dave"), "dave", defaultErrCode}, - {New("nonce", abci.CodeType_BadNonce), "nonce", abci.CodeType_BadNonce}, - {Wrap(stderr.New("wrap")), "wrap", defaultErrCode}, - {WithCode(stderr.New("coded"), abci.CodeType_BaseInvalidInput), "coded", abci.CodeType_BaseInvalidInput}, - {ErrDecoding(), errDecoding.Error(), abci.CodeType_EncodingError}, - {ErrUnauthorized(), errUnauthorized.Error(), abci.CodeType_Unauthorized}, + {stderr.New("base"), "base", CodeTypeInternalErr}, + {pkerr.New("dave"), "dave", CodeTypeInternalErr}, + {New("nonce", CodeTypeBadNonce), "nonce", CodeTypeBadNonce}, + {Wrap(stderr.New("wrap")), "wrap", CodeTypeInternalErr}, + {WithCode(stderr.New("coded"), CodeTypeBaseInvalidInput), "coded", CodeTypeBaseInvalidInput}, + {ErrDecoding(), errDecoding.Error(), CodeTypeEncodingErr}, + {ErrUnauthorized(), errUnauthorized.Error(), CodeTypeUnauthorized}, } for idx, tc := range cases { diff --git a/examples/basecoin/cmd/baseserver/main.go b/examples/basecoin/cmd/baseserver/main.go index d41ac45a6de6..99c686d5620e 100644 --- a/examples/basecoin/cmd/baseserver/main.go +++ b/examples/basecoin/cmd/baseserver/main.go @@ -10,13 +10,16 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + rpcserver "github.com/tendermint/tendermint/rpc/lib/server" + "github.com/tendermint/tmlibs/cli" + tmlog "github.com/tendermint/tmlibs/log" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/commands" rest "github.com/cosmos/cosmos-sdk/client/rest" coinrest "github.com/cosmos/cosmos-sdk/modules/coin/rest" noncerest "github.com/cosmos/cosmos-sdk/modules/nonce/rest" rolerest "github.com/cosmos/cosmos-sdk/modules/roles/rest" - "github.com/tendermint/tmlibs/cli" ) var srvCli = &cobra.Command{ @@ -79,13 +82,13 @@ func serve(cmd *cobra.Command, args []string) error { port := viper.GetInt(envPortFlag) addr := fmt.Sprintf(":%d", port) - onDisconnect := rpc.OnDisconnect(func(remoteAddr string) { + onDisconnect := rpcserver.OnDisconnect(func(remoteAddr string) { // FIXME: TODO // n.eventBus.UnsubscribeAll(context.Background(), remoteAddr) }) routes := client.RPCRoutes(rpcClient) wm := rpcserver.NewWebsocketManager(routes, onDisconnect) - wsLogger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "ws") + wsLogger := tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)).With("module", "ws") wm.SetLogger(wsLogger) router.HandleFunc("/websocket", wm.WebsocketHandler) diff --git a/examples/counter/plugins/counter/counter.go b/examples/counter/plugins/counter/counter.go index 7ce08761db46..6cfd05d65dc8 100644 --- a/examples/counter/plugins/counter/counter.go +++ b/examples/counter/plugins/counter/counter.go @@ -3,7 +3,6 @@ package counter import ( "fmt" - abci "github.com/tendermint/abci/types" "github.com/tendermint/go-wire" sdk "github.com/cosmos/cosmos-sdk" @@ -74,7 +73,7 @@ var ( // ErrInvalidCounter - custom error class func ErrInvalidCounter() error { - return errors.WithCode(errInvalidCounter, abci.CodeType_BaseInvalidInput) + return errors.WithCode(errInvalidCounter, errors.CodeTypeBaseInvalidInput) } // IsInvalidCounterErr - custom error class check diff --git a/examples/counter/plugins/counter/counter_test.go b/examples/counter/plugins/counter/counter_test.go index f727bb571577..34269d273b1b 100644 --- a/examples/counter/plugins/counter/counter_test.go +++ b/examples/counter/plugins/counter/counter_test.go @@ -53,7 +53,7 @@ func TestCounterPlugin(t *testing.T) { // Test a basic send, no fee res := DeliverCounterTx(true, nil, 1) - assert.True(res.Code.IsOK(), res.String()) + assert.True(res.IsOK(), res.String()) // Test an invalid send, no fee res = DeliverCounterTx(false, nil, 2) @@ -65,7 +65,7 @@ func TestCounterPlugin(t *testing.T) { // Test an valid send, with supported fee res = DeliverCounterTx(true, coin.Coins{{"gold", 100}}, 3) - assert.True(res.Code.IsOK(), res.String()) + assert.True(res.IsOK(), res.String()) // Test unsupported fee res = DeliverCounterTx(true, coin.Coins{{"silver", 100}}, 4) diff --git a/modules/coin/ibc_test.go b/modules/coin/ibc_test.go index a51b5359d893..f350171f4cd6 100644 --- a/modules/coin/ibc_test.go +++ b/modules/coin/ibc_test.go @@ -3,14 +3,14 @@ package coin import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk" "github.com/cosmos/cosmos-sdk/errors" "github.com/cosmos/cosmos-sdk/modules/auth" "github.com/cosmos/cosmos-sdk/modules/ibc" "github.com/cosmos/cosmos-sdk/stack" "github.com/cosmos/cosmos-sdk/state" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" wire "github.com/tendermint/go-wire" ) @@ -24,7 +24,7 @@ func TestIBCPostPacket(t *testing.T) { otherID := "chain-2" ourID := "dex" - start := 200 + start := int64(200) // create the app and our chain app := stack.New(). diff --git a/modules/coin/rest/handlers.go b/modules/coin/rest/handlers.go index 2e1841f8ae30..8559c642ed9d 100644 --- a/modules/coin/rest/handlers.go +++ b/modules/coin/rest/handlers.go @@ -48,14 +48,15 @@ func doQueryAccount(w http.ResponseWriter, r *http.Request) { return } - var h int + var h int64 qHeight := r.URL.Query().Get("height") if qHeight != "" { - h, err = strconv.Atoi(qHeight) + _h, err := strconv.Atoi(qHeight) if err != nil { common.WriteError(w, err) return } + h = int64(_h) } actor = coin.ChainAddr(actor) diff --git a/modules/eyes/errors.go b/modules/eyes/errors.go index 286e24776e6c..55ad167f0a6d 100644 --- a/modules/eyes/errors.go +++ b/modules/eyes/errors.go @@ -3,15 +3,13 @@ package eyes import ( "fmt" - abci "github.com/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/errors" ) var ( errMissingData = fmt.Errorf("All tx fields must be filled") - malformed = errors.CodeTypeEncodingError + malformed = errors.CodeTypeEncodingErr ) //nolint diff --git a/modules/ibc/ibc_test.go b/modules/ibc/ibc_test.go index 659d28456cae..42166218a728 100644 --- a/modules/ibc/ibc_test.go +++ b/modules/ibc/ibc_test.go @@ -150,7 +150,7 @@ func TestIBCUpdate(t *testing.T) { // this is the root seed, that others are evaluated against keys := lite.GenValKeys(7) appHash := []byte{0, 4, 7, 23} - start := 100 // initial height + start := int64(100) // initial height root := genEmptyCommit(keys, "chain-1", 100, appHash, len(keys)) keys2 := keys.Extend(2) @@ -225,7 +225,7 @@ func TestIBCCreatePacket(t *testing.T) { // this is the root seed, that others are evaluated against keys := lite.GenValKeys(7) appHash := []byte{1, 2, 3, 4} - start := 100 // initial height + start := int64(100) // initial height chainID := "cosmos-hub" root := genEmptyCommit(keys, chainID, start, appHash, len(keys)) @@ -327,7 +327,7 @@ func TestIBCPostPacket(t *testing.T) { otherID := "chain-1" ourID := "hub" - start := 200 + start := int64(200) msg := "it's okay" // create the app and our chain diff --git a/modules/ibc/provider_test.go b/modules/ibc/provider_test.go index 120253312a42..4690198c7960 100644 --- a/modules/ibc/provider_test.go +++ b/modules/ibc/provider_test.go @@ -83,7 +83,7 @@ func makeCommits(keys lite.ValKeys, count int, chainID, app string) []lite.FullC // two commits for each validator, to check how we handle dups // (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ... vals := keys.ToValidators(10, int64(count/2)) - h := 20 + 10*i + h := int64(20 + 10*i) commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, len(keys)) } return commits @@ -130,7 +130,7 @@ func checkProvider(t *testing.T, p lite.Provider, chainID, app string) { fc, err = p.GetByHeight(47) if assert.Nil(err) { // we only step by 10, so 40 must be the one below this - assert.Equal(40, fc.Height()) + assert.Equal(int64(40), fc.Height()) } } diff --git a/modules/nonce/rest/handlers.go b/modules/nonce/rest/handlers.go index 05c0b2cd899c..9186f6c36a60 100644 --- a/modules/nonce/rest/handlers.go +++ b/modules/nonce/rest/handlers.go @@ -30,14 +30,15 @@ func doQueryNonce(w http.ResponseWriter, r *http.Request) { return } - var h int + var h int64 qHeight := r.URL.Query().Get("height") if qHeight != "" { - h, err = strconv.Atoi(qHeight) + _h, err := strconv.Atoi(qHeight) if err != nil { common.WriteError(w, err) return } + h = int64(_h) } actor = coin.ChainAddr(actor) diff --git a/modules/roles/rest/handlers.go b/modules/roles/rest/handlers.go index 315ddcb13dd0..4d5f08b9710a 100644 --- a/modules/roles/rest/handlers.go +++ b/modules/roles/rest/handlers.go @@ -6,7 +6,6 @@ import ( "github.com/gorilla/mux" - abci "github.com/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk" "github.com/cosmos/cosmos-sdk/client/commands" "github.com/cosmos/cosmos-sdk/errors" @@ -37,7 +36,7 @@ type RoleInput struct { func decodeRoleHex(roleInHex string) ([]byte, error) { parsedRole, err := hex.DecodeString(common.StripHex(roleInHex)) if err != nil { - err = errors.WithMessage("invalid hex", err, errors.CodeTypeEncodingError) + err = errors.WithMessage("invalid hex", err, errors.CodeTypeEncodingErr) return nil, err } return parsedRole, nil diff --git a/state/merkle.go b/state/merkle.go index 7d11aa8ddb58..2ee244249926 100644 --- a/state/merkle.go +++ b/state/merkle.go @@ -53,8 +53,8 @@ func (s State) Check() SimpleDB { } // LatestHeight is the last block height we have committed -func (s State) LatestHeight() uint64 { - return s.committed.Tree.LatestVersion() +func (s State) LatestHeight() int64 { + return int64(s.committed.Tree.LatestVersion()) } // LatestHash is the root hash of the last state we have