cosmos-sdk/x/ibc/04-channel/simulation/decoder.go
Anil Kumar Kammari 3bafd8255a
Remove hybrid codec usage (#6843)
* remove hybrid codec for slashing, staking and upgrade

* Remove hybridcodec from params and mint

* revert staking

* Fix gov

* Fix ibc and evidence

* Fix ibc-transfer

* Fix staking

* remove evidence json marshaling

* Fix tests

Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
2020-07-25 08:03:58 +00:00

50 lines
1.8 KiB
Go

package simulation
import (
"bytes"
"fmt"
tmkv "github.com/tendermint/tendermint/libs/kv"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding channel type.
func NewDecodeStore(cdc codec.BinaryMarshaler, kvA, kvB tmkv.Pair) (string, bool) {
switch {
case bytes.HasPrefix(kvA.Key, []byte(host.KeyChannelPrefix)):
var channelA, channelB types.Channel
cdc.MustUnmarshalBinaryBare(kvA.Value, &channelA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &channelB)
return fmt.Sprintf("Channel A: %v\nChannel B: %v", channelA, channelB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqSendPrefix)):
seqA := sdk.BigEndianToUint64(kvA.Value)
seqB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("NextSeqSend A: %d\nNextSeqSend B: %d", seqA, seqB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqRecvPrefix)):
seqA := sdk.BigEndianToUint64(kvA.Value)
seqB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("NextSeqRecv A: %d\nNextSeqRecv B: %d", seqA, seqB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqAckPrefix)):
seqA := sdk.BigEndianToUint64(kvA.Value)
seqB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("NextSeqAck A: %d\nNextSeqAck B: %d", seqA, seqB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyPacketCommitmentPrefix)):
return fmt.Sprintf("CommitmentHash A: %X\nCommitmentHash B: %X", kvA.Value, kvB.Value), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyPacketAckPrefix)):
return fmt.Sprintf("AckHash A: %X\nAckHash B: %X", kvA.Value, kvB.Value), true
default:
return "", false
}
}