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
The difference in this approach between handling data and payload would be the ability to deserialize the payload into separate fields like:
#[sv::msg(reply)]fnon_something_happened(&self,ctx:ReplyCtx,#[sv::data(raw, opt)]data:Option<Binary>,coins:Coins,// First parameter deserialized from the `payload`receiver:String,// Second parameter deserialized from the `payload`) -> Result<Response,ContractError>{}
This is because #[sv::payload] can be omitted. In case of the #[sv::data] it would require the user to either mark every attribute with the exact parameters in the sv::data attribute.
#[sv::data()]
Marks field to which data should be forwarded.
No #[sv::data]
The data not forwarded.
If no #[sv::data] attribute found in the method signature, Sylvia won't forward the data to the method so the data field should not be present at all.
#[sv::data(raw)]
Fails if the data is None. Extracts and forwards data: Binary if it's Some.
#[sv::data(raw, opt)]
Forwards data: Option<Binary>.
#[sv::data(opt)]
Expects data in the method signature to be data: Option<T> where T: Deserialize
Tries to deserialize data to type defined in the method signature and forwards it wrapped in the Option.
If data is:
None - forwards None
Some(valid) - forwards Some(valid)
Some(invalid) - early returns error specifying what went wrong with serde error attached.
#[sv::data]
Expects data in the method signature to be data: T where T: Deserialize
Tries to deserialize data to type defined in the method signature and forwards it.
If data is:
None - early returns error specifying the data is missing.
Some(valid) - forwards Some(valid)
Some(invalid) - early returns error specifying what went wrong with serde error attached.
Optional attribute variants for future development
#[sv::data(fallible)]
Expects data in the method signature to be data: Result<T, sylvia::DeserializeError> where T: Deserialize.
The sylvia::DeserializeError would have to implement From:
StdError
serde::Error
custom contract error - this might be tricky. Instead author of the contract might have to implement From on those types on their custom error.
Tries to deserialize data to type defined in the method signature and forwards it.
If data is:
None - early returns error specifying the data is missing.
As in case of payload we can provide a way to auto deserialize the payload in the dispatch so user won't have to.
Similary to payload we would mark the
data
with an attribute.The difference in this approach between handling
data
andpayload
would be the ability to deserialize thepayload
into separate fields like:This is because
#[sv::payload]
can be omitted. In case of the#[sv::data]
it would require the user to either mark every attribute with the exact parameters in thesv::data
attribute.#[sv::data()]
Marks field to which
data
should be forwarded.No #[sv::data]
The
data
not forwarded.If no
#[sv::data]
attribute found in the method signature, Sylvia won't forward thedata
to the method so thedata
field should not be present at all.#[sv::data(raw)]
Fails if the
data
isNone
. Extracts and forwardsdata: Binary
if it'sSome
.#[sv::data(raw, opt)]
Forwards
data: Option<Binary>
.#[sv::data(opt)]
Expects
data
in the method signature to bedata: Option<T> where T: Deserialize
Tries to deserialize
data
to type defined in the method signature and forwards it wrapped in theOption
.If
data
is:None
- forwardsNone
Some(valid)
- forwardsSome(valid)
Some(invalid)
- early returns error specifying what went wrong withserde
error attached.#[sv::data]
Expects
data
in the method signature to bedata: T where T: Deserialize
Tries to deserialize
data
to type defined in the method signature and forwards it.If
data
is:None
- early returns error specifying thedata
is missing.Some(valid)
- forwardsSome(valid)
Some(invalid)
- early returns error specifying what went wrong withserde
error attached.Optional attribute variants for future development
#[sv::data(fallible)]
Expects
data
in the method signature to bedata: Result<T, sylvia::DeserializeError> where T: Deserialize
.The
sylvia::DeserializeError
would have to implementFrom
:StdError
serde::Error
From
on those types on their custom error.Tries to deserialize
data
to type defined in the method signature and forwards it.If
data
is:None
- early returns error specifying thedata
is missing.Some(valid)
- forwardsOk(valid)
Some(invalid)
- forwardsErr(serde::Error)
#[sv::data(instantiate)]
Special case in which
parse_instantiate_response_data
would be called underneath and passed to the method.This should be handled the similar to
#[sv::data]
.#[sv::data(instantiate, opt)]
As in case of lone
instantiate
, but handled similar to#[sv::data(opt)]
.#[sv::payload]
To make the API concise we would change it's usage in case we don't want to deserialize the payload to be:
#[sv::payload(raw)]
.The text was updated successfully, but these errors were encountered: