github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/04-channel/simulation/decoder.go (about)

     1  package simulation
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
     8  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     9  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types"
    10  	host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host"
    11  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/common"
    12  	"github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv"
    13  )
    14  
    15  // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
    16  // Value to the corresponding channel type.
    17  func NewDecodeStore(cdc *codec.CodecProxy, kvA, kvB kv.Pair) (string, bool) {
    18  	switch {
    19  	case bytes.HasPrefix(kvA.Key, []byte(host.KeyChannelEndPrefix)):
    20  		var channelA, channelB types.Channel
    21  		channelA = *common.MustUnmarshalChannel(cdc, kvA.Value)
    22  		channelB = *common.MustUnmarshalChannel(cdc, kvB.Value)
    23  		//cdc.MustUnMarshal(kvA.Value, &channelA)
    24  		//cdc.MustUnMarshal(kvB.Value, &channelB)
    25  		return fmt.Sprintf("Channel A: %v\nChannel B: %v", channelA, channelB), true
    26  
    27  	case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqSendPrefix)):
    28  		seqA := sdk.BigEndianToUint64(kvA.Value)
    29  		seqB := sdk.BigEndianToUint64(kvB.Value)
    30  		return fmt.Sprintf("NextSeqSend A: %d\nNextSeqSend B: %d", seqA, seqB), true
    31  
    32  	case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqRecvPrefix)):
    33  		seqA := sdk.BigEndianToUint64(kvA.Value)
    34  		seqB := sdk.BigEndianToUint64(kvB.Value)
    35  		return fmt.Sprintf("NextSeqRecv A: %d\nNextSeqRecv B: %d", seqA, seqB), true
    36  
    37  	case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqAckPrefix)):
    38  		seqA := sdk.BigEndianToUint64(kvA.Value)
    39  		seqB := sdk.BigEndianToUint64(kvB.Value)
    40  		return fmt.Sprintf("NextSeqAck A: %d\nNextSeqAck B: %d", seqA, seqB), true
    41  
    42  	case bytes.HasPrefix(kvA.Key, []byte(host.KeyPacketCommitmentPrefix)):
    43  		return fmt.Sprintf("CommitmentHash A: %X\nCommitmentHash B: %X", kvA.Value, kvB.Value), true
    44  
    45  	case bytes.HasPrefix(kvA.Key, []byte(host.KeyPacketAckPrefix)):
    46  		return fmt.Sprintf("AckHash A: %X\nAckHash B: %X", kvA.Value, kvB.Value), true
    47  
    48  	default:
    49  		return "", false
    50  	}
    51  }