Skip to content

Commit db7895d

Browse files
authored
accounts/abi: improve readability of method-to-string conversion (#28530)
refactor: improve readability of NewMethod print
1 parent fcc7ae1 commit db7895d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

accounts/abi/method.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str
117117
sig = fmt.Sprintf("%v(%v)", rawName, strings.Join(types, ","))
118118
id = crypto.Keccak256([]byte(sig))[:4]
119119
}
120-
// Extract meaningful state mutability of solidity method.
121-
// If it's default value, never print it.
122-
state := mutability
123-
if state == "nonpayable" {
124-
state = ""
125-
}
126-
if state != "" {
127-
state = state + " "
128-
}
129120
identity := fmt.Sprintf("function %v", rawName)
130121
switch funType {
131122
case Fallback:
@@ -135,7 +126,14 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str
135126
case Constructor:
136127
identity = "constructor"
137128
}
138-
str := fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputNames, ", "), state, strings.Join(outputNames, ", "))
129+
var str string
130+
// Extract meaningful state mutability of solidity method.
131+
// If it's empty string or default value "nonpayable", never print it.
132+
if mutability == "" || mutability == "nonpayable" {
133+
str = fmt.Sprintf("%v(%v) returns(%v)", identity, strings.Join(inputNames, ", "), strings.Join(outputNames, ", "))
134+
} else {
135+
str = fmt.Sprintf("%v(%v) %s returns(%v)", identity, strings.Join(inputNames, ", "), mutability, strings.Join(outputNames, ", "))
136+
}
139137

140138
return Method{
141139
Name: name,

0 commit comments

Comments
 (0)