Commit e82d9a0d authored by Robin Freyler's avatar Robin Freyler

[examples/lang] remove all lang 1.0 examples

parent b9b9a9b3
Pipeline #56484 failed with stages
in 1 minute and 51 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 = "delegator", 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 = "delegator"
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 }
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 }
adder = { path = "adder", default-features = false, features = ["ink-as-dependency"] }
subber = { path = "subber", default-features = false, features = ["ink-as-dependency"] }
accumulator = { path = "accumulator", default-features = false, features = ["ink-as-dependency"] }
[lib]
name = "delegator"
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",
"adder/std",
"subber/std",
"accumulator/std",
]
test-env = [
"std",
"ink_core/test-env",
"ink_model/test-env",
"ink_lang/test-env",
"type-metadata/std",
"adder/test-env",
"subber/test-env",
"accumulator/test-env",
]
ink-generate-abi = [
"std",
"ink_abi",
"type-metadata",
"ink_core/ink-generate-abi",
"adder/ink-generate-abi",
"subber/ink-generate-abi",
"accumulator/ink-generate-abi",
]
ink-as-dependency = []
[profile.release]
panic = "abort"
lto = true
opt-level = "z"
overflow-checks = true
[workspace]
members = [
".ink/abi_gen",
"accumulator",
"adder",
"subber",
]
exclude = [
".ink"
]
# Delegator Smart Contract
The delegator smart contract is our showcase for executing other smart contracts on-chain.
It consists in total of 4 different smart contract:
- Delegator (root): Delegates calls either to the Adder or Subber smart contract
- Adder: Increases a value in the Accumulator smart contract
- Subber: Decreases a value in the Accumulator smart contract
- Accumulator: Owns a simple `i32` value that can be incremented or decremented
In order to test this bundle of smart contracts you need to do the following:
1. Compile all dependencies of the Delegator smart contract using the `./build-all.sh` script.
As usual you will receive their respective Wasm blobs in their respective `target` folders.
1. Go to the delegator directory (root of the example) and run `cargo run -p abi-gen` in order
to generate the ABI file for the Delegator smart contract.
Note: You won't need an ABI file for the other smart contracts since we won't operate on them
using the Polkadot UI.
1. Put the Wasm blobs of Accumulator, Adder, Subber and the Delegator on the chain via `put_code` command.
While doing so note down their respective code hashes that you can inspect by extracting this information
out from the signalling events upon putting the code on the chain.
1. Instantiate the Delegator smart contract given all of the code hashes and a starting value.
The Delegator smart contract will take over the work of instantiating the other smart contracts for you.
1. Now you are able to run the operations provided by the Delegator smart contract.
Namely `delegate` to delegate the call to either the Adder or the Subber to either increase or decrease
the value stored in the Accumulator smart contract respectively and `switch` to switch the currently
delegated-to smart contract.
The initial delegated-to smart contract is the Adder.
[package]
name = "accumulator"
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 }
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 = "accumulator"
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",
"type-metadata/std",
]
ink-generate-abi = [
"std",
"ink_abi",
"type-metadata",
"ink_core/ink-generate-abi",
"ink_lang/ink-generate-abi",
]
ink-as-dependency = []
// 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/>.
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_lang::contract;
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
/// Holds a simple i32 value that can be incremented and decremented.
struct Accumulator {
/// The current value.
value: storage::Value<i32>,
}
impl Deploy for Accumulator {
/// Initializes the value to the initial value.
fn deploy(&mut self, init_value: i32) {
self.value.set(init_value)
}
}
impl Accumulator {
/// Mutates the internal value.
pub(external) fn inc(&mut self, by: i32) {
self.value += by;
}
/// Returns the current state.
pub(external) fn get(&self) -> i32 {
*self.value
}
}
}
[package]
name = "adder"
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 }
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 }
accumulator = { path = "../accumulator", default-features = false, features = ["ink-as-dependency"] }
[lib]
name = "adder"
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",
"accumulator/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",
"accumulator/ink-generate-abi",
]
ink-as-dependency = []
// 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/>.
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_lang::contract;
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
/// Increments the accumulator's value.
struct Adder {
/// The accumulator to store values.
accumulator: storage::Value<accumulator::Accumulator>,
}
impl Deploy for Adder {
fn deploy(&mut self, accumulator: AccountId) {
self.accumulator.set(accumulator::Accumulator::from_account_id(accumulator));
}
}
impl Adder {
/// Flips the current state of our smart contract.
pub(external) fn inc(&mut self, by: i32) {
self.accumulator.inc(by);
}
}
}
#!/bin/bash
pushd accumulator && cargo contract build && popd &&
pushd adder && cargo contract build && popd &&
pushd subber && cargo contract build && popd &&
cargo contract build
// 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/>.
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_lang::contract;
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "ink-generate-abi", derive(type_metadata::Metadata))]
pub enum Which {
Adder,
Subber,
}
impl ink_core::storage::Flush for Which {
fn flush(&mut self) {}
}
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
/// Delegates calls to an adder or subber contract to mutate
/// a value in an accumulator contract.
///
/// In order to deploy the delegator smart contract we first
/// have to manually put the code of the accumulator, adder
/// and subber smart contracts, receive their code hashes from
/// the signalled events and put their code hash into our
/// delegator smart contract.
struct Delegator {
/// Says which of adder or subber is currently in use.
which: storage::Value<Which>,
/// The accumulator smart contract.
accumulator: storage::Value<accumulator::Accumulator>,
/// The adder smart contract.
adder: storage::Value<adder::Adder>,
/// The subber smart contract.
subber: storage::Value<subber::Subber>,
}
impl Deploy for Delegator {
/// Initializes the value to the initial value.
fn deploy(
&mut self,
init_value: i32,
accumulator_code_hash: Hash,
adder_code_hash: Hash,
subber_code_hash: Hash,
) {
self.which.set(Which::Adder);
let total_balance = env.balance();
let accumulator = accumulator::Accumulator::new(accumulator_code_hash, init_value)
.value(total_balance / 4)
.create()
.expect("failed at instantiating the accumulator contract");
self.accumulator.set(accumulator.clone());
self.adder.set(
adder::Adder::new(adder_code_hash, accumulator.account_id())
.value(total_balance / 4)
.create()
.expect("failed at instantiating the adder contract")
);
self.subber.set(
subber::Subber::new(subber_code_hash, accumulator.account_id())
.value(total_balance / 4)
.create()
.expect("failed at instantiating the subber contract")
);
}
}
impl Delegator {
/// Delegates the call.
pub(external) fn delegate(&mut self, by: i32) {
match &*self.which {
Which::Adder => self.adder.inc(by),
Which::Subber => self.subber.dec(by),
}
}
/// Switches the delegator.
pub(external) fn switch(&mut self) {
match *self.which {
Which::Adder => {
*self.which = Which::Subber;
}
Which::Subber => {
*self.which = Which::Adder;
}
}
}
}
}
[package]
name = "subber"
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 }
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 }
accumulator = { path = "../accumulator", default-features = false, features = ["ink-as-dependency"] }
[lib]
name = "subber"
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",
"type-metadata/std",
]
ink-generate-abi = [
"std",
"ink_abi",
"type-metadata",
"ink_core/ink-generate-abi",
"ink_lang/ink-generate-abi",
]
ink-as-dependency = []
// 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/>.
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_lang::contract;
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
/// Decrements the accumulator's value.
struct Subber {
/// The accumulator to store values.
accumulator: storage::Value<accumulator::Accumulator>,
}
impl Deploy for Subber {
fn deploy(&mut self, accumulator: AccountId) {
self.accumulator.set(accumulator::Accumulator::from_account_id(accumulator));
}
}
impl Subber {
pub(external) fn dec(&mut self, by: i32) {
self.accumulator.inc(-by);
}
}
}
[target.wasm32-unknown-unknown]
rustflags = [
"-C", "link-args=-z stack-size=65536 --import-memory"
]
[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 = "erc20", 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 = "erc20"
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 }
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 = "erc20"
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",
"type-metadata/std",
"scale/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/>.
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
env::DefaultSrmlTypes,
memory::format,
storage,
};
use ink_lang::contract;
use ink_model::EnvHandler;
contract! {
#![env = DefaultSrmlTypes]
// Event deposited when a token transfer occurs
event Transfer {
from: Option<AccountId>,
to: Option<AccountId>,
value: Balance,
}
// Event deposited when an approval occurs
event Approval {
owner: AccountId,
spender: AccountId,
value: Balance,
}
/// The storage items for a typical ERC20 token implementation.