Skip to content

Commit

Permalink
separated lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Sep 26, 2022
1 parent e439c39 commit 06ef29e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
5 changes: 4 additions & 1 deletion analyzer/emerald/incoming.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func registerEthAddress(addressPreimages map[string]*AddressPreimageData, ethAdd
return addr, nil
}

//nolint:unparam
func registerRelatedSdkAddress(relatedAddresses map[string]bool, sdkAddr *sdkTypes.Address) (string, error) {
addr, err := common.StringifySdkAddress(sdkAddr)
if err != nil {
Expand All @@ -154,6 +155,7 @@ func registerRelatedAddressSpec(addressPreimages map[string]*AddressPreimageData
return addr, nil
}

//nolint:unparam
func registerRelatedEthAddress(addressPreimages map[string]*AddressPreimageData, relatedAddresses map[string]bool, ethAddr []byte) (string, error) {
addr, err := registerEthAddress(addressPreimages, ethAddr)
if err != nil {
Expand All @@ -165,6 +167,7 @@ func registerRelatedEthAddress(addressPreimages map[string]*AddressPreimageData,
return addr, nil
}

//nolint:gocyclo
func extractRound(sigContext signature.Context, b *block.Block, txrs []*sdkClient.TransactionWithResults) (*BlockData, error) {
var blockData BlockData
blockData.Hash = b.Header.EncodedHash().String()
Expand Down Expand Up @@ -331,7 +334,7 @@ func extractRound(sigContext signature.Context, b *block.Block, txrs []*sdkClien
if (txr.Result.IsUnknown() || txr.Result.IsSuccess()) && tx != nil {
// Treat as if it used all the gas.
txGasUsed = int64(tx.AuthInfo.Fee.Gas)
} else {
} else { //nolint:staticcheck
// Inaccurate: Treat as not using any gas.
}
}
Expand Down
6 changes: 4 additions & 2 deletions analyzer/uncategorized/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"golang.org/x/crypto/sha3"
)

var TopicErc20Transfer = Keccak256([]byte("Transfer(address,address,uint256)"))
var TopicErc20Approval = Keccak256([]byte("Approval(address,address,uint256)"))
var (
TopicErc20Transfer = Keccak256([]byte("Transfer(address,address,uint256)"))
TopicErc20Approval = Keccak256([]byte("Approval(address,address,uint256)"))
)

var ZeroEthAddr = make([]byte, 20)

Expand Down
10 changes: 5 additions & 5 deletions analyzer/uncategorized/evm_raw_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
sdkTypes "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
)

func decodeEthRawTx(body []byte, expectedChainId uint64) (*sdkTypes.Transaction, error) {
func decodeEthRawTx(body []byte, expectedChainID uint64) (*sdkTypes.Transaction, error) {
var ethTx ethTypes.Transaction
if err := ethTx.UnmarshalBinary(body); err != nil {
return nil, fmt.Errorf("rlp decode bytes: %w", err)
Expand All @@ -23,11 +23,11 @@ func decodeEthRawTx(body []byte, expectedChainId uint64) (*sdkTypes.Transaction,
} else {
tb = evmV1.Create(ethTx.Value().Bytes(), ethTx.Data())
}
chainIdBI := ethTx.ChainId()
if !chainIdBI.IsUint64() || chainIdBI.Uint64() != expectedChainId {
return nil, fmt.Errorf("chain ID %v, expected %v", chainIdBI, expectedChainId)
chainIDBI := ethTx.ChainId()
if !chainIDBI.IsUint64() || chainIDBI.Uint64() != expectedChainID {
return nil, fmt.Errorf("chain ID %v, expected %v", chainIDBI, expectedChainID)
}
signer := ethTypes.LatestSignerForChainID(chainIdBI)
signer := ethTypes.LatestSignerForChainID(chainIDBI)
pubUncompressed, err := LondonSenderPub(signer, &ethTx)
if err != nil {
return nil, fmt.Errorf("recover signer public key: %w", err)
Expand Down
18 changes: 9 additions & 9 deletions analyzer/uncategorized/evm_raw_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import (
func decodeExpectCall(
t *testing.T,
raw string,
expectedChainId uint64,
expectedChainID uint64,
expectedTo string,
expectedValue uint64,
expectedData string,
expectedData string, //nolint:unparam
expectedGasLimit uint64,
expectedGasPrice uint64,
expectedFrom string,
expectedNonce uint64,
) {
rawBytes, err := hex.DecodeString(raw)
require.NoError(t, err)
tx, err := decodeEthRawTx(rawBytes, expectedChainId)
tx, err := decodeEthRawTx(rawBytes, expectedChainID)
require.NoError(t, err)
t.Logf("%#v\n", tx)
require.Equal(t, tx.Call.Method, "evm.Call")
Expand Down Expand Up @@ -63,7 +63,7 @@ func decodeExpectCall(
func decodeExpectCreate(
t *testing.T,
raw string,
expectedChainId uint64,
expectedChainID uint64,
expectedValue uint64,
expectedInitCode string,
expectedGasLimit uint64,
Expand All @@ -73,7 +73,7 @@ func decodeExpectCreate(
) {
rawBytes, err := hex.DecodeString(raw)
require.NoError(t, err)
tx, err := decodeEthRawTx(rawBytes, expectedChainId)
tx, err := decodeEthRawTx(rawBytes, expectedChainID)
require.NoError(t, err)
t.Logf("%#v\n", tx)
require.Equal(t, tx.Call.Method, "evm.Create")
Expand All @@ -100,23 +100,23 @@ func decodeExpectCreate(
require.Equal(t, expectedGasLimit, tx.AuthInfo.Fee.Gas)
}

func decodeExpectInvalid(t *testing.T, raw string, expectedChainId uint64) {
func decodeExpectInvalid(t *testing.T, raw string, expectedChainID uint64) {
rawBytes, err := hex.DecodeString(raw)
require.NoError(t, err)
_, err = decodeEthRawTx(rawBytes, expectedChainId)
_, err = decodeEthRawTx(rawBytes, expectedChainID)
require.Error(t, err)
t.Logf("%#v\n", err)
}

func decodeExpectFromMismatch(
t *testing.T,
raw string,
expectedChainId uint64,
expectedChainID uint64,
unexpectedFrom string,
) {
rawBytes, err := hex.DecodeString(raw)
require.NoError(t, err)
tx, err := decodeEthRawTx(rawBytes, expectedChainId)
tx, err := decodeEthRawTx(rawBytes, expectedChainID)
require.NoError(t, err)
t.Logf("%#v\n", tx)
require.Len(t, tx.AuthInfo.SignerInfo, 1)
Expand Down
1 change: 1 addition & 0 deletions analyzer/uncategorized/geth_sender_pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// This file contains code from go-ethereum, adapted to recover a public key instead of an address.

//nolint:gocritic,godot
package common

import (
Expand Down
42 changes: 22 additions & 20 deletions analyzer/uncategorized/visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type CallHandler struct {
EvmCall func(body *evm.Call, ok *[]byte) error
}

//nolint:nestif
func VisitCall(call *sdkTypes.Call, result *sdkTypes.CallResult, handler *CallHandler) error {
switch call.Method {
case "accounts.Transfer":
Expand Down Expand Up @@ -178,27 +179,28 @@ type EvmEventHandler struct {
}

func VisitEvmEvent(event *evm.Event, handler *EvmEventHandler) error {
if len(event.Topics) >= 1 {
switch {
case bytes.Equal(event.Topics[0], TopicErc20Transfer) && len(event.Topics) == 3:
if handler.Erc20Transfer != nil {
if err := handler.Erc20Transfer(
SliceEthAddress(event.Topics[1]),
SliceEthAddress(event.Topics[2]),
event.Data,
); err != nil {
return fmt.Errorf("erc20 transfer: %w", err)
}
if len(event.Topics) == 0 {
return nil
}
switch {
case bytes.Equal(event.Topics[0], TopicErc20Transfer) && len(event.Topics) == 3:
if handler.Erc20Transfer != nil {
if err := handler.Erc20Transfer(
SliceEthAddress(event.Topics[1]),
SliceEthAddress(event.Topics[2]),
event.Data,
); err != nil {
return fmt.Errorf("erc20 transfer: %w", err)
}
case bytes.Equal(event.Topics[0], TopicErc20Approval) && len(event.Topics) == 3:
if handler.Erc20Approval != nil {
if err := handler.Erc20Approval(
SliceEthAddress(event.Topics[1]),
SliceEthAddress(event.Topics[2]),
event.Data,
); err != nil {
return fmt.Errorf("erc20 approval: %w", err)
}
}
case bytes.Equal(event.Topics[0], TopicErc20Approval) && len(event.Topics) == 3:
if handler.Erc20Approval != nil {
if err := handler.Erc20Approval(
SliceEthAddress(event.Topics[1]),
SliceEthAddress(event.Topics[2]),
event.Data,
); err != nil {
return fmt.Errorf("erc20 approval: %w", err)
}
}
}
Expand Down

0 comments on commit 06ef29e

Please sign in to comment.