Synopsis
Learn how to define custom packet and acknowledgement structs and how to encode and decode them.Pre-requisite readings
Custom packets
Modules connected by a channel must agree on what application data they are sending over the channel, as well as how they will encode/decode it. This process is not specified by IBC as it is up to each application module to determine how to implement this agreement. However, for most applications this will happen as a version negotiation during the channel handshake. While more complex version negotiation is possible to implement inside the channel opening handshake, a very simple version negotiation is implemented in the ibc-transfer module. Thus, a module must define its custom packet data structure, along with a well-defined way to encode and decode it to and from[]byte
.
Note that the CustomPacketData
struct is defined in the proto definition and then compiled by the protobuf compiler.
Then a module must encode its packet data before sending it through IBC.
PacketData
into a structure it expects so that it can
act on it.
Optional interfaces
The following interfaces are optional and MAY be implemented by a custom packet type. They allow middlewares such as callbacks to access information stored within the packet data.PacketData interface
ThePacketData
interface is defined as follows:
GetPacketSender
should return the sender of the packet data.
If the packet sender is unknown or undefined, an empty string should be returned.
This interface is intended to give IBC middlewares access to the packet sender of a packet data type.
PacketDataProvider interface
ThePacketDataProvider
interface is defined as follows:
GetCustomPacketData
should return packet data held on behalf of another application (if present and supported).
If this functionality is not supported, it should return nil. Otherwise it should return the packet data associated with the provided key.
This interface gives IBC applications access to the packet data information embedded into the base packet data type.
Within transfer and interchain accounts, the embedded packet data is stored within the Memo field.
Once all IBC applications within an IBC stack are capable of creating/maintaining their own packet data type’s, this interface function will be deprecated and removed.