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

     1  package simulation
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  	"fmt"
     7  
     8  	tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv"
     9  
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    11  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/gov/types"
    12  )
    13  
    14  // DecodeStore unmarshals the KVPair's Value to the corresponding gov type
    15  func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string {
    16  	switch {
    17  	case bytes.Equal(kvA.Key[:1], types.ProposalsKeyPrefix):
    18  		var proposalA, proposalB types.Proposal
    19  		cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &proposalA)
    20  		cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &proposalB)
    21  		return fmt.Sprintf("%v\n%v", proposalA, proposalB)
    22  
    23  	case bytes.Equal(kvA.Key[:1], types.ActiveProposalQueuePrefix),
    24  		bytes.Equal(kvA.Key[:1], types.InactiveProposalQueuePrefix),
    25  		bytes.Equal(kvA.Key[:1], types.ProposalIDKey):
    26  		proposalIDA := binary.LittleEndian.Uint64(kvA.Value)
    27  		proposalIDB := binary.LittleEndian.Uint64(kvB.Value)
    28  		return fmt.Sprintf("proposalIDA: %d\nProposalIDB: %d", proposalIDA, proposalIDB)
    29  
    30  	case bytes.Equal(kvA.Key[:1], types.DepositsKeyPrefix):
    31  		var depositA, depositB types.Deposit
    32  		cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &depositA)
    33  		cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &depositB)
    34  		return fmt.Sprintf("%v\n%v", depositA, depositB)
    35  
    36  	case bytes.Equal(kvA.Key[:1], types.VotesKeyPrefix):
    37  		var voteA, voteB types.Vote
    38  		cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &voteA)
    39  		cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &voteB)
    40  		return fmt.Sprintf("%v\n%v", voteA, voteB)
    41  
    42  	default:
    43  		panic(fmt.Sprintf("invalid governance key prefix %X", kvA.Key[:1]))
    44  	}
    45  }