From b89f5b4bec5fa45ff841a96dcdf40d693d595b9d Mon Sep 17 00:00:00 2001 From: Andrey Luiz Date: Fri, 13 Dec 2024 15:31:13 +0100 Subject: [PATCH] Fix linting issues --- cmd/handler/plugin.go | 2 +- internal/model/correctness.go | 2 +- internal/model/logs.go | 2 +- internal/service/ai/fees.go | 1 + internal/service/evmlog/process.go | 6 +++++- internal/service/pos/pos.go | 2 ++ internal/service/pos/pos_mock.go | 7 ++++++- internal/service/rpc/runtime/unix.go | 1 + internal/service/uniswap/uniswap.go | 1 + internal/transport/client/conn/conn.go | 2 +- internal/transport/server/websocket/websocket.go | 8 ++++---- 11 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cmd/handler/plugin.go b/cmd/handler/plugin.go index 1f1dafb9..31206de3 100644 --- a/cmd/handler/plugin.go +++ b/cmd/handler/plugin.go @@ -33,7 +33,7 @@ var plugin = &cobra.Command{ Short: "Run an Unchained plugin locally", Long: `Run an Unchained plugin locally`, - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { os.Exit(1) }, } diff --git a/internal/model/correctness.go b/internal/model/correctness.go index e119f97b..9bb18d6b 100644 --- a/internal/model/correctness.go +++ b/internal/model/correctness.go @@ -93,7 +93,7 @@ func (c *Correctness) FromSia(sia sia.Sia) *Correctness { func (c *Correctness) Bls() (bls12381.G1Affine, error) { hash, err := bls.Hash(c.Sia().Bytes()) if err != nil { - utils.Logger.Error("Can't hash bls: %v", err) + utils.Logger.Error("Can't hash bls: %v", "error", err.Error()) return bls12381.G1Affine{}, err } diff --git a/internal/model/logs.go b/internal/model/logs.go index 2d845702..27e938ca 100644 --- a/internal/model/logs.go +++ b/internal/model/logs.go @@ -119,7 +119,7 @@ func (e *EventLog) FromSia(sia sia.Sia) *EventLog { func (e *EventLog) Bls() (bls12381.G1Affine, error) { hash, err := bls.Hash(e.Sia().Bytes()) if err != nil { - utils.Logger.Error("Can't hash bls: %v", err) + utils.Logger.With("Error", err).Error("Can't hash bls") return bls12381.G1Affine{}, err } diff --git a/internal/service/ai/fees.go b/internal/service/ai/fees.go index f96a042e..12099850 100644 --- a/internal/service/ai/fees.go +++ b/internal/service/ai/fees.go @@ -57,6 +57,7 @@ func (tc *TxChecker) CheckTransaction(txHash common.Hash, toAddress common.Addre return false, fmt.Errorf("could not retrieve block header: %w", err) } + //nolint:gosec // refactoring needed blockTime := time.Unix(int64(header.Time), 0) if time.Since(blockTime) > 5*time.Minute { tc.txCache.MarkExpired(txHash) diff --git a/internal/service/evmlog/process.go b/internal/service/evmlog/process.go index 93f9db48..fe5918b5 100644 --- a/internal/service/evmlog/process.go +++ b/internal/service/evmlog/process.go @@ -67,7 +67,9 @@ func (s *service) ProcessBlocks(ctx context.Context, chain string) error { } query := goEthereum.FilterQuery{ + //nolint:gosec //refactoring needed FromBlock: big.NewInt(int64(fromBlock)), + //nolint:gosec // refactoring needed ToBlock: big.NewInt(int64(toBlock)), Addresses: []common.Address{contractAddress}, } @@ -139,7 +141,9 @@ func (s *service) ProcessBlocks(ctx context.Context, chain string) error { value := eventData[key] if strings.HasPrefix(argTypes[key], "uint") || strings.HasPrefix(argTypes[key], "int") { - value = value.(*big.Int).String() + if bigInt, ok := value.(*big.Int); ok { + value = bigInt.String() + } } args = append( diff --git a/internal/service/pos/pos.go b/internal/service/pos/pos.go index aaf64a8f..b7a7e1b2 100644 --- a/internal/service/pos/pos.go +++ b/internal/service/pos/pos.go @@ -86,6 +86,7 @@ func (s *service) GetVotingPowerOfEvm(ctx context.Context, evmAddress string) (* return nil, err } address := common.HexToAddress(evmAddress) + //nolint:gosec // refactoring needed return s.GetVotingPower(address, big.NewInt(int64(block))) } @@ -99,6 +100,7 @@ func (s *service) GetVotingPowerOfPublicKey(ctx context.Context, pkBytes [96]byt if err != nil { return nil, err } + //nolint:gosec // refactoring needed return s.GetVotingPower(addrHex, big.NewInt(int64(block))) } diff --git a/internal/service/pos/pos_mock.go b/internal/service/pos/pos_mock.go index 2cf30251..01b27e9c 100644 --- a/internal/service/pos/pos_mock.go +++ b/internal/service/pos/pos_mock.go @@ -39,5 +39,10 @@ func (m *MockService) GetVotingPowerOfPublicKey(_ context.Context, pkBytes [96]b func (m *MockService) GetSchnorrSigners(_ context.Context) ([]common.Address, error) { args := m.Called() - return args.Get(0).([]common.Address), args.Error(1) + if result := args.Get(0); result != nil { + if addresses, ok := result.([]common.Address); ok { + return addresses, args.Error(1) + } + } + return nil, args.Error(1) } diff --git a/internal/service/rpc/runtime/unix.go b/internal/service/rpc/runtime/unix.go index 0cdbf6ee..a9b43e1c 100644 --- a/internal/service/rpc/runtime/unix.go +++ b/internal/service/rpc/runtime/unix.go @@ -20,6 +20,7 @@ type UnixPayload struct { func NewUnixPayload(params *dto.RPCRequest) *UnixPayload { payload := params.Sia().Bytes() return &UnixPayload{ + //nolint:gosec // refactoring needed Size: uint32(len(payload)), Params: payload, } diff --git a/internal/service/uniswap/uniswap.go b/internal/service/uniswap/uniswap.go index 1bbdc6da..614f7212 100644 --- a/internal/service/uniswap/uniswap.go +++ b/internal/service/uniswap/uniswap.go @@ -252,6 +252,7 @@ func (s *service) GetPriceAtBlockFromPair( data, err := pair.Slot0( &bind.CallOpts{ + //nolint:gosec // refactoring needed BlockNumber: big.NewInt(int64(blockNumber)), }) diff --git a/internal/transport/client/conn/conn.go b/internal/transport/client/conn/conn.go index 87a15bc3..97e6000c 100644 --- a/internal/transport/client/conn/conn.go +++ b/internal/transport/client/conn/conn.go @@ -146,7 +146,7 @@ func Send(opCode consts.OpCode, payload []byte) { append([]byte{byte(opCode)}, payload...), ) if err != nil { - utils.Logger.Error("Can't send packet: %v", err) + utils.Logger.With("Error", err).Error("Can't send packet") } } diff --git a/internal/transport/server/websocket/websocket.go b/internal/transport/server/websocket/websocket.go index a23ad228..5f9c9009 100644 --- a/internal/transport/server/websocket/websocket.go +++ b/internal/transport/server/websocket/websocket.go @@ -28,11 +28,11 @@ func WithWebsocket() func() { // multiplexer is a function that routes incoming messages to the appropriate handler. func multiplexer(w http.ResponseWriter, r *http.Request) { - upgrader.CheckOrigin = func(r *http.Request) bool { return true } // remove this line in production + upgrader.CheckOrigin = func(_ *http.Request) bool { return true } // remove this line in production conn, err := upgrader.Upgrade(w, r, nil) if err != nil { - utils.Logger.Error("Can't upgrade the HTTP connection: %v", err) + utils.Logger.With("Error", err).Error("Can't upgrade the HTTP connection") return } @@ -45,11 +45,11 @@ func multiplexer(w http.ResponseWriter, r *http.Request) { for { _, payload, err := conn.ReadMessage() if err != nil { - utils.Logger.Error("Can't read message: %v", err) + utils.Logger.With("Error", err).Error("Can't read message") err := conn.Close() if err != nil { - utils.Logger.Error("Can't close connection: %v", err) + utils.Logger.With("Error", err).Error("Can't close connection") } break