signed_execute_one

Attribute Macro signed_execute_one 

Source
#[signed_execute_one]
Expand description

Procedural macro for the CW84 standard that injects execute variants for signed message execution into an execute enum, supporting both generic and non-generic CosmosMsg types.

This macro extends an enum with standardized execute variants for smart accounts as defined in the CW84 specification. It checks if the input enum is generic over T and adjusts the Execute variant to use CosmosMsg<T> or CosmosMsg accordingly. The macro supports custom types for the inner action message and signed data, enabling execution of a single signed message.

§Arguments

The macro accepts zero to two type arguments via the attribute:

  • First type (optional): The inner action message type (e.g., ExecuteMsg) for the ExecuteSigned variant. Defaults to the enum’s own type if not provided.
  • Second type (optional): The signed data type (e.g., SignedDataMsg) for the ExecuteSigned variant. Defaults to cosmwasm_std::Binary if not provided.

§Generated Variants

The macro injects the following execute variants:

  • Execute: Executes a list of CosmosMsg messages by a smart account.
  • ExecuteSigned: Executes a single signed message, using the provided action and data types.

§Notes

  • The #[signed_execute] attribute must be applied before #[cw_serde] or other derive macros.
  • Unlike query macros, this macro does not require #[derive(QueryResponses)] since it targets execute messages.
  • This macro is designed for single-message execution, in contrast to signed_execute_multi, which supports multiple messages in the ExecuteSigned variant.

§Examples

§Example 1: Basic usage with no arguments

use cosmwasm_schema::cw_serde;

#[cw_serde]
#[signed_execute]
pub enum ExecuteMsg {
    // User-defined execute messages
}

// Generated:
// pub enum ExecuteMsg {
//     // User-defined execute messages
//
//     Execute {
//         msgs: Vec<::cosmwasm_std::CosmosMsg>,
//     },
//
//     ExecuteSigned {
//         msg: Box<ExecuteMsg>,
//         signed: ::cosmwasm_std::Binary,
//         nonce: Option<::cosmwasm_std::Uint64>,
//     },
// }

§Example 2: Usage with a custom execute message type

#[cw_serde]
pub enum InnerActionMsg {
    Foo {},
}

#[signed_execute(InnerActionMsg)]
#[cw_serde]
pub enum ExecuteMsg {
    // User-defined execute messages
}

// Generated:
// pub enum ExecuteMsg {
//     // User-defined execute messages
//
//     Execute {
//         msgs: Vec<::cosmwasm_std::CosmosMsg>,
//     },
//
//     ExecuteSigned {
//         msg: InnerActionMsg,
//         signed: ::cosmwasm_std::Binary,
//         nonce: Option<::cosmwasm_std::Uint64>,
//     },
// }

§Example 3: Usage with custom execute and signed data types

#[cw_serde]
pub struct SignedDataMsg {
    pub data: String,
    pub signature: String,
}

#[signed_execute(InnerActionMsg, SignedDataMsg)]
#[cw_serde]
pub enum ExecuteMsgSigned {
    // User-defined execute messages
}

// Generated:
// pub enum ExecuteMsgSigned {
//     // User-defined execute messages
//
//     Execute {
//         msgs: Vec<::cosmwasm_std::CosmosMsg>,
//     },
//
//     ExecuteSigned {
//         msg: InnerActionMsg,
//         signed: SignedDataMsg,
//         nonce: Option<::cosmwasm_std::Uint64>,
//     },
// }

§Example 4: Generic enum with custom types

#[signed_execute(InnerActionMsg, SignedDataMsg)]
#[cw_serde]
pub enum ExecuteMsgCustom<T> {
    // User-defined execute messages
}

// Generated:
// pub enum ExecuteMsgCustom<T> {
//     // User-defined execute messages
//
//     Execute {
//         msgs: Vec<::cosmwasm_std::CosmosMsg<T>>,
//     },
//
//     ExecuteSigned {
//         msg: InnerActionMsg,
//         signed: SignedDataMsg,
//         nonce: Option<::cosmwasm_std::Uint64>,
//     },
// }

§Errors

  • Fails with a compile-time error if the attribute arguments are invalid (e.g., not a type path or more than two arguments).
  • Fails if the input is not a valid enum or if the merge with generated variants cannot be performed.

This macro is part of the CW84 specification for smart account signed message execution.