[lang2] add lang2 flipper contract example for testing purposes

parent f607d69c
Pipeline #53357 failed with stages
in 5 minutes and 11 seconds
[target.wasm32-unknown-unknown]
rustflags = [
"-C", "link-args=-z stack-size=65536 --import-memory"
]
\ No newline at end of file
# Ignore build artifacts from the local tests sub-crate.
/target/
# Ignore backup files creates by cargo fmt.
**/*.rs.bk
# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
\ No newline at end of file
[package]
name = "abi-gen"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
publish = false
[[bin]]
name = "abi-gen"
path = "main.rs"
[dependencies]
contract = { path = "../..", package = "flipper", features = ["ink-generate-abi"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
fn main() -> Result<(), std::io::Error> {
let abi = contract::ink_generate_abi();
let contents = serde_json::to_string_pretty(&abi)?;
std::fs::create_dir("target").ok();
std::fs::write("target/abi.json", contents)?;
Ok(())
}
[package]
name = "flipper"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
ink_abi = { path = "../../../abi", default-features = false, features = ["derive"], optional = true }
ink_core = { path = "../../../core", default-features = false }
ink_model = { path = "../../../model", default-features = false }
ink_lang = { path = "../../../lang", default-features = false }
ink_lang2 = { path = "../../../lang2", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
[lib]
name = "flipper"
crate-type = [
# Used for normal contract Wasm blobs.
"cdylib",
# Used for ABI generation.
"rlib",
]
[features]
default = ["test-env"]
std = [
"ink_abi/std",
"ink_core/std",
"ink_model/std",
"ink_lang/std",
"scale/std",
"type-metadata/std",
]
test-env = [
"std",
"ink_core/test-env",
"ink_model/test-env",
"ink_lang/test-env",
]
ink-generate-abi = [
"std",
"ink_abi",
"type-metadata",
"ink_core/ink-generate-abi",
"ink_lang/ink-generate-abi",
]
ink-as-dependency = []
[profile.release]
panic = "abort"
lto = true
opt-level = "z"
overflow-checks = true
[workspace]
members = [
".ink/abi_gen"
]
exclude = [
".ink"
]
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
// This file is part of ink!.
//
// ink! is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ink! is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ink!. If not, see <http://www.gnu.org/licenses/>.
#![feature(proc_macro_hygiene)]
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
env::DefaultSrmlTypes,
memory::format,
storage,
};
use ink_lang2 as ink;
#[ink::contract(
env = DefaultSrmlTypes,
version = "0.1.0",
)]
mod flipper {
#[ink(storage)]
struct Flipper {
value: storage::Value<bool>,
}
impl Flipper {
#[ink(constructor)]
fn new(&mut self, init_value: bool) {
self.value.set(init_value);
}
#[ink(constructor)]
fn default(&mut self) {
self.new(false)
}
#[ink(message)]
fn flip(&mut self) {
*self.value = !self.get();
}
#[ink(message)]
fn get(&self) -> bool {
*self.value
}
}
}
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