Skip to main content

Crate miden_base_macros

Crate miden_base_macros 

Source
Expand description

Module for Miden SDK macros

§How to use WIT generation.

  1. Add #[component] on you impl MyAccountType {.
  2. Add #[export_type] on every defined type that is used in the public(exported) method signature.

Example:


#[export_type]
pub struct StructA {
    pub foo: Word,
    pub asset: Asset,
}

#[export_type]
pub struct StructB {
    pub bar: Felt,
    pub baz: Felt,
}

#[component]
struct MyAccount;

#[component]
impl MyAccount {
    pub fn foo(&self, a: StructA) -> StructB {
        ...
    }
}

§Escape hatch (disable WIT generation)

in a small fraction of the cases where the WIT generation is not possible (think a type defined only in an external WIT file) or not desirable the WIT generation can be disabled:

To disable WIT interface generation:

  • Don’t use #[component] attribute macro in the impl MyAccountType section;

To use manually crafted WIT interface:

  • Put the WIT file in the wit folder;
  • call miden::generate!(); and bindings::export!(MyAccountType);
  • implement impl Guest for MyAccountType;

Macros§

generate
Generate bindings for an input WIT document.

Attribute Macros§

component
Generates the WIT interface and storage metadata.
export_type
Generates an equvalent type in the WIT interface. Required for every type mentioned in the public methods of an account component.
note
Marks a type/impl as a note script definition.
note_script
Marks a method as the note script entrypoint (#[note_script]).
tx_script
Marks the function as a transaction script