github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/slashing/simulation/decoder.go (about)

     1  package simulation
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/fibonacci-chain/fbc/libs/tendermint/crypto"
     8  	tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv"
     9  
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    11  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    12  	"github.com/fibonacci-chain/fbc/x/slashing/internal/types"
    13  )
    14  
    15  // DecodeStore unmarshals the KVPair's Value to the corresponding slashing type
    16  func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string {
    17  	switch {
    18  	case bytes.Equal(kvA.Key[:1], types.ValidatorSigningInfoKey):
    19  		var infoA, infoB types.ValidatorSigningInfo
    20  		cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &infoA)
    21  		cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &infoB)
    22  		return fmt.Sprintf("%v\n%v", infoA, infoB)
    23  
    24  	case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey):
    25  		var missedA, missedB bool
    26  		cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA)
    27  		cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB)
    28  		return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA, missedB)
    29  
    30  	case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey):
    31  		var pubKeyA, pubKeyB crypto.PubKey
    32  		cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &pubKeyA)
    33  		cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &pubKeyB)
    34  		bechPKA := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyA)
    35  		bechPKB := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyB)
    36  		return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPKA, bechPKB)
    37  
    38  	default:
    39  		panic(fmt.Sprintf("invalid slashing key prefix %X", kvA.Key[:1]))
    40  	}
    41  }