Use GoAmino 0.9.9 and change impl of Rational.MarshalAmino
This commit is contained in:
parent
71d2e9bb55
commit
cb2491bbb8
|
@ -277,8 +277,8 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/tendermint/go-amino"
|
name = "github.com/tendermint/go-amino"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "3668c02a8feace009f80754a5e5a8541e5d7b996"
|
revision = "ed62928576cfcaf887209dc96142cd79cdfff389"
|
||||||
version = "0.9.8"
|
version = "0.9.9"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/tendermint/go-crypto"
|
name = "github.com/tendermint/go-crypto"
|
||||||
|
@ -460,6 +460,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "48f831a7ccc2c0fd3b790c16ca99ec864b89253d087ff4190d821c01c13e635a"
|
inputs-digest = "fad966346d3b6042faf2bf793168b6ce9a8ff59ae207b7ad57008ead0f3ff7d4"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tendermint/go-amino"
|
name = "github.com/tendermint/go-amino"
|
||||||
version = "~0.9.8"
|
version = "~0.9.9"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tendermint/iavl"
|
name = "github.com/tendermint/iavl"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -153,26 +152,16 @@ func (r Rat) ToLeftPadded(totalDigits int8) string {
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
//___________________________________________________________________________________
|
||||||
|
|
||||||
//Wraps r.MarshalText() in quotes to make it a valid JSON string.
|
//Wraps r.MarshalText().
|
||||||
func (r Rat) MarshalJSON() ([]byte, error) {
|
func (r Rat) MarshalAmino() (string, error) {
|
||||||
bz, err := (&(r.Rat)).MarshalText()
|
bz, err := (&(r.Rat)).MarshalText()
|
||||||
if err != nil {
|
return string(bz), err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return []byte(fmt.Sprintf("\"%s\"", bz)), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Requires a valid JSON string - strings quotes and calls UnmarshalText
|
// Requires a valid JSON string - strings quotes and calls UnmarshalText
|
||||||
func (r *Rat) UnmarshalJSON(data []byte) (err error) {
|
func (r *Rat) UnmarshalAmino(text string) (err error) {
|
||||||
quote := []byte(`"`)
|
|
||||||
if len(data) < 2 ||
|
|
||||||
!bytes.HasPrefix(data, quote) ||
|
|
||||||
!bytes.HasSuffix(data, quote) {
|
|
||||||
return fmt.Errorf("JSON encoded Rat must be a quote-delimitted string, have %v", string(data))
|
|
||||||
}
|
|
||||||
data = bytes.Trim(data, `"`)
|
|
||||||
tempRat := big.NewRat(0, 1)
|
tempRat := big.NewRat(0, 1)
|
||||||
err = tempRat.UnmarshalText(data)
|
err = tempRat.UnmarshalText([]byte(text))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,7 @@ func TestSerializationText(t *testing.T) {
|
||||||
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSerializationGoWire(t *testing.T) {
|
func TestSerializationGoWireJSON(t *testing.T) {
|
||||||
r := NewRat(1, 3)
|
r := NewRat(1, 3)
|
||||||
bz, err := cdc.MarshalJSON(r)
|
bz, err := cdc.MarshalJSON(r)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -246,6 +246,17 @@ func TestSerializationGoWire(t *testing.T) {
|
||||||
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSerializationGoWireBinary(t *testing.T) {
|
||||||
|
r := NewRat(1, 3)
|
||||||
|
bz, err := cdc.MarshalBinary(r)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
r2 := NewRat(0, 1)
|
||||||
|
err = cdc.UnmarshalBinary(bz, &r2)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
||||||
|
}
|
||||||
|
|
||||||
type testEmbedStruct struct {
|
type testEmbedStruct struct {
|
||||||
Field1 string `json:"f1"`
|
Field1 string `json:"f1"`
|
||||||
Field2 int `json:"f2"`
|
Field2 int `json:"f2"`
|
||||||
|
|
Loading…
Reference in New Issue