Skip to content

Commit

Permalink
Merge pull request #290 from InjectiveLabs/feat/remove_deprecated_pre…
Browse files Browse the repository at this point in the history
…_commit_repo

Feat/remove deprecated pre commit repo
  • Loading branch information
aarmoa authored Feb 13, 2025
2 parents 49b9c7f + b192fa9 commit 291a94f
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 70 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: golangci-lint
on:
pull_request:
push:
branches: [master, dev]
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --timeout=15m -v

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: false

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
5 changes: 1 addition & 4 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
- uses: actions/checkout@master
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- run: go install golang.org/x/tools/cmd/goimports@latest
- run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.0
- uses: pre-commit/action@v2.0.2
102 changes: 48 additions & 54 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,48 @@
{
"run": {
"tests": false,
},
"linters": {
"fast": false,
"enable": [
"errcheck",
"errorlint",
"gas",
"gocritic",
"gosimple",
"govet",
"ineffassign",
"megacheck",
"misspell",
"nakedret",
"prealloc",
"revive",
"staticcheck",
"unconvert",
"unparam",
],
"disable": [
"unused",
]
},
"linters-settings": {
"revive": {
"enableAllRules": true,
"rules": [
{
"name": "var-naming",
"arguments": [
["ID"]
]
}
]
},
"gocritic": {
"enabled-tags": [
"diagnostic",
"experimental",
"opinionated",
"performance",
"style",
],
"disabled-checks": [
"hugeParam",
"unnamedResult",
]
}
},
}
run:
tests: false
skip-dirs:
- chain
- exchange
- injective_data
- proto

linters:
fast: false
enable:
- errcheck
- errorlint
- gas
- gocritic
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- megacheck
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- unconvert
- unparam
disable:
- unused

linters-settings:
revive:
enableAllRules: true
rules:
- name: var-naming
arguments:
- ["ID"]
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- hugeParam
- unnamedResult
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,3 @@ repos:
- id: end-of-file-fixer
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/dnephin/pre-commit-golang
rev: master
hooks:
- id: go-fmt
- id: go-imports
- id: golangci-lint
args: [--timeout=15m]
22 changes: 18 additions & 4 deletions eip712_cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"encoding/json"
"fmt"
"math"
"math/big"
"reflect"
"runtime/debug"
"strings"
"time"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cosmtypes "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -64,6 +65,12 @@ func WrapTxToEIP712(
[]cosmtypes.Msg{}, memo,
)

if chainID > uint64(math.MaxInt64) {
err := fmt.Errorf("chainID is too large: %v (max supported value is %v)", chainID, math.MaxInt64)
return typeddata.TypedData{}, err
}
intChainId := int64(chainID)

txData := make(map[string]interface{})
if err := json.Unmarshal(data, &txData); err != nil {
err = errors.Wrap(err, "failed to unmarshal data provided into WrapTxToEIP712")
Expand Down Expand Up @@ -98,7 +105,7 @@ func WrapTxToEIP712(
domain := typeddata.TypedDataDomain{
Name: "Injective Web3",
Version: "1.0.0",
ChainId: ethmath.NewHexOrDecimal256(int64(chainID)),
ChainId: ethmath.NewHexOrDecimal256(intChainId),
VerifyingContract: "cosmos",
Salt: "0",
}
Expand Down Expand Up @@ -413,7 +420,7 @@ var (
hashType = reflect.TypeOf(common.Hash{})
addressType = reflect.TypeOf(common.Address{})
bigIntType = reflect.TypeOf(big.Int{})
cosmIntType = reflect.TypeOf(math.Int{})
cosmIntType = reflect.TypeOf(sdkmath.Int{})
cosmosAnyType = reflect.TypeOf(&codectypes.Any{})
timeType = reflect.TypeOf(time.Time{})
)
Expand Down Expand Up @@ -531,10 +538,17 @@ func WrapTxToEIP712V2(
msgs []cosmtypes.Msg,
feeDelegation *FeeDelegationOptions,
) (typeddata.TypedData, error) {

if chainID > uint64(math.MaxInt64) {
err := fmt.Errorf("chainID is too large: %v (max supported value is %v)", chainID, math.MaxInt64)
return typeddata.TypedData{}, err
}
intChainId := int64(chainID)

domain := typeddata.TypedDataDomain{
Name: "Injective Web3",
Version: "1.0.0",
ChainId: ethmath.NewHexOrDecimal256(int64(chainID)),
ChainId: ethmath.NewHexOrDecimal256(intChainId),
VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
Salt: "0",
}
Expand Down
8 changes: 7 additions & 1 deletion ethereum/util/noncecache.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"math"
"sync"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -127,7 +128,12 @@ func (n nonceCache) Sync(account common.Address, syncFn func() (uint64, error))
}
if nonce, err := syncFn(); err == nil {
n.mux.Lock()
n.nonces[account] = int64(nonce)
if nonce > uint64(math.MaxInt64) {
// Handle overflow case - could log error or take other action
n.nonces[account] = math.MaxInt64
} else {
n.nonces[account] = int64(nonce)
}
n.mux.Unlock()
}
}
Expand Down

0 comments on commit 291a94f

Please sign in to comment.