Attribute Macro pbc_contract_codegen::state

source ·
#[state]
Expand description

State contract annotation

REQUIRED ANNOTATION: This is a required annotation. A contract cannot be created without a state.

Declares that the annotated struct is the top level of the contract state. This macro must occur exactly once in any given contract.

§Example

#[state]
pub struct VotingContractState {
    proposal_id: u64,
    mp_addresses: Vec<Address>,
    votes: SortedVecMap<Address, u8>,
    closed: u8,
}

This macro implicitly derives ReadWriteState for the struct. The ReadWriteState derive may fail if any of the state struct’s fields aren’t impl ReadWriteState.

Furthermore, note that state serialization speeds are heavily affected by the types contained in the state struct. Types with dynamic sizes (Option<T>, String) are especially slow. For more background, see ReadWriteState::SERIALIZABLE_BY_COPY