Skip to content

Commit

Permalink
Update abiencoder.go for compatible with double quoted string to numb…
Browse files Browse the repository at this point in the history
…er. (#208)

* Update abiencoder.go for compatible with double quoted string to number.

Because the params of number with quotation marks are supported on the command of cleos push action.

* Update abiencoder.go for compatible with double quoted string to number.

I modify the code for pull request 208

* Update abiencoder.go for compatible with double quoted string to number. 

add comment on changed code.

* Update CHANGELOG.md for pull request #208
  • Loading branch information
yjwxfq authored Jun 9, 2023
1 parent bb75101 commit 5d4ee54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Unreleased

* Changed valueToInt, valueToUint, valueToFload function in abiencode.go for compatible with double quoted string to number.
* Changed `NewAssetFromString` validation to allow parsing of empty assets
* Added `action_trace_v1` field
* Added `AsTime` helper functions to convert `TimePoint` and `TimePointSec` to `time.Time`
Expand Down
10 changes: 6 additions & 4 deletions abiencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,17 @@ func (a *ABI) writeField(binaryEncoder *Encoder, fieldName string, fieldType str
}

func valueToInt(fieldName string, value gjson.Result, bitSize int) (int64, error) {
i, err := strconv.ParseInt(value.Raw, 10, bitSize)
// Compatible with conversion of quoted strings to int
i, err := strconv.ParseInt(strings.Trim(value.Raw, `"`), 10, bitSize)
if err != nil {
return i, fmt.Errorf("writing field: [%s] type int%d : %w", fieldName, bitSize, err)
}
return i, nil
}

func valueToUint(fieldName string, value gjson.Result, bitSize int) (uint64, error) {
i, err := strconv.ParseUint(value.Raw, 10, bitSize)
// Compatible with conversion of quoted strings to uint
i, err := strconv.ParseUint(strings.Trim(value.Raw, `"`), 10, bitSize)
if err != nil {
return i, fmt.Errorf("writing field: [%s] type uint%d : %w", fieldName, bitSize, err)
}
Expand All @@ -424,8 +426,8 @@ func valueToFloat(fieldName string, value gjson.Result, bitSize int) (float64, e
return math.NaN(), nil
default:
}

f, err := strconv.ParseFloat(value.Raw, bitSize)
// Compatible with conversion of quoted strings to float
f, err := strconv.ParseFloat(strings.Trim(value.Raw, `"`), bitSize)
if err != nil {
return f, fmt.Errorf("writing field: [%s] type float%d : %w", fieldName, bitSize, err)
}
Expand Down

0 comments on commit 5d4ee54

Please sign in to comment.