Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:eoscanada/eos-go into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Jun 3, 2020
2 parents 22f1741 + 24c0eb7 commit a729145
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 209 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Greatly improved performance of `NameToString` (`~230%`) method.
- `TimePoint` will decode with `0` nanoseconds, when the `fitNodeos` flag is set on the ABI.
- Ability to decode a `int128` and `uint128` in decimal format when `fitNodeos` flag is set on the ABI
- Ability to decode nested `arrays` in ABI decoder.
Expand All @@ -14,14 +15,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `ActionTrace.ContextFree` field of type `bool` that was previously missing from the struct definition.

### Fixed
- Optional encoding of primitive types.

A struct with a non-pointer type tagged with `eos:"optional"` is now properly encoded at the binary level. **Important** that means that for non-pointer type, when the value of the type is the "emtpy" value according to Golang rules, it will be written as not-present at the binary level. If it's something that you do want want, use a pointer to a primitive type. It's actually a good habit to use a pointer type for "optional" element anyway, to increase awarness.

- Fix json tags for delegatebw action data.
- Unpacking binary `Except` now correctly works.
- Unpacking binary `Action` and `ActionTrace` now correctly works.
- Unpacking binary `TransactionTrace` now correctly works.
- Unpacking binary `TransactionReceipt` type will now correctly set the inner `TransactionWithID.ID` field correctly.
- Unpacking binary `BlockState` now correctly works but is restricted to EOSIO 2.0.x version.

### Changed
- **BREAKING**: Fixed binary unpacking of `BlockState`, `TransactionTrace`, `SignedTransaction`, `Action` (and some inner types). This required changing a few struct fields to better fit with EOSIO definition, here the full list:
- **BREAKING**: Fixed binary unpacking of `BlockState`, `TransactionTrace`, `SignedTransaction`, `Action` (and some inner types). This required changing a few struct fields to better fit with EOSIO definition, here the full list:
- `MerkleRoot.ActiveNodes` is now a `[]Checksum256`, was previously `[]string`
- `MerkleRoot.NodeCount` is now a `uint64`, was previously `uint32`
- Type `EOSNameOrUint32` has been removed and replaced by `PairAccountNameBlockNum` which is strictly typed now.
Expand Down
27 changes: 14 additions & 13 deletions abidecoder.go
Expand Up @@ -42,8 +42,6 @@ func (a *ABI) Decode(binaryDecoder *Decoder, structName string) ([]byte, error)
return a.decode(binaryDecoder, structName)
}



func (a *ABI) decode(binaryDecoder *Decoder, structName string) ([]byte, error) {
if loggingEnabled {
abiDecoderLog.Debug("decode struct", zap.String("name", structName))
Expand Down Expand Up @@ -104,7 +102,7 @@ func (a *ABI) resolveField(binaryDecoder *Decoder, fieldName, fieldType string,

// check if this field is an alias
aliasFieldType, isAlias := a.TypeNameForNewTypeName(fieldType)
if isAlias {
if isAlias {
if loggingEnabled {
abiDecoderLog.Debug("type is an alias",
zap.String("from", fieldType),
Expand Down Expand Up @@ -187,7 +185,7 @@ func (a *ABI) readArray(binaryDecoder *Decoder, fieldName, fieldType string, jso
}

// Decodes the EOS ABIs built-in types
func (a *ABI) read(binaryDecoder *Decoder, fieldName string, fieldType string, json []byte) ([]byte, error){
func (a *ABI) read(binaryDecoder *Decoder, fieldName string, fieldType string, json []byte) ([]byte, error) {
variant := a.VariantForName(fieldType)
if variant != nil {
variantIndex, err := binaryDecoder.ReadUvarint32()
Expand Down Expand Up @@ -329,19 +327,13 @@ func (a *ABI) read(binaryDecoder *Decoder, fieldName string, fieldType string, j
case "bool":
if a.fitNodeos {
value, err = binaryDecoder.ReadByte()
break
} else {
value, err = binaryDecoder.ReadBool()
}
value, err = binaryDecoder.ReadBool()
case "time_point":
timePoint, e := binaryDecoder.ReadTimePoint() //todo double check
if e == nil {
t := time.Unix(0, int64(timePoint*1000))
if a.fitNodeos && t.Nanosecond() == 0{
// nodeos time_point will contains the nano seconds even if they are 0
value = fmt.Sprintf("%s.000", t.UTC().Format("2006-01-02T15:04:05"))
} else {
value = t.UTC().Format("2006-01-02T15:04:05.999")
}
value = formatTimePoint(timePoint, a.fitNodeos)
}
err = e
case "time_point_sec":
Expand Down Expand Up @@ -426,3 +418,12 @@ func analyzeFieldType(fieldType string) (typeName string, isOptional bool, isArr

return fieldType, false, false, false
}

func formatTimePoint(timePoint TimePoint, shouldFitNodeos bool) string {
t := time.Unix(0, int64(timePoint*1000))
format := "2006-01-02T15:04:05.999"
if shouldFitNodeos {
format = "2006-01-02T15:04:05.000"
}
return t.UTC().Format(format)
}

0 comments on commit a729145

Please sign in to comment.