Skip to content

Commit e872083

Browse files
accounts/abi: removed Kind from Type struct (#21009)
* accounts/abi: removed Kind from Type struct * accounts/abi: removed unused code
1 parent 510b6f9 commit e872083

5 files changed

Lines changed: 89 additions & 100 deletions

File tree

‎accounts/abi/error.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ func formatSliceString(kind reflect.Kind, sliceSize int) string {
3939
// type in t.
4040
func sliceTypeCheck(t Type, val reflect.Value) error {
4141
if val.Kind() != reflect.Slice && val.Kind() != reflect.Array {
42-
return typeErr(formatSliceString(t.Kind, t.Size), val.Type())
42+
return typeErr(formatSliceString(t.Type.Kind(), t.Size), val.Type())
4343
}
4444

4545
if t.T == ArrayTy && val.Len() != t.Size {
46-
return typeErr(formatSliceString(t.Elem.Kind, t.Size), formatSliceString(val.Type().Elem().Kind(), val.Len()))
46+
return typeErr(formatSliceString(t.Elem.Type.Kind(), t.Size), formatSliceString(val.Type().Elem().Kind(), val.Len()))
4747
}
4848

4949
if t.Elem.T == SliceTy || t.Elem.T == ArrayTy {
@@ -52,8 +52,8 @@ func sliceTypeCheck(t Type, val reflect.Value) error {
5252
}
5353
}
5454

55-
if elemKind := val.Type().Elem().Kind(); elemKind != t.Elem.Kind {
56-
return typeErr(formatSliceString(t.Elem.Kind, t.Size), val.Type())
55+
if elemKind := val.Type().Elem().Kind(); elemKind != t.Elem.Type.Kind() {
56+
return typeErr(formatSliceString(t.Elem.Type.Kind(), t.Size), val.Type())
5757
}
5858
return nil
5959
}
@@ -66,8 +66,8 @@ func typeCheck(t Type, value reflect.Value) error {
6666
}
6767

6868
// Check base type validity. Element types will be checked later on.
69-
if t.Kind != value.Kind() {
70-
return typeErr(t.Kind, value.Kind())
69+
if t.Type.Kind() != value.Kind() {
70+
return typeErr(t.Type.Kind(), value.Kind())
7171
} else if t.T == FixedBytesTy && t.Size != value.Len() {
7272
return typeErr(t.Type, value.Type())
7373
} else {

‎accounts/abi/reflect.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,32 @@ func indirectInterfaceOrPtr(v reflect.Value) reflect.Value {
3939
return v
4040
}
4141

42-
// reflectIntKind returns the reflect using the given size and
42+
// reflectIntType returns the reflect using the given size and
4343
// unsignedness.
44-
func reflectIntKindAndType(unsigned bool, size int) (reflect.Kind, reflect.Type) {
44+
func reflectIntType(unsigned bool, size int) reflect.Type {
4545
if unsigned {
4646
switch size {
4747
case 8:
48-
return reflect.Uint8, uint8T
48+
return uint8T
4949
case 16:
50-
return reflect.Uint16, uint16T
50+
return uint16T
5151
case 32:
52-
return reflect.Uint32, uint32T
52+
return uint32T
5353
case 64:
54-
return reflect.Uint64, uint64T
54+
return uint64T
5555
}
5656
}
5757
switch size {
5858
case 8:
59-
return reflect.Int8, int8T
59+
return int8T
6060
case 16:
61-
return reflect.Int16, int16T
61+
return int16T
6262
case 32:
63-
return reflect.Int32, int32T
63+
return int32T
6464
case 64:
65-
return reflect.Int64, int64T
65+
return int64T
6666
}
67-
return reflect.Ptr, bigT
67+
return bigT
6868
}
6969

7070
// mustArrayToBytesSlice creates a new byte slice with the exact same size as value

‎accounts/abi/type.go‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const (
4545
// Type is the reflection of the supported argument type
4646
type Type struct {
4747
Elem *Type
48-
Kind reflect.Kind
4948
Type reflect.Type
5049
Size int
5150
T byte // Our own type checking
@@ -94,14 +93,12 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
9493
if len(intz) == 0 {
9594
// is a slice
9695
typ.T = SliceTy
97-
typ.Kind = reflect.Slice
9896
typ.Elem = &embeddedType
9997
typ.Type = reflect.SliceOf(embeddedType.Type)
10098
typ.stringKind = embeddedType.stringKind + sliced
10199
} else if len(intz) == 1 {
102100
// is a array
103101
typ.T = ArrayTy
104-
typ.Kind = reflect.Array
105102
typ.Elem = &embeddedType
106103
typ.Size, err = strconv.Atoi(intz[0])
107104
if err != nil {
@@ -139,34 +136,29 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
139136
// varType is the parsed abi type
140137
switch varType := parsedType[1]; varType {
141138
case "int":
142-
typ.Kind, typ.Type = reflectIntKindAndType(false, varSize)
139+
typ.Type = reflectIntType(false, varSize)
143140
typ.Size = varSize
144141
typ.T = IntTy
145142
case "uint":
146-
typ.Kind, typ.Type = reflectIntKindAndType(true, varSize)
143+
typ.Type = reflectIntType(true, varSize)
147144
typ.Size = varSize
148145
typ.T = UintTy
149146
case "bool":
150-
typ.Kind = reflect.Bool
151147
typ.T = BoolTy
152148
typ.Type = reflect.TypeOf(bool(false))
153149
case "address":
154-
typ.Kind = reflect.Array
155150
typ.Type = addressT
156151
typ.Size = 20
157152
typ.T = AddressTy
158153
case "string":
159-
typ.Kind = reflect.String
160154
typ.Type = reflect.TypeOf("")
161155
typ.T = StringTy
162156
case "bytes":
163157
if varSize == 0 {
164158
typ.T = BytesTy
165-
typ.Kind = reflect.Slice
166159
typ.Type = reflect.SliceOf(reflect.TypeOf(byte(0)))
167160
} else {
168161
typ.T = FixedBytesTy
169-
typ.Kind = reflect.Array
170162
typ.Size = varSize
171163
typ.Type = reflect.ArrayOf(varSize, reflect.TypeOf(byte(0)))
172164
}
@@ -199,7 +191,6 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
199191
}
200192
}
201193
expression += ")"
202-
typ.Kind = reflect.Struct
203194
typ.Type = reflect.StructOf(fields)
204195
typ.TupleElems = elems
205196
typ.TupleRawNames = names
@@ -217,7 +208,6 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
217208
}
218209

219210
case "function":
220-
typ.Kind = reflect.Array
221211
typ.T = FunctionTy
222212
typ.Size = 24
223213
typ.Type = reflect.ArrayOf(24, reflect.TypeOf(byte(0)))

0 commit comments

Comments
 (0)