Crates.io | piecrust-uplink |
lib.rs | piecrust-uplink |
version | 0.17.1 |
source | src |
created_at | 2023-02-06 10:29:16.358016 |
updated_at | 2024-09-24 12:45:21.708678 |
description | Build smart contracts directly on top of Dusk's `piecrust` virtual machine. |
homepage | |
repository | https://github.com/dusk-network/piecrust |
max_upload_size | |
id | 777844 |
size | 55,892 |
Piecrust Uplink is the library that allows you to build smart contracts directly on top of Dusk's Piecrust virtual machine.
The library allows users of the contract platform to manage the interface and state with the host environment of the contracts. The example below describes a barebones contract. For more detailed examples, see the contracts folder.
Add piecrust_uplink
as a dependency to your contract project:
cargo add piecrust_uplink
To make use of uplink
, import the dependency in your project and mark it as no_std
:
#![no_std]
use piecrust_uplink as uplink;
To attach state to a contract:
/// Struct that describe the state for your contract
pub struct Counter {
value: i64,
};
/// State of the contract
static mut STATE: Counter = Counter { value: 0x1 };
To define logic for your contract, define an implementation:
impl Counter {
pub fn read_value(&self) -> i64 {
self.value
}
pub fn increment(&mut self) {
let value = self.value + 1;
}
}
Read and write operations need to be exposed to the host. Add the following below the implementation:
unsafe fn read_value(arg_len: u32) -> u32 {
uplink::wrap_call(arg_len, |_: ()| STATE.read_value())
}
#[no_mangle]
unsafe fn increment(arg_len: u32) -> u32 {
uplink::wrap_call(arg_len, |panic: bool| STATE.increment(panic))
}
To see the release history for this crate, please see the CHANGELOG file.
This code is licensed under the Mozilla Public License Version 2.0 (MPL-2.0). Please see the LICENSE for further details.
If you want to contribute to this project, please check the CONTRIBUTING file.