...
 
Commits (7)
......@@ -30,7 +30,7 @@ pub fn create(
create_data: &[u8],
) -> RetCode {
unsafe {
sys::ext_create(
sys::ext_instantiate(
code_hash.as_ptr() as u32,
code_hash.len() as u32,
gas_limit,
......@@ -165,7 +165,7 @@ pub fn println(content: &str) {
mod sys {
extern "C" {
pub fn ext_create(
pub fn ext_instantiate(
init_code_ptr: u32,
init_code_len: u32,
gas: u64,
......
......@@ -320,7 +320,7 @@ where
// the result value.
let req_len = ext::scratch_size();
buffer.enlarge_to(req_len);
let ret = ext::scratch_read(buffer.as_mut(), 0);
let ret = ext::scratch_read(&mut buffer.as_mut()[0..req_len], 0);
if !ret.is_success() {
return Err(Error::InvalidContractInstantiationReturn)
}
......
fn main() -> Result<(), std::io::Error> {
let abi = contract::ink_generate_abi();
let abi = <contract::Delegator as ink_lang2::GenerateAbi>::generate_abi();
let contents = serde_json::to_string_pretty(&abi)?;
std::fs::create_dir("target").ok();
std::fs::write("target/abi.json", contents)?;
......
#!/usr/bin/env
#!/usr/bin/env bash
pushd accumulator && cargo contract build && popd &&
pushd adder && cargo contract build && popd &&
......
......@@ -94,6 +94,11 @@ mod delegator {
self.adder.set(adder.clone());
self.subber.set(subber.clone());
}
/// Returns the accumulator's value.
#[ink(message)]
fn get(&self) -> i32 {
self.accumulator.get().get()
}
/// Delegates the call to either `Adder` or `Subber`.
#[ink(message)]
......@@ -105,6 +110,7 @@ mod delegator {
}
/// Switches the delegator.
#[ink(message)]
fn switch(&mut self) {
match *self.which {
Which::Adder => {
......
......@@ -72,6 +72,16 @@ mod erc20 {
self.balance_of_or_zero(&owner)
}
#[ink(message)]
fn allowance(
&self,
owner: AccountId,
spender: AccountId,
) -> Balance {
let allowance = self.allowance_of_or_zero(&owner, &spender);
allowance
}
#[ink(message)]
fn transfer(&mut self, to: AccountId, amount: Balance) -> bool {
let from = self.env().caller();
......
[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 = "incrementer", default-features = false, features = ["ink-generate-abi"] }
ink_lang2 = { path = "../../../../../lang2", default-features = false, features = ["ink-generate-abi"] }
serde = "1.0"
serde_json = "1.0"
fn main() -> Result<(), std::io::Error> {
let abi = <contract::Incrementer as ink_lang2::GenerateAbi>::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 = "incrementer"
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_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 = "incrementer"
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",
"scale/std",
"type-metadata/std",
]
test-env = [
"std",
"ink_core/test-env",
"ink_lang2/test-env",
]
ink-generate-abi = [
"std",
"ink_abi",
"type-metadata",
"ink_core/ink-generate-abi",
"ink_lang2/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::storage;
use ink_lang2 as ink;
#[ink::contract(version = "0.1.0")]
mod incrementer {
#[ink(storage)]
struct Incrementer {
value: storage::Value<i32>,
}
impl Incrementer {
#[ink(constructor)]
fn new(&mut self, init_value: i32) {
self.value.set(init_value);
}
#[ink(constructor)]
fn default(&mut self) {
self.new(0)
}
#[ink(message)]
fn inc(&mut self, by: i32) {
*self.value += by;
}
#[ink(message)]
fn get(&self) -> i32 {
*self.value
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_works() {
let contract = Incrementer::default();
assert_eq!(contract.get(), 0);
}
#[test]
fn it_works() {
let mut contract = Incrementer::new(42);
assert_eq!(contract.get(), 42);
contract.inc(5);
assert_eq!(contract.get(), 47);
contract.inc(-50);
assert_eq!(contract.get(), -3);
}
}
}
......@@ -145,6 +145,10 @@ impl CrossCalling<'_> {
quote! {
#( #attrs )*
#[derive(Clone, Debug, scale::Encode, scale::Decode)]
#[cfg_attr(
feature = "ink-generate-abi",
derive(type_metadata::Metadata)
)]
pub struct StorageAsDependency {
account_id: AccountId,
}
......@@ -160,6 +164,27 @@ impl CrossCalling<'_> {
}
}
#[cfg(feature = "ink-generate-abi")]
impl ink_core::storage::alloc::AllocateUsing for StorageAsDependency {
unsafe fn allocate_using<A>(alloc: &mut A) -> Self
where
A: ink_core::storage::alloc::Allocate,
{
// We don't want to carry this implementation arround.
// Please remove as soon as possible.
unimplemented!()
}
}
#[cfg(feature = "ink-generate-abi")]
impl ink_abi::HasLayout for StorageAsDependency {
fn layout(&self) -> ink_abi::StorageLayout {
ink_abi::LayoutStruct::new(
<Self as type_metadata::Metadata>::meta_type(), vec![]
).into()
}
}
impl ink_core::env2::call::FromAccountId<Env> for StorageAsDependency {
#[inline]
fn from_account_id(account_id: AccountId) -> Self {
......
......@@ -175,7 +175,7 @@ impl Storage<'_> {
impl ink_core::storage::Flush for Storage {
fn flush(&mut self) {
#(
self.#field_idents.flush();
ink_core::storage::Flush::flush(&mut self.#field_idents);
)*
}
}
......@@ -264,11 +264,13 @@ impl Storage<'_> {
impl ink_core::storage::Flush for StorageAndEnv {
fn flush(&mut self) {
self.__storage.flush();
self.__env.flush();
ink_core::storage::Flush::flush(&mut self.__storage);
ink_core::storage::Flush::flush(&mut self.__env);
}
}
impl ink_core::storage::alloc::Initialize for StorageAndEnv {
type Args = ();
......@@ -277,8 +279,8 @@ impl Storage<'_> {
}
fn initialize(&mut self, _args: Self::Args) {
self.__storage.try_default_initialize();
self.__env.try_default_initialize();
ink_core::storage::alloc::Initialize::try_default_initialize(&mut self.__storage);
ink_core::storage::alloc::Initialize::try_default_initialize(&mut self.__env);
}
}
......