cosmos-sdk/x/slashing/simulation/decoder.go
Federico Kunze c441ce2fab Merge PR #4847: Sim refactor 1 move store decoders to modules
* move store decoders to modules

* fix

* module pattern

* compile

* update Decoders params

* fix

* address @colin-axner comments

* Update cmd_test.go

* simulation manager

* mino fixes

* cleanup

* Apply suggestions from code review

Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com>

* address @rigelrozanski comments

* changelog

* Apply suggestions from code review

Co-Authored-By: colin axner <colinaxner@berkeley.edu>

* restructure modules simulation pkgs

* address @alexanderbez comments

* fix
2019-08-13 18:16:03 -04:00

42 lines
1.4 KiB
Go

package simulation
import (
"bytes"
"fmt"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/internal/types"
)
// DecodeStore unmarshals the KVPair's Value to the corresponding slashing type
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.ValidatorSigningInfoKey):
var infoA, infoB types.ValidatorSigningInfo
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &infoA)
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &infoB)
return fmt.Sprintf("%v\n%v", infoA, infoB)
case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey):
var missedA, missedB bool
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA)
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB)
return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA, missedB)
case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey):
var pubKeyA, pubKeyB crypto.PubKey
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &pubKeyA)
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &pubKeyB)
bechPKA := sdk.MustBech32ifyAccPub(pubKeyA)
bechPKB := sdk.MustBech32ifyAccPub(pubKeyB)
return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPKA, bechPKB)
default:
panic(fmt.Sprintf("invalid slashing key prefix %X", kvA.Key[:1]))
}
}