github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/staking/simulation/decoder.go (about) 1 package simulation 2 3 import ( 4 "bytes" 5 "fmt" 6 7 tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv" 8 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 10 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 11 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/staking/types" 12 ) 13 14 // DecodeStore unmarshals the KVPair's Value to the corresponding staking type 15 func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { 16 switch { 17 case bytes.Equal(kvA.Key[:1], types.LastTotalPowerKey): 18 var powerA, powerB sdk.Int 19 cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &powerA) 20 cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &powerB) 21 return fmt.Sprintf("%v\n%v", powerA, powerB) 22 23 case bytes.Equal(kvA.Key[:1], types.ValidatorsKey): 24 var validatorA, validatorB types.Validator 25 cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &validatorA) 26 cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &validatorB) 27 return fmt.Sprintf("%v\n%v", validatorA, validatorB) 28 29 case bytes.Equal(kvA.Key[:1], types.LastValidatorPowerKey), 30 bytes.Equal(kvA.Key[:1], types.ValidatorsByConsAddrKey), 31 bytes.Equal(kvA.Key[:1], types.ValidatorsByPowerIndexKey): 32 return fmt.Sprintf("%v\n%v", sdk.ValAddress(kvA.Value), sdk.ValAddress(kvB.Value)) 33 34 case bytes.Equal(kvA.Key[:1], types.DelegationKey): 35 var delegationA, delegationB types.Delegation 36 cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &delegationA) 37 cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &delegationB) 38 return fmt.Sprintf("%v\n%v", delegationA, delegationB) 39 40 case bytes.Equal(kvA.Key[:1], types.UnbondingDelegationKey), 41 bytes.Equal(kvA.Key[:1], types.UnbondingDelegationByValIndexKey): 42 var ubdA, ubdB types.UnbondingDelegation 43 cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &ubdA) 44 cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &ubdB) 45 return fmt.Sprintf("%v\n%v", ubdA, ubdB) 46 47 case bytes.Equal(kvA.Key[:1], types.RedelegationKey), 48 bytes.Equal(kvA.Key[:1], types.RedelegationByValSrcIndexKey): 49 var redA, redB types.Redelegation 50 cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &redA) 51 cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &redB) 52 return fmt.Sprintf("%v\n%v", redA, redB) 53 54 default: 55 panic(fmt.Sprintf("invalid staking key prefix %X", kvA.Key[:1])) 56 } 57 }