github.com/cosmos/cosmos-sdk@v0.50.10/x/slashing/simulation/decoder.go (about) 1 package simulation 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/cosmos/cosmos-sdk/codec" 8 cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" 9 sdk "github.com/cosmos/cosmos-sdk/types" 10 "github.com/cosmos/cosmos-sdk/types/kv" 11 "github.com/cosmos/cosmos-sdk/x/slashing/types" 12 ) 13 14 // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's 15 // Value to the corresponding slashing type. 16 func NewDecodeStore(cdc codec.BinaryCodec) func(kvA, kvB kv.Pair) string { 17 return func(kvA, kvB kv.Pair) string { 18 switch { 19 case bytes.Equal(kvA.Key[:1], types.ValidatorSigningInfoKeyPrefix): 20 var infoA, infoB types.ValidatorSigningInfo 21 cdc.MustUnmarshal(kvA.Value, &infoA) 22 cdc.MustUnmarshal(kvB.Value, &infoB) 23 return fmt.Sprintf("%v\n%v", infoA, infoB) 24 25 case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitmapKeyPrefix): 26 addrBzLen := int(kvA.Key[1]) 27 addrBz := kvA.Key[2 : 2+addrBzLen] 28 addr := sdk.ConsAddress(addrBz) 29 return fmt.Sprintf("missedA: %v\nmissedB: %v\nfor %s\n", kvA.Value, kvB.Value, addr) 30 case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKeyPrefix): 31 var pubKeyA, pubKeyB cryptotypes.PubKey 32 if err := cdc.UnmarshalInterface(kvA.Value, &pubKeyA); err != nil { 33 panic(fmt.Sprint("Can't unmarshal kvA; ", err)) 34 } 35 if err := cdc.UnmarshalInterface(kvB.Value, &pubKeyB); err != nil { 36 panic(fmt.Sprint("Can't unmarshal kvB; ", err)) 37 } 38 return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", pubKeyA, pubKeyB) 39 40 default: 41 panic(fmt.Sprintf("invalid slashing key prefix %X", kvA.Key[:1])) 42 } 43 } 44 }