icacontroller
and x/wasm
, you can skip this section.
Interfaces for developing the Underlying IBC Application
PacketDataUnmarshaler
PacketDataUnmarshaler
interface so that it can unmarshal the packet data bytes into the appropriate packet data type. This allows usage of interface functions implemented by the packet data type. The packet data type is expected to implement the PacketDataProvider
interface (see section below), which is used to parse the callback data that is currently stored in the packet memo field for transfer
and ica
packets as a JSON string. See its implementation in the transfer
and icacontroller
modules for reference.
If the underlying application is a middleware itself, then it can implement this interface by simply passing the function call to its underlying application. See its implementation in the fee middleware
for reference.
PacketDataProvider
PacketDataProvider
interface. This interface is used to retrieve the callback data from the packet data (using the memo field in the case of transfer
and ica
). For example, see its implementation in the transfer
module.
Since middlewares do not have packet types, they do not need to implement this interface.
PacketData
PacketData
is an optional interface that can be implemented by the underlying ibc application’s packet data type. It is used to retrieve the packet sender address from the packet data. The callbacks middleware uses this interface to retrieve the packet sender address and pass it to the callback function during a source callback. If this interface is not implemented, then the callbacks middleware passes and empty string as the sender address. For example, see its implementation in the transfer
and ica
module.
This interface was added so that secondary applications can retrieve the packet sender address to perform custom authorization logic if needed.
Since middlewares do not have packet types, they do not need to implement this interface.
Interfaces for developing the Secondary Application
ContractKeeper
The callbacks middleware requires the secondary application to implement the ContractKeeper
interface. The contract keeper will be invoked at each step of the packet lifecycle. When a packet is sent, if callback information is provided, the contract keeper will be invoked via the IBCSendPacketCallback
. This allows the contract keeper to prevent packet sends when callback information is provided, for example if the sender is unauthorized to perform callbacks on the given information. If the packet send is successful, the contract keeper on the destination (if present) will be invoked when a packet has been received and the acknowledgement is written, this will occur via IBCReceivePacketCallback
. At the end of the packet lifecycle, when processing acknowledgements or timeouts, the source contract keeper will be invoked either via IBCOnAcknowledgementPacket
or IBCOnTimeoutPacket
. Once a packet has been sent, each step of the packet lifecycle can be processed given that a relayer sets the gas limit to be more than or equal to the required CommitGasLimit
. State changes performed in the callback will only be committed upon successful execution.
Note that the source callback entry points are provided with the
packetSenderAddress
and MAY choose to use this to perform validation on the origin of a given packet. It is recommended to perform the same validation on all source chain callbacks (SendPacket, AcknowledgePacket, TimeoutPacket). This defensively guards against exploits due to incorrectly wired SendPacket ordering in IBC stacks.