diff --git a/Gopkg.lock b/Gopkg.lock index d773b4d7ad4c..f474e77564b2 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -277,8 +277,8 @@ [[projects]] name = "github.com/tendermint/go-amino" packages = ["."] - revision = "3668c02a8feace009f80754a5e5a8541e5d7b996" - version = "0.9.8" + revision = "ed62928576cfcaf887209dc96142cd79cdfff389" + version = "0.9.9" [[projects]] name = "github.com/tendermint/go-crypto" @@ -460,6 +460,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "48f831a7ccc2c0fd3b790c16ca99ec864b89253d087ff4190d821c01c13e635a" + inputs-digest = "fad966346d3b6042faf2bf793168b6ce9a8ff59ae207b7ad57008ead0f3ff7d4" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 1e71e68e261b..d2d4ee2ff31d 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -62,7 +62,7 @@ [[constraint]] name = "github.com/tendermint/go-amino" - version = "~0.9.8" + version = "~0.9.9" [[constraint]] name = "github.com/tendermint/iavl" diff --git a/cmd/gaia/app/app_test.go b/cmd/gaia/app/app_test.go index 25c6b2d97b59..3bca2654b839 100644 --- a/cmd/gaia/app/app_test.go +++ b/cmd/gaia/app/app_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" @@ -107,7 +108,7 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error { StakeData: stake.GetDefaultGenesisState(), } - stateBytes, err := json.MarshalIndent(genesisState, "", "\t") + stateBytes, err := wire.MarshalJSONIndent(gapp.cdc, genesisState) if err != nil { return err } diff --git a/types/rational.go b/types/rational.go index 550c96825a64..7e0a091075c7 100644 --- a/types/rational.go +++ b/types/rational.go @@ -1,7 +1,6 @@ package types import ( - "bytes" "fmt" "math/big" "strconv" @@ -153,26 +152,16 @@ func (r Rat) ToLeftPadded(totalDigits int8) string { //___________________________________________________________________________________ -//Wraps r.MarshalText() in quotes to make it a valid JSON string. -func (r Rat) MarshalJSON() ([]byte, error) { +//Wraps r.MarshalText(). +func (r Rat) MarshalAmino() (string, error) { bz, err := (&(r.Rat)).MarshalText() - if err != nil { - return nil, err - } - return []byte(fmt.Sprintf("\"%s\"", bz)), nil + return string(bz), err } // Requires a valid JSON string - strings quotes and calls UnmarshalText -func (r *Rat) UnmarshalJSON(data []byte) (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, `"`) +func (r *Rat) UnmarshalAmino(text string) (err error) { tempRat := big.NewRat(0, 1) - err = tempRat.UnmarshalText(data) + err = tempRat.UnmarshalText([]byte(text)) if err != nil { return err } diff --git a/types/rational_test.go b/types/rational_test.go index 39207034cbef..e59545bfc787 100644 --- a/types/rational_test.go +++ b/types/rational_test.go @@ -229,23 +229,34 @@ func TestSerializationText(t *testing.T) { bz, err := r.MarshalText() require.NoError(t, err) - r2 := NewRat(0, 1) + var r2 Rat err = r2.UnmarshalText(bz) require.NoError(t, err) 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) bz, err := cdc.MarshalJSON(r) require.NoError(t, err) - r2 := NewRat(0, 1) + var r2 Rat err = cdc.UnmarshalJSON(bz, &r2) require.NoError(t, err) 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) + + var r2 Rat + err = cdc.UnmarshalBinary(bz, &r2) + require.NoError(t, err) + assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2) +} + type testEmbedStruct struct { Field1 string `json:"f1"` Field2 int `json:"f2"` diff --git a/x/stake/client/cli/query.go b/x/stake/client/cli/query.go index bb2a2b8db45d..145333e486c7 100644 --- a/x/stake/client/cli/query.go +++ b/x/stake/client/cli/query.go @@ -74,7 +74,7 @@ func GetCmdQueryCandidate(storeName string, cdc *wire.Codec) *cobra.Command { // parse out the candidate candidate := new(stake.Candidate) - err = cdc.UnmarshalJSON(res, candidate) + err = cdc.UnmarshalBinary(res, candidate) if err != nil { return err } @@ -122,7 +122,7 @@ func GetCmdQueryDelegatorBond(storeName string, cdc *wire.Codec) *cobra.Command // parse out the bond bond := new(stake.DelegatorBond) - err = cdc.UnmarshalJSON(res, bond) + err = cdc.UnmarshalBinary(res, bond) if err != nil { return err } diff --git a/x/stake/client/rest/query.go b/x/stake/client/rest/query.go index 22175d75a732..8eb0e03ceb5e 100644 --- a/x/stake/client/rest/query.go +++ b/x/stake/client/rest/query.go @@ -59,7 +59,7 @@ func BondingStatusHandlerFn(storeName string, cdc *wire.Codec, kb keys.Keybase, } var bond stake.DelegatorBond - err = cdc.UnmarshalJSON(res, &bond) + err = cdc.UnmarshalBinary(res, &bond) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode bond. Error: %s", err.Error()))) diff --git a/x/stake/keeper.go b/x/stake/keeper.go index d9fa293f5fdc..605f675db0ee 100644 --- a/x/stake/keeper.go +++ b/x/stake/keeper.go @@ -41,7 +41,7 @@ func (k Keeper) getCounter(ctx sdk.Context) int16 { return 0 } var counter int16 - err := k.cdc.UnmarshalJSON(b, &counter) + err := k.cdc.UnmarshalBinary(b, &counter) if err != nil { panic(err) } @@ -51,7 +51,7 @@ func (k Keeper) getCounter(ctx sdk.Context) int16 { // set the current in-block validator operation counter func (k Keeper) setCounter(ctx sdk.Context, counter int16) { store := ctx.KVStore(k.storeKey) - bz, err := k.cdc.MarshalJSON(counter) + bz, err := k.cdc.MarshalBinary(counter) if err != nil { panic(err) } @@ -67,7 +67,7 @@ func (k Keeper) GetCandidate(ctx sdk.Context, addr sdk.Address) (candidate Candi if b == nil { return candidate, false } - err := k.cdc.UnmarshalJSON(b, &candidate) + err := k.cdc.UnmarshalBinary(b, &candidate) if err != nil { panic(err) } @@ -88,7 +88,7 @@ func (k Keeper) GetCandidates(ctx sdk.Context, maxRetrieve int16) (candidates Ca } bz := iterator.Value() var candidate Candidate - err := k.cdc.UnmarshalJSON(bz, &candidate) + err := k.cdc.UnmarshalBinary(bz, &candidate) if err != nil { panic(err) } @@ -112,7 +112,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) { } // marshal the candidate record and add to the state - bz, err := k.cdc.MarshalJSON(candidate) + bz, err := k.cdc.MarshalBinary(candidate) if err != nil { panic(err) } @@ -145,7 +145,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) { } // update the candidate record - bz, err = k.cdc.MarshalJSON(candidate) + bz, err = k.cdc.MarshalBinary(candidate) if err != nil { panic(err) } @@ -153,7 +153,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) { // marshal the new validator record validator := candidate.validator() - bz, err = k.cdc.MarshalJSON(validator) + bz, err = k.cdc.MarshalBinary(validator) if err != nil { panic(err) } @@ -171,7 +171,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) { setAcc = true } if setAcc { - bz, err = k.cdc.MarshalJSON(validator.abciValidator(k.cdc)) + bz, err = k.cdc.MarshalBinary(validator.abciValidator(k.cdc)) if err != nil { panic(err) } @@ -200,7 +200,7 @@ func (k Keeper) removeCandidate(ctx sdk.Context, address sdk.Address) { if store.Get(GetRecentValidatorKey(address)) == nil { return } - bz, err := k.cdc.MarshalJSON(candidate.validator().abciValidatorZero(k.cdc)) + bz, err := k.cdc.MarshalBinary(candidate.validator().abciValidatorZero(k.cdc)) if err != nil { panic(err) } @@ -242,7 +242,7 @@ func (k Keeper) GetValidators(ctx sdk.Context) (validators []Validator) { } bz := iterator.Value() var validator Validator - err := k.cdc.UnmarshalJSON(bz, &validator) + err := k.cdc.UnmarshalBinary(bz, &validator) if err != nil { panic(err) } @@ -266,11 +266,11 @@ func (k Keeper) GetValidators(ctx sdk.Context) (validators []Validator) { // get the zero abci validator from the ToKickOut iterator value bz := iterator.Value() var validator Validator - err := k.cdc.UnmarshalJSON(bz, &validator) + err := k.cdc.UnmarshalBinary(bz, &validator) if err != nil { panic(err) } - bz, err = k.cdc.MarshalJSON(validator.abciValidatorZero(k.cdc)) + bz, err = k.cdc.MarshalBinary(validator.abciValidatorZero(k.cdc)) if err != nil { panic(err) } @@ -297,7 +297,7 @@ func (k Keeper) isNewValidator(ctx sdk.Context, store sdk.KVStore, address sdk.A } bz := iterator.Value() var val Validator - err := k.cdc.UnmarshalJSON(bz, &val) + err := k.cdc.UnmarshalBinary(bz, &val) if err != nil { panic(err) } @@ -330,7 +330,7 @@ func (k Keeper) getAccUpdateValidators(ctx sdk.Context) (updates []abci.Validato for ; iterator.Valid(); iterator.Next() { valBytes := iterator.Value() var val abci.Validator - err := k.cdc.UnmarshalJSON(valBytes, &val) + err := k.cdc.UnmarshalBinary(valBytes, &val) if err != nil { panic(err) } @@ -364,7 +364,7 @@ func (k Keeper) GetDelegatorBond(ctx sdk.Context, return bond, false } - err := k.cdc.UnmarshalJSON(delegatorBytes, &bond) + err := k.cdc.UnmarshalBinary(delegatorBytes, &bond) if err != nil { panic(err) } @@ -385,7 +385,7 @@ func (k Keeper) getBonds(ctx sdk.Context, maxRetrieve int16) (bonds []DelegatorB } bondBytes := iterator.Value() var bond DelegatorBond - err := k.cdc.UnmarshalJSON(bondBytes, &bond) + err := k.cdc.UnmarshalBinary(bondBytes, &bond) if err != nil { panic(err) } @@ -410,7 +410,7 @@ func (k Keeper) GetDelegatorBonds(ctx sdk.Context, delegator sdk.Address, maxRet } bondBytes := iterator.Value() var bond DelegatorBond - err := k.cdc.UnmarshalJSON(bondBytes, &bond) + err := k.cdc.UnmarshalBinary(bondBytes, &bond) if err != nil { panic(err) } @@ -422,7 +422,7 @@ func (k Keeper) GetDelegatorBonds(ctx sdk.Context, delegator sdk.Address, maxRet func (k Keeper) setDelegatorBond(ctx sdk.Context, bond DelegatorBond) { store := ctx.KVStore(k.storeKey) - b, err := k.cdc.MarshalJSON(bond) + b, err := k.cdc.MarshalBinary(bond) if err != nil { panic(err) } @@ -448,7 +448,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params Params) { panic("Stored params should not have been nil") } - err := k.cdc.UnmarshalJSON(b, ¶ms) + err := k.cdc.UnmarshalBinary(b, ¶ms) if err != nil { panic(err) } @@ -456,7 +456,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params Params) { } func (k Keeper) setParams(ctx sdk.Context, params Params) { store := ctx.KVStore(k.storeKey) - b, err := k.cdc.MarshalJSON(params) + b, err := k.cdc.MarshalBinary(params) if err != nil { panic(err) } @@ -477,7 +477,7 @@ func (k Keeper) GetPool(ctx sdk.Context) (pool Pool) { if b == nil { panic("Stored pool should not have been nil") } - err := k.cdc.UnmarshalJSON(b, &pool) + err := k.cdc.UnmarshalBinary(b, &pool) if err != nil { panic(err) // This error should never occur big problem if does } @@ -486,7 +486,7 @@ func (k Keeper) GetPool(ctx sdk.Context) (pool Pool) { func (k Keeper) setPool(ctx sdk.Context, p Pool) { store := ctx.KVStore(k.storeKey) - b, err := k.cdc.MarshalJSON(p) + b, err := k.cdc.MarshalBinary(p) if err != nil { panic(err) }