Commit 61c89eb8 authored by Hero Bird's avatar Hero Bird

[examples/fleet_inc] Add fleet_inc example

parent 5d7bc08f
[target.wasm32-unknown-unknown]
rustflags = [
"-C", "link-args=-z stack-size=65536 --import-memory"
]
[package]
name = "fleet-inc"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
pdsl_core = { path = "../../core" }
pdsl_model = { path = "../../model" }
parity-codec = { version = "2.2", default-features = false, features = ["derive"] }
[lib]
name = "fleet_inc"
crate-type = ["cdylib"]
[features]
default = []
test-env = [
"pdsl_core/test-env",
"pdsl_model/test-env",
]
[profile.release]
panic = "abort"
lto = true
opt-level = "z"
#!/bin/bash
# The wasm-build executable that is used to tree-shake the wasm binary
# resulting from the cargo build in the first step expects to find it
# under target/release/wasm32-unknown-unknown/ in the cwd.
cargo +nightly build --release --target=wasm32-unknown-unknown --verbose
wasm-build target fleet_inc --target-runtime=substrate --final=fleet_inc --save-raw=./target/fleet_inc-deployed.wasm --target wasm32-unknown-unknown
#![no_std]
#![feature(const_str_as_bytes)]
use pdsl_model::{
ContractDecl,
Contract,
state,
messages,
};
use pdsl_core::storage;
state! {
/// A simple contract having just one value that can be incremented and returned.
struct Adder {
/// The simple value on the contract storage.
val: storage::Value<u32>
}
}
messages! {
/// Increases the storage value by the given amount.
0 => Inc(by: u32);
/// Returns the storage value.
1 => Get() -> u32;
}
fn instantiate() -> impl Contract {
ContractDecl::new::<Adder>()
.on_deploy(|env, init_val| {
env.state.val.set(init_val)
})
.on_msg_mut::<Inc>(|env, by| {
env.state.val += by
})
.on_msg::<Get>(|env, _| {
*env.state.val.get()
})
.instantiate()
}
#[no_mangle]
fn deploy() {
instantiate().deploy()
}
#[no_mangle]
fn call() {
instantiate().dispatch()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment