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 methodSome(invalid)Some(valid)None
No sv::dataN/ANo data forwardedNo data forwardedNo data forwarded
sv::data(raw)N/AForwards BinaryForwards BinaryEarly returns no data error
sv::data(raw, opt)N/AForwards Option<Binary>Forwards Option<Binary>Forwards Option<Binary>
sv::datafrom_json (opens in a new tab)Early returns deserialize errorForwards deserialized dataEarly returns no data error
sv::data(opt)from_json (opens in a new tab)Early returns deserialize errorForwards Option<DeserializedData>Forwards None
sv::data(instantiate)parse_instantiate_response_data (opens in a new tab)Early returns deserialize errorForwards 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 errorForwards Option<MsgInstantiateContractResponse> (opens in a new tab)Forwards None