sv::attr attribute

Use sv::attr to forward an external attribute to the generated message variant.

Macros

List of macros supporting the sv::attr attribute:

Usage

Use the sv::attr above any of the methods marked with #[sv::msg(exec|sudo|query)] attribute.

use sylvia::contract;
use sylvia::cw_std::{Response, StdResult};
use sylvia::types::{ExecCtx, InstantiateCtx};
 
pub struct MyContract;
 
#[contract]
impl Contract {
    pub fn new() -> Self {
        Self
    }
 
    #[sv::msg(instantiate)]
    fn instantiate(&self, ctx: InstantiateCtx) -> StdResult<Response> {
        Ok(Response::new())
    }
 
    #[sv::msg(exec)]
    #[sv::attr(serde(rename = "execute"))]
    fn exec(&self, ctx: ExecCtx) -> StdResult<Response> {
        Ok(Response::new())
    }
}

The contract and interface macros will decorate the message variant with the attribute provided in sv::attr.

pub enum ExecMsg {
    #[serde(rename = "execute")]
    Exec {},
}