2019-08-13 15:16:03 -07:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
|
2020-02-19 16:04:13 -08:00
|
|
|
gogotypes "github.com/gogo/protobuf/types"
|
2019-08-13 15:16:03 -07:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-07-30 07:53:02 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
2020-02-19 16:04:13 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
2019-08-13 15:16:03 -07:00
|
|
|
)
|
|
|
|
|
2020-04-21 14:33:56 -07:00
|
|
|
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
|
|
|
|
// Value to the corresponding slashing type.
|
2020-07-30 07:53:02 -07:00
|
|
|
func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string {
|
|
|
|
return func(kvA, kvB kv.Pair) string {
|
2020-04-21 14:33:56 -07:00
|
|
|
switch {
|
2020-05-13 14:23:00 -07:00
|
|
|
case bytes.Equal(kvA.Key[:1], types.ValidatorSigningInfoKeyPrefix):
|
2020-04-21 14:33:56 -07:00
|
|
|
var infoA, infoB types.ValidatorSigningInfo
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvA.Value, &infoA)
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvB.Value, &infoB)
|
|
|
|
return fmt.Sprintf("%v\n%v", infoA, infoB)
|
2019-08-13 15:16:03 -07:00
|
|
|
|
2020-05-13 14:23:00 -07:00
|
|
|
case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKeyPrefix):
|
2020-04-21 14:33:56 -07:00
|
|
|
var missedA, missedB gogotypes.BoolValue
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvA.Value, &missedA)
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvB.Value, &missedB)
|
|
|
|
return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA.Value, missedB.Value)
|
2019-08-13 15:16:03 -07:00
|
|
|
|
2020-05-13 14:23:00 -07:00
|
|
|
case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKeyPrefix):
|
2020-04-21 14:33:56 -07:00
|
|
|
var pubKeyA, pubKeyB gogotypes.StringValue
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvA.Value, &pubKeyA)
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvB.Value, &pubKeyB)
|
|
|
|
return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", pubKeyA.Value, pubKeyB.Value)
|
2019-08-13 15:16:03 -07:00
|
|
|
|
2020-04-21 14:33:56 -07:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("invalid slashing key prefix %X", kvA.Key[:1]))
|
|
|
|
}
|
2019-08-13 15:16:03 -07:00
|
|
|
}
|
|
|
|
}
|