mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi: addressed comments
This commit is contained in:
parent
4434cb4d0a
commit
6b6c912462
4 changed files with 10 additions and 8 deletions
|
|
@ -141,10 +141,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
||||||
case "constructor":
|
case "constructor":
|
||||||
abi.Constructor = NewMethod("", "", field.StateMutability, field.Constant, field.Payable, false, false, field.Inputs, nil)
|
abi.Constructor = NewMethod("", "", field.StateMutability, field.Constant, field.Payable, false, false, field.Inputs, nil)
|
||||||
// empty defaults to function according to the abi spec
|
// empty defaults to function according to the abi spec
|
||||||
case "function", "":
|
case "function":
|
||||||
name := abi.methodName(field.Name)
|
name := abi.methodName(field.Name)
|
||||||
isConst := field.Constant || field.StateMutability == "pure" || field.StateMutability == "view"
|
abi.Methods[name] = NewMethod(name, field.Name, field.StateMutability, field.Constant, field.Payable, false, false, field.Inputs, field.Outputs)
|
||||||
abi.Methods[name] = NewMethod(name, field.Name, field.StateMutability, isConst, field.Payable, false, false, field.Inputs, field.Outputs)
|
|
||||||
case "fallback":
|
case "fallback":
|
||||||
// New introduced function type in v0.6.0, check more detail
|
// New introduced function type in v0.6.0, check more detail
|
||||||
// here https://solidity.readthedocs.io/en/v0.6.0/contracts.html#fallback-function
|
// 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" {
|
if field.StateMutability != "payable" {
|
||||||
return errors.New("the statemutability of receive can only be 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":
|
case "event":
|
||||||
name := abi.eventName(field.Name)
|
name := abi.eventName(field.Name)
|
||||||
abi.Events[name] = NewEvent(name, field.Name, field.Anonymous, field.Inputs)
|
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.
|
// 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
|
// e.g. if the abi contains Methods send, send1
|
||||||
// methodName would return send2 for input send.
|
// 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.
|
// 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
|
// e.g. if the abi contains events received, received1
|
||||||
// eventName would return received2 for input received.
|
// eventName would return received2 for input received.
|
||||||
|
|
|
||||||
|
|
@ -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
|
// correctly handled
|
||||||
// The test runs the abi of the following contract.
|
// The test runs the abi of the following contract.
|
||||||
// contract TestEvent {
|
// contract TestEvent {
|
||||||
|
|
|
||||||
|
|
@ -103,12 +103,12 @@ func (arguments Arguments) Unpack(v interface{}, data []byte) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if arguments.isTuple() {
|
|
||||||
return arguments.unpackTuple(v, marshalledValues)
|
|
||||||
}
|
|
||||||
if len(marshalledValues) == 0 {
|
if len(marshalledValues) == 0 {
|
||||||
return fmt.Errorf("abi: Unpack(no-values unmarshalled %T)", v)
|
return fmt.Errorf("abi: Unpack(no-values unmarshalled %T)", v)
|
||||||
}
|
}
|
||||||
|
if arguments.isTuple() {
|
||||||
|
return arguments.unpackTuple(v, marshalledValues)
|
||||||
|
}
|
||||||
return arguments.unpackAtomic(v, marshalledValues[0])
|
return arguments.unpackAtomic(v, marshalledValues[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ type Method struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMethod creates a new Method.
|
// NewMethod creates a new Method.
|
||||||
|
// A method should always be created using NewMethod.
|
||||||
// It also precomputes the sig representation and the string representation
|
// It also precomputes the sig representation and the string representation
|
||||||
// of the method.
|
// of the method.
|
||||||
// A method should always be created using NewMethod.
|
// A method should always be created using NewMethod.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue