接口
部分接口差异如下:- 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 Applicationto implement the newCallbacksCompatibleModuleV2interface. channeltypesv2.Payloadis now used instead ofchanneltypes.Packet- With IBC classic, the
OnRecvPacketcallback returns theack, whereas v2 returns therecvResultwhich is the status of the packet: unspecified, success, failue or asynchronous api.WriteAcknowledgementWrapperis used instead ofICS4Wrapper.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 aPayload 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.