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
24 changes: 12 additions & 12 deletions accounts/abi/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.TypeOf(big.Int{}) {
if v.Kind() == reflect.Ptr && v.Elem().Type() != reflect.TypeFor[big.Int]() {
return indirect(v.Elem())
}
return v
Expand All @@ -65,32 +65,32 @@ func reflectIntType(unsigned bool, size int) reflect.Type {
if unsigned {
switch size {
case 8:
return reflect.TypeOf(uint8(0))
return reflect.TypeFor[uint8]()
case 16:
return reflect.TypeOf(uint16(0))
return reflect.TypeFor[uint16]()
case 32:
return reflect.TypeOf(uint32(0))
return reflect.TypeFor[uint32]()
case 64:
return reflect.TypeOf(uint64(0))
return reflect.TypeFor[uint64]()
}
}
switch size {
case 8:
return reflect.TypeOf(int8(0))
return reflect.TypeFor[int8]()
case 16:
return reflect.TypeOf(int16(0))
return reflect.TypeFor[int16]()
case 32:
return reflect.TypeOf(int32(0))
return reflect.TypeFor[int32]()
case 64:
return reflect.TypeOf(int64(0))
return reflect.TypeFor[int64]()
}
return reflect.TypeOf(&big.Int{})
return reflect.TypeFor[*big.Int]()
}

// mustArrayToByteSlice creates a new byte slice with the exact same size as value
// and copies the bytes in value to the new slice.
func mustArrayToByteSlice(value reflect.Value) reflect.Value {
slice := reflect.MakeSlice(reflect.TypeOf([]byte{}), value.Len(), value.Len())
slice := reflect.ValueOf(make([]byte, value.Len()))
reflect.Copy(slice, value)
return slice
}
Expand All @@ -104,7 +104,7 @@ func set(dst, src reflect.Value) error {
switch {
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid() && (dst.Elem().Type().Kind() == reflect.Ptr || dst.Elem().CanSet()):
return set(dst.Elem(), src)
case dstType.Kind() == reflect.Ptr && dstType.Elem() != reflect.TypeOf(big.Int{}):
case dstType.Kind() == reflect.Ptr && dstType.Elem() != reflect.TypeFor[big.Int]():
return set(dst.Elem(), src)
case srcType.AssignableTo(dstType) && dst.CanSet():
dst.Set(src)
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ func TestConvertType(t *testing.T) {
var fields []reflect.StructField
fields = append(fields, reflect.StructField{
Name: "X",
Type: reflect.TypeOf(new(big.Int)),
Type: reflect.TypeFor[*big.Int](),
Tag: "json:\"" + "x" + "\"",
})
fields = append(fields, reflect.StructField{
Name: "Y",
Type: reflect.TypeOf(new(big.Int)),
Type: reflect.TypeFor[*big.Int](),
Tag: "json:\"" + "y" + "\"",
})
val := reflect.New(reflect.StructOf(fields))
Expand Down
20 changes: 8 additions & 12 deletions accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,25 @@ func (t Type) GetType() reflect.Type {
case UintTy:
return reflectIntType(true, t.Size)
case BoolTy:
return reflect.TypeOf(false)
return reflect.TypeFor[bool]()
case StringTy:
return reflect.TypeOf("")
return reflect.TypeFor[string]()
case SliceTy:
return reflect.SliceOf(t.Elem.GetType())
case ArrayTy:
return reflect.ArrayOf(t.Size, t.Elem.GetType())
case TupleTy:
return t.TupleType
case AddressTy:
return reflect.TypeOf(common.Address{})
return reflect.TypeFor[common.Address]()
case FixedBytesTy:
return reflect.ArrayOf(t.Size, reflect.TypeOf(byte(0)))
return reflect.ArrayOf(t.Size, reflect.TypeFor[byte]())
case BytesTy:
return reflect.SliceOf(reflect.TypeOf(byte(0)))
case HashTy:
// hashtype currently not used
return reflect.ArrayOf(32, reflect.TypeOf(byte(0)))
case FixedPointTy:
// fixedpoint type currently not used
return reflect.ArrayOf(32, reflect.TypeOf(byte(0)))
return reflect.TypeFor[[]byte]()
case HashTy, FixedPointTy: // currently not used
return reflect.TypeFor[[32]byte]()
case FunctionTy:
return reflect.ArrayOf(24, reflect.TypeOf(byte(0)))
return reflect.TypeFor[[24]byte]()
default:
panic("Invalid type")
}
Expand Down
2 changes: 1 addition & 1 deletion accounts/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
)

// KeyStoreType is the reflect type of a keystore backend.
var KeyStoreType = reflect.TypeOf(&KeyStore{})
var KeyStoreType = reflect.TypeFor[*KeyStore]()

// KeyStoreScheme is the protocol scheme prefixing account and wallet URLs.
const KeyStoreScheme = "keystore"
Expand Down