diff --git a/.golangci.yml b/.golangci.yml index e0a8fc5..408fd9a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,9 +8,11 @@ run: linters: disable-all: true enable: - - depguard - dogsled + - errcheck + - errorlint - exportloopref + - gci - goconst - gocritic - gofumpt @@ -21,9 +23,10 @@ linters: - misspell - nakedret - nolintlint - - staticcheck - revive + - staticcheck - stylecheck + - thelper - typecheck - unconvert - unused @@ -54,6 +57,18 @@ issues: max-same-issues: 10000 linters-settings: + gci: + custom-order: true + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(cosmossdk.io) + - prefix(github.com/cosmos/cosmos-sdk) + - prefix(github.com/cosmos/rosetta) + revive: + rules: + - name: redefines-builtin-id + disabled: true gosec: # To select a subset of rules to run. # Available rules: https://github.com/securego/gosec#available-rules diff --git a/client_offline.go b/client_offline.go index 323d1da..3ddb7bb 100644 --- a/client_offline.go +++ b/client_offline.go @@ -7,9 +7,9 @@ import ( "github.com/coinbase/rosetta-sdk-go/types" - crgerrs "github.com/cosmos/rosetta/lib/errors" - sdk "github.com/cosmos/cosmos-sdk/types" + + crgerrs "github.com/cosmos/rosetta/lib/errors" ) // ---------- cosmos-rosetta-gateway.types.NetworkInformationProvider implementation ------------ // diff --git a/client_online.go b/client_online.go index e1a82c3..26a4160 100644 --- a/client_online.go +++ b/client_online.go @@ -10,28 +10,24 @@ import ( "strconv" "time" - "github.com/cosmos/cosmos-sdk/version" - - abcitypes "github.com/cometbft/cometbft/abci/types" - rosettatypes "github.com/coinbase/rosetta-sdk-go/types" - "google.golang.org/grpc/credentials/insecure" - "google.golang.org/grpc/metadata" - + abcitypes "github.com/cometbft/cometbft/abci/types" + tmrpc "github.com/cometbft/cometbft/rpc/client" "github.com/cometbft/cometbft/rpc/client/http" "google.golang.org/grpc" - - crgerrs "github.com/cosmos/rosetta/lib/errors" - crgtypes "github.com/cosmos/rosetta/lib/types" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/metadata" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/cosmos/cosmos-sdk/version" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" auth "github.com/cosmos/cosmos-sdk/x/auth/types" bank "github.com/cosmos/cosmos-sdk/x/bank/types" - tmrpc "github.com/cometbft/cometbft/rpc/client" - "github.com/cosmos/cosmos-sdk/types/query" + crgerrs "github.com/cosmos/rosetta/lib/errors" + crgtypes "github.com/cosmos/rosetta/lib/types" ) // interface assertion diff --git a/cmd/rosetta.go b/cmd/rosetta.go index 24678da..181fe95 100644 --- a/cmd/rosetta.go +++ b/cmd/rosetta.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/rosetta" ) diff --git a/cmd/rosetta/main.go b/cmd/rosetta/main.go index 8b3ad17..d56c20d 100644 --- a/cmd/rosetta/main.go +++ b/cmd/rosetta/main.go @@ -3,9 +3,9 @@ package main import ( "os" - "github.com/cosmos/rosetta" - "cosmossdk.io/log" + + "github.com/cosmos/rosetta" rosettaCmd "github.com/cosmos/rosetta/cmd" ) diff --git a/codec.go b/codec.go index 02afd99..c9c76a6 100644 --- a/codec.go +++ b/codec.go @@ -1,7 +1,10 @@ package rosetta import ( + "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -10,7 +13,6 @@ import ( txtypes "github.com/cosmos/cosmos-sdk/types/tx" authcodec "github.com/cosmos/cosmos-sdk/x/auth/types" bankcodec "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/gogoproto/proto" ) // MakeCodec generates the codec required to interact diff --git a/config.go b/config.go index 67f44ce..90bcaa0 100644 --- a/config.go +++ b/config.go @@ -4,18 +4,17 @@ import ( "fmt" "time" - crgerrs "github.com/cosmos/rosetta/lib/errors" - "github.com/coinbase/rosetta-sdk-go/types" url "github.com/goware/urlx" "github.com/spf13/pflag" - crg "github.com/cosmos/rosetta/lib/server" - clientflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + + crgerrs "github.com/cosmos/rosetta/lib/errors" + crg "github.com/cosmos/rosetta/lib/server" ) const ( diff --git a/converter.go b/converter.go index a10628b..39c4b5f 100644 --- a/converter.go +++ b/converter.go @@ -8,7 +8,6 @@ import ( "fmt" "reflect" - signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" rosettatypes "github.com/coinbase/rosetta-sdk-go/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto" @@ -16,7 +15,9 @@ import ( cmttypes "github.com/cometbft/cometbft/types" secp "github.com/decred/dcrd/dcrec/secp256k1/v4" + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" sdkmath "cosmossdk.io/math" + sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -26,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + crgerrs "github.com/cosmos/rosetta/lib/errors" crgtypes "github.com/cosmos/rosetta/lib/types" ) diff --git a/converter_test.go b/converter_test.go index 2594b8c..503bb21 100644 --- a/converter_test.go +++ b/converter_test.go @@ -5,9 +5,6 @@ import ( "encoding/json" "testing" - "github.com/cosmos/rosetta" - crgerrs "github.com/cosmos/rosetta/lib/errors" - rosettatypes "github.com/coinbase/rosetta-sdk-go/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/stretchr/testify/suite" @@ -19,6 +16,9 @@ import ( authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" bank "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/cosmos/rosetta" + crgerrs "github.com/cosmos/rosetta/lib/errors" ) type ConverterTestSuite struct { diff --git a/lib/errors/errors.go b/lib/errors/errors.go index c406618..3cd4f03 100644 --- a/lib/errors/errors.go +++ b/lib/errors/errors.go @@ -4,14 +4,14 @@ package errors // plus some extra utilities to parse those errors import ( + "errors" "fmt" "net/http" - grpccodes "google.golang.org/grpc/codes" - grpcstatus "google.golang.org/grpc/status" - "github.com/coinbase/rosetta-sdk-go/types" cmttypes "github.com/cometbft/cometbft/rpc/jsonrpc/types" + grpccodes "google.golang.org/grpc/codes" + grpcstatus "google.golang.org/grpc/status" ) // ListErrors lists all the registered errors @@ -41,7 +41,8 @@ func (e *Error) Error() string { // if their error codes are identical func (e *Error) Is(err error) bool { // assert it can be casted - rosErr, ok := err.(*Error) + var rosErr *Error + ok := errors.As(err, &rosErr) if rosErr == nil || !ok { return false } @@ -70,9 +71,11 @@ func WrapError(err *Error, msg string) *Error { // error, if the error cannot be converted it will be parsed as unknown func ToRosetta(err error) *types.Error { // if it's null or not known - rosErr, ok := err.(*Error) + var rosErr *Error + ok := errors.As(err, &rosErr) if rosErr == nil || !ok { - tmErr, ok := err.(*cmttypes.RPCError) + var tmErr *cmttypes.RPCError + ok := errors.As(err, &tmErr) if tmErr != nil && ok { return fromCometToRosettaError(tmErr).rosErr } diff --git a/lib/errors/errors_test.go b/lib/errors/errors_test.go index a7dbfde..42bc2ca 100644 --- a/lib/errors/errors_test.go +++ b/lib/errors/errors_test.go @@ -20,7 +20,7 @@ func TestRegisterError(t *testing.T) { registeredErrorsCount++ assert.Equal(t, len(ListErrors()), registeredErrorsCount) // re-register an error should not change anything - RegisterError(69, "nice!", false, "nice!") + _ = RegisterError(69, "nice!", false, "nice!") assert.Equal(t, len(ListErrors()), registeredErrorsCount) // test sealing diff --git a/lib/internal/service/account.go b/lib/internal/service/account.go index f97b6c9..bd6669f 100644 --- a/lib/internal/service/account.go +++ b/lib/internal/service/account.go @@ -4,6 +4,7 @@ import ( "context" "github.com/coinbase/rosetta-sdk-go/types" + "github.com/cosmos/rosetta/lib/errors" crgtypes "github.com/cosmos/rosetta/lib/types" ) diff --git a/lib/internal/service/block.go b/lib/internal/service/block.go index d8a4e67..cc66815 100644 --- a/lib/internal/service/block.go +++ b/lib/internal/service/block.go @@ -4,6 +4,7 @@ import ( "context" "github.com/coinbase/rosetta-sdk-go/types" + "github.com/cosmos/rosetta/lib/errors" crgtypes "github.com/cosmos/rosetta/lib/types" ) diff --git a/lib/internal/service/construction.go b/lib/internal/service/construction.go index b4dd36d..81d4d64 100644 --- a/lib/internal/service/construction.go +++ b/lib/internal/service/construction.go @@ -7,11 +7,13 @@ import ( "strconv" "strings" - sdkmath "cosmossdk.io/math" "github.com/coinbase/rosetta-sdk-go/types" - "github.com/cosmos/rosetta/lib/errors" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/rosetta/lib/errors" ) // ConstructionCombine Combine creates a network-specific transaction from an unsigned transaction diff --git a/lib/internal/service/mempool.go b/lib/internal/service/mempool.go index 95ff6d9..eeee768 100644 --- a/lib/internal/service/mempool.go +++ b/lib/internal/service/mempool.go @@ -4,6 +4,7 @@ import ( "context" "github.com/coinbase/rosetta-sdk-go/types" + "github.com/cosmos/rosetta/lib/errors" ) diff --git a/lib/internal/service/network.go b/lib/internal/service/network.go index e00ae79..ec2e957 100644 --- a/lib/internal/service/network.go +++ b/lib/internal/service/network.go @@ -4,6 +4,7 @@ import ( "context" coinbase "github.com/coinbase/rosetta-sdk-go/types" + "github.com/cosmos/rosetta/lib/errors" ) diff --git a/lib/internal/service/online.go b/lib/internal/service/online.go index 5513a77..c893ffe 100644 --- a/lib/internal/service/online.go +++ b/lib/internal/service/online.go @@ -7,6 +7,7 @@ import ( "github.com/coinbase/rosetta-sdk-go/types" "cosmossdk.io/log" + crgerrs "github.com/cosmos/rosetta/lib/errors" crgtypes "github.com/cosmos/rosetta/lib/types" ) diff --git a/lib/server/server.go b/lib/server/server.go index 4c3c684..37f52de 100644 --- a/lib/server/server.go +++ b/lib/server/server.go @@ -7,10 +7,11 @@ import ( "time" "github.com/coinbase/rosetta-sdk-go/types" - assert "github.com/cosmos/rosetta-sdk-go/asserter" - "github.com/cosmos/rosetta-sdk-go/server" "cosmossdk.io/log" + + assert "github.com/cosmos/rosetta-sdk-go/asserter" + "github.com/cosmos/rosetta-sdk-go/server" "github.com/cosmos/rosetta/lib/internal/service" crgtypes "github.com/cosmos/rosetta/lib/types" ) diff --git a/lib/types/types.go b/lib/types/types.go index 00711b5..34e377b 100644 --- a/lib/types/types.go +++ b/lib/types/types.go @@ -4,6 +4,7 @@ import ( "context" "github.com/coinbase/rosetta-sdk-go/types" + "github.com/cosmos/rosetta-sdk-go/server" ) diff --git a/load.go b/load.go index 61b3f41..9dc1a09 100644 --- a/load.go +++ b/load.go @@ -4,20 +4,22 @@ package rosetta import ( "context" "crypto/tls" + "errors" "fmt" "io" "strings" - crgerrs "github.com/cosmos/rosetta/lib/errors" - - reflectionv1beta1 "cosmossdk.io/api/cosmos/base/reflection/v1beta1" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/reflection/grpc_reflection_v1alpha" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/descriptorpb" + + reflectionv1beta1 "cosmossdk.io/api/cosmos/base/reflection/v1beta1" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + + crgerrs "github.com/cosmos/rosetta/lib/errors" ) func ReflectInterfaces(ir codectypes.InterfaceRegistry, endpoint string) (err error) { @@ -71,7 +73,7 @@ func getFileDescriptorSet(c context.Context, client *grpc.ClientConn) (fdSet *de go func() { for { in, err := reflectClient.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { close(wait) return } diff --git a/plugins/cosmos-hub/main.go b/plugins/cosmos-hub/main.go index 8139022..81760a2 100644 --- a/plugins/cosmos-hub/main.go +++ b/plugins/cosmos-hub/main.go @@ -3,13 +3,8 @@ package main import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - - // ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - // ibcLightClient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - sdk "github.com/cosmos/cosmos-sdk/types" txtypes "github.com/cosmos/cosmos-sdk/types/tx" - bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) diff --git a/utils.go b/utils.go index 97c8a1a..6ecd9be 100644 --- a/utils.go +++ b/utils.go @@ -6,14 +6,15 @@ import ( "strconv" "time" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + "google.golang.org/protobuf/types/known/anypb" v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" signing2 "cosmossdk.io/x/tx/signing" - "google.golang.org/protobuf/types/known/anypb" sdk "github.com/cosmos/cosmos-sdk/types" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + crgerrs "github.com/cosmos/rosetta/lib/errors" )