piecrust-macros

Crates.iopiecrust-macros
lib.rspiecrust-macros
version0.1.0
sourcesrc
created_at2024-01-02 17:11:23.611461
updated_at2024-01-02 17:11:23.611461
descriptionMacro library for the Dusk Piecrust VM
homepage
repository
max_upload_size
id1086454
size25,298
Hein Dauven (HDauven)

documentation

README

π-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.

Commit count: 0

cargo fmt