From 09e8ec1ef62ad7ef20dbf845b30927bf084abffe Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 16 Jun 2021 19:41:36 +0200 Subject: [PATCH 1/8] Enable debug output for `contract-transfer` example It uses `debug_println!`. --- examples/contract-transfer/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/contract-transfer/Cargo.toml b/examples/contract-transfer/Cargo.toml index af2a7fb5c2..46fc674aaf 100644 --- a/examples/contract-transfer/Cargo.toml +++ b/examples/contract-transfer/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] ink_primitives = { version = "3.0.0-rc3", path = "../../crates/primitives", default-features = false } ink_metadata = { version = "3.0.0-rc3", path = "../../crates/metadata", default-features = false, features = ["derive"], optional = true } -ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false } +ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false, features = [ "ink-debug" ] } ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false } ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false } ink_prelude = { version = "3.0.0-rc3", path = "../../crates/prelude", default-features = false } From 9b051d2c388522a69db3dac64287fa07d5955805 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 16 Jun 2021 19:42:03 +0200 Subject: [PATCH 2/8] Enable sending payments to `fn invoke_transaction()` It needs to be possible to send value with the transaction, because `t.transferred_value` in this function could be set to > 0. --- examples/multisig_plain/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/multisig_plain/lib.rs b/examples/multisig_plain/lib.rs index 590f2685ef..e5ca81466f 100755 --- a/examples/multisig_plain/lib.rs +++ b/examples/multisig_plain/lib.rs @@ -486,7 +486,7 @@ mod multisig_plain { /// /// Its return value indicates whether the called transaction was successful. /// This can be called by anyone. - #[ink(message)] + #[ink(message, payable)] pub fn invoke_transaction( &mut self, trans_id: TransactionId, From cca614b0607e0c82f9e4f2cf01a94bc703cbb9bf Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 16 Jun 2021 19:46:01 +0200 Subject: [PATCH 3/8] Rename `Error::UnknownError` to `Error::Unknown` Clippy fails otherwise: = note: `-D clippy::enum-variant-names` implied by `-D warnings` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names --- crates/engine/src/ext.rs | 4 ++-- crates/env/src/engine/experimental_off_chain/impls.rs | 2 +- crates/env/src/engine/on_chain/ext.rs | 4 ++-- crates/env/src/engine/on_chain/impls.rs | 2 +- crates/env/src/error.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/ext.rs b/crates/engine/src/ext.rs index 0ae04076f3..df916e8896 100644 --- a/crates/engine/src/ext.rs +++ b/crates/engine/src/ext.rs @@ -50,7 +50,7 @@ macro_rules! define_error_codes { $name = $discr, )* /// Returns if an unknown error was received from the host module. - UnknownError, + Unknown, } impl From for Result { @@ -61,7 +61,7 @@ macro_rules! define_error_codes { $( $discr => Err(Error::$name), )* - _ => Err(Error::UnknownError), + _ => Err(Error::Unknown), } } } diff --git a/crates/env/src/engine/experimental_off_chain/impls.rs b/crates/env/src/engine/experimental_off_chain/impls.rs index 3c627c7b04..acf4128c02 100644 --- a/crates/env/src/engine/experimental_off_chain/impls.rs +++ b/crates/env/src/engine/experimental_off_chain/impls.rs @@ -102,7 +102,7 @@ impl CryptoHash for Keccak256 { impl From for crate::Error { fn from(ext_error: ext::Error) -> Self { match ext_error { - ext::Error::UnknownError => Self::UnknownError, + ext::Error::Unknown => Self::Unknown, ext::Error::CalleeTrapped => Self::CalleeTrapped, ext::Error::CalleeReverted => Self::CalleeReverted, ext::Error::KeyNotFound => Self::KeyNotFound, diff --git a/crates/env/src/engine/on_chain/ext.rs b/crates/env/src/engine/on_chain/ext.rs index d621247bef..33c74eb30b 100644 --- a/crates/env/src/engine/on_chain/ext.rs +++ b/crates/env/src/engine/on_chain/ext.rs @@ -35,7 +35,7 @@ macro_rules! define_error_codes { $name = $discr, )* /// Returns if an unknown error was received from the host module. - UnknownError, + Unknown, } impl From for Result { @@ -46,7 +46,7 @@ macro_rules! define_error_codes { $( $discr => Err(Error::$name), )* - _ => Err(Error::UnknownError), + _ => Err(Error::Unknown), } } } diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 0e426cf46f..d3fc2da3a3 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -101,7 +101,7 @@ impl CryptoHash for Keccak256 { impl From for Error { fn from(ext_error: ext::Error) -> Self { match ext_error { - ext::Error::UnknownError => Self::UnknownError, + ext::Error::Unknown => Self::Unknown, ext::Error::CalleeTrapped => Self::CalleeTrapped, ext::Error::CalleeReverted => Self::CalleeReverted, ext::Error::KeyNotFound => Self::KeyNotFound, diff --git a/crates/env/src/error.rs b/crates/env/src/error.rs index babd7c2e74..fd47ce0f53 100644 --- a/crates/env/src/error.rs +++ b/crates/env/src/error.rs @@ -45,7 +45,7 @@ pub enum Error { /// The account that was called is either no contract (e.g. user account) or is a tombstone. NotCallable, /// An unknown error has occurred. - UnknownError, + Unknown, /// The call to `seal_debug_message` had no effect because debug message /// recording was disabled. LoggingDisabled, From 690bbdd6a7767837da6c14e556c501a4bb585f00 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 17 Jun 2021 08:17:00 +0200 Subject: [PATCH 4/8] Revert "Enable sending payments to `fn invoke_transaction()`" This reverts commit 9b051d2c388522a69db3dac64287fa07d5955805. --- examples/multisig_plain/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/multisig_plain/lib.rs b/examples/multisig_plain/lib.rs index e5ca81466f..590f2685ef 100755 --- a/examples/multisig_plain/lib.rs +++ b/examples/multisig_plain/lib.rs @@ -486,7 +486,7 @@ mod multisig_plain { /// /// Its return value indicates whether the called transaction was successful. /// This can be called by anyone. - #[ink(message, payable)] + #[ink(message)] pub fn invoke_transaction( &mut self, trans_id: TransactionId, From 2d4368c9cf9c30764da4920ca3d0803da4583204 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 17 Jun 2021 09:11:00 +0200 Subject: [PATCH 5/8] Require sending transaction payment to `fn invoke_transaction()` It needs to be possible to send value with the transaction, because `t.transferred_value` in this function could be set to > 0. --- examples/multisig_plain/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/multisig_plain/lib.rs b/examples/multisig_plain/lib.rs index 590f2685ef..9c4babe68e 100755 --- a/examples/multisig_plain/lib.rs +++ b/examples/multisig_plain/lib.rs @@ -484,15 +484,20 @@ mod multisig_plain { /// Invoke a confirmed execution without getting its output. /// + /// If the transaction which is invoked transfers value this value has + /// to be sent as payment with this call. The method will fail otherwise, + /// and the transaction would then be reverted. + /// /// Its return value indicates whether the called transaction was successful. /// This can be called by anyone. - #[ink(message)] + #[ink(message, payable)] pub fn invoke_transaction( &mut self, trans_id: TransactionId, ) -> Result<(), Error> { self.ensure_confirmed(trans_id); let t = self.take_transaction(trans_id).expect(WRONG_TRANSACTION_ID); + assert!(self.env().transferred_balance() == t.transferred_value); let result = build_call::<::Env>() .callee(t.callee) .gas_limit(t.gas_limit) From 3891d794c4ca42ad148fb5dbab300178668ebda6 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 17 Jun 2021 09:12:44 +0200 Subject: [PATCH 6/8] Fix interpunctuation --- examples/multisig_plain/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/multisig_plain/lib.rs b/examples/multisig_plain/lib.rs index 9c4babe68e..22612b1e47 100755 --- a/examples/multisig_plain/lib.rs +++ b/examples/multisig_plain/lib.rs @@ -484,7 +484,7 @@ mod multisig_plain { /// Invoke a confirmed execution without getting its output. /// - /// If the transaction which is invoked transfers value this value has + /// If the transaction which is invoked transfers value, this value has /// to be sent as payment with this call. The method will fail otherwise, /// and the transaction would then be reverted. /// From e61673a50eb21f33d5dab6c5dce00f897813bdcc Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 17 Jun 2021 13:33:15 +0200 Subject: [PATCH 7/8] Introduce `ink-debug` feature --- examples/contract-transfer/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/contract-transfer/Cargo.toml b/examples/contract-transfer/Cargo.toml index 46fc674aaf..414c158eac 100644 --- a/examples/contract-transfer/Cargo.toml +++ b/examples/contract-transfer/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] ink_primitives = { version = "3.0.0-rc3", path = "../../crates/primitives", default-features = false } ink_metadata = { version = "3.0.0-rc3", path = "../../crates/metadata", default-features = false, features = ["derive"], optional = true } -ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false, features = [ "ink-debug" ] } +ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false } ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false } ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false } ink_prelude = { version = "3.0.0-rc3", path = "../../crates/prelude", default-features = false } @@ -21,7 +21,7 @@ path = "lib.rs" crate-type = ["cdylib"] [features] -default = ["std"] +default = ["std", "ink-debug"] std = [ "ink_primitives/std", "ink_metadata", @@ -35,3 +35,4 @@ std = [ ] ink-as-dependency = [] ink-experimental-engine = ["ink_env/ink-experimental-engine"] +ink-debug = ["ink_env/ink-debug"] From 9ed01e6068081f62876c3c61b34cc1965cea036d Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 17 Jun 2021 13:37:14 +0200 Subject: [PATCH 8/8] Revert "Introduce `ink-debug` feature" This reverts commit e61673a50eb21f33d5dab6c5dce00f897813bdcc. --- examples/contract-transfer/Cargo.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/contract-transfer/Cargo.toml b/examples/contract-transfer/Cargo.toml index 414c158eac..46fc674aaf 100644 --- a/examples/contract-transfer/Cargo.toml +++ b/examples/contract-transfer/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] ink_primitives = { version = "3.0.0-rc3", path = "../../crates/primitives", default-features = false } ink_metadata = { version = "3.0.0-rc3", path = "../../crates/metadata", default-features = false, features = ["derive"], optional = true } -ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false } +ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false, features = [ "ink-debug" ] } ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false } ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false } ink_prelude = { version = "3.0.0-rc3", path = "../../crates/prelude", default-features = false } @@ -21,7 +21,7 @@ path = "lib.rs" crate-type = ["cdylib"] [features] -default = ["std", "ink-debug"] +default = ["std"] std = [ "ink_primitives/std", "ink_metadata", @@ -35,4 +35,3 @@ std = [ ] ink-as-dependency = [] ink-experimental-engine = ["ink_env/ink-experimental-engine"] -ink-debug = ["ink_env/ink-debug"]