Skip to content

Commit

Permalink
accounts/abi: improve readability of method-to-string conversion (eth…
Browse files Browse the repository at this point in the history
…ereum#28530)

refactor: improve readability of NewMethod print
  • Loading branch information
Halimao authored and Dergarcon committed Jan 31, 2024
1 parent c0f1c98 commit beb5dbf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions accounts/abi/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str
sig = fmt.Sprintf("%v(%v)", rawName, strings.Join(types, ","))
id = crypto.Keccak256([]byte(sig))[:4]
}
// Extract meaningful state mutability of solidity method.
// If it's default value, never print it.
state := mutability
if state == "nonpayable" {
state = ""
}
if state != "" {
state = state + " "
}
identity := fmt.Sprintf("function %v", rawName)
switch funType {
case Fallback:
Expand All @@ -135,7 +126,14 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str
case Constructor:
identity = "constructor"
}
str := fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputNames, ", "), state, strings.Join(outputNames, ", "))
var str string
// Extract meaningful state mutability of solidity method.
// If it's empty string or default value "nonpayable", never print it.
if mutability == "" || mutability == "nonpayable" {
str = fmt.Sprintf("%v(%v) returns(%v)", identity, strings.Join(inputNames, ", "), strings.Join(outputNames, ", "))
} else {
str = fmt.Sprintf("%v(%v) %s returns(%v)", identity, strings.Join(inputNames, ", "), mutability, strings.Join(outputNames, ", "))
}

return Method{
Name: name,
Expand Down

0 comments on commit beb5dbf

Please sign in to comment.