Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the error handling when decoding table rows with variant types #214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Fixed

* Improved the error handling when decoding table rows with variant types.

* Fixed decoding of table rows with variant types.

* Fixed serialization of `map[K]V` when using `eos.MarshalBinary` so that ordering in which the keys are serialized is in lexicographical order, just like JSON serialization.
Expand Down
8 changes: 5 additions & 3 deletions abidecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ func (a *ABI) decode(binaryDecoder *Decoder, structName string) (map[string]inte
}

if variant := a.VariantForName(structName); variant != nil {
out, err := binaryDecoder.ReadUvarint32()
variantIndex, err := binaryDecoder.ReadUvarint32()
if err != nil {
zlog.Error("error reading variant", zap.Error(err))
return nil, fmt.Errorf("error reading variant: %w", err)
} else if int(variantIndex) >= len(variant.Types) {
return nil, fmt.Errorf("variant type index is unknown, got type index %d, know up to index %d", variantIndex, len(variant.Types)-1)
}
structName = variant.Types[out]
structName, _ = a.TypeNameForNewTypeName(variant.Types[variantIndex])
}

structure := a.StructForName(structName)
Expand Down
Loading