diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 5077f02b6d..7953abd717 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -141,10 +141,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { case "constructor": abi.Constructor = NewMethod("", "", field.StateMutability, field.Constant, field.Payable, false, false, field.Inputs, nil) // empty defaults to function according to the abi spec - case "function", "": + case "function": name := abi.methodName(field.Name) - isConst := field.Constant || field.StateMutability == "pure" || field.StateMutability == "view" - abi.Methods[name] = NewMethod(name, field.Name, field.StateMutability, isConst, field.Payable, false, false, field.Inputs, field.Outputs) + abi.Methods[name] = NewMethod(name, field.Name, field.StateMutability, field.Constant, field.Payable, false, false, field.Inputs, field.Outputs) case "fallback": // New introduced function type in v0.6.0, check more detail // here https://solidity.readthedocs.io/en/v0.6.0/contracts.html#fallback-function @@ -161,7 +160,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { if field.StateMutability != "payable" { return errors.New("the statemutability of receive can only be payable") } - abi.Receive = NewMethod("", "", "payable", field.Constant, field.Payable, false, true, nil, nil) + abi.Receive = NewMethod("", "", field.StateMutability, field.Constant, field.Payable, false, true, nil, nil) case "event": name := abi.eventName(field.Name) abi.Events[name] = NewEvent(name, field.Name, field.Anonymous, field.Inputs) @@ -171,6 +170,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { } // methodName returns the next available name for a given function. +// Needed since solidity allows for function overload. // // e.g. if the abi contains Methods send, send1 // methodName would return send2 for input send. @@ -185,6 +185,7 @@ func (abi *ABI) methodName(rawName string) string { } // eventName returns the next available name for a given event. +// Needed since solidity allows for event overload. // // e.g. if the abi contains events received, received1 // eventName would return received2 for input received. diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 303ee49142..8c184e6430 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -1046,7 +1046,7 @@ func TestDoubleDuplicateMethodNames(t *testing.T) { } } -// TestDoubleDuplicateEventNames checks that an event with unnamed parameters is +// TestUnnamedEventParam checks that an event with unnamed parameters is // correctly handled // The test runs the abi of the following contract. // contract TestEvent { diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index 531eaae696..27af0d8a66 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -103,12 +103,12 @@ func (arguments Arguments) Unpack(v interface{}, data []byte) error { if err != nil { return err } - if arguments.isTuple() { - return arguments.unpackTuple(v, marshalledValues) - } if len(marshalledValues) == 0 { return fmt.Errorf("abi: Unpack(no-values unmarshalled %T)", v) } + if arguments.isTuple() { + return arguments.unpackTuple(v, marshalledValues) + } return arguments.unpackAtomic(v, marshalledValues[0]) } diff --git a/accounts/abi/method.go b/accounts/abi/method.go index a263201c1e..95beda4007 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -71,6 +71,7 @@ type Method struct { } // NewMethod creates a new Method. +// A method should always be created using NewMethod. // It also precomputes the sig representation and the string representation // of the method. // A method should always be created using NewMethod.