Skip to content

Commit

Permalink
Move save int conversion to safecast lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Nov 25, 2024
1 parent 67f4b85 commit d44fa7f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
filippo.io/edwards25519 v1.1.0
github.com/beevik/ntp v1.4.3
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/ccoveille/go-safecast v1.2.0
github.com/cenkalti/backoff/v4 v4.3.0
github.com/cespare/xxhash/v2 v2.3.0
github.com/consensys/gnark v0.11.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurT
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/ccoveille/go-safecast v1.2.0 h1:H4X7aosepsU1Mfk+098CTdKpsDH0cfYJ2RmwXFjgvfc=
github.com/ccoveille/go-safecast v1.2.0/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down
12 changes: 5 additions & 7 deletions pkg/util/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"math"
"math/big"
"os/user"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/ccoveille/go-safecast"
"github.com/mr-tron/base58/base58"
"github.com/pkg/errors"
"golang.org/x/exp/constraints"
Expand Down Expand Up @@ -247,11 +247,9 @@ func padBytes(p byte, bytes []byte) []byte {
}

func SafeIntToUint32(v int) uint32 {
if v < 0 {
panic("negative value")
}
if v > math.MaxUint32 {
panic("value is too big")
r, err := safecast.ToUint32(v)
if err != nil {
panic(err)
}
return uint32(v)
return r
}

0 comments on commit d44fa7f

Please sign in to comment.