#macro #dusk #automatic #generate #wrapper #self #piecrust

nightly macro piecrust-macros

Macro library for the Dusk Piecrust VM

1 unstable release

0.1.0 Jan 2, 2024

#16 in #dusk

MPL-2.0 license

9KB
65 lines

π-crust Macros

Repository Documentation

piecrust-macros is a macro library designed to simplify the development of smart contracts for Dusk's Piecrust virtual machine. It provides macros to automatically generate the boilerplate code required for interfacing smart contracts with the Piecrust VM.

Usage

The main feature of piecrust-macros is the #[contract] attribute macro. This macro automatically generates wrapper functions required for interfacing with the Piecrust VM, reducing boilerplate code in your project.

Add piecrust_macros as a dependency to your contract project:

cargo install piecrust_macros

To use the macro, import it into your Rust smart contract and annotate your contract's implementation with #[contract]:

#![no_std]

use piecrust_macros::contract;

/// Struct that describes the state of the Counter contract
pub struct Counter {
    value: i64,
}

/// State of the Counter contract
static mut STATE: Counter = Counter { value: 0xfc };

#[contract]
impl Counter {
    /// Read the value of the counter
    pub fn read_value(&self) -> i64 {
        self.value
    }

    /// Increment the value of the counter by 1
    pub fn increment(&mut self) {
        let value = self.value + 1;
        self.value = value;
    }
}

With #[contract], the macro automatically generates the necessary wrapper functions for each public method in the impl block you want to expose.

Release History

To see the release history for this crate, please see the CHANGELOG file.

License

This code is licensed under the Mozilla Public License Version 2.0 (MPL-2.0). Please see the LICENSE for further details.

Contribute

If you want to contribute to this project, feel free to open an issue, fork the repository and open a pull request.

Dependencies

~4MB
~87K SLoC