account/abi: convert if-else-if chain to tagged switch (#27869)

account/abi: conver if-else-if chain to tagged switch
pull/27994/head
Shude Li 1 year ago committed by GitHub
parent 4af98d4ee6
commit 76d4ac1acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      accounts/abi/method.go
  2. 7
      accounts/abi/method_test.go
  3. 7
      accounts/abi/unpack.go

@ -127,11 +127,12 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str
state = state + " "
}
identity := fmt.Sprintf("function %v", rawName)
if funType == Fallback {
switch funType {
case Fallback:
identity = "fallback"
} else if funType == Receive {
case Receive:
identity = "receive"
} else if funType == Constructor {
case Constructor:
identity = "constructor"
}
str := fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputNames, ", "), state, strings.Join(outputNames, ", "))

@ -84,11 +84,12 @@ func TestMethodString(t *testing.T) {
for _, test := range table {
var got string
if test.method == "fallback" {
switch test.method {
case "fallback":
got = abi.Fallback.String()
} else if test.method == "receive" {
case "receive":
got = abi.Receive.String()
} else {
default:
got = abi.Methods[test.method].String()
}
if got != test.expectation {

@ -160,13 +160,14 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error)
// this value will become our slice or our array, depending on the type
var refSlice reflect.Value
if t.T == SliceTy {
switch t.T {
case SliceTy:
// declare our slice
refSlice = reflect.MakeSlice(t.GetType(), size, size)
} else if t.T == ArrayTy {
case ArrayTy:
// declare our array
refSlice = reflect.New(t.GetType()).Elem()
} else {
default:
return nil, errors.New("abi: invalid type in array/slice unpacking stage")
}

Loading…
Cancel
Save