github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/ibctesting/path.go (about)

     1  package ibctesting
     2  
     3  //import (
     4  //	"bytes"
     5  //	"fmt"
     6  //
     7  //	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  //	channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
     9  //)
    10  //
    11  //// Path contains two endpoints representing two chains connected over IBC
    12  //type Path struct {
    13  //	EndpointA *Endpoint
    14  //	EndpointB *Endpoint
    15  //}
    16  //
    17  //// NewPath constructs an endpoint for each chain using the default values
    18  //// for the endpoints. Each endpoint is updated to have a pointer to the
    19  //// counterparty endpoint.
    20  //func NewPath(chainA, chainB *TestChain) *Path {
    21  //	endpointA := NewDefaultEndpoint(chainA)
    22  //	endpointB := NewDefaultEndpoint(chainB)
    23  //
    24  //	endpointA.Counterparty = endpointB
    25  //	endpointB.Counterparty = endpointA
    26  //
    27  //	return &Path{
    28  //		EndpointA: endpointA,
    29  //		EndpointB: endpointB,
    30  //	}
    31  //}
    32  //
    33  //// SetChannelOrdered sets the channel order for both endpoints to ORDERED.
    34  //func (path *Path) SetChannelOrdered() {
    35  //	path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
    36  //	path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED
    37  //}
    38  //
    39  //// RelayPacket attempts to relay the packet first on EndpointA and then on EndpointB
    40  //// if EndpointA does not contain a packet commitment for that packet. An error is returned
    41  //// if a relay step fails or the packet commitment does not exist on either endpoint.
    42  //func (path *Path) RelayPacket(packet channeltypes.Packet, ack []byte) error {
    43  //	pc := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointA.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
    44  //	if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointA.Chain.App.AppCodec(), packet)) {
    45  //
    46  //		// packet found, relay from A to B
    47  //		if err := path.EndpointB.UpdateClient(); err != nil {
    48  //			return err
    49  //		}
    50  //
    51  //		if err := path.EndpointB.RecvPacket(packet); err != nil {
    52  //			return err
    53  //		}
    54  //
    55  //		if err := path.EndpointA.AcknowledgePacket(packet, ack); err != nil {
    56  //			return err
    57  //		}
    58  //		return nil
    59  //
    60  //	}
    61  //
    62  //	pc = path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointB.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
    63  //	if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointB.Chain.App.AppCodec(), packet)) {
    64  //
    65  //		// packet found, relay B to A
    66  //		if err := path.EndpointA.UpdateClient(); err != nil {
    67  //			return err
    68  //		}
    69  //
    70  //		if err := path.EndpointA.RecvPacket(packet); err != nil {
    71  //			return err
    72  //		}
    73  //		if err := path.EndpointB.AcknowledgePacket(packet, ack); err != nil {
    74  //			return err
    75  //		}
    76  //		return nil
    77  //	}
    78  //
    79  //	return fmt.Errorf("packet commitment does not exist on either endpoint for provided packet")
    80  //}
    81  //
    82  //// SendMsg delivers the provided messages to the chain. The counterparty
    83  //// client is updated with the new source consensus state.
    84  //func (path *Path) SendMsg(msgs ...sdk.Msg) error {
    85  //	if err := path.EndpointA.Chain.sendMsgs(msgs...); err != nil {
    86  //		return err
    87  //	}
    88  //	if err := path.EndpointA.UpdateClient(); err != nil {
    89  //		return err
    90  //	}
    91  //	return path.EndpointB.UpdateClient()
    92  //}
    93  //
    94  //func (path *Path) Invert() *Path {
    95  //	return &Path{
    96  //		EndpointA: path.EndpointB,
    97  //		EndpointB: path.EndpointA,
    98  //	}
    99  //}