github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/transfer/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  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/transfer/types"
     9  	"github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv"
    10  )
    11  
    12  // TransferUnmarshaler defines the expected encoding store functions.
    13  type TransferUnmarshaler interface {
    14  	MustUnmarshalDenomTrace([]byte) types.DenomTrace
    15  }
    16  
    17  // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
    18  // Value to the corresponding DenomTrace type.
    19  func NewDecodeStore(kCdc TransferUnmarshaler) func(cdc *codec.Codec, kvA, kvB kv.Pair) string {
    20  	return func(cdc *codec.Codec, kvA, kvB kv.Pair) string {
    21  		switch {
    22  		case bytes.Equal(kvA.Key[:1], types.PortKey):
    23  			return fmt.Sprintf("Port A: %s\nPort B: %s", string(kvA.Value), string(kvB.Value))
    24  
    25  		case bytes.Equal(kvA.Key[:1], types.DenomTraceKey):
    26  			denomTraceA := kCdc.MustUnmarshalDenomTrace(kvA.Value)
    27  			denomTraceB := kCdc.MustUnmarshalDenomTrace(kvB.Value)
    28  			return fmt.Sprintf("DenomTrace A: %s\nDenomTrace B: %s", denomTraceA.IBCDenom(), denomTraceB.IBCDenom())
    29  
    30  		default:
    31  			panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
    32  		}
    33  	}
    34  }