cleanup stake marshalJson -> marshalBinary
This commit is contained in:
parent
cb2491bbb8
commit
dd9b5e78f7
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc"
|
"github.com/cosmos/cosmos-sdk/x/ibc"
|
||||||
|
@ -107,7 +108,7 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
|
||||||
StakeData: stake.GetDefaultGenesisState(),
|
StakeData: stake.GetDefaultGenesisState(),
|
||||||
}
|
}
|
||||||
|
|
||||||
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
stateBytes, err := wire.MarshalJSONIndent(gapp.cdc, genesisState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ func TestSerializationText(t *testing.T) {
|
||||||
bz, err := r.MarshalText()
|
bz, err := r.MarshalText()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r2 := NewRat(0, 1)
|
var r2 Rat
|
||||||
err = r2.UnmarshalText(bz)
|
err = r2.UnmarshalText(bz)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
||||||
|
@ -240,7 +240,7 @@ func TestSerializationGoWireJSON(t *testing.T) {
|
||||||
bz, err := cdc.MarshalJSON(r)
|
bz, err := cdc.MarshalJSON(r)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r2 := NewRat(0, 1)
|
var r2 Rat
|
||||||
err = cdc.UnmarshalJSON(bz, &r2)
|
err = cdc.UnmarshalJSON(bz, &r2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
||||||
|
@ -251,7 +251,7 @@ func TestSerializationGoWireBinary(t *testing.T) {
|
||||||
bz, err := cdc.MarshalBinary(r)
|
bz, err := cdc.MarshalBinary(r)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r2 := NewRat(0, 1)
|
var r2 Rat
|
||||||
err = cdc.UnmarshalBinary(bz, &r2)
|
err = cdc.UnmarshalBinary(bz, &r2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2)
|
||||||
|
|
|
@ -74,7 +74,7 @@ func GetCmdQueryCandidate(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||||
|
|
||||||
// parse out the candidate
|
// parse out the candidate
|
||||||
candidate := new(stake.Candidate)
|
candidate := new(stake.Candidate)
|
||||||
err = cdc.UnmarshalJSON(res, candidate)
|
err = cdc.UnmarshalBinary(res, candidate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func GetCmdQueryDelegatorBond(storeName string, cdc *wire.Codec) *cobra.Command
|
||||||
|
|
||||||
// parse out the bond
|
// parse out the bond
|
||||||
bond := new(stake.DelegatorBond)
|
bond := new(stake.DelegatorBond)
|
||||||
err = cdc.UnmarshalJSON(res, bond)
|
err = cdc.UnmarshalBinary(res, bond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func BondingStatusHandlerFn(storeName string, cdc *wire.Codec, kb keys.Keybase,
|
||||||
}
|
}
|
||||||
|
|
||||||
var bond stake.DelegatorBond
|
var bond stake.DelegatorBond
|
||||||
err = cdc.UnmarshalJSON(res, &bond)
|
err = cdc.UnmarshalBinary(res, &bond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(fmt.Sprintf("Couldn't decode bond. Error: %s", err.Error())))
|
w.Write([]byte(fmt.Sprintf("Couldn't decode bond. Error: %s", err.Error())))
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (k Keeper) getCounter(ctx sdk.Context) int16 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
var counter int16
|
var counter int16
|
||||||
err := k.cdc.UnmarshalJSON(b, &counter)
|
err := k.cdc.UnmarshalBinary(b, &counter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (k Keeper) getCounter(ctx sdk.Context) int16 {
|
||||||
// set the current in-block validator operation counter
|
// set the current in-block validator operation counter
|
||||||
func (k Keeper) setCounter(ctx sdk.Context, counter int16) {
|
func (k Keeper) setCounter(ctx sdk.Context, counter int16) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz, err := k.cdc.MarshalJSON(counter)
|
bz, err := k.cdc.MarshalBinary(counter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func (k Keeper) GetCandidate(ctx sdk.Context, addr sdk.Address) (candidate Candi
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return candidate, false
|
return candidate, false
|
||||||
}
|
}
|
||||||
err := k.cdc.UnmarshalJSON(b, &candidate)
|
err := k.cdc.UnmarshalBinary(b, &candidate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func (k Keeper) GetCandidates(ctx sdk.Context, maxRetrieve int16) (candidates Ca
|
||||||
}
|
}
|
||||||
bz := iterator.Value()
|
bz := iterator.Value()
|
||||||
var candidate Candidate
|
var candidate Candidate
|
||||||
err := k.cdc.UnmarshalJSON(bz, &candidate)
|
err := k.cdc.UnmarshalBinary(bz, &candidate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// marshal the candidate record and add to the state
|
// marshal the candidate record and add to the state
|
||||||
bz, err := k.cdc.MarshalJSON(candidate)
|
bz, err := k.cdc.MarshalBinary(candidate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the candidate record
|
// update the candidate record
|
||||||
bz, err = k.cdc.MarshalJSON(candidate)
|
bz, err = k.cdc.MarshalBinary(candidate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
|
||||||
|
|
||||||
// marshal the new validator record
|
// marshal the new validator record
|
||||||
validator := candidate.validator()
|
validator := candidate.validator()
|
||||||
bz, err = k.cdc.MarshalJSON(validator)
|
bz, err = k.cdc.MarshalBinary(validator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
|
||||||
setAcc = true
|
setAcc = true
|
||||||
}
|
}
|
||||||
if setAcc {
|
if setAcc {
|
||||||
bz, err = k.cdc.MarshalJSON(validator.abciValidator(k.cdc))
|
bz, err = k.cdc.MarshalBinary(validator.abciValidator(k.cdc))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ func (k Keeper) removeCandidate(ctx sdk.Context, address sdk.Address) {
|
||||||
if store.Get(GetRecentValidatorKey(address)) == nil {
|
if store.Get(GetRecentValidatorKey(address)) == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bz, err := k.cdc.MarshalJSON(candidate.validator().abciValidatorZero(k.cdc))
|
bz, err := k.cdc.MarshalBinary(candidate.validator().abciValidatorZero(k.cdc))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func (k Keeper) GetValidators(ctx sdk.Context) (validators []Validator) {
|
||||||
}
|
}
|
||||||
bz := iterator.Value()
|
bz := iterator.Value()
|
||||||
var validator Validator
|
var validator Validator
|
||||||
err := k.cdc.UnmarshalJSON(bz, &validator)
|
err := k.cdc.UnmarshalBinary(bz, &validator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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
|
// get the zero abci validator from the ToKickOut iterator value
|
||||||
bz := iterator.Value()
|
bz := iterator.Value()
|
||||||
var validator Validator
|
var validator Validator
|
||||||
err := k.cdc.UnmarshalJSON(bz, &validator)
|
err := k.cdc.UnmarshalBinary(bz, &validator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
bz, err = k.cdc.MarshalJSON(validator.abciValidatorZero(k.cdc))
|
bz, err = k.cdc.MarshalBinary(validator.abciValidatorZero(k.cdc))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ func (k Keeper) isNewValidator(ctx sdk.Context, store sdk.KVStore, address sdk.A
|
||||||
}
|
}
|
||||||
bz := iterator.Value()
|
bz := iterator.Value()
|
||||||
var val Validator
|
var val Validator
|
||||||
err := k.cdc.UnmarshalJSON(bz, &val)
|
err := k.cdc.UnmarshalBinary(bz, &val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ func (k Keeper) getAccUpdateValidators(ctx sdk.Context) (updates []abci.Validato
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
valBytes := iterator.Value()
|
valBytes := iterator.Value()
|
||||||
var val abci.Validator
|
var val abci.Validator
|
||||||
err := k.cdc.UnmarshalJSON(valBytes, &val)
|
err := k.cdc.UnmarshalBinary(valBytes, &val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,7 @@ func (k Keeper) GetDelegatorBond(ctx sdk.Context,
|
||||||
return bond, false
|
return bond, false
|
||||||
}
|
}
|
||||||
|
|
||||||
err := k.cdc.UnmarshalJSON(delegatorBytes, &bond)
|
err := k.cdc.UnmarshalBinary(delegatorBytes, &bond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ func (k Keeper) getBonds(ctx sdk.Context, maxRetrieve int16) (bonds []DelegatorB
|
||||||
}
|
}
|
||||||
bondBytes := iterator.Value()
|
bondBytes := iterator.Value()
|
||||||
var bond DelegatorBond
|
var bond DelegatorBond
|
||||||
err := k.cdc.UnmarshalJSON(bondBytes, &bond)
|
err := k.cdc.UnmarshalBinary(bondBytes, &bond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,7 @@ func (k Keeper) GetDelegatorBonds(ctx sdk.Context, delegator sdk.Address, maxRet
|
||||||
}
|
}
|
||||||
bondBytes := iterator.Value()
|
bondBytes := iterator.Value()
|
||||||
var bond DelegatorBond
|
var bond DelegatorBond
|
||||||
err := k.cdc.UnmarshalJSON(bondBytes, &bond)
|
err := k.cdc.UnmarshalBinary(bondBytes, &bond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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) {
|
func (k Keeper) setDelegatorBond(ctx sdk.Context, bond DelegatorBond) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b, err := k.cdc.MarshalJSON(bond)
|
b, err := k.cdc.MarshalBinary(bond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params Params) {
|
||||||
panic("Stored params should not have been nil")
|
panic("Stored params should not have been nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := k.cdc.UnmarshalJSON(b, ¶ms)
|
err := k.cdc.UnmarshalBinary(b, ¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -456,7 +456,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params Params) {
|
||||||
}
|
}
|
||||||
func (k Keeper) setParams(ctx sdk.Context, params Params) {
|
func (k Keeper) setParams(ctx sdk.Context, params Params) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b, err := k.cdc.MarshalJSON(params)
|
b, err := k.cdc.MarshalBinary(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ func (k Keeper) GetPool(ctx sdk.Context) (pool Pool) {
|
||||||
if b == nil {
|
if b == nil {
|
||||||
panic("Stored pool should not have been nil")
|
panic("Stored pool should not have been nil")
|
||||||
}
|
}
|
||||||
err := k.cdc.UnmarshalJSON(b, &pool)
|
err := k.cdc.UnmarshalBinary(b, &pool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // This error should never occur big problem if does
|
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) {
|
func (k Keeper) setPool(ctx sdk.Context, p Pool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b, err := k.cdc.MarshalJSON(p)
|
b, err := k.cdc.MarshalBinary(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue