mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi: address marius's comment
This commit is contained in:
parent
b821eda702
commit
47d0a8c409
3 changed files with 23 additions and 13 deletions
|
|
@ -172,7 +172,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
|||
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
|
||||
if abi.Fallback.Fallback {
|
||||
if abi.HasFallback() {
|
||||
return errors.New("only single fallback is allowed")
|
||||
}
|
||||
abi.Fallback = Method{
|
||||
|
|
@ -182,7 +182,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
|||
// The `StateMutability` can only be payable or nonpayable,
|
||||
// so the constant is always false.
|
||||
StateMutability: field.StateMutability,
|
||||
Fallback: true,
|
||||
IsFallback: true,
|
||||
|
||||
// Fallback doesn't have any input or output
|
||||
Inputs: nil,
|
||||
|
|
@ -195,7 +195,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
|||
case "receive":
|
||||
// New introduced function type in v0.6.0, check more detail
|
||||
// here https://solidity.readthedocs.io/en/v0.6.0/contracts.html#fallback-function
|
||||
if abi.Receive.Receive {
|
||||
if abi.HasReceive() {
|
||||
return errors.New("only single receive is allowed")
|
||||
}
|
||||
if field.StateMutability != "payable" {
|
||||
|
|
@ -208,7 +208,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
|
|||
// The `StateMutability` can only be payable, so constant
|
||||
// is always true while payable is always false.
|
||||
StateMutability: field.StateMutability,
|
||||
Receive: true,
|
||||
IsReceive: true,
|
||||
|
||||
// Receive doesn't have any input or output
|
||||
Inputs: nil,
|
||||
|
|
@ -260,3 +260,13 @@ func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
|
|||
}
|
||||
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
|
||||
}
|
||||
|
||||
// HasFallback returns an indicator whether a fallback function is included.
|
||||
func (abi *ABI) HasFallback() bool {
|
||||
return abi.Fallback.IsFallback
|
||||
}
|
||||
|
||||
// HasReceive returns an indicator whether a receive function is included.
|
||||
func (abi *ABI) HasReceive() bool {
|
||||
return abi.Receive.IsReceive
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,10 +159,10 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
|
|||
events[original.Name] = &tmplEvent{Original: original, Normalized: normalized}
|
||||
}
|
||||
// Add two special fallback functions if they exist
|
||||
if evmABI.Fallback.Fallback {
|
||||
if evmABI.HasFallback() {
|
||||
fallback = &tmplMethod{Original: evmABI.Fallback}
|
||||
}
|
||||
if evmABI.Receive.Receive {
|
||||
if evmABI.HasReceive() {
|
||||
receive = &tmplMethod{Original: evmABI.Receive}
|
||||
}
|
||||
// There is no easy way to pass arbitrary java objects to the Go side.
|
||||
|
|
@ -639,9 +639,9 @@ func formatMethod(method abi.Method, structs map[string]*tmplStruct) string {
|
|||
state = state + " "
|
||||
}
|
||||
identity := fmt.Sprintf("function %v", method.RawName)
|
||||
if method.Fallback {
|
||||
if method.IsFallback {
|
||||
identity = "fallback"
|
||||
} else if method.Receive {
|
||||
} else if method.IsReceive {
|
||||
identity = "receive"
|
||||
}
|
||||
return fmt.Sprintf("%s(%v) %sreturns(%v)", identity, strings.Join(inputs, ", "), state, strings.Join(outputs, ", "))
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ type Method struct {
|
|||
|
||||
// The following two flags indicates whether the method is a
|
||||
// special fallback introduced in solidity v0.6.0
|
||||
Fallback bool
|
||||
Receive bool
|
||||
IsFallback bool
|
||||
IsReceive bool
|
||||
|
||||
Inputs Arguments
|
||||
Outputs Arguments
|
||||
|
|
@ -72,7 +72,7 @@ type Method struct {
|
|||
func (method Method) Sig() string {
|
||||
// Short circuit if the method is special. Fallback
|
||||
// and Receive don't have signature at all.
|
||||
if method.Fallback || method.Receive {
|
||||
if method.IsFallback || method.IsReceive {
|
||||
return ""
|
||||
}
|
||||
types := make([]string, len(method.Inputs))
|
||||
|
|
@ -104,9 +104,9 @@ func (method Method) String() string {
|
|||
state = state + " "
|
||||
}
|
||||
identity := fmt.Sprintf("function %v", method.RawName)
|
||||
if method.Fallback {
|
||||
if method.IsFallback {
|
||||
identity = "fallback"
|
||||
} else if method.Receive {
|
||||
} else if method.IsReceive {
|
||||
identity = "receive"
|
||||
}
|
||||
return fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputs, ", "), state, strings.Join(outputs, ", "))
|
||||
|
|
|
|||
Loading…
Reference in a new issue