本页重点说明了 IBC v2 与 IBC classic 在 callbacks 中间件相关方面的一些差异,以及如何在 IBC v2 中使用该模块。有关 IBC v2 中间件的更多细节,请参见中间件章节。

接口

部分接口差异如下:
  • IBC v2 的 callbacks 中间件要求底层应用实现新的 CallbacksCompatibleModuleV2 接口。
  • 现在使用 channeltypesv2.Payload 替代 channeltypes.Packet。
  • 在 IBC classic 中,OnRecvPacket 回调返回 ack;而在 v2 中,返回的是 recvResult,即数据包状态:未指定、成功、失败或异步。
  • 使用 api.WriteAcknowledgementWrapper 替代 ICS4Wrapper.WriteAcknowledgement。只有当更底层的应用需要写入异步确认时,才需要它。

合约开发者

wasmd 合约 keeper 使 cosmwasm 开发者能够使用 callbacks 中间件。cosmwasm 文档提供了面向合约开发者的信息。IBC v2 的 callbacks 实现使用 Payload,但会重新构造一个 IBC classic Packet,以保持 cosmwasm 合约 keeper 接口不变。此外,在失败场景下,合约现在还必须处理 IBC v2 的 ErrorAcknowledgement 哨兵值。 callbacks 中间件可用于 transfer + action 工作流,例如接收后执行转账和兑换。这些工作流需要了解已接收的 ibc denom。为帮助解析 ics20 数据包,可以在 solidity-ibc-eureka 仓库中找到辅助函数。

集成

在使用 IBC v2 的 transfer 栈中集成 callbacks 中间件的示例,可在 ibc-go 集成章节中找到。
This page highlights some of the differences between IBC v2 and IBC classic relevant for the callbacks middleware and how to use the module with IBC v2. More details on middleware for IBC v2 can be found in the middleware section.

Interfaces

Some of the interface differences are:
  • The callbacks middleware for IBC v2 requires the Underlying Application to implement the new CallbacksCompatibleModuleV2 interface.
  • channeltypesv2.Payload is now used instead of channeltypes.Packet
  • With IBC classic, the OnRecvPacket callback returns the ack, whereas v2 returns the recvResult which is the status of the packet: unspecified, success, failue or asynchronous
  • api.WriteAcknowledgementWrapper is used instead of ICS4Wrapper.WriteAcknowledgement. It is only needed if the lower level application is going to write an asynchronous acknowledgement.

Contract Developers

The wasmd contract keeper enables cosmwasm developers to use the callbacks middleware. The cosmwasm documentation provides information for contract developers. The IBC v2 callbacks implementation uses a Payload but reconstructs an IBC classic Packet to preserve the cosmwasm contract keeper interface. Additionally contracts must now handle the IBC v2 ErrorAcknowledgement sentinel value in the case of a failure. The callbacks middleware can be used for transfer + action workflows, for example a transfer and swap on recieve. These workflows require knowledge of the ibc denom that has been recieved. To assist with parsing the ics20 packet, helper functions can be found in the solidity-ibc-eureka repository.

Integration

An example integration of the callbacks middleware in a transfer stack that is using IBC v2 can be found in the ibc-go integration section