Skip to content

Commit 47d0a8c

Browse files
committed
accounts/abi: address marius's comment
1 parent b821eda commit 47d0a8c

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

accounts/abi/abi.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
172172
case "fallback":
173173
// New introduced function type in v0.6.0, check more detail
174174
// here https://solidity.readthedocs.io/en/v0.6.0/contracts.html#fallback-function
175-
if abi.Fallback.Fallback {
175+
if abi.HasFallback() {
176176
return errors.New("only single fallback is allowed")
177177
}
178178
abi.Fallback = Method{
@@ -182,7 +182,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
182182
// The `StateMutability` can only be payable or nonpayable,
183183
// so the constant is always false.
184184
StateMutability: field.StateMutability,
185-
Fallback: true,
185+
IsFallback: true,
186186

187187
// Fallback doesn't have any input or output
188188
Inputs: nil,
@@ -195,7 +195,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
195195
case "receive":
196196
// New introduced function type in v0.6.0, check more detail
197197
// here https://solidity.readthedocs.io/en/v0.6.0/contracts.html#fallback-function
198-
if abi.Receive.Receive {
198+
if abi.HasReceive() {
199199
return errors.New("only single receive is allowed")
200200
}
201201
if field.StateMutability != "payable" {
@@ -208,7 +208,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
208208
// The `StateMutability` can only be payable, so constant
209209
// is always true while payable is always false.
210210
StateMutability: field.StateMutability,
211-
Receive: true,
211+
IsReceive: true,
212212

213213
// Receive doesn't have any input or output
214214
Inputs: nil,
@@ -260,3 +260,13 @@ func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
260260
}
261261
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
262262
}
263+
264+
// HasFallback returns an indicator whether a fallback function is included.
265+
func (abi *ABI) HasFallback() bool {
266+
return abi.Fallback.IsFallback
267+
}
268+
269+
// HasReceive returns an indicator whether a receive function is included.
270+
func (abi *ABI) HasReceive() bool {
271+
return abi.Receive.IsReceive
272+
}

accounts/abi/bind/bind.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
159159
events[original.Name] = &tmplEvent{Original: original, Normalized: normalized}
160160
}
161161
// Add two special fallback functions if they exist
162-
if evmABI.Fallback.Fallback {
162+
if evmABI.HasFallback() {
163163
fallback = &tmplMethod{Original: evmABI.Fallback}
164164
}
165-
if evmABI.Receive.Receive {
165+
if evmABI.HasReceive() {
166166
receive = &tmplMethod{Original: evmABI.Receive}
167167
}
168168
// 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 {
639639
state = state + " "
640640
}
641641
identity := fmt.Sprintf("function %v", method.RawName)
642-
if method.Fallback {
642+
if method.IsFallback {
643643
identity = "fallback"
644-
} else if method.Receive {
644+
} else if method.IsReceive {
645645
identity = "receive"
646646
}
647647
return fmt.Sprintf("%s(%v) %sreturns(%v)", identity, strings.Join(inputs, ", "), state, strings.Join(outputs, ", "))

accounts/abi/method.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ type Method struct {
5555

5656
// The following two flags indicates whether the method is a
5757
// special fallback introduced in solidity v0.6.0
58-
Fallback bool
59-
Receive bool
58+
IsFallback bool
59+
IsReceive bool
6060

6161
Inputs Arguments
6262
Outputs Arguments
@@ -72,7 +72,7 @@ type Method struct {
7272
func (method Method) Sig() string {
7373
// Short circuit if the method is special. Fallback
7474
// and Receive don't have signature at all.
75-
if method.Fallback || method.Receive {
75+
if method.IsFallback || method.IsReceive {
7676
return ""
7777
}
7878
types := make([]string, len(method.Inputs))
@@ -104,9 +104,9 @@ func (method Method) String() string {
104104
state = state + " "
105105
}
106106
identity := fmt.Sprintf("function %v", method.RawName)
107-
if method.Fallback {
107+
if method.IsFallback {
108108
identity = "fallback"
109-
} else if method.Receive {
109+
} else if method.IsReceive {
110110
identity = "receive"
111111
}
112112
return fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputs, ", "), state, strings.Join(outputs, ", "))

0 commit comments

Comments
 (0)