Skip to content

Commit ec97ac7

Browse files
authored
common, common/hexutil: use reflect.TypeFor (#32321)
1 parent dfde155 commit ec97ac7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

common/hexutil/json.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828
)
2929

3030
var (
31-
bytesT = reflect.TypeOf(Bytes(nil))
32-
bigT = reflect.TypeOf((*Big)(nil))
33-
uintT = reflect.TypeOf(Uint(0))
34-
uint64T = reflect.TypeOf(Uint64(0))
35-
u256T = reflect.TypeOf((*uint256.Int)(nil))
31+
bytesT = reflect.TypeFor[Bytes]()
32+
bigT = reflect.TypeFor[*Big]()
33+
uintT = reflect.TypeFor[Uint]()
34+
uint64T = reflect.TypeFor[Uint64]()
35+
u256T = reflect.TypeFor[*uint256.Int]()
3636
)
3737

3838
// Bytes marshals/unmarshals as a JSON string with 0x prefix.

common/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ const (
4242
)
4343

4444
var (
45-
hashT = reflect.TypeOf(Hash{})
46-
addressT = reflect.TypeOf(Address{})
45+
hashT = reflect.TypeFor[Hash]()
46+
addressT = reflect.TypeFor[Address]()
4747

4848
// MaxAddress represents the maximum possible address value.
4949
MaxAddress = HexToAddress("0xffffffffffffffffffffffffffffffffffffffff")
@@ -466,7 +466,7 @@ func isString(input []byte) bool {
466466
// UnmarshalJSON parses a hash in hex syntax.
467467
func (d *Decimal) UnmarshalJSON(input []byte) error {
468468
if !isString(input) {
469-
return &json.UnmarshalTypeError{Value: "non-string", Type: reflect.TypeOf(uint64(0))}
469+
return &json.UnmarshalTypeError{Value: "non-string", Type: reflect.TypeFor[uint64]()}
470470
}
471471
if i, err := strconv.ParseUint(string(input[1:len(input)-1]), 10, 64); err == nil {
472472
*d = Decimal(i)

0 commit comments

Comments
 (0)