Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:

- name: Check `modernize` (code style)
run: |
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.20.0 -test ./...
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.21.1 -test ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8
with:
version: v2.11.3
version: v2.12.2
# use the default if on main branch, otherwise use the pull request config
args: --timeout=30m --config=.golangci.yml
only-new-issues: false
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Build thor in a Go builder container
FROM golang:1.26.1-alpine AS builder
FROM golang:1.26.5-alpine AS builder

RUN apk add --no-cache make gcc musl-dev linux-headers git
WORKDIR /go/thor
COPY . /go/thor
RUN make all

# Pull thor into a second stage deploy alpine container
FROM alpine:3.23.3
FROM alpine:3.24.1

RUN apk add --no-cache ca-certificates
COPY --from=builder /go/thor/bin/thor /usr/local/bin/
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PACKAGES = `go list ./... | grep -v '/vendor/'`
FUZZTIME=1m

REQUIRED_GO_MAJOR = 1
REQUIRED_GO_MINOR = 25
REQUIRED_GO_MINOR = 26
MAJOR = $(shell go version | cut -d' ' -f3 | cut -b 3- | cut -d. -f1)
MINOR = $(shell go version | cut -d' ' -f3 | cut -b 3- | cut -d. -f2)
export GO111MODULE=on
Expand Down Expand Up @@ -84,7 +84,7 @@ lint: | go_version_check lint_command_check #@ Run 'golangci-lint'
@echo "running golangci-lint..."
@golangci-lint run --config .golangci.yml
@echo "running modernize..."
@go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.20.0 ./...
@go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.21.1 ./...
@echo "done."

lint-fix: | go_version_check lint_command_check #@ Attempt to fix linting issues
Expand Down
29 changes: 15 additions & 14 deletions abi/ethabi/abifuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func unpackPack(abi ABI, method string, input []byte) ([]any, bool) {

func packUnpack(abi ABI, method string, input *[]any) bool {
if packed, err := abi.Pack(method, input); err == nil {
outptr := reflect.New(reflect.TypeOf(input))
outptr := reflect.New(reflect.TypeFor[*[]any]())
err := abi.UnpackIntoInterface(outptr.Interface(), method, packed)
if err != nil {
panic(err)
Expand All @@ -101,34 +101,35 @@ type arg struct {
}

func createABI(name string, stateMutability, payable *string, inputs []arg) (ABI, error) {
sig := fmt.Sprintf(`[{ "type" : "function", "name" : "%v" `, name)
var sig strings.Builder
fmt.Fprintf(&sig, `[{ "type" : "function", "name" : "%v" `, name)
if stateMutability != nil {
sig += fmt.Sprintf(`, "stateMutability": "%v" `, *stateMutability)
fmt.Fprintf(&sig, `, "stateMutability": "%v" `, *stateMutability)
}
if payable != nil {
sig += fmt.Sprintf(`, "payable": %v `, *payable)
fmt.Fprintf(&sig, `, "payable": %v `, *payable)
}
if len(inputs) > 0 {
sig += `, "inputs" : [ {`
sig.WriteString(`, "inputs" : [ {`)
for i, inp := range inputs {
sig += fmt.Sprintf(`"name" : "%v", "type" : "%v" `, inp.name, inp.typ)
fmt.Fprintf(&sig, `"name" : "%v", "type" : "%v" `, inp.name, inp.typ)
if i+1 < len(inputs) {
sig += ","
sig.WriteString(",")
}
}
sig += "} ]"
sig += `, "outputs" : [ {`
sig.WriteString("} ]")
sig.WriteString(`, "outputs" : [ {`)
for i, inp := range inputs {
sig += fmt.Sprintf(`"name" : "%v", "type" : "%v" `, inp.name, inp.typ)
fmt.Fprintf(&sig, `"name" : "%v", "type" : "%v" `, inp.name, inp.typ)
if i+1 < len(inputs) {
sig += ","
sig.WriteString(",")
}
}
sig += "} ]"
sig.WriteString("} ]")
}
sig += `}]`
sig.WriteString(`}]`)
// fmt.Printf("sig: %s\n", sig)
return JSON(strings.NewReader(sig))
return JSON(strings.NewReader(sig.String()))
}

func fuzzAbi(input []byte) {
Expand Down
2 changes: 1 addition & 1 deletion abi/ethabi/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (arguments Arguments) UnpackIntoMap(v map[string]any, data []byte) error {
// Copy performs the operation go format -> provided struct.
func (arguments Arguments) Copy(v any, values []any) error {
// make sure the passed value is arguments pointer
if reflect.Ptr != reflect.ValueOf(v).Kind() {
if reflect.Pointer != reflect.ValueOf(v).Kind() {
return fmt.Errorf("abi: Unpack(non-pointer %T)", v)
}
if len(values) == 0 {
Expand Down
6 changes: 3 additions & 3 deletions abi/ethabi/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func packElement(t Type, reflectValue reflect.Value) ([]byte, error) {
switch t.T {
case UintTy:
// make sure to not pack a negative value into a uint type.
if reflectValue.Kind() == reflect.Ptr {
if reflectValue.Kind() == reflect.Pointer {
val := new(big.Int).Set(reflectValue.Interface().(*big.Int))
if val.Sign() == -1 {
return nil, errInvalidSign
Expand All @@ -65,7 +65,7 @@ func packElement(t Type, reflectValue reflect.Value) ([]byte, error) {
if reflectValue.Kind() == reflect.Array {
reflectValue = mustArrayToByteSlice(reflectValue)
}
if reflectValue.Type() != reflect.TypeOf([]byte{}) {
if reflectValue.Type() != reflect.TypeFor[[]byte]() {
return []byte{}, errors.New("bytes type is neither slice nor array")
}
return packBytesSlice(reflectValue.Bytes(), reflectValue.Len()), nil
Expand All @@ -86,7 +86,7 @@ func packNum(value reflect.Value) []byte {
return u256Bytes(new(big.Int).SetUint64(value.Uint()))
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return u256Bytes(big.NewInt(value.Int()))
case reflect.Ptr:
case reflect.Pointer:
return u256Bytes(new(big.Int).Set(value.Interface().(*big.Int)))
default:
panic("abi: fatal error")
Expand Down
14 changes: 7 additions & 7 deletions abi/ethabi/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func ConvertType(in any, proto any) any {
// indirect recursively dereferences the value until it either gets the value
// or finds a big.Int
func indirect(v reflect.Value) reflect.Value {
if v.Kind() == reflect.Ptr && v.Elem().Type() != reflect.TypeFor[big.Int]() {
if v.Kind() == reflect.Pointer && v.Elem().Type() != reflect.TypeFor[big.Int]() {
return indirect(v.Elem())
}
return v
Expand Down Expand Up @@ -102,9 +102,9 @@ func mustArrayToByteSlice(value reflect.Value) reflect.Value {
func set(dst, src reflect.Value) error {
dstType, srcType := dst.Type(), src.Type()
switch {
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid() && (dst.Elem().Type().Kind() == reflect.Ptr || dst.Elem().CanSet()):
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid() && (dst.Elem().Type().Kind() == reflect.Pointer || dst.Elem().CanSet()):
return set(dst.Elem(), src)
case dstType.Kind() == reflect.Ptr && dstType.Elem() != reflect.TypeFor[big.Int]():
case dstType.Kind() == reflect.Pointer && dstType.Elem() != reflect.TypeFor[big.Int]():
return set(dst.Elem(), src)
case srcType.AssignableTo(dstType) && dst.CanSet():
dst.Set(src)
Expand Down Expand Up @@ -138,7 +138,7 @@ func setSlice(dst, src reflect.Value) error {
}

func setArray(dst, src reflect.Value) error {
if src.Kind() == reflect.Ptr {
if src.Kind() == reflect.Pointer {
return set(dst, indirect(src))
}
array := reflect.New(dst.Type()).Elem()
Expand Down Expand Up @@ -188,15 +188,15 @@ func mapArgNamesToStructFields(argNames []string, value reflect.Value) (map[stri
struct2abi := make(map[string]string)

// first round ~~~
for i := 0; i < typ.NumField(); i++ {
structFieldName := typ.Field(i).Name
for i := range typ.Fields() {
structFieldName := i.Name

// skip private struct fields.
if structFieldName[:1] != strings.ToUpper(structFieldName[:1]) {
continue
}
// skip fields that have no abi:"" tag.
tagName, ok := typ.Field(i).Tag.Lookup("abi")
tagName, ok := i.Tag.Lookup("abi")
if !ok {
continue
}
Expand Down
20 changes: 10 additions & 10 deletions abi/ethabi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
}
case "tuple":
var (
fields []reflect.StructField
elems []*Type
names []string
expression string // canonical parameter expression
used = make(map[string]bool)
fields []reflect.StructField
elems []*Type
names []string
used = make(map[string]bool)
)
expression += "("
var expression strings.Builder // canonical parameter expression
expression.WriteString("(")
for idx, c := range components {
cType, err := NewType(c.Type, c.InternalType, c.Components)
if err != nil {
Expand All @@ -192,18 +192,18 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
})
elems = append(elems, &cType)
names = append(names, c.Name)
expression += cType.stringKind
expression.WriteString(cType.stringKind)
if idx != len(components)-1 {
expression += ","
expression.WriteString(",")
}
}
expression += ")"
expression.WriteString(")")

typ.TupleType = reflect.StructOf(fields)
typ.TupleElems = elems
typ.TupleRawNames = names
typ.T = TupleTy
typ.stringKind = expression
typ.stringKind = expression.String()

const structPrefix = "struct "
// After solidity 0.5.10, a new field of abi "internalType"
Expand Down
10 changes: 3 additions & 7 deletions api/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestOptionalIndexes(t *testing.T) {
filter := api.EventFilter{
CriteriaSet: make([]*api.EventCriteria, 0),
Range: nil,
Options: &api.Options{Limit: ptr(6), IncludeIndexes: tc.includeIndexes},
Options: &api.Options{Limit: new(uint64(6)), IncludeIndexes: tc.includeIndexes},
Order: logdb.DESC,
}

Expand Down Expand Up @@ -132,10 +132,6 @@ func TestEvents_WithOptionsNoLimit(t *testing.T) {
assert.Equal(t, 4, len(tLogs))
}

func ptr(v uint64) *uint64 {
return &v
}

func TestOption(t *testing.T) {
thorChain := initEventServer(t, 5)
defer ts.Close()
Expand All @@ -145,7 +141,7 @@ func TestOption(t *testing.T) {
filter := api.EventFilter{
CriteriaSet: make([]*api.EventCriteria, 0),
Range: nil,
Options: &api.Options{Limit: ptr(6)},
Options: &api.Options{Limit: new(uint64(6))},
Order: logdb.DESC,
}

Expand All @@ -154,7 +150,7 @@ func TestOption(t *testing.T) {
assert.Equal(t, "options.limit exceeds the maximum allowed value of 5", strings.Trim(string(res), "\n"))
assert.Equal(t, http.StatusForbidden, statusCode)

filter.Options.Limit = ptr(5)
filter.Options.Limit = new(uint64(5))
_, statusCode, err = tclient.RawHTTPClient().RawHTTPPost("/logs/event", filter)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, statusCode)
Expand Down
12 changes: 4 additions & 8 deletions api/transfers/transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestOption(t *testing.T) {
filter := api.TransferFilter{
CriteriaSet: make([]*logdb.TransferCriteria, 0),
Range: nil,
Options: &api.Options{Limit: ptr(6)},
Options: &api.Options{Limit: new(uint64(6))},
Order: logdb.DESC,
}

Expand All @@ -76,7 +76,7 @@ func TestOption(t *testing.T) {
assert.Equal(t, "options.limit exceeds the maximum allowed value of 5", strings.Trim(string(res), "\n"))
assert.Equal(t, http.StatusForbidden, statusCode)

filter.Options.Limit = ptr(5)
filter.Options.Limit = new(uint64(5))
_, statusCode, err = tclient.RawHTTPClient().RawHTTPPost("/logs/transfer", filter)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, statusCode)
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestOptionalData(t *testing.T) {
filter := api.TransferFilter{
CriteriaSet: make([]*logdb.TransferCriteria, 0),
Range: nil,
Options: &api.Options{Limit: ptr(5), IncludeIndexes: tc.includeIndexes},
Options: &api.Options{Limit: new(uint64(5)), IncludeIndexes: tc.includeIndexes},
Order: logdb.DESC,
}

Expand Down Expand Up @@ -194,7 +194,7 @@ func testTransferBadRequest(t *testing.T) {
emptyFilter := api.TransferFilter{
CriteriaSet: criteriaSet,
Range: nil,
Options: &api.Options{Limit: ptr(6)},
Options: &api.Options{Limit: new(uint64(6))},
Order: logdb.DESC,
}

Expand Down Expand Up @@ -297,7 +297,3 @@ func newReceipt() *tx.Receipt {
},
}
}

func ptr(v uint64) *uint64 {
return &v
}
4 changes: 2 additions & 2 deletions block/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestHeaderHash(t *testing.T) {
}
h := builder.Build().Header()

expectedFieldsLen := reflect.TypeOf(h.body).NumField() - 1
expectedFieldsLen := reflect.TypeFor[headerBody]().NumField() - 1
if h.body.Extension.BaseFee == nil {
expectedFieldsLen--
}
Expand All @@ -441,7 +441,7 @@ func TestHeaderHash(t *testing.T) {
// signingHash returns the signing hash the block header.
// this is a reflect based implementation used for cross checking.
func signingHash(h *Header, t *testing.T) thor.Bytes32 {
types := reflect.TypeOf(h.body)
types := reflect.TypeFor[headerBody]()
values := reflect.ValueOf(h.body)

fields := make([]any, 0)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vechain/thor/v2

go 1.26.1
go 1.26.5

require (
github.com/beevik/ntp v0.2.0
Expand Down
2 changes: 1 addition & 1 deletion log/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func FormatSlogValue(v slog.Value, tmp []byte) (result []byte) {
var value any
defer func() {
if err := recover(); err != nil {
if v := reflect.ValueOf(value); v.Kind() == reflect.Ptr && v.IsNil() {
if v := reflect.ValueOf(value); v.Kind() == reflect.Pointer && v.IsNil() {
result = []byte("<nil>")
} else {
panic(err)
Expand Down
13 changes: 4 additions & 9 deletions thorclient/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestContract_Send(t *testing.T) {
receipt, _, err := env.bindContract.Method("setValue", big.NewInt(100)).
Send().
WithSigner(env.owner).
WithOptions(&TxOptions{Gas: ptr(uint64(100000))}).
WithOptions(&TxOptions{Gas: new(uint64(100000))}).
SubmitAndConfirm(ctx)
require.NoError(t, err)
assert.False(t, receipt.Reverted)
Expand All @@ -128,7 +128,7 @@ func TestContract_Send(t *testing.T) {
receipt, _, err := env.bindContract.Method("transferOwnership", env.user.Address()).
Send().
WithSigner(env.user).
WithOptions(&TxOptions{Gas: ptr(uint64(100000))}).
WithOptions(&TxOptions{Gas: new(uint64(100000))}).
SubmitAndConfirm(ctx)
require.NoError(t, err)
assert.True(t, receipt.Reverted)
Expand All @@ -137,7 +137,7 @@ func TestContract_Send(t *testing.T) {
receipt, _, err = env.bindContract.Method("transferOwnership", env.user.Address()).
Send().
WithSigner(env.owner).
WithOptions(&TxOptions{Gas: ptr(uint64(100000))}).
WithOptions(&TxOptions{Gas: new(uint64(100000))}).
SubmitAndConfirm(ctx)
require.NoError(t, err)
assert.False(t, receipt.Reverted)
Expand All @@ -164,7 +164,7 @@ func TestContract_Filter(t *testing.T) {
receipt, _, err := env.bindContract.Method("setValue", big.NewInt(200)).
Send().
WithSigner(env.owner).
WithOptions(&TxOptions{Gas: ptr(uint64(100000))}).
WithOptions(&TxOptions{Gas: new(uint64(100000))}).
SubmitAndConfirm(ctx)
require.NoError(t, err)
assert.False(t, receipt.Reverted)
Expand Down Expand Up @@ -199,8 +199,3 @@ func TestContract_Filter(t *testing.T) {
assert.Equal(t, uint64(200), newValue.Uint64())
})
}

// Helper function to create a pointer to uint64
func ptr(v uint64) *uint64 {
return &v
}
Loading
Loading