From a9267e6d77f94fa5f94a04de27d8140ca49c616b Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 1 Dec 2021 19:56:37 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Name=20API=20consistently:=20`transferred?= =?UTF-8?q?=5Fbalance`=20=E2=9E=94=20`transferred=5Fvalue`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RELEASES.md | 7 +++++++ crates/env/src/api.rs | 6 +++--- crates/env/src/backend.rs | 6 +++--- .../engine/experimental_off_chain/impls.rs | 2 +- crates/env/src/engine/off_chain/impls.rs | 4 ++-- crates/env/src/engine/on_chain/impls.rs | 2 +- .../src/generator/trait_def/call_builder.rs | 2 +- crates/lang/macro/src/lib.rs | 2 +- crates/lang/src/codegen/dispatch/execution.rs | 2 +- crates/lang/src/env_access.rs | 12 +++++------ .../lang/tests/ui/contract/pass/env-access.rs | 4 ++-- examples/contract-transfer/lib.rs | 20 +++++++++---------- examples/multisig/lib.rs | 2 +- examples/proxy/lib.rs | 2 +- 14 files changed, 40 insertions(+), 33 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index f8402dba14b..ac7b46c7408 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,10 @@ +# Version 3.0-rc8 (UNRELEASED) + +This is the 8th release candidate for ink! 3.0. + +## Change +- Renamed the `ink_env` function `transferred_balance()` to `transferred_value()` ‒ [#1063](/~https://github.com/paritytech/ink/pull/1063). + # Version 3.0-rc7 This is the 7th release candidate for ink! 3.0. diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 3f4891984f4..363308a05a7 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -53,17 +53,17 @@ where }) } -/// Returns the transferred balance for the contract execution. +/// Returns the transferred value for the contract execution. /// /// # Errors /// /// If the returned value cannot be properly decoded. -pub fn transferred_balance() -> T::Balance +pub fn transferred_value() -> T::Balance where T: Environment, { ::on_instance(|instance| { - TypedEnvBackend::transferred_balance::(instance) + TypedEnvBackend::transferred_value::(instance) }) } diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index 84c6df038c4..1c2a09e2811 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -290,12 +290,12 @@ pub trait TypedEnvBackend: EnvBackend { /// For more details visit: [`caller`][`crate::caller`] fn caller(&mut self) -> T::AccountId; - /// Returns the transferred balance for the contract execution. + /// Returns the transferred value for the contract execution. /// /// # Note /// - /// For more details visit: [`transferred_balance`][`crate::transferred_balance`] - fn transferred_balance(&mut self) -> T::Balance; + /// For more details visit: [`transferred_value`][`crate::transferred_value`] + fn transferred_value(&mut self) -> T::Balance; /// Returns the price for the specified amount of gas. /// diff --git a/crates/env/src/engine/experimental_off_chain/impls.rs b/crates/env/src/engine/experimental_off_chain/impls.rs index 74d255f5780..458622ddf94 100644 --- a/crates/env/src/engine/experimental_off_chain/impls.rs +++ b/crates/env/src/engine/experimental_off_chain/impls.rs @@ -324,7 +324,7 @@ impl TypedEnvBackend for EnvInstance { }) } - fn transferred_balance(&mut self) -> T::Balance { + fn transferred_value(&mut self) -> T::Balance { self.get_property::(Engine::value_transferred) .unwrap_or_else(|error| { panic!("could not read `transferred_value` property: {:?}", error) diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 1ef53f1c046..8db90d5d62e 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -332,12 +332,12 @@ impl TypedEnvBackend for EnvInstance { }) } - fn transferred_balance(&mut self) -> T::Balance { + fn transferred_value(&mut self) -> T::Balance { self.exec_context() .expect(UNINITIALIZED_EXEC_CONTEXT) .transferred_value::() .unwrap_or_else(|error| { - panic!("could not read `transferred_balance` property: {:?}", error) + panic!("could not read `transferred_value` property: {:?}", error) }) } diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 2be6718333f..87c1a07da67 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -357,7 +357,7 @@ impl TypedEnvBackend for EnvInstance { self.get_property_inplace::(ext::caller) } - fn transferred_balance(&mut self) -> T::Balance { + fn transferred_value(&mut self) -> T::Balance { self.get_property_little_endian::(ext::value_transferred) } diff --git a/crates/lang/codegen/src/generator/trait_def/call_builder.rs b/crates/lang/codegen/src/generator/trait_def/call_builder.rs index d067dbb19f7..ad108d89c96 100644 --- a/crates/lang/codegen/src/generator/trait_def/call_builder.rs +++ b/crates/lang/codegen/src/generator/trait_def/call_builder.rs @@ -307,7 +307,7 @@ impl CallBuilder<'_> { /// the respective ink! trait message calls of the called smart contract /// instance. /// The way these messages are built-up allows the caller to customize message - /// parameters such as gas limit and transferred balance. + /// parameters such as gas limit and transferred value. fn generate_ink_trait_impl(&self) -> TokenStream2 { let span = self.trait_def.span(); let trait_ident = self.trait_def.trait_def.item().ident(); diff --git a/crates/lang/macro/src/lib.rs b/crates/lang/macro/src/lib.rs index 21487eb1793..e36b02c1434 100644 --- a/crates/lang/macro/src/lib.rs +++ b/crates/lang/macro/src/lib.rs @@ -481,7 +481,7 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream { /// #[ink(message, payable)] /// pub fn fund(&self) { /// let caller = self.env().caller(); -/// let value = self.env().transferred_balance(); +/// let value = self.env().transferred_value(); /// debug_println!("thanks for the funding of {:?} from {:?}", value, caller); /// } /// } diff --git a/crates/lang/src/codegen/dispatch/execution.rs b/crates/lang/src/codegen/dispatch/execution.rs index 28d28e0879b..2618992b0ff 100644 --- a/crates/lang/src/codegen/dispatch/execution.rs +++ b/crates/lang/src/codegen/dispatch/execution.rs @@ -63,7 +63,7 @@ pub fn deny_payment() -> Result<(), DispatchError> where E: Environment, { - let transferred = ink_env::transferred_balance::(); + let transferred = ink_env::transferred_value::(); if transferred != ::Balance::from(0_u32) { return Err(DispatchError::PaidUnpayableMessage) } diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index 1fdc6af27b6..95b57007cff 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -107,7 +107,7 @@ where ink_env::caller::() } - /// Returns the transferred balance for the contract execution. + /// Returns the transferred value for the contract execution. /// /// # Example /// @@ -125,11 +125,11 @@ where /// # Self {} /// # } /// # - /// /// Allows funding the contract. Prints a debug message with the transferred balance. + /// /// Allows funding the contract. Prints a debug message with the transferred value. /// #[ink(message, payable)] /// pub fn fund(&self) { /// let caller = self.env().caller(); - /// let value = self.env().transferred_balance(); + /// let value = self.env().transferred_value(); /// ink_env::debug_println!("thanks for the funding of {:?} from {:?}", value, caller); /// } /// # @@ -139,9 +139,9 @@ where /// /// # Note /// - /// For more details visit: [`ink_env::transferred_balance`] - pub fn transferred_balance(self) -> T::Balance { - ink_env::transferred_balance::() + /// For more details visit: [`ink_env::transferred_value`] + pub fn transferred_value(self) -> T::Balance { + ink_env::transferred_value::() } /// Returns the price for the specified amount of gas. diff --git a/crates/lang/tests/ui/contract/pass/env-access.rs b/crates/lang/tests/ui/contract/pass/env-access.rs index 46437085c51..77170407426 100644 --- a/crates/lang/tests/ui/contract/pass/env-access.rs +++ b/crates/lang/tests/ui/contract/pass/env-access.rs @@ -16,7 +16,7 @@ mod contract { let _ = Self::env().gas_left(); let _ = Self::env().minimum_balance(); let _ = Self::env().random(&[]); - let _ = Self::env().transferred_balance(); + let _ = Self::env().transferred_value(); let _ = Self::env().weight_to_fee(0); Self {} } @@ -31,7 +31,7 @@ mod contract { let _ = self.env().gas_left(); let _ = self.env().minimum_balance(); let _ = self.env().random(&[]); - let _ = self.env().transferred_balance(); + let _ = self.env().transferred_value(); let _ = self.env().weight_to_fee(0); } } diff --git a/examples/contract-transfer/lib.rs b/examples/contract-transfer/lib.rs index b72cd6a2bd1..c4235fcbe23 100644 --- a/examples/contract-transfer/lib.rs +++ b/examples/contract-transfer/lib.rs @@ -73,10 +73,10 @@ pub mod give_me { pub fn was_it_ten(&self) { ink_env::debug_println!( "received payment: {}", - self.env().transferred_balance() + self.env().transferred_value() ); assert!( - self.env().transferred_balance() == 10, + self.env().transferred_value() == 10, "payment was not ten" ); } @@ -137,16 +137,16 @@ pub mod give_me { 0xCA, 0xFE, 0xBA, 0xBE, ])); data.push_arg(&accounts.eve); - let mock_transferred_balance = 10; + let mock_transferred_value = 10; // Push the new execution context which sets Eve as caller and - // the `mock_transferred_balance` as the value which the contract + // the `mock_transferred_value` as the value which the contract // will see as transferred to it. ink_env::test::push_execution_context::( accounts.eve, contract_id(), 1000000, - mock_transferred_balance, + mock_transferred_value, data, ); @@ -168,16 +168,16 @@ pub mod give_me { 0xCA, 0xFE, 0xBA, 0xBE, ])); data.push_arg(&accounts.eve); - let mock_transferred_balance = 13; + let mock_transferred_value = 13; // Push the new execution context which sets Eve as caller and - // the `mock_transferred_balance` as the value which the contract + // the `mock_transferred_value` as the value which the contract // will see as transferred to it. ink_env::test::push_execution_context::( accounts.eve, contract_id(), 1000000, - mock_transferred_balance, + mock_transferred_value, data, ); @@ -277,7 +277,7 @@ pub mod give_me { // when // Push the new execution context which sets Eve as caller and - // the `mock_transferred_balance` as the value which the contract + // the `mock_transferred_value` as the value which the contract // will see as transferred to it. set_sender(accounts.eve); ink_env::test::set_value_transferred::(10); @@ -296,7 +296,7 @@ pub mod give_me { // when // Push the new execution context which sets Eve as caller and - // the `mock_transferred_balance` as the value which the contract + // the `mock_transferred_value` as the value which the contract // will see as transferred to it. set_sender(accounts.eve); ink_env::test::set_value_transferred::(13); diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index 658fc335f5a..65a633cebbd 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -483,7 +483,7 @@ mod multisig { ) -> 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); + assert!(self.env().transferred_value() == t.transferred_value); let result = build_call::<::Env>() .callee(t.callee) .gas_limit(t.gas_limit) diff --git a/examples/proxy/lib.rs b/examples/proxy/lib.rs index 2758a6843f2..1224e54e119 100644 --- a/examples/proxy/lib.rs +++ b/examples/proxy/lib.rs @@ -76,7 +76,7 @@ pub mod proxy { .set_forward_input(true) .set_tail_call(true), ) - .transferred_value(self.env().transferred_balance()) + .transferred_value(self.env().transferred_value()) .fire() .unwrap_or_else(|err| { panic!( From 06b678cd58e2ab7559398032471d81eb96a85033 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 1 Dec 2021 20:03:12 +0100 Subject: [PATCH 2/2] Apply `cargo fmt` --- examples/contract-transfer/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/contract-transfer/lib.rs b/examples/contract-transfer/lib.rs index c4235fcbe23..18173674e03 100644 --- a/examples/contract-transfer/lib.rs +++ b/examples/contract-transfer/lib.rs @@ -75,10 +75,7 @@ pub mod give_me { "received payment: {}", self.env().transferred_value() ); - assert!( - self.env().transferred_value() == 10, - "payment was not ten" - ); + assert!(self.env().transferred_value() == 10, "payment was not ten"); } }