Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name API consistently: transferred_balancetransferred_value #1063

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() -> T::Balance
pub fn transferred_value<T>() -> T::Balance
where
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::transferred_balance::<T>(instance)
TypedEnvBackend::transferred_value::<T>(instance)
})
}

Expand Down
6 changes: 3 additions & 3 deletions crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ pub trait TypedEnvBackend: EnvBackend {
/// For more details visit: [`caller`][`crate::caller`]
fn caller<T: Environment>(&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<T: Environment>(&mut self) -> T::Balance;
/// For more details visit: [`transferred_value`][`crate::transferred_value`]
fn transferred_value<T: Environment>(&mut self) -> T::Balance;

/// Returns the price for the specified amount of gas.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/engine/experimental_off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl TypedEnvBackend for EnvInstance {
})
}

fn transferred_balance<T: Environment>(&mut self) -> T::Balance {
fn transferred_value<T: Environment>(&mut self) -> T::Balance {
self.get_property::<T::Balance>(Engine::value_transferred)
.unwrap_or_else(|error| {
panic!("could not read `transferred_value` property: {:?}", error)
Expand Down
4 changes: 2 additions & 2 deletions crates/env/src/engine/off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ impl TypedEnvBackend for EnvInstance {
})
}

fn transferred_balance<T: Environment>(&mut self) -> T::Balance {
fn transferred_value<T: Environment>(&mut self) -> T::Balance {
self.exec_context()
.expect(UNINITIALIZED_EXEC_CONTEXT)
.transferred_value::<T>()
.unwrap_or_else(|error| {
panic!("could not read `transferred_balance` property: {:?}", error)
panic!("could not read `transferred_value` property: {:?}", error)
})
}

Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/engine/on_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl TypedEnvBackend for EnvInstance {
self.get_property_inplace::<T::AccountId>(ext::caller)
}

fn transferred_balance<T: Environment>(&mut self) -> T::Balance {
fn transferred_value<T: Environment>(&mut self) -> T::Balance {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really wanted to nitpick on the consistency then the seal fn value_transferred should also be the same 😀

self.get_property_little_endian::<T::Balance>(ext::value_transferred)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/// }
/// }
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/src/codegen/dispatch/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn deny_payment<E>() -> Result<(), DispatchError>
where
E: Environment,
{
let transferred = ink_env::transferred_balance::<E>();
let transferred = ink_env::transferred_value::<E>();
if transferred != <E as Environment>::Balance::from(0_u32) {
return Err(DispatchError::PaidUnpayableMessage)
}
Expand Down
12 changes: 6 additions & 6 deletions crates/lang/src/env_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
ink_env::caller::<T>()
}

/// Returns the transferred balance for the contract execution.
/// Returns the transferred value for the contract execution.
///
/// # Example
///
Expand All @@ -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);
/// }
/// #
Expand All @@ -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::<T>()
/// For more details visit: [`ink_env::transferred_value`]
pub fn transferred_value(self) -> T::Balance {
ink_env::transferred_value::<T>()
}

/// Returns the price for the specified amount of gas.
Expand Down
4 changes: 2 additions & 2 deletions crates/lang/tests/ui/contract/pass/env-access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
Expand All @@ -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);
}
}
Expand Down
23 changes: 10 additions & 13 deletions examples/contract-transfer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ pub mod give_me {
pub fn was_it_ten(&self) {
ink_env::debug_println!(
"received payment: {}",
self.env().transferred_balance()
);
assert!(
self.env().transferred_balance() == 10,
"payment was not ten"
self.env().transferred_value()
);
assert!(self.env().transferred_value() == 10, "payment was not ten");
}
}

Expand Down Expand Up @@ -137,16 +134,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::<ink_env::DefaultEnvironment>(
accounts.eve,
contract_id(),
1000000,
mock_transferred_balance,
mock_transferred_value,
data,
);

Expand All @@ -168,16 +165,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::<ink_env::DefaultEnvironment>(
accounts.eve,
contract_id(),
1000000,
mock_transferred_balance,
mock_transferred_value,
data,
);

Expand Down Expand Up @@ -277,7 +274,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::<ink_env::DefaultEnvironment>(10);
Expand All @@ -296,7 +293,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::<ink_env::DefaultEnvironment>(13);
Expand Down
2 changes: 1 addition & 1 deletion examples/multisig/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<<Self as ::ink_lang::reflect::ContractEnv>::Env>()
.callee(t.callee)
.gas_limit(t.gas_limit)
Expand Down
2 changes: 1 addition & 1 deletion examples/proxy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down