Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate contract index duplication between commit objects #404

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"callcenter",
"initializer",
"counter",
"counter_float",
"debugger",
"double_counter",
"empty_initializer",
Expand Down
16 changes: 16 additions & 0 deletions contracts/counter_float/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "counter_float"
version = "0.1.0"
authors = [
"Kristoffer Ström <kristoffer@dusk.network>",
"Milosz Muszynski <milosz@dusk.network>",
]
edition = "2021"

license = "MPL-2.0"

[dependencies]
piecrust-uplink = { path = "../../piecrust-uplink", features = ["abi", "dlmalloc"] }

[lib]
crate-type = ["cdylib", "rlib"]
45 changes: 45 additions & 0 deletions contracts/counter_float/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

//! Contract to implement a simple counter that can be read and incremented by
//! one count.

#![no_std]

use piecrust_uplink as uplink;

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

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

impl Counter {
/// Read the value of the counter
pub fn read_value(&self) -> f64 {
self.value
}

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

/// Expose `Counter::read_value()` to the host
#[no_mangle]
unsafe fn read_value(arg_len: u32) -> u32 {
uplink::wrap_call_unchecked(arg_len, |_: ()| STATE.read_value())
}

/// Expose `Counter::increment()` to the host
#[no_mangle]
unsafe fn increment(arg_len: u32) -> u32 {
uplink::wrap_call_unchecked(arg_len, |_: ()| STATE.increment())
}
2 changes: 1 addition & 1 deletion piecrust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ categories = ["wasm", "no-std", "cryptography::cryptocurrencies"]
keywords = ["virtual", "machine", "smart", "contract", "wasm"]

repository = "https://github.com/dusk-network/piecrust"
version = "0.26.0"
version = "0.27.0-rc.0"

edition = "2021"
license = "MPL-2.0"
Expand Down
Loading