StackBuilder 结构体是一种新的基础原语,用于以更简单且更不易出错的方式组装中间件。它不是破坏性变更,因此现有的中间件组装方式仍然可用,但强烈建议迁移到新的组装方式。
请参考集成指南,了解如何使用这一新的中间件机制来改进链应用初始化中的中间件组装。
面向应用开发者的迁移说明
为了能够接入新的StackBuilder 原语,应用和中间件必须在各自接口中实现新的方法。
IBC 应用必须实现新的 SetICS4Wrapper,用于设置应用调用 SendPacket 和 WriteAcknowledgement 时所经过的 ICS4Wrapper。建议 IBC 应用在初始化时先直接使用 IBC ChannelKeeper,然后在栈组装过程中再通过中间件的 ICS4Wrapper 进行修改。
ics4Wrapper,因为它会在后续通过 SetICS4Wrapper 再进行设置。构造函数也必须返回指针引用,以便栈构建器可以原地修改它。
下面是一个支持栈构建器组装方式的 IBCModule 示例。
例如:
面向中间件开发者的迁移说明
由于中间件本身也实现了 IBC 应用接口,因此它也必须像 IBC 应用一样实现SetICS4Wrapper。
此外,IBC 中间件本身还会调用其底层的 IBC 应用。此前,这个应用通常会在中间件构造时传入并设置。引入栈构建器原语后,这个应用只会在调用 stack.Build() 时才被设置。因此,中间件还需要额外实现一个新方法:SetUnderlyingApplication:
ICS4Wrapper 和应用参数,因为它们会在后续再被设置。中间件的构造函数必须修改为返回指针引用,以便栈构建器可以原地修改它。
下面是一个中间件配置示例:
The StackBuilder struct is a new primitive for wiring middleware in a simpler and less error-prone manner. It is not a breaking change thus the existing method of wiring middleware still works, though it is highly recommended to transition to the new wiring method. Refer to the integration guide to understand how to use this new middleware to improve middleware wiring in the chain application setup.
Migrations for Application Developers
In order to be wired with the new StackBuilder primitive, applications and middlewares must implement new methods as part of their respective interfaces. IBC Applications must implement a newSetICS4Wrapper which will set the ICS4Wrapper through which the application will call SendPacket and WriteAcknowledgement. It is recommended that IBC applications are initialized first with the IBC ChannelKeeper directly, and then modified with a middleware ICS4Wrapper during the stack wiring.
ics4Wrapper as this gets modified later by SetICS4Wrapper. The constructor function must also return a pointer reference so that it may be modified in-place by the stack builder.
Below is an example IBCModule that supports the stack builder wiring.
E.g.
Migration for Middleware Developers
Since Middleware is itself implement the IBC application interface, it must also implementSetICS4Wrapper in the same way as IBC applications.
Additionally, IBC Middleware has an underlying IBC application that it calls into as well. Previously this application would be set in the middleware upon construction. With the stack builder primitive, the application is only set during upon calling stack.Build(). Thus, middleware is additionally responsible for implementing the new method: SetUnderlyingApplication: