Skip to content

Commit 08c5d4d

Browse files
committed
accounts/abi: address review concerns
1 parent f0f594d commit 08c5d4d

4 files changed

Lines changed: 5 additions & 352 deletions

File tree

‎accounts/abi/abi.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
142142
return &method, nil
143143
}
144144
}
145-
return nil, fmt.Errorf("ABI spec does not contain method signature in data: 0x%x", sigdata[:4])
145+
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4])
146146
}

‎accounts/abi/abi_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ func TestABI_MethodById(t *testing.T) {
691691
a := fmt.Sprintf("%v", m)
692692
m2, err := abi.MethodById(m.Id())
693693
if err != nil {
694-
t.Fatal(err)
694+
t.Fatalf("Failed to look up ABI method: %v", err)
695695
}
696696
b := fmt.Sprintf("%v", m2)
697697
if a != b {

‎accounts/abi/argument.go‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (arguments Arguments) LengthNonIndexed() int {
6767
return out
6868
}
6969

70+
// NonIndexed returns the arguments with indexed arguments filtered out
7071
func (arguments Arguments) NonIndexed() Arguments {
7172
var ret []Argument
7273
for _, arg := range arguments {
@@ -89,12 +90,10 @@ func (arguments Arguments) Unpack(v interface{}, data []byte) error {
8990
if reflect.Ptr != reflect.ValueOf(v).Kind() {
9091
return fmt.Errorf("abi: Unpack(non-pointer %T)", v)
9192
}
92-
9393
marshalledValues, err := arguments.UnpackValues(data)
9494
if err != nil {
9595
return err
9696
}
97-
9897
if arguments.isTuple() {
9998
return arguments.unpackTuple(v, marshalledValues)
10099
}
@@ -162,11 +161,9 @@ func (arguments Arguments) unpackTuple(v interface{}, marshalledValues []interfa
162161

163162
// unpackAtomic unpacks ( hexdata -> go ) a single value
164163
func (arguments Arguments) unpackAtomic(v interface{}, marshalledValues []interface{}) error {
165-
166164
if len(marshalledValues) != 1 {
167165
return fmt.Errorf("abi: wrong length, expected single value, got %d", len(marshalledValues))
168166
}
169-
170167
elem := reflect.ValueOf(v).Elem()
171168
reflectValue := reflect.ValueOf(marshalledValues[0])
172169
return set(elem, reflectValue, arguments.NonIndexed()[0])
@@ -176,24 +173,18 @@ func (arguments Arguments) unpackAtomic(v interface{}, marshalledValues []interf
176173
// without supplying a struct to unpack into. Instead, this method returns a list containing the
177174
// values. An atomic argument will be a list with one element.
178175
func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error) {
179-
180176
retval := make([]interface{}, 0, arguments.LengthNonIndexed())
181-
182177
virtualArgs := 0
183-
184178
for index, arg := range arguments.NonIndexed() {
185-
186179
marshalledValue, err := toGoType((index+virtualArgs)*32, arg.Type, data)
187-
188180
if arg.Type.T == ArrayTy {
189-
//If we have a static array, like [3]uint256, these are coded as
181+
// If we have a static array, like [3]uint256, these are coded as
190182
// just like uint256,uint256,uint256.
191183
// This means that we need to add two 'virtual' arguments when
192184
// we count the index from now on
193185

194186
virtualArgs += arg.Type.Size - 1
195187
}
196-
197188
if err != nil {
198189
return nil, err
199190
}
@@ -202,7 +193,7 @@ func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error) {
202193
return retval, nil
203194
}
204195

205-
// UnpackValues performs the operation Go format -> Hexdata
196+
// PackValues performs the operation Go format -> Hexdata
206197
// It is the semantic opposite of UnpackValues
207198
func (arguments Arguments) PackValues(args []interface{}) ([]byte, error) {
208199
return arguments.Pack(args...)
@@ -215,7 +206,6 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) {
215206
if len(args) != len(abiArgs) {
216207
return nil, fmt.Errorf("argument count mismatch: %d for %d", len(args), len(abiArgs))
217208
}
218-
219209
// variable input is the output appended at the end of packed
220210
// output. This is used for strings and bytes types input.
221211
var variableInput []byte
@@ -229,7 +219,6 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) {
229219
inputOffset += 32
230220
}
231221
}
232-
233222
var ret []byte
234223
for i, a := range args {
235224
input := abiArgs[i]
@@ -238,7 +227,6 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) {
238227
if err != nil {
239228
return nil, err
240229
}
241-
242230
// check for a slice type (string, bytes, slice)
243231
if input.Type.requiresLengthPrefix() {
244232
// calculate the offset

0 commit comments

Comments
 (0)