sv::data attribute
Use sv::data
to specify if the
SubMsgResponse::data
(opens in a new tab)
field should be deserialized or not.
💡
To use sv::data
attribute pre Sylvia 2.0.0
, you need to enable the replies
feature using the
sv::features
.
Macros
List of macros supporting the sv::data
attribute:
Usage
pub struct Contract;
#[cfg_attr(feature = "library", sylvia::entry_points)]
#[contract]
#[sv::features(replies)]
impl Contract {
pub const fn new() -> Self {
Self
}
#[sv::msg(instantiate)]
fn instantiate(&self, ctx: InstantiateCtx) -> StdResult<Response> {
Ok(Response::new())
}
#[sv::msg(reply, handlers=[remote_instantiated], reply_on=success)]
fn store_remote_address(
&self,
ctx: ReplyCtx,
#[sv::data(instantiate)] data: MsgInstantiateContractResponse,
#[sv::payload(raw)] payload: Binary,
) -> StdResult<Response> {
Ok(Response::new())
}
}
Use the sv::data
next to the reply method argument. Based on the passed parameters it enables
different behavior:
Deserialize method | Some(invalid) | Some(valid) | None | |
---|---|---|---|---|
No sv::data | N/A | No data forwarded | No data forwarded | No data forwarded |
sv::data(raw) | N/A | Forwards Binary | Forwards Binary | Early returns no data error |
sv::data(raw, opt) | N/A | Forwards Option<Binary> | Forwards Option<Binary> | Forwards Option<Binary> |
sv::data | from_json (opens in a new tab) | Early returns deserialize error | Forwards deserialized data | Early returns no data error |
sv::data(opt) | from_json (opens in a new tab) | Early returns deserialize error | Forwards Option<DeserializedData> | Forwards None |
sv::data(instantiate) | parse_instantiate_response_data (opens in a new tab) | Early returns deserialize error | Forwards MsgInstantiateContractResponse (opens in a new tab) | Early returns no data error |
sv::data(instantiate, opt) | parse_instantiate_response_data (opens in a new tab) | Early returns deserialize error | Forwards Option<MsgInstantiateContractResponse> (opens in a new tab) | Forwards None |