diff --git a/app/store.go b/app/store.go index ed4af7a9fa76..3b523f3e5cc0 100644 --- a/app/store.go +++ b/app/store.go @@ -37,7 +37,7 @@ type StoreApp struct { pending []*abci.Validator // height is last committed block, DeliverTx is the next one - height uint64 + height int64 logger log.Logger } @@ -99,12 +99,12 @@ func (app *StoreApp) Check() sm.SimpleDB { // CommittedHeight gets the last block height committed // to the db -func (app *StoreApp) CommittedHeight() uint64 { +func (app *StoreApp) CommittedHeight() int64 { return app.height } // WorkingHeight gets the current block we are writing -func (app *StoreApp) WorkingHeight() uint64 { +func (app *StoreApp) WorkingHeight() int64 { return app.height + 1 } @@ -243,7 +243,7 @@ func pubKeyIndex(val *abci.Validator, list []*abci.Validator) int { return -1 } -func loadState(dbName string, cacheSize int, historySize uint64) (*sm.State, error) { +func loadState(dbName string, cacheSize int, historySize int64) (*sm.State, error) { // memory backed case, just for testing if dbName == "" { tree := iavl.NewVersionedTree(0, dbm.NewMemDB()) diff --git a/app/val_test.go b/app/val_test.go index d79d4ee78b85..677a903ea9d6 100644 --- a/app/val_test.go +++ b/app/val_test.go @@ -17,8 +17,8 @@ import ( //----------------------------------- // Test cases start here -func randPower() uint64 { - return uint64(cmn.RandInt()%50 + 60) +func randPower() int64 { + return int64(cmn.RandInt()%50 + 60) } func makeVal() *abci.Validator { diff --git a/client/commands/commits/export.go b/client/commands/commits/export.go index 0bcb3f5589cd..c9789258f737 100644 --- a/client/commands/commits/export.go +++ b/client/commands/commits/export.go @@ -34,7 +34,7 @@ func exportCommit(cmd *cobra.Command, args []string) error { // load the seed as specified trust, _ := commands.GetProviders() - h := viper.GetInt(heightFlag) + h := int64(viper.GetInt(heightFlag)) hash := viper.GetString(hashFlag) fc, err := loadCommit(trust, h, hash, "") if err != nil { diff --git a/client/commands/commits/show.go b/client/commands/commits/show.go index f7d5fee58d6d..f107c5899f87 100644 --- a/client/commands/commits/show.go +++ b/client/commands/commits/show.go @@ -37,7 +37,7 @@ func init() { RootCmd.AddCommand(showCmd) } -func loadCommit(p lite.Provider, h int, hash, file string) (fc lite.FullCommit, err error) { +func loadCommit(p lite.Provider, h int64, hash, file string) (fc lite.FullCommit, err error) { // load the commit from the proper place if h != 0 { fc, err = p.GetByHeight(h) @@ -59,7 +59,7 @@ func loadCommit(p lite.Provider, h int, hash, file string) (fc lite.FullCommit, func showCommit(cmd *cobra.Command, args []string) error { trust, _ := commands.GetProviders() - h := viper.GetInt(heightFlag) + h := int64(viper.GetInt(heightFlag)) hash := viper.GetString(hashFlag) file := viper.GetString(fileFlag) fc, err := loadCommit(trust, h, hash, file) diff --git a/client/commands/commits/update.go b/client/commands/commits/update.go index 3bc0449722c3..d3d6d4a66274 100644 --- a/client/commands/commits/update.go +++ b/client/commands/commits/update.go @@ -29,7 +29,7 @@ func updateCommit(cmd *cobra.Command, args []string) error { return err } - h := viper.GetInt(heightFlag) + h := int64(viper.GetInt(heightFlag)) var fc lite.FullCommit if h <= 0 { // get the lastest from our source diff --git a/client/commands/query/get.go b/client/commands/query/get.go index 59c44c05f8c5..35f1bfad86dc 100644 --- a/client/commands/query/get.go +++ b/client/commands/query/get.go @@ -27,7 +27,7 @@ import ( // It will try to get the proof for the given key. If it is successful, // it will return the height and also unserialize proof.Data into the data // argument (so pass in a pointer to the appropriate struct) -func GetParsed(key []byte, data interface{}, height int, prove bool) (uint64, error) { +func GetParsed(key []byte, data interface{}, height int64, prove bool) (int64, error) { bs, h, err := Get(key, height, prove) if err != nil { return 0, err @@ -47,7 +47,7 @@ func GetParsed(key []byte, data interface{}, height int, prove bool) (uint64, er // we just repeat whatever any (potentially malicious) node gives us. // Only use that if you are running the full node yourself, // and it is localhost or you have a secure connection (not HTTP) -func Get(key []byte, height int, prove bool) (data.Bytes, uint64, error) { +func Get(key []byte, height int64, prove bool) (data.Bytes, int64, error) { if height < 0 { return nil, 0, fmt.Errorf("Height cannot be negative") } @@ -55,8 +55,11 @@ func Get(key []byte, height int, prove bool) (data.Bytes, uint64, error) { if !prove { node := commands.GetNode() resp, err := node.ABCIQueryWithOptions("/key", key, - rpcclient.ABCIQueryOptions{Trusted: true, Height: uint64(height)}) - return data.Bytes(resp.Value), resp.Height, err + rpcclient.ABCIQueryOptions{Trusted: true, Height: int64(height)}) + if resp == nil { + return nil, height, err + } + return data.Bytes(resp.Response.Value), resp.Response.Height, err } val, h, _, err := GetWithProof(key, height) return val, h, err @@ -65,7 +68,7 @@ func Get(key []byte, height int, prove bool) (data.Bytes, uint64, error) { // GetWithProof returns the values stored under a given key at the named // height as in Get. Additionally, it will return a validated merkle // proof for the key-value pair if it exists, and all checks pass. -func GetWithProof(key []byte, height int) (data.Bytes, uint64, iavl.KeyProof, error) { +func GetWithProof(key []byte, height int64) (data.Bytes, int64, iavl.KeyProof, error) { node := commands.GetNode() cert, err := commands.GetCertifier() if err != nil { @@ -93,19 +96,19 @@ func ParseHexKey(args []string, argname string) ([]byte, error) { } // GetHeight reads the viper config for the query height -func GetHeight() int { - return viper.GetInt(FlagHeight) +func GetHeight() int64 { + return int64(viper.GetInt(FlagHeight)) } type proof struct { - Height uint64 `json:"height"` + Height int64 `json:"height"` Data interface{} `json:"data"` } // FoutputProof writes the output of wrapping height and info // in the form {"data": , "height": } // to the provider io.Writer -func FoutputProof(w io.Writer, v interface{}, height uint64) error { +func FoutputProof(w io.Writer, v interface{}, height int64) error { wrap := &proof{height, v} blob, err := data.ToJSON(wrap) if err != nil { @@ -118,6 +121,6 @@ func FoutputProof(w io.Writer, v interface{}, height uint64) error { // OutputProof prints the proof to stdout // reuse this for printing proofs and we should enhance this for text/json, // better presentation of height -func OutputProof(data interface{}, height uint64) error { +func OutputProof(data interface{}, height int64) error { return FoutputProof(os.Stdout, data, height) } diff --git a/client/commands/query/tx.go b/client/commands/query/tx.go index f3fed3472fa1..9db6a727c15e 100644 --- a/client/commands/query/tx.go +++ b/client/commands/query/tx.go @@ -67,7 +67,7 @@ func txQueryCmd(cmd *cobra.Command, args []string) error { } // showTx parses anything that was previously registered as sdk.Tx -func showTx(h uint64, tx types.Tx) error { +func showTx(h int64, tx types.Tx) error { var info sdk.Tx err := wire.ReadBinaryBytes(tx, &info) if err != nil { diff --git a/client/commands/rpc/helpers.go b/client/commands/rpc/helpers.go index 7bcd074a0fa8..82ff88686ce2 100644 --- a/client/commands/rpc/helpers.go +++ b/client/commands/rpc/helpers.go @@ -25,10 +25,10 @@ func init() { func runWait(cmd *cobra.Command, args []string) error { c := commands.GetNode() - h := viper.GetInt(FlagHeight) + h := int64(viper.GetInt(FlagHeight)) if h == -1 { // read from delta - d := viper.GetInt(FlagDelta) + d := int64(viper.GetInt(FlagDelta)) if d == -1 { return errors.New("Must set --height or --delta") } diff --git a/client/commands/rpc/secure.go b/client/commands/rpc/secure.go index 86cf64f0c254..4ea350881375 100644 --- a/client/commands/rpc/secure.go +++ b/client/commands/rpc/secure.go @@ -26,7 +26,7 @@ func runBlock(cmd *cobra.Command, args []string) error { return err } - h := viper.GetInt(FlagHeight) + h := int64(viper.GetInt(FlagHeight)) block, err := c.Block(&h) if err != nil { return err @@ -46,7 +46,7 @@ func runCommit(cmd *cobra.Command, args []string) error { return err } - h := viper.GetInt(FlagHeight) + h := int64(viper.GetInt(FlagHeight)) commit, err := c.Commit(&h) if err != nil { return err @@ -66,8 +66,8 @@ func runHeaders(cmd *cobra.Command, args []string) error { return err } - min := viper.GetInt(FlagMin) - max := viper.GetInt(FlagMax) + min := int64(viper.GetInt(FlagMin)) + max := int64(viper.GetInt(FlagMax)) headers, err := c.BlockchainInfo(min, max) if err != nil { return err diff --git a/client/query.go b/client/query.go index 62ea8635bc83..f6e488bed062 100644 --- a/client/query.go +++ b/client/query.go @@ -19,9 +19,9 @@ import ( // If there is any error in checking, returns an error. // If val is non-empty, proof should be KeyExistsProof // If val is empty, proof should be KeyMissingProof -func GetWithProof(key []byte, reqHeight int, node rpcclient.Client, +func GetWithProof(key []byte, reqHeight int64, node rpcclient.Client, cert lite.Certifier) ( - val data.Bytes, height uint64, proof iavl.KeyProof, err error) { + val data.Bytes, height int64, proof iavl.KeyProof, err error) { if reqHeight < 0 { err = errors.Errorf("Height cannot be negative") @@ -33,7 +33,7 @@ func GetWithProof(key []byte, reqHeight int, node rpcclient.Client, node, cert) if _resp != nil { resp := _resp.Response - val, height = resp.Value, uint64(resp.Height) + val, height = resp.Value, resp.Height } return val, height, proof, err } @@ -79,7 +79,7 @@ func GetWithProofOptions(path string, key []byte, opts rpcclient.ABCIQueryOption if err != nil { return nil, nil, errors.Wrap(err, "Couldn't verify proof") } - return resp, eproof, nil + return &ctypes.ResultABCIQuery{resp}, eproof, nil } // The key wasn't found, construct a proof of non-existence. @@ -93,30 +93,27 @@ func GetWithProofOptions(path string, key []byte, opts rpcclient.ABCIQueryOption if err != nil { return nil, nil, errors.Wrap(err, "Couldn't verify proof") } - return resp, aproof, ErrNoData() + return &ctypes.ResultABCIQuery{resp}, aproof, ErrNoData() } // GetCertifiedCommit gets the signed header for a given height // and certifies it. Returns error if unable to get a proven header. -func GetCertifiedCommit(h uint64, node rpcclient.Client, +func GetCertifiedCommit(h int64, node rpcclient.Client, cert lite.Certifier) (empty lite.Commit, err error) { - // TODO: please standardize all int types - ih := int(h) - // FIXME: cannot use cert.GetByHeight for now, as it also requires // Validators and will fail on querying tendermint for non-current height. // When this is supported, we should use it instead... - rpcclient.WaitForHeight(node, ih, nil) - cresp, err := node.Commit(&ih) + rpcclient.WaitForHeight(node, h, nil) + cresp, err := node.Commit(&h) if err != nil { return } commit := client.CommitFromResult(cresp) // validate downloaded checkpoint with our request and trust store. - if commit.Height() != ih { - return empty, certerr.ErrHeightMismatch(ih, commit.Height()) + if commit.Height() != h { + return empty, certerr.ErrHeightMismatch(h, commit.Height()) } err = cert.Certify(commit) return commit, nil diff --git a/client/query_test.go b/client/query_test.go index 29bde63bea01..8f93ff40044d 100644 --- a/client/query_test.go +++ b/client/query_test.go @@ -81,7 +81,7 @@ func TestAppProofs(t *testing.T) { bs, height, proof, err = GetWithProof(k, brh, cl, cert) require.NoError(err, "%+v", err) require.NotNil(proof) - require.True(height >= uint64(latest.Header.Height)) + require.True(height >= int64(latest.Header.Height)) // Alexis there is a bug here, somehow the above code gives us rootHash = nil // and proof.Verify doesn't care, while proofNotExists.Verify fails. diff --git a/client/wrapper.go b/client/wrapper.go index ffe6dd4259e7..e901881042a2 100644 --- a/client/wrapper.go +++ b/client/wrapper.go @@ -51,7 +51,7 @@ func (w Wrapper) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) { if !prove || err != nil { return res, err } - h := uint64(res.Height) + h := int64(res.Height) check, err := GetCertifiedCommit(h, w.Client, w.cert) if err != nil { return res, err @@ -64,7 +64,7 @@ func (w Wrapper) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) { // Rather expensive. // // TODO: optimize this if used for anything needing performance -func (w Wrapper) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) { +func (w Wrapper) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { r, err := w.Client.BlockchainInfo(minHeight, maxHeight) if err != nil { return nil, err @@ -88,7 +88,7 @@ func (w Wrapper) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockch } // Block returns an entire block and verifies all signatures -func (w Wrapper) Block(height *int) (*ctypes.ResultBlock, error) { +func (w Wrapper) Block(height *int64) (*ctypes.ResultBlock, error) { r, err := w.Client.Block(height) if err != nil { return nil, err @@ -115,7 +115,7 @@ func (w Wrapper) Block(height *int) (*ctypes.ResultBlock, error) { // Commit downloads the Commit and certifies it with the lite. // // This is the foundation for all other verification in this module -func (w Wrapper) Commit(height *int) (*ctypes.ResultCommit, error) { +func (w Wrapper) Commit(height *int64) (*ctypes.ResultCommit, error) { rpcclient.WaitForHeight(w.Client, *height, nil) r, err := w.Client.Commit(height) // if we got it, then certify it diff --git a/context.go b/context.go index fedca0def4f1..9444d9963e76 100644 --- a/context.go +++ b/context.go @@ -78,7 +78,7 @@ type Context interface { IsParent(ctx Context) bool Reset() Context ChainID() string - BlockHeight() uint64 + BlockHeight() int64 } //////////////////////////////// Sort Interface diff --git a/errors/code.go b/errors/code.go new file mode 100644 index 000000000000..ec9a24cf35d7 --- /dev/null +++ b/errors/code.go @@ -0,0 +1,15 @@ +package errors + +const ( + defaultErrCode uint32 = 0x1 + + 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 +) diff --git a/errors/common.go b/errors/common.go index c8854f12207f..535a3469c683 100644 --- a/errors/common.go +++ b/errors/common.go @@ -32,7 +32,7 @@ func unwrap(i interface{}) interface{} { func ErrUnknownTxType(tx interface{}) TMError { msg := fmt.Sprintf("%T", unwrap(tx)) - return WithMessage(msg, errUnknownTxType, unknownRequest) + return WithMessage(msg, errUnknownTxType, CodeTypeUnknownRequest) } func IsUnknownTxTypeErr(err error) bool { return IsSameError(errUnknownTxType, err) @@ -40,61 +40,61 @@ func IsUnknownTxTypeErr(err error) bool { func ErrInvalidFormat(expected string, tx interface{}) TMError { msg := fmt.Sprintf("%T not %s", unwrap(tx), expected) - return WithMessage(msg, errInvalidFormat, unknownRequest) + return WithMessage(msg, errInvalidFormat, CodeTypeUnknownRequest) } func IsInvalidFormatErr(err error) bool { return IsSameError(errInvalidFormat, err) } func ErrUnknownModule(mod string) TMError { - return WithMessage(mod, errUnknownModule, unknownRequest) + return WithMessage(mod, errUnknownModule, CodeTypeUnknownRequest) } func IsUnknownModuleErr(err error) bool { return IsSameError(errUnknownModule, err) } func ErrUnknownKey(mod string) TMError { - return WithMessage(mod, errUnknownKey, unknownRequest) + return WithMessage(mod, errUnknownKey, CodeTypeUnknownRequest) } func IsUnknownKeyErr(err error) bool { return IsSameError(errUnknownKey, err) } func ErrInternal(msg string) TMError { - return New(msg, internalErr) + return New(msg, CodeTypeInternalErr) } // IsInternalErr matches any error that is not classified func IsInternalErr(err error) bool { - return HasErrorCode(err, internalErr) + return HasErrorCode(err, CodeTypeInternalErr) } func ErrDecoding() TMError { - return WithCode(errDecoding, encodingErr) + return WithCode(errDecoding, CodeTypeEncodingErr) } func IsDecodingErr(err error) bool { return IsSameError(errDecoding, err) } func ErrUnauthorized() TMError { - return WithCode(errUnauthorized, unauthorized) + return WithCode(errUnauthorized, CodeTypeUnauthorized) } // IsUnauthorizedErr is generic helper for any unauthorized errors, // also specific sub-types func IsUnauthorizedErr(err error) bool { - return HasErrorCode(err, unauthorized) + return HasErrorCode(err, CodeTypeUnauthorized) } func ErrMissingSignature() TMError { - return WithCode(errMissingSignature, unauthorized) + return WithCode(errMissingSignature, CodeTypeUnauthorized) } func IsMissingSignatureErr(err error) bool { return IsSameError(errMissingSignature, err) } func ErrTooLarge() TMError { - return WithCode(errTooLarge, encodingErr) + return WithCode(errTooLarge, CodeTypeEncodingErr) } func IsTooLargeErr(err error) bool { return IsSameError(errTooLarge, err) diff --git a/handler.go b/handler.go index 638fe4cc6648..5bfc24194e0a 100644 --- a/handler.go +++ b/handler.go @@ -109,14 +109,14 @@ type CheckResult struct { Data data.Bytes Log string // GasAllocated is the maximum units of work we allow this tx to perform - GasAllocated uint64 + GasAllocated int64 // GasPayment is the total fees for this tx (or other source of payment) - GasPayment uint64 + GasPayment int64 } // NewCheck sets the gas used and the response data but no more info // these are the most common info needed to be set by the Handler -func NewCheck(gasAllocated uint64, log string) CheckResult { +func NewCheck(gasAllocated int64, log string) CheckResult { return CheckResult{ GasAllocated: gasAllocated, Log: log, @@ -143,7 +143,7 @@ type DeliverResult struct { Log string Diff []*abci.Validator Tags []*abci.KVPair - GasUsed uint64 // unused + GasUsed int64 // unused } func (d DeliverResult) ToABCI() abci.ResponseDeliverTx { diff --git a/modules/auth/errors.go b/modules/auth/errors.go index 46b562cf4e49..7db2d27698d8 100644 --- a/modules/auth/errors.go +++ b/modules/auth/errors.go @@ -4,8 +4,6 @@ package auth import ( "fmt" - abci "github.com/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/errors" ) @@ -13,7 +11,7 @@ var ( errInvalidSignature = fmt.Errorf("Invalid Signature") //move auth errTooManySignatures = fmt.Errorf("Too many signatures") //move auth - unauthorized = abci.CodeType_Unauthorized + unauthorized = errors.CodeTypeUnauthorized ) func ErrTooManySignatures() errors.TMError { diff --git a/modules/base/chain.go b/modules/base/chain.go index 61f919c0efe0..1fa32ce6cc21 100644 --- a/modules/base/chain.go +++ b/modules/base/chain.go @@ -44,7 +44,7 @@ func (c Chain) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next // checkChainTx makes sure the tx is a Chain Tx, it is on the proper chain, // and it has not expired. -func (c Chain) checkChainTx(chainID string, height uint64, tx sdk.Tx) (sdk.Tx, error) { +func (c Chain) checkChainTx(chainID string, height int64, tx sdk.Tx) (sdk.Tx, error) { // make sure it is a chaintx ctx, ok := tx.Unwrap().(ChainTx) if !ok { diff --git a/modules/base/chain_test.go b/modules/base/chain_test.go index 4ce1a53a72a2..a8d58bff92d7 100644 --- a/modules/base/chain_test.go +++ b/modules/base/chain_test.go @@ -19,7 +19,7 @@ func TestChainValidate(t *testing.T) { cases := []struct { name string - expires uint64 + expires int64 valid bool }{ {"hello", 0, true}, @@ -48,7 +48,7 @@ func TestChain(t *testing.T) { assert := assert.New(t) msg := "got it" chainID := "my-chain" - height := uint64(100) + height := int64(100) raw := stack.NewRawTx([]byte{1, 2, 3, 4}) cases := []struct { diff --git a/modules/base/commands/wrap.go b/modules/base/commands/wrap.go index b9be03779f94..caca2904fdb6 100644 --- a/modules/base/commands/wrap.go +++ b/modules/base/commands/wrap.go @@ -29,7 +29,7 @@ func (ChainWrapper) Wrap(tx sdk.Tx) (res sdk.Tx, err error) { if chain == "" { return res, errors.New("No chain-id provided") } - res = base.NewChainTx(chain, uint64(expires), tx) + res = base.NewChainTx(chain, int64(expires), tx) return } diff --git a/modules/base/errors.go b/modules/base/errors.go index 4ebf626b8f9c..7da6b985b3a2 100644 --- a/modules/base/errors.go +++ b/modules/base/errors.go @@ -4,8 +4,6 @@ package base import ( "fmt" - abci "github.com/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/errors" ) @@ -14,7 +12,7 @@ var ( errWrongChain = fmt.Errorf("Wrong chain for tx") //move base errExpired = fmt.Errorf("Tx expired") //move base - unauthorized = abci.CodeType_Unauthorized + unauthorized = errors.CodeTypeUnauthorized ) func ErrNoChain() errors.TMError { diff --git a/modules/base/helpers.go b/modules/base/helpers.go index 4958a8bfbbe4..1e6d5bffdbc8 100644 --- a/modules/base/helpers.go +++ b/modules/base/helpers.go @@ -103,11 +103,11 @@ func (PriceHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB, // PriceShowTx lets us bounce back a given fee/gas on CheckTx type PriceShowTx struct { - GasAllocated uint64 - GasPayment uint64 + GasAllocated int64 + GasPayment int64 } -func NewPriceShowTx(gasAllocated, gasPayment uint64) sdk.Tx { +func NewPriceShowTx(gasAllocated, gasPayment int64) sdk.Tx { return PriceShowTx{GasAllocated: gasAllocated, GasPayment: gasPayment}.Wrap() } diff --git a/modules/base/multiplexer.go b/modules/base/multiplexer.go index d899a76ebe06..a949c542ba69 100644 --- a/modules/base/multiplexer.go +++ b/modules/base/multiplexer.go @@ -77,7 +77,7 @@ func runAllDelivers(ctx sdk.Context, store state.SimpleDB, txs []sdk.Tx, next sd func combineChecks(all []sdk.CheckResult) sdk.CheckResult { datas := make([]data.Bytes, len(all)) logs := make([]string, len(all)) - var allocated, payments uint64 + var allocated, payments int64 for i, r := range all { datas[i] = r.Data logs[i] = r.Log @@ -97,7 +97,7 @@ func combineChecks(all []sdk.CheckResult) sdk.CheckResult { func combineDelivers(all []sdk.DeliverResult) sdk.DeliverResult { datas := make([]data.Bytes, len(all)) logs := make([]string, len(all)) - var used uint64 + var used int64 var diffs []*abci.Validator for i, r := range all { datas[i] = r.Data diff --git a/modules/base/multiplexer_test.go b/modules/base/multiplexer_test.go index 97d5324ee64d..1b3a447c9afb 100644 --- a/modules/base/multiplexer_test.go +++ b/modules/base/multiplexer_test.go @@ -16,7 +16,7 @@ func TestMultiplexer(t *testing.T) { assert := assert.New(t) msg := "diddly" chainID := "multi-verse" - height := uint64(100) + height := int64(100) // Generic args here... store := state.NewMemKVStore() @@ -43,8 +43,8 @@ func TestMultiplexer(t *testing.T) { cases := [...]struct { tx sdk.Tx valid bool - gasAllocated uint64 - gasPayment uint64 + gasAllocated int64 + gasPayment int64 log string data data.Bytes }{ diff --git a/modules/base/tx.go b/modules/base/tx.go index 8b3a88fb2c0e..f7379ce8975b 100644 --- a/modules/base/tx.go +++ b/modules/base/tx.go @@ -59,7 +59,7 @@ type ChainTx struct { // name of chain, must be [A-Za-z0-9_-]+ ChainID string `json:"chain_id"` // block height at which it is no longer valid, 0 means no expiration - ExpiresAt uint64 `json:"expires_at"` + ExpiresAt int64 `json:"expires_at"` Tx sdk.Tx `json:"tx"` } @@ -71,7 +71,7 @@ var ( // NewChainTx wraps a particular tx with the ChainTx wrapper, // to enforce chain and height -func NewChainTx(chainID string, expires uint64, tx sdk.Tx) sdk.Tx { +func NewChainTx(chainID string, expires int64, tx sdk.Tx) sdk.Tx { c := ChainTx{ ChainID: chainID, ExpiresAt: expires, diff --git a/modules/coin/errors.go b/modules/coin/errors.go index caf7d4c9b975..ce37da3fb71d 100644 --- a/modules/coin/errors.go +++ b/modules/coin/errors.go @@ -4,8 +4,6 @@ package coin import ( "fmt" - abci "github.com/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/errors" ) @@ -18,10 +16,10 @@ var ( errInvalidAddress = fmt.Errorf("Invalid address") errInvalidCoins = fmt.Errorf("Invalid coins") - invalidInput = abci.CodeType_BaseInvalidInput - invalidOutput = abci.CodeType_BaseInvalidOutput - unknownAddress = abci.CodeType_BaseUnknownAddress - unknownRequest = abci.CodeType_UnknownRequest + invalidInput = errors.CodeTypeBaseInvalidInput + invalidOutput = errors.CodeTypeBaseInvalidOutput + unknownAddress = errors.CodeTypeBaseUnknownAddress + unknownRequest = errors.CodeTypeUnknownRequest ) // here are some generic handlers to grab classes of errors based on code diff --git a/modules/coin/handler.go b/modules/coin/handler.go index 90d8642f6b38..6f3d6ee45770 100644 --- a/modules/coin/handler.go +++ b/modules/coin/handler.go @@ -17,9 +17,9 @@ const ( //NameCoin - name space of the coin module NameCoin = "coin" // CostSend is GasAllocation per input/output - CostSend = uint64(10) + CostSend = int64(10) // CostCredit is GasAllocation of a credit allocation - CostCredit = uint64(20) + CostCredit = int64(20) ) // Handler includes an accountant @@ -54,7 +54,7 @@ func (h Handler) CheckTx(ctx sdk.Context, store state.SimpleDB, switch t := tx.Unwrap().(type) { case SendTx: // price based on inputs and outputs - used := uint64(len(t.Inputs) + len(t.Outputs)) + used := int64(len(t.Inputs) + len(t.Outputs)) return sdk.NewCheck(used*CostSend, ""), h.checkSendTx(ctx, store, t) case CreditTx: // default price of 20, constant work diff --git a/modules/coin/handler_test.go b/modules/coin/handler_test.go index 3df51d8e56b0..81e18c521fc3 100644 --- a/modules/coin/handler_test.go +++ b/modules/coin/handler_test.go @@ -110,7 +110,7 @@ func TestCheckDeliverSendTx(t *testing.T) { tx sdk.Tx perms []sdk.Actor final []money // nil for error - cost uint64 // gas allocated (if not error) + cost int64 // gas allocated (if not error) }{ { []money{{addr1, moreCoins}}, @@ -175,7 +175,7 @@ func TestCheckDeliverSendTx(t *testing.T) { assert.Nil(err, "%d: %+v", i, err) assert.Nil(err2, "%d: %+v", i, err2) // make sure proper gas is set - assert.Equal(uint64(0), cres.GasPayment, "%d", i) + assert.Equal(int64(0), cres.GasPayment, "%d", i) assert.Equal(tc.cost, cres.GasAllocated, "%d", i) // make sure the final balances are correct for _, f := range tc.final { diff --git a/modules/eyes/errors.go b/modules/eyes/errors.go index ae7babc6ca07..286e24776e6c 100644 --- a/modules/eyes/errors.go +++ b/modules/eyes/errors.go @@ -11,7 +11,7 @@ import ( var ( errMissingData = fmt.Errorf("All tx fields must be filled") - malformed = abci.CodeType_EncodingError + malformed = errors.CodeTypeEncodingError ) //nolint diff --git a/modules/eyes/handler.go b/modules/eyes/handler.go index 34a54877e4b9..0e3946730d7c 100644 --- a/modules/eyes/handler.go +++ b/modules/eyes/handler.go @@ -14,7 +14,7 @@ const ( Name = "eyes" // CostSet is the gas needed for the set operation - CostSet uint64 = 10 + CostSet int64 = 10 // CostRemove is the gas needed for the remove operation CostRemove = 10 ) diff --git a/modules/eyes/handler_test.go b/modules/eyes/handler_test.go index 1e44ae438114..fd70b29fddfe 100644 --- a/modules/eyes/handler_test.go +++ b/modules/eyes/handler_test.go @@ -15,7 +15,7 @@ func TestHandler(t *testing.T) { key := []byte("one") val := []byte("foo") - var height uint64 = 123 + var height int64 = 123 h := NewHandler() ctx := stack.MockContext("role-chain", height) diff --git a/modules/eyes/store.go b/modules/eyes/store.go index 38d892064f03..b103ea4fabbd 100644 --- a/modules/eyes/store.go +++ b/modules/eyes/store.go @@ -5,14 +5,14 @@ import "github.com/tendermint/go-wire/data" // Data is the struct we use to store in the merkle tree type Data struct { // SetAt is the block height this was set at - SetAt uint64 `json:"set_at"` + SetAt int64 `json:"set_at"` // Value is the data that was stored. // data.Bytes is like []byte but json encodes as hex not base64 Value data.Bytes `json:"value"` } // NewData creates a new Data item -func NewData(value []byte, setAt uint64) Data { +func NewData(value []byte, setAt int64) Data { return Data{ SetAt: setAt, Value: value, diff --git a/modules/fee/errors.go b/modules/fee/errors.go index 80cc9818aa30..dcbbf58e13c8 100644 --- a/modules/fee/errors.go +++ b/modules/fee/errors.go @@ -4,8 +4,6 @@ package fee import ( "fmt" - abci "github.com/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/errors" ) @@ -14,7 +12,7 @@ var ( errWrongFeeDenom = fmt.Errorf("Required fee denomination") errSkipFees = fmt.Errorf("Skip fees") - invalidInput = abci.CodeType_BaseInvalidInput + invalidInput = errors.CodeTypeBaseInvalidInput ) func ErrInsufficientFees() errors.TMError { diff --git a/modules/fee/handler.go b/modules/fee/handler.go index 0a1df3f49d91..2e9392dcae81 100644 --- a/modules/fee/handler.go +++ b/modules/fee/handler.go @@ -55,14 +55,14 @@ func (h SimpleFeeMiddleware) CheckTx(ctx sdk.Context, store state.SimpleDB, tx s return res, err } - var paid, used uint64 + var paid, used int64 if !fee.Fee.IsZero() { // now, try to make a IPC call to coins... send := coin.NewSendOneTx(fee.Payer, h.Collector, coin.Coins{fee.Fee}) sendRes, err := next.CheckTx(ctx, store, send) if err != nil { return res, err } - paid = uint64(fee.Fee.Amount) + paid = int64(fee.Fee.Amount) used = sendRes.GasAllocated } diff --git a/modules/fee/handler_test.go b/modules/fee/handler_test.go index a4fc0cc9baf6..bbb07e2d80a0 100644 --- a/modules/fee/handler_test.go +++ b/modules/fee/handler_test.go @@ -71,7 +71,7 @@ func TestFeeChecks(t *testing.T) { left coin.Coins collected coin.Coins // expected gas allocated - expectedCost uint64 + expectedCost int64 }{ // make sure it works with no fee (control group) {true, app1, act1, false, act1, zero, mixed, nil, 0}, diff --git a/modules/ibc/commands/query.go b/modules/ibc/commands/query.go index fb1da6506764..cd37ebae9e79 100644 --- a/modules/ibc/commands/query.go +++ b/modules/ibc/commands/query.go @@ -47,7 +47,7 @@ var PacketsQueryCmd = &cobra.Command{ Use: "packets", Short: "Get latest packet in a queue", RunE: commands.RequireInit(packetsQueryCmd), - // uint64 + // int64 } // PacketQueryCmd - get the names packet (by queue and sequence) @@ -156,7 +156,7 @@ func packetsQueryCmd(cmd *cobra.Command, args []string) error { key = stack.PrefixedKey(ibc.NameIBC, ibc.QueueOutKey(to)) } - var res uint64 + var res int64 prove := !viper.GetBool(commands.FlagTrustNode) h, err := query.GetParsed(key, &res, query.GetHeight(), prove) if err != nil { @@ -182,9 +182,9 @@ func packetQueryCmd(cmd *cobra.Command, args []string) error { var key []byte if from != "" { - key = stack.PrefixedKey(ibc.NameIBC, ibc.QueueInPacketKey(from, uint64(seq))) + key = stack.PrefixedKey(ibc.NameIBC, ibc.QueueInPacketKey(from, int64(seq))) } else { - key = stack.PrefixedKey(ibc.NameIBC, ibc.QueueOutPacketKey(to, uint64(seq))) + key = stack.PrefixedKey(ibc.NameIBC, ibc.QueueOutPacketKey(to, int64(seq))) } // Input queue just display the results diff --git a/modules/ibc/errors.go b/modules/ibc/errors.go index 8c3c99a611bb..04b52adb0818 100644 --- a/modules/ibc/errors.go +++ b/modules/ibc/errors.go @@ -3,7 +3,6 @@ package ibc import ( "fmt" - abci "github.com/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/errors" ) @@ -20,14 +19,14 @@ var ( errInvalidProof = fmt.Errorf("Invalid merkle proof") msgInvalidCommit = "Invalid header and commit" - IBCCodeChainNotRegistered = abci.CodeType(1001) - IBCCodeChainAlreadyExists = abci.CodeType(1002) - IBCCodeUnknownChain = abci.CodeType(1003) - IBCCodeInvalidPacketSequence = abci.CodeType(1004) - IBCCodeUnknownHeight = abci.CodeType(1005) - IBCCodeInvalidCommit = abci.CodeType(1006) - IBCCodeInvalidProof = abci.CodeType(1007) - IBCCodeInvalidCall = abci.CodeType(1008) + IBCCodeChainNotRegistered = uint32(1001) + IBCCodeChainAlreadyExists = uint32(1002) + IBCCodeUnknownChain = uint32(1003) + IBCCodeInvalidPacketSequence = uint32(1004) + IBCCodeUnknownHeight = uint32(1005) + IBCCodeInvalidCommit = uint32(1006) + IBCCodeInvalidProof = uint32(1007) + IBCCodeInvalidCall = uint32(1008) ) func ErrNotRegistered(chainID string) error { @@ -65,7 +64,7 @@ func IsCannotSetPermissionErr(err error) bool { return errors.IsSameError(errCannotSetPermission, err) } -func ErrHeaderNotFound(h int) error { +func ErrHeaderNotFound(h int64) error { msg := fmt.Sprintf("height %d", h) return errors.WithMessage(msg, errHeaderNotFound, IBCCodeUnknownHeight) } @@ -80,7 +79,7 @@ func IsPacketAlreadyExistsErr(err error) bool { return errors.IsSameError(errPacketAlreadyExists, err) } -func ErrPacketOutOfOrder(seq uint64) error { +func ErrPacketOutOfOrder(seq int64) error { msg := fmt.Sprintf("expected %d", seq) return errors.WithMessage(msg, errPacketOutOfOrder, IBCCodeInvalidPacketSequence) } diff --git a/modules/ibc/ibc_test.go b/modules/ibc/ibc_test.go index 70a560f98f45..659d28456cae 100644 --- a/modules/ibc/ibc_test.go +++ b/modules/ibc/ibc_test.go @@ -302,7 +302,7 @@ func TestIBCCreatePacket(t *testing.T) { q := OutputQueue(p, chainID) if assert.Equal(2, q.Size()) { expected := []struct { - seq uint64 + seq int64 perm sdk.Actors }{ {0, nil}, diff --git a/modules/ibc/keys.go b/modules/ibc/keys.go index 4b5a53f980f0..90c098a38f74 100644 --- a/modules/ibc/keys.go +++ b/modules/ibc/keys.go @@ -46,14 +46,14 @@ func QueueOutKey(chainID string) []byte { } // QueueInPacketKey is the key to get given packet from this chain's input queue -func QueueInPacketKey(chainID string, seq uint64) []byte { +func QueueInPacketKey(chainID string, seq int64) []byte { return stack.PrefixedKey(chainID, stack.PrefixedKey(prefixInput, state.QueueItemKey(seq))) } // QueueOutPacketKey is the key to get given packet from this chain's output queue -func QueueOutPacketKey(chainID string, seq uint64) []byte { +func QueueOutPacketKey(chainID string, seq int64) []byte { return stack.PrefixedKey(chainID, stack.PrefixedKey(prefixOutput, state.QueueItemKey(seq))) diff --git a/modules/ibc/middleware.go b/modules/ibc/middleware.go index 09ffabb14241..83866f8fe959 100644 --- a/modules/ibc/middleware.go +++ b/modules/ibc/middleware.go @@ -96,7 +96,7 @@ func (m Middleware) verifyPost(ctx sdk.Context, store state.SimpleDB, provider := newDBProvider(space) // if the query was on height H, the proof is in header H+1 - proofHeight := int(tx.FromChainHeight + 1) + proofHeight := tx.FromChainHeight + 1 seed, err := provider.GetExactHeight(proofHeight) if err != nil { return ictx, itx, err diff --git a/modules/ibc/noop.go b/modules/ibc/noop.go index 3e111caf9bf1..9c6825694eff 100644 --- a/modules/ibc/noop.go +++ b/modules/ibc/noop.go @@ -15,7 +15,7 @@ func NewMissingProvider() lite.Provider { } func (missingProvider) StoreCommit(lite.FullCommit) error { return nil } -func (missingProvider) GetByHeight(int) (lite.FullCommit, error) { +func (missingProvider) GetByHeight(int64) (lite.FullCommit, error) { return lite.FullCommit{}, liteErr.ErrCommitNotFound() } func (missingProvider) GetByHash([]byte) (lite.FullCommit, error) { diff --git a/modules/ibc/provider.go b/modules/ibc/provider.go index 2e9d9584c3d4..6314840c104c 100644 --- a/modules/ibc/provider.go +++ b/modules/ibc/provider.go @@ -18,7 +18,7 @@ const ( // newCertifier loads up the current state of this chain to make a proper certifier // it will load the most recent height before block h if h is positive // if h < 0, it will load the latest height -func newCertifier(store state.SimpleDB, chainID string, h int) (*lite.Inquiring, error) { +func newCertifier(store state.SimpleDB, chainID string, h int64) (*lite.Inquiring, error) { // each chain has their own prefixed subspace p := newDBProvider(store) @@ -60,7 +60,7 @@ func (d *dbProvider) StoreCommit(fc lite.FullCommit) error { // TODO: don't duplicate data.... b := wire.BinaryBytes(fc) d.byHash.Set(fc.ValidatorsHash(), b) - d.byHeight.Set(uint64(fc.Height()), b) + d.byHeight.Set(int64(fc.Height()), b) return nil } @@ -73,8 +73,8 @@ func (d *dbProvider) LatestCommit() (fc lite.FullCommit, err error) { return } -func (d *dbProvider) GetByHeight(h int) (fc lite.FullCommit, err error) { - b, _ := d.byHeight.LTE(uint64(h)) +func (d *dbProvider) GetByHeight(h int64) (fc lite.FullCommit, err error) { + b, _ := d.byHeight.LTE(int64(h)) if b == nil { return fc, certerr.ErrCommitNotFound() } @@ -93,7 +93,7 @@ func (d *dbProvider) GetByHash(hash []byte) (fc lite.FullCommit, err error) { // GetExactHeight is like GetByHeight, but returns an error instead of // closest match if there is no exact match -func (d *dbProvider) GetExactHeight(h int) (fc lite.FullCommit, err error) { +func (d *dbProvider) GetExactHeight(h int64) (fc lite.FullCommit, err error) { fc, err = d.GetByHeight(h) if err != nil { return diff --git a/modules/ibc/store.go b/modules/ibc/store.go index 6da04f004b9f..13e798e2d602 100644 --- a/modules/ibc/store.go +++ b/modules/ibc/store.go @@ -30,8 +30,8 @@ func LoadInfo(store state.SimpleDB) (h HandlerInfo) { // ChainInfo is the global info we store for each registered chain, // besides the headers, proofs, and packets type ChainInfo struct { - RegisteredAt uint64 `json:"registered_at"` - RemoteBlock int `json:"remote_block"` + RegisteredAt int64 `json:"registered_at"` + RemoteBlock int64 `json:"remote_block"` } // ChainSet is the set of all registered chains @@ -49,7 +49,7 @@ func NewChainSet(store state.SimpleDB) ChainSet { // Register adds the named chain with some info // returns error if already present -func (c ChainSet) Register(chainID string, ourHeight uint64, theirHeight int) error { +func (c ChainSet) Register(chainID string, ourHeight int64, theirHeight int64) error { if c.Exists([]byte(chainID)) { return ErrAlreadyRegistered(chainID) } @@ -64,7 +64,7 @@ func (c ChainSet) Register(chainID string, ourHeight uint64, theirHeight int) er // Update sets the new tracked height on this chain // returns error if not present -func (c ChainSet) Update(chainID string, theirHeight int) error { +func (c ChainSet) Update(chainID string, theirHeight int64) error { d := c.Set.Get([]byte(chainID)) if len(d) == 0 { return ErrNotRegistered(chainID) @@ -86,14 +86,14 @@ func (c ChainSet) Update(chainID string, theirHeight int) error { // Packet is a wrapped transaction and permission that we want to // send off to another chain. type Packet struct { - DestChain string `json:"dest_chain"` - Sequence uint64 `json:"sequence"` + DestChain string `json:"dest_chain"` + Sequence int64 `json:"sequence"` Permissions sdk.Actors `json:"permissions"` Tx sdk.Tx `json:"tx"` } // NewPacket creates a new outgoing packet -func NewPacket(tx sdk.Tx, dest string, seq uint64, perm ...sdk.Actor) Packet { +func NewPacket(tx sdk.Tx, dest string, seq int64, perm ...sdk.Actor) Packet { return Packet{ DestChain: dest, Sequence: seq, diff --git a/modules/ibc/test_helpers.go b/modules/ibc/test_helpers.go index 6e2baba5c8cc..480a9254aca2 100644 --- a/modules/ibc/test_helpers.go +++ b/modules/ibc/test_helpers.go @@ -31,14 +31,14 @@ func NewMockChain(chainID string, numKeys int) MockChain { } // GetRegistrationTx returns a valid tx to register this chain -func (m MockChain) GetRegistrationTx(h int) RegisterChainTx { +func (m MockChain) GetRegistrationTx(h int64) RegisterChainTx { fc := genEmptyCommit(m.keys, m.chainID, h, m.tree.Hash(), len(m.keys)) return RegisterChainTx{fc} } // MakePostPacket commits the packet locally and returns the proof, // in the form of two packets to update the header and prove this packet. -func (m MockChain) MakePostPacket(packet Packet, h int) ( +func (m MockChain) MakePostPacket(packet Packet, h int64) ( PostPacketTx, UpdateChainTx) { post := makePostPacket(m.tree, packet, m.chainID, h) @@ -48,14 +48,14 @@ func (m MockChain) MakePostPacket(packet Packet, h int) ( return post, update } -func genEmptyCommit(keys lite.ValKeys, chain string, h int, +func genEmptyCommit(keys lite.ValKeys, chain string, h int64, appHash []byte, count int) lite.FullCommit { vals := keys.ToValidators(10, 0) return keys.GenFullCommit(chain, h, nil, vals, appHash, 0, count) } -func makePostPacket(tree *iavl.Tree, packet Packet, fromID string, fromHeight int) PostPacketTx { +func makePostPacket(tree *iavl.Tree, packet Packet, fromID string, fromHeight int64) PostPacketTx { key := []byte(fmt.Sprintf("some-long-prefix-%06d", packet.Sequence)) tree.Set(key, packet.Bytes()) _, proof, err := tree.GetWithProof(key) @@ -68,7 +68,7 @@ func makePostPacket(tree *iavl.Tree, packet Packet, fromID string, fromHeight in return PostPacketTx{ FromChainID: fromID, - FromChainHeight: uint64(fromHeight), + FromChainHeight: int64(fromHeight), Proof: proof.(*iavl.KeyExistsProof), Key: key, Packet: packet, @@ -80,7 +80,7 @@ type AppChain struct { chainID string app sdk.Handler store state.SimpleDB - height int + height int64 } // NewAppChain returns a chain that is ready to respond to tx @@ -95,7 +95,7 @@ func NewAppChain(app sdk.Handler, chainID string) *AppChain { // IncrementHeight allows us to jump heights, more than the auto-step // of 1. It returns the new height we are at. -func (a *AppChain) IncrementHeight(delta int) int { +func (a *AppChain) IncrementHeight(delta int64) int64 { a.height += delta return a.height } @@ -103,7 +103,7 @@ func (a *AppChain) IncrementHeight(delta int) int { // DeliverTx runs the tx and commits the new tree, incrementing height // by one. func (a *AppChain) DeliverTx(tx sdk.Tx, perms ...sdk.Actor) (sdk.DeliverResult, error) { - ctx := stack.MockContext(a.chainID, uint64(a.height)).WithPermissions(perms...) + ctx := stack.MockContext(a.chainID, int64(a.height)).WithPermissions(perms...) store := a.store.Checkpoint() res, err := a.app.DeliverTx(ctx, store, tx) if err == nil { diff --git a/modules/ibc/tx.go b/modules/ibc/tx.go index 10b69686192b..be9dbefefc7c 100644 --- a/modules/ibc/tx.go +++ b/modules/ibc/tx.go @@ -114,7 +114,7 @@ type PostPacketTx struct { FromChainID string `json:"src_chain"` // The block height in which Packet was committed, to check Proof // AppHash for the proof in header for FromChainHeight+1 - FromChainHeight uint64 `json:"src_height"` + FromChainHeight int64 `json:"src_height"` // this proof must match the header and the packet.Bytes() Proof *iavl.KeyExistsProof `json:"proof"` Key data.Bytes `json:"key"` diff --git a/modules/nonce/commands/query.go b/modules/nonce/commands/query.go index 7021c8ca5a2c..9d3bb0a16b81 100644 --- a/modules/nonce/commands/query.go +++ b/modules/nonce/commands/query.go @@ -41,7 +41,7 @@ func nonceQueryCmd(cmd *cobra.Command, args []string) error { return query.OutputProof(seq, height) } -func doNonceQuery(signers []sdk.Actor) (sequence uint32, height uint64, err error) { +func doNonceQuery(signers []sdk.Actor) (sequence uint32, height int64, err error) { key := stack.PrefixedKey(nonce.NameNonce, nonce.GetSeqKey(signers)) prove := !viper.GetBool(commands.FlagTrustNode) height, err = query.GetParsed(key, &sequence, query.GetHeight(), prove) diff --git a/modules/nonce/errors.go b/modules/nonce/errors.go index 0d77b798427c..9d456dd650ec 100644 --- a/modules/nonce/errors.go +++ b/modules/nonce/errors.go @@ -4,8 +4,6 @@ package nonce import ( "fmt" - abci "github.com/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/errors" ) @@ -16,9 +14,9 @@ var ( errNoSigners = fmt.Errorf("There are no signers") errTxEmpty = fmt.Errorf("The provided Tx is empty") - unauthorized = abci.CodeType_Unauthorized - badNonce = abci.CodeType_BadNonce - invalidInput = abci.CodeType_BaseInvalidInput + unauthorized = errors.CodeTypeUnauthorized + badNonce = errors.CodeTypeBadNonce + invalidInput = errors.CodeTypeBaseInvalidInput ) func ErrBadNonce(got, expected uint32) errors.TMError { diff --git a/modules/nonce/tx_test.go b/modules/nonce/tx_test.go index e47a7711645c..84d62d4e887d 100644 --- a/modules/nonce/tx_test.go +++ b/modules/nonce/tx_test.go @@ -19,7 +19,7 @@ func TestNonce(t *testing.T) { chainID := "my-chain" chain2ID := "woohoo" - height := uint64(100) + height := int64(100) ctx := stack.MockContext(chainID, height) store := state.NewMemKVStore() diff --git a/modules/roles/commands/wrap.go b/modules/roles/commands/wrap.go index 9ea855e9e4c8..174113d20ff5 100644 --- a/modules/roles/commands/wrap.go +++ b/modules/roles/commands/wrap.go @@ -6,7 +6,6 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" - abci "github.com/tendermint/abci/types" cmn "github.com/tendermint/tmlibs/common" sdk "github.com/cosmos/cosmos-sdk" @@ -53,7 +52,7 @@ func parseRole(role string) ([]byte, error) { res, err := hex.DecodeString(cmn.StripHex(role)) if err != nil { err = errors.WithMessage("Address is invalid hex", err, - abci.CodeType_EncodingError) + errors.CodeTypeEncodingErr) } return res, err } diff --git a/modules/roles/error.go b/modules/roles/error.go index 4abdbf895671..57e8914a463f 100644 --- a/modules/roles/error.go +++ b/modules/roles/error.go @@ -4,8 +4,6 @@ package roles import ( "fmt" - abci "github.com/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/errors" ) @@ -18,7 +16,7 @@ var ( errTooManyMembers = fmt.Errorf("Too many members specified") errNotEnoughMembers = fmt.Errorf("Not enough members specified") - unauthorized = abci.CodeType_Unauthorized + unauthorized = errors.CodeTypeUnauthorized ) // TODO: codegen? diff --git a/modules/roles/handler.go b/modules/roles/handler.go index f70091e89cdf..34d64391f23f 100644 --- a/modules/roles/handler.go +++ b/modules/roles/handler.go @@ -10,9 +10,9 @@ const ( //NameRole - name space of the roles module NameRole = "role" // CostCreate is the cost to create a new role - CostCreate = uint64(40) + CostCreate = int64(40) // CostAssume is the cost to assume a role as part of a tx - CostAssume = uint64(5) + CostAssume = int64(5) ) // Handler allows us to create new roles diff --git a/modules/roles/handler_test.go b/modules/roles/handler_test.go index f654f5acee05..7658ccdb7d72 100644 --- a/modules/roles/handler_test.go +++ b/modules/roles/handler_test.go @@ -44,7 +44,7 @@ func TestCreateRole(t *testing.T) { assert.Nil(err, "%d/%s: %+v", i, tc.role, err) assert.Nil(err2, "%d/%s: %+v", i, tc.role, err2) assert.Equal(roles.CostCreate, cres.GasAllocated) - assert.Equal(uint64(0), cres.GasPayment) + assert.Equal(int64(0), cres.GasPayment) } else { assert.NotNil(err, "%d/%s", i, tc.role) assert.NotNil(err2, "%d/%s", i, tc.role) diff --git a/modules/roles/middleware_test.go b/modules/roles/middleware_test.go index 459405cf9c66..7886e5ab6c48 100644 --- a/modules/roles/middleware_test.go +++ b/modules/roles/middleware_test.go @@ -99,8 +99,8 @@ func TestAssumeRole(t *testing.T) { assert.Nil(err, "%d: %+v", i, err) assert.Nil(err2, "%d: %+v", i, err2) // make sure we charge for each role - assert.Equal(roles.CostAssume*uint64(len(tc.roles)), cres.GasAllocated) - assert.Equal(uint64(0), cres.GasPayment) + assert.Equal(roles.CostAssume*int64(len(tc.roles)), cres.GasAllocated) + assert.Equal(int64(0), cres.GasPayment) } else { assert.NotNil(err, "%d", i) assert.NotNil(err2, "%d", i) diff --git a/modules/roles/rest/handlers.go b/modules/roles/rest/handlers.go index 1943634a34e4..315ddcb13dd0 100644 --- a/modules/roles/rest/handlers.go +++ b/modules/roles/rest/handlers.go @@ -37,7 +37,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, abci.CodeType_EncodingError) + err = errors.WithMessage("invalid hex", err, errors.CodeTypeEncodingError) return nil, err } return parsedRole, nil diff --git a/stack/context.go b/stack/context.go index f923e89ad96d..fe01ec7059ec 100644 --- a/stack/context.go +++ b/stack/context.go @@ -20,7 +20,7 @@ type secureContext struct { } // NewContext - create a new secureContext -func NewContext(chain string, height uint64, logger log.Logger) sdk.Context { +func NewContext(chain string, height int64, logger log.Logger) sdk.Context { mock := MockContext(chain, height).(naiveContext) mock.Logger = logger return secureContext{ diff --git a/stack/mock.go b/stack/mock.go index 7327875f6a3e..67a2fa84cbae 100644 --- a/stack/mock.go +++ b/stack/mock.go @@ -11,7 +11,7 @@ import ( type naiveContext struct { id nonce chain string - height uint64 + height int64 perms []sdk.Actor log.Logger } @@ -19,7 +19,7 @@ type naiveContext struct { // MockContext returns a simple, non-checking context for test cases. // // Always use NewContext() for production code to sandbox malicious code better -func MockContext(chain string, height uint64) sdk.Context { +func MockContext(chain string, height int64) sdk.Context { return naiveContext{ id: nonce(rand.Int63()), chain: chain, @@ -34,7 +34,7 @@ func (c naiveContext) ChainID() string { return c.chain } -func (c naiveContext) BlockHeight() uint64 { +func (c naiveContext) BlockHeight() int64 { return c.height } diff --git a/state/bonsai.go b/state/bonsai.go index 2ab75b2df830..dfa3d3a9a886 100644 --- a/state/bonsai.go +++ b/state/bonsai.go @@ -54,8 +54,8 @@ func (b *Bonsai) GetWithProof(key []byte) ([]byte, iavl.KeyProof, error) { return b.Tree.GetWithProof(key) } -func (b *Bonsai) GetVersionedWithProof(key []byte, version uint64) ([]byte, iavl.KeyProof, error) { - return b.Tree.GetVersionedWithProof(key, version) +func (b *Bonsai) GetVersionedWithProof(key []byte, version int64) ([]byte, iavl.KeyProof, error) { + return b.Tree.GetVersionedWithProof(key, uint64(version)) } func (b *Bonsai) List(start, end []byte, limit int) []Model { diff --git a/state/errors.go b/state/errors.go index 54b5badd3d5d..2693e5a08b1a 100644 --- a/state/errors.go +++ b/state/errors.go @@ -4,7 +4,6 @@ package state import ( "fmt" - abci "github.com/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/errors" ) @@ -13,7 +12,7 @@ var ( ) func ErrNotASubTransaction() errors.TMError { - return errors.WithCode(errNotASubTransaction, abci.CodeType_InternalError) + return errors.WithCode(errNotASubTransaction, errors.CodeTypeInternalErr) } func IsNotASubTransactionErr(err error) bool { return errors.IsSameError(errNotASubTransaction, err) diff --git a/state/merkle.go b/state/merkle.go index 7bfabc43752c..7d11aa8ddb58 100644 --- a/state/merkle.go +++ b/state/merkle.go @@ -8,12 +8,12 @@ type State struct { committed *Bonsai deliverTx SimpleDB checkTx SimpleDB - historySize uint64 + historySize int64 } // NewState wraps a versioned tree and maintains all needed // states for the abci app -func NewState(tree *iavl.VersionedTree, historySize uint64) *State { +func NewState(tree *iavl.VersionedTree, historySize int64) *State { base := NewBonsai(tree) return &State{ committed: base, @@ -64,7 +64,7 @@ func (s State) LatestHash() []byte { } // Commit saves persistent nodes to the database and re-copies the trees -func (s *State) Commit(version uint64) ([]byte, error) { +func (s *State) Commit(version int64) ([]byte, error) { // commit (if we didn't do hash earlier) err := s.committed.Commit(s.deliverTx) if err != nil { @@ -74,7 +74,7 @@ func (s *State) Commit(version uint64) ([]byte, error) { // store a new version var hash []byte if !s.IsEmpty() { - hash, err = s.committed.Tree.SaveVersion(version) + hash, err = s.committed.Tree.SaveVersion(uint64(version)) if err != nil { return nil, err } @@ -82,7 +82,7 @@ func (s *State) Commit(version uint64) ([]byte, error) { // release an old version if version > s.historySize { - s.committed.Tree.DeleteVersion(version - s.historySize) + s.committed.Tree.DeleteVersion(uint64(version - s.historySize)) } s.deliverTx = s.committed.Checkpoint() diff --git a/state/merkle_test.go b/state/merkle_test.go index 5fc7e9e56a91..1bb5ee53cc3f 100644 --- a/state/merkle_test.go +++ b/state/merkle_test.go @@ -77,7 +77,7 @@ func TestStateCommitHash(t *testing.T) { deliver.Set(k, v) } // commit and add hash to result - hash, err := store.Commit(uint64(n + 1)) + hash, err := store.Commit(int64(n + 1)) require.Nil(err, "tc:%d / rnd:%d - %+v", i, n, err) result[n] = hash } diff --git a/state/queue.go b/state/queue.go index 756f90bb644e..e4629414d7d6 100644 --- a/state/queue.go +++ b/state/queue.go @@ -19,15 +19,15 @@ func QueueTailKey() []byte { } // QueueItemKey gives us the key to look up one item by sequence -func QueueItemKey(i uint64) []byte { +func QueueItemKey(i int64) []byte { return makeKey(i) } // Queue allows us to fill up a range of the db, and grab from either end type Queue struct { store KVStore - head uint64 // if Size() > 0, the first element is here - tail uint64 // this is the first empty slot to Push() to + head int64 // if Size() > 0, the first element is here + tail int64 // this is the first empty slot to Push() to } // NewQueue will load or initialize a queue in this state-space @@ -41,7 +41,7 @@ func NewQueue(store KVStore) *Queue { } // Tail returns the next slot that Push() will use -func (q *Queue) Tail() uint64 { +func (q *Queue) Tail() int64 { return q.tail } @@ -51,7 +51,7 @@ func (q *Queue) Size() int { } // Push adds an element to the tail of the queue and returns it's location -func (q *Queue) Push(value []byte) uint64 { +func (q *Queue) Push(value []byte) int64 { key := makeKey(q.tail) q.store.Set(key, value) q.tail++ @@ -72,31 +72,32 @@ func (q *Queue) Pop() []byte { } // Item looks at any element in the queue, without modifying anything -func (q *Queue) Item(seq uint64) []byte { +func (q *Queue) Item(seq int64) []byte { if seq >= q.tail || seq < q.head { return nil } return q.store.Get(makeKey(seq)) } -func (q *Queue) setCount(key []byte, val uint64) { +func (q *Queue) setCount(key []byte, val int64) { b := make([]byte, 8) - binary.BigEndian.PutUint64(b, val) + binary.BigEndian.PutUint64(b, uint64(val)) q.store.Set(key, b) } -func (q *Queue) getCount(key []byte) (val uint64) { +func (q *Queue) getCount(key []byte) (val int64) { b := q.store.Get(key) + var v uint64 if b != nil { - val = binary.BigEndian.Uint64(b) + v = binary.BigEndian.Uint64(b) } - return val + return int64(v) } // makeKey returns the key for a data point -func makeKey(val uint64) []byte { +func makeKey(val int64) []byte { b := make([]byte, 8+len(dataKey)) copy(b, dataKey) - binary.BigEndian.PutUint64(b[len(dataKey):], val) + binary.BigEndian.PutUint64(b[len(dataKey):], uint64(val)) return b } diff --git a/state/queue_test.go b/state/queue_test.go index d6212be90e4c..21d466debad5 100644 --- a/state/queue_test.go +++ b/state/queue_test.go @@ -44,7 +44,7 @@ func TestQueue(t *testing.T) { q := NewQueue(store) for j, in := range tc.pushes { cnt := q.Push(in) - assert.Equal(uint64(j), cnt, "%d", i) + assert.Equal(int64(j), cnt, "%d", i) } assert.EqualValues(len(tc.pushes), q.Size()) diff --git a/state/span.go b/state/span.go index 5b97084179fc..a3a65d8b7f3b 100644 --- a/state/span.go +++ b/state/span.go @@ -18,7 +18,7 @@ var ( type Span struct { store KVStore // keys is sorted ascending and cannot contain duplicates - keys []uint64 + keys []int64 } // NewSpan loads or initializes a span of keys @@ -29,7 +29,7 @@ func NewSpan(store KVStore) *Span { } // Set puts a value at a given height -func (s *Span) Set(h uint64, value []byte) { +func (s *Span) Set(h int64, value []byte) { key := makeKey(h) s.store.Set(key, value) s.addKey(h) @@ -37,13 +37,13 @@ func (s *Span) Set(h uint64, value []byte) { } // Get returns the element at h if it exists -func (s *Span) Get(h uint64) []byte { +func (s *Span) Get(h int64) []byte { key := makeKey(h) return s.store.Get(key) } // Bottom returns the lowest element in the Span, along with its index -func (s *Span) Bottom() ([]byte, uint64) { +func (s *Span) Bottom() ([]byte, int64) { if len(s.keys) == 0 { return nil, 0 } @@ -52,7 +52,7 @@ func (s *Span) Bottom() ([]byte, uint64) { } // Top returns the highest element in the Span, along with its index -func (s *Span) Top() ([]byte, uint64) { +func (s *Span) Top() ([]byte, int64) { l := len(s.keys) if l == 0 { return nil, 0 @@ -62,7 +62,7 @@ func (s *Span) Top() ([]byte, uint64) { } // GTE returns the lowest element in the Span that is >= h, along with its index -func (s *Span) GTE(h uint64) ([]byte, uint64) { +func (s *Span) GTE(h int64) ([]byte, int64) { for _, k := range s.keys { if k >= h { return s.Get(k), k @@ -73,8 +73,8 @@ func (s *Span) GTE(h uint64) ([]byte, uint64) { // LTE returns the highest element in the Span that is <= h, // along with its index -func (s *Span) LTE(h uint64) ([]byte, uint64) { - var k uint64 +func (s *Span) LTE(h int64) ([]byte, int64) { + var k int64 // start from the highest and go down for the first match for i := len(s.keys) - 1; i >= 0; i-- { k = s.keys[i] @@ -86,7 +86,7 @@ func (s *Span) LTE(h uint64) ([]byte, uint64) { } // addKey inserts this key, maintaining sorted order, no duplicates -func (s *Span) addKey(h uint64) { +func (s *Span) addKey(h int64) { for i, k := range s.keys { // don't add duplicates if h == k { diff --git a/state/span_test.go b/state/span_test.go index 8362f3d90f56..b8c708fa81b7 100644 --- a/state/span_test.go +++ b/state/span_test.go @@ -8,7 +8,7 @@ import ( ) type kv struct { - k uint64 + k int64 v []byte } @@ -28,7 +28,7 @@ func TestBasicSpan(t *testing.T) { lots := make([]kv, 1000) for i := range lots { - lots[i] = kv{uint64(3 * i), []byte{byte(i / 100), byte(i % 100)}} + lots[i] = kv{int64(3 * i), []byte{byte(i / 100), byte(i % 100)}} } cases := []bscase{