diff options
author | RJ Catalano <catalanor0220@gmail.com> | 2017-10-17 19:07:08 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-10-17 19:07:08 +0800 |
commit | dec8bba9d4c5fcb3dd7e51f0f794b3e895c7f52d (patch) | |
tree | 7e4713ca276ac1a2cef7cd2dd19dcf8c6fd1f6c4 /accounts/abi/error.go | |
parent | e9295163aa25479e817efee4aac23eaeb7554bba (diff) | |
download | go-tangerine-dec8bba9d4c5fcb3dd7e51f0f794b3e895c7f52d.tar.gz go-tangerine-dec8bba9d4c5fcb3dd7e51f0f794b3e895c7f52d.tar.zst go-tangerine-dec8bba9d4c5fcb3dd7e51f0f794b3e895c7f52d.zip |
accounts/abi: improve type handling, add event support (#14743)
Diffstat (limited to 'accounts/abi/error.go')
-rw-r--r-- | accounts/abi/error.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/accounts/abi/error.go b/accounts/abi/error.go index 420acf418..9d8674ad0 100644 --- a/accounts/abi/error.go +++ b/accounts/abi/error.go @@ -39,22 +39,23 @@ func formatSliceString(kind reflect.Kind, sliceSize int) string { // type in t. func sliceTypeCheck(t Type, val reflect.Value) error { if val.Kind() != reflect.Slice && val.Kind() != reflect.Array { - return typeErr(formatSliceString(t.Kind, t.SliceSize), val.Type()) + return typeErr(formatSliceString(t.Kind, t.Size), val.Type()) } - if t.IsArray && val.Len() != t.SliceSize { - return typeErr(formatSliceString(t.Elem.Kind, t.SliceSize), formatSliceString(val.Type().Elem().Kind(), val.Len())) + + if t.T == ArrayTy && val.Len() != t.Size { + return typeErr(formatSliceString(t.Elem.Kind, t.Size), formatSliceString(val.Type().Elem().Kind(), val.Len())) } - if t.Elem.IsSlice { + if t.Elem.T == SliceTy { if val.Len() > 0 { return sliceTypeCheck(*t.Elem, val.Index(0)) } - } else if t.Elem.IsArray { + } else if t.Elem.T == ArrayTy { return sliceTypeCheck(*t.Elem, val.Index(0)) } if elemKind := val.Type().Elem().Kind(); elemKind != t.Elem.Kind { - return typeErr(formatSliceString(t.Elem.Kind, t.SliceSize), val.Type()) + return typeErr(formatSliceString(t.Elem.Kind, t.Size), val.Type()) } return nil } @@ -62,20 +63,19 @@ func sliceTypeCheck(t Type, val reflect.Value) error { // typeCheck checks that the given reflection value can be assigned to the reflection // type in t. func typeCheck(t Type, value reflect.Value) error { - if t.IsSlice || t.IsArray { + if t.T == SliceTy || t.T == ArrayTy { return sliceTypeCheck(t, value) } // Check base type validity. Element types will be checked later on. if t.Kind != value.Kind() { return typeErr(t.Kind, value.Kind()) + } else if t.T == FixedBytesTy && t.Size != value.Len() { + return typeErr(t.Type, value.Type()) + } else { + return nil } - return nil -} -// varErr returns a formatted error. -func varErr(expected, got reflect.Kind) error { - return typeErr(expected, got) } // typeErr returns a formatted type casting error. |