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