You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since Sylvia already supports sv::msg(reply) and we will change the ReplyCtx type this feature should be considered breaking.
Although Sylvia allows marking methods with #[sv::msg(reply)] and generate reply entry point we do not utilize the possibilities of Sylvia macros like with ExecutorBuilder and BoundQuerier.
By generating the IDs in Sylvia we remove the responsibility from the user as well as need for some boilerplate code.
The user will still be able to access those IDs in the sv module if needed.
In case an alias is provided it should be used to generate the reply id.
We keep the dispatching logic outside of the entry point and instead move it to a method like dispatch_reply() to provide reusability.
The method should match over every generated ID and provide additional checks for result of the submessage.
In case the handler for success or failure is not defined we will simply forward the result.
Note that above approach requires methods for a single identifier to have the same fields received from the Payload.
You can also define a single handler for an identifier-result pair.
For above to work we have to provide some new functionality.
FromData trait
** UPDATE **
Since Binary implements the Deserialize trait this specialization won't be possible due to overlapping implementations.
Most likely this part of feature will be obsoleted.
FromData trait will be used for deserialization of the Option<Binary>
Option<Binary> => Binary
Option<Binary> => Option<Binary>
Option<Binary> => T where T: Deserialize
Option<Binary> => Option<T> where T: Deserialize
The trait is performing Binary deserialization, keeping the special case converting to Binary skipping the deserialization, which would be later performed by the user - when the data field is not Json serialized.
We will hide some informations that are less used in the ReplyCtx not to polute the methods signatures.
/// Represantation of `reply` context received in entry point aspubstructReplyCtx<'a,C: cosmwasm_std::CustomQuery = Empty>{pubdeps:DepsMut<'a,C>,pubenv:Env,pubgas_used:u64,/// From payload/// Empty vector if errorpubevents:Vec<Event>,/// From result/// Empty vector if errorpubmsg_responses:Vec<MsgResponse>,}
Payload deserialization
The payload carry some information passed while constructing the SubMsg and works as a context.
We will make it seamless to use by deserializing it in the dispatching.
As this data is an JSON we can deserialize it to some intermediate generated type and pass it's fields to the methods.
Message building
Ideally we should provide a way to build not only WasmMsg::Execute messages, but also the WasmMsg::Instantiate and WasmMsg::Instantiate2.
The execute message should be sent to the external contract and it would be good to reuse the existing ExecutorBuilder for that.
In case of the Instantiate messages we do not have yet have the address so reusing the Remote and ExecutorBuilder is pointless, thus we should move the SubMsg creation to separate SubMsgBuilder type.
Example usage
For the WasmMsg::Execute we would use the existing ExecutorBuilder.
We should preserve the current functionality of constructing WasmMsg to not break the API.
Single Response can carry multiple submessages and we will provide a way to construct them with the schedule method. Additionally, the user will be able to call reply derived method to provide a handler
self.remote.executor(&mut resp)// Caches the message.call_me()// Creates submessage with above message and below reply id.reply_foo()// Adds the submessage to the `Response`.schedule().call_me_later().schedule().call_me_again().reply_bar().schedule();
To build on top of the existing infrastructure we can generate a trait with method for every method in the contract marked with sv::msg(reply).
We will generate the implementation for WasmMsg, CosmosMsg and SubMsg constructing the SubMsg from them with appropriate reply_id and reply_on.
Since we know what payload is expected on the reply side we can require user to provide the values in the trait methods.
The serialization of the payload would occur underneath.
This would require user to always provide the payload, even if it would be the Binary::default, but I don't think there is a better approach.
The benefit of this approach is its simplicity as we won't have to provide multiple builders with different states.
Also the SubMsg construction will work well with non sylvia contracts.
Feature outline based on #29 .
Since Sylvia already supports
sv::msg(reply)
and we will change theReplyCtx
type this feature should be considered breaking.Although Sylvia allows marking methods with
#[sv::msg(reply)]
and generate reply entry point we do not utilize the possibilities of Sylvia macros like withExecutorBuilder
andBoundQuerier
.In this feature we should effortless:
Affected macros
Desired API
IDs generation
For every unique reply method name or alias an ID should be created.
By generating the IDs in Sylvia we remove the responsibility from the user as well as need for some boilerplate code.
The user will still be able to access those IDs in the
sv
module if needed.In case an alias is provided it should be used to generate the reply id.
Dispatching
We keep the dispatching logic outside of the entry point and instead move it to a method like
dispatch_reply()
to provide reusability.The method should match over every generated ID and provide additional checks for result of the submessage.
In case the handler for success or failure is not defined we will simply forward the result.
Note that above approach requires methods for a single identifier to have the same fields received from the
Payload
.You can also define a single handler for an identifier-result pair.
For above to work we have to provide some new functionality.
FromData trait
** UPDATE **
Since
Binary
implements theDeserialize
trait this specialization won't be possible due to overlapping implementations.Most likely this part of feature will be obsoleted.
FromData
trait will be used for deserialization of theOption<Binary>
Option<Binary>
=>Binary
Option<Binary>
=>Option<Binary>
Option<Binary>
=>T
whereT: Deserialize
Option<Binary>
=>Option<T>
whereT: Deserialize
The trait is performing
Binary
deserialization, keeping the special case converting toBinary
skipping the deserialization, which would be later performed by the user - when the data field is not Json serialized.ReplyCtx update
We will hide some informations that are less used in the
ReplyCtx
not to polute the methods signatures.Payload deserialization
The payload carry some information passed while constructing the
SubMsg
and works as a context.We will make it seamless to use by deserializing it in the dispatching.
As this data is an JSON we can deserialize it to some intermediate generated type and pass it's fields to the methods.
Message building
Ideally we should provide a way to build not only
WasmMsg::Execute
messages, but also theWasmMsg::Instantiate
andWasmMsg::Instantiate2
.The execute message should be sent to the external contract and it would be good to reuse the existing
ExecutorBuilder
for that.In case of the
Instantiate
messages we do not have yet have the address so reusing theRemote
andExecutorBuilder
is pointless, thus we should move theSubMsg
creation to separateSubMsgBuilder
type.Example usage
For the
WasmMsg::Execute
we would use the existingExecutorBuilder
.We should preserve the current functionality of constructing
WasmMsg
to not break the API.Single
Response
can carry multiple submessages and we will provide a way to construct them with theschedule
method. Additionally, the user will be able to call reply derived method to provide a handlerRoadmap
#[sv::msg(reply=alias1|alias2, reply_on=...)]
#426data
#445sv::features
attribute to avoid breaking API #446ReplyCtx
type with additional fields #450The text was updated successfully, but these errors were encountered: