Skip to content

Commit a9267e6

Browse files
committed
Name API consistently: transferred_balancetransferred_value
1 parent 44c51d1 commit a9267e6

File tree

14 files changed

+40
-33
lines changed

14 files changed

+40
-33
lines changed

RELEASES.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Version 3.0-rc8 (UNRELEASED)
2+
3+
This is the 8th release candidate for ink! 3.0.
4+
5+
## Change
6+
- Renamed the `ink_env` function `transferred_balance()` to `transferred_value()`[#1063](https://github.com/paritytech/ink/pull/1063).
7+
18
# Version 3.0-rc7
29

310
This is the 7th release candidate for ink! 3.0.

crates/env/src/api.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ where
5353
})
5454
}
5555

56-
/// Returns the transferred balance for the contract execution.
56+
/// Returns the transferred value for the contract execution.
5757
///
5858
/// # Errors
5959
///
6060
/// If the returned value cannot be properly decoded.
61-
pub fn transferred_balance<T>() -> T::Balance
61+
pub fn transferred_value<T>() -> T::Balance
6262
where
6363
T: Environment,
6464
{
6565
<EnvInstance as OnInstance>::on_instance(|instance| {
66-
TypedEnvBackend::transferred_balance::<T>(instance)
66+
TypedEnvBackend::transferred_value::<T>(instance)
6767
})
6868
}
6969

crates/env/src/backend.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ pub trait TypedEnvBackend: EnvBackend {
290290
/// For more details visit: [`caller`][`crate::caller`]
291291
fn caller<T: Environment>(&mut self) -> T::AccountId;
292292

293-
/// Returns the transferred balance for the contract execution.
293+
/// Returns the transferred value for the contract execution.
294294
///
295295
/// # Note
296296
///
297-
/// For more details visit: [`transferred_balance`][`crate::transferred_balance`]
298-
fn transferred_balance<T: Environment>(&mut self) -> T::Balance;
297+
/// For more details visit: [`transferred_value`][`crate::transferred_value`]
298+
fn transferred_value<T: Environment>(&mut self) -> T::Balance;
299299

300300
/// Returns the price for the specified amount of gas.
301301
///

crates/env/src/engine/experimental_off_chain/impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl TypedEnvBackend for EnvInstance {
324324
})
325325
}
326326

327-
fn transferred_balance<T: Environment>(&mut self) -> T::Balance {
327+
fn transferred_value<T: Environment>(&mut self) -> T::Balance {
328328
self.get_property::<T::Balance>(Engine::value_transferred)
329329
.unwrap_or_else(|error| {
330330
panic!("could not read `transferred_value` property: {:?}", error)

crates/env/src/engine/off_chain/impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ impl TypedEnvBackend for EnvInstance {
332332
})
333333
}
334334

335-
fn transferred_balance<T: Environment>(&mut self) -> T::Balance {
335+
fn transferred_value<T: Environment>(&mut self) -> T::Balance {
336336
self.exec_context()
337337
.expect(UNINITIALIZED_EXEC_CONTEXT)
338338
.transferred_value::<T>()
339339
.unwrap_or_else(|error| {
340-
panic!("could not read `transferred_balance` property: {:?}", error)
340+
panic!("could not read `transferred_value` property: {:?}", error)
341341
})
342342
}
343343

crates/env/src/engine/on_chain/impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl TypedEnvBackend for EnvInstance {
357357
self.get_property_inplace::<T::AccountId>(ext::caller)
358358
}
359359

360-
fn transferred_balance<T: Environment>(&mut self) -> T::Balance {
360+
fn transferred_value<T: Environment>(&mut self) -> T::Balance {
361361
self.get_property_little_endian::<T::Balance>(ext::value_transferred)
362362
}
363363

crates/lang/codegen/src/generator/trait_def/call_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl CallBuilder<'_> {
307307
/// the respective ink! trait message calls of the called smart contract
308308
/// instance.
309309
/// The way these messages are built-up allows the caller to customize message
310-
/// parameters such as gas limit and transferred balance.
310+
/// parameters such as gas limit and transferred value.
311311
fn generate_ink_trait_impl(&self) -> TokenStream2 {
312312
let span = self.trait_def.span();
313313
let trait_ident = self.trait_def.trait_def.item().ident();

crates/lang/macro/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream {
481481
/// #[ink(message, payable)]
482482
/// pub fn fund(&self) {
483483
/// let caller = self.env().caller();
484-
/// let value = self.env().transferred_balance();
484+
/// let value = self.env().transferred_value();
485485
/// debug_println!("thanks for the funding of {:?} from {:?}", value, caller);
486486
/// }
487487
/// }

crates/lang/src/codegen/dispatch/execution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn deny_payment<E>() -> Result<(), DispatchError>
6363
where
6464
E: Environment,
6565
{
66-
let transferred = ink_env::transferred_balance::<E>();
66+
let transferred = ink_env::transferred_value::<E>();
6767
if transferred != <E as Environment>::Balance::from(0_u32) {
6868
return Err(DispatchError::PaidUnpayableMessage)
6969
}

crates/lang/src/env_access.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ where
107107
ink_env::caller::<T>()
108108
}
109109

110-
/// Returns the transferred balance for the contract execution.
110+
/// Returns the transferred value for the contract execution.
111111
///
112112
/// # Example
113113
///
@@ -125,11 +125,11 @@ where
125125
/// # Self {}
126126
/// # }
127127
/// #
128-
/// /// Allows funding the contract. Prints a debug message with the transferred balance.
128+
/// /// Allows funding the contract. Prints a debug message with the transferred value.
129129
/// #[ink(message, payable)]
130130
/// pub fn fund(&self) {
131131
/// let caller = self.env().caller();
132-
/// let value = self.env().transferred_balance();
132+
/// let value = self.env().transferred_value();
133133
/// ink_env::debug_println!("thanks for the funding of {:?} from {:?}", value, caller);
134134
/// }
135135
/// #
@@ -139,9 +139,9 @@ where
139139
///
140140
/// # Note
141141
///
142-
/// For more details visit: [`ink_env::transferred_balance`]
143-
pub fn transferred_balance(self) -> T::Balance {
144-
ink_env::transferred_balance::<T>()
142+
/// For more details visit: [`ink_env::transferred_value`]
143+
pub fn transferred_value(self) -> T::Balance {
144+
ink_env::transferred_value::<T>()
145145
}
146146

147147
/// Returns the price for the specified amount of gas.

crates/lang/tests/ui/contract/pass/env-access.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod contract {
1616
let _ = Self::env().gas_left();
1717
let _ = Self::env().minimum_balance();
1818
let _ = Self::env().random(&[]);
19-
let _ = Self::env().transferred_balance();
19+
let _ = Self::env().transferred_value();
2020
let _ = Self::env().weight_to_fee(0);
2121
Self {}
2222
}
@@ -31,7 +31,7 @@ mod contract {
3131
let _ = self.env().gas_left();
3232
let _ = self.env().minimum_balance();
3333
let _ = self.env().random(&[]);
34-
let _ = self.env().transferred_balance();
34+
let _ = self.env().transferred_value();
3535
let _ = self.env().weight_to_fee(0);
3636
}
3737
}

examples/contract-transfer/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ pub mod give_me {
7373
pub fn was_it_ten(&self) {
7474
ink_env::debug_println!(
7575
"received payment: {}",
76-
self.env().transferred_balance()
76+
self.env().transferred_value()
7777
);
7878
assert!(
79-
self.env().transferred_balance() == 10,
79+
self.env().transferred_value() == 10,
8080
"payment was not ten"
8181
);
8282
}
@@ -137,16 +137,16 @@ pub mod give_me {
137137
0xCA, 0xFE, 0xBA, 0xBE,
138138
]));
139139
data.push_arg(&accounts.eve);
140-
let mock_transferred_balance = 10;
140+
let mock_transferred_value = 10;
141141

142142
// Push the new execution context which sets Eve as caller and
143-
// the `mock_transferred_balance` as the value which the contract
143+
// the `mock_transferred_value` as the value which the contract
144144
// will see as transferred to it.
145145
ink_env::test::push_execution_context::<ink_env::DefaultEnvironment>(
146146
accounts.eve,
147147
contract_id(),
148148
1000000,
149-
mock_transferred_balance,
149+
mock_transferred_value,
150150
data,
151151
);
152152

@@ -168,16 +168,16 @@ pub mod give_me {
168168
0xCA, 0xFE, 0xBA, 0xBE,
169169
]));
170170
data.push_arg(&accounts.eve);
171-
let mock_transferred_balance = 13;
171+
let mock_transferred_value = 13;
172172

173173
// Push the new execution context which sets Eve as caller and
174-
// the `mock_transferred_balance` as the value which the contract
174+
// the `mock_transferred_value` as the value which the contract
175175
// will see as transferred to it.
176176
ink_env::test::push_execution_context::<ink_env::DefaultEnvironment>(
177177
accounts.eve,
178178
contract_id(),
179179
1000000,
180-
mock_transferred_balance,
180+
mock_transferred_value,
181181
data,
182182
);
183183

@@ -277,7 +277,7 @@ pub mod give_me {
277277

278278
// when
279279
// Push the new execution context which sets Eve as caller and
280-
// the `mock_transferred_balance` as the value which the contract
280+
// the `mock_transferred_value` as the value which the contract
281281
// will see as transferred to it.
282282
set_sender(accounts.eve);
283283
ink_env::test::set_value_transferred::<ink_env::DefaultEnvironment>(10);
@@ -296,7 +296,7 @@ pub mod give_me {
296296

297297
// when
298298
// Push the new execution context which sets Eve as caller and
299-
// the `mock_transferred_balance` as the value which the contract
299+
// the `mock_transferred_value` as the value which the contract
300300
// will see as transferred to it.
301301
set_sender(accounts.eve);
302302
ink_env::test::set_value_transferred::<ink_env::DefaultEnvironment>(13);

examples/multisig/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ mod multisig {
483483
) -> Result<(), Error> {
484484
self.ensure_confirmed(trans_id);
485485
let t = self.take_transaction(trans_id).expect(WRONG_TRANSACTION_ID);
486-
assert!(self.env().transferred_balance() == t.transferred_value);
486+
assert!(self.env().transferred_value() == t.transferred_value);
487487
let result = build_call::<<Self as ::ink_lang::reflect::ContractEnv>::Env>()
488488
.callee(t.callee)
489489
.gas_limit(t.gas_limit)

examples/proxy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub mod proxy {
7676
.set_forward_input(true)
7777
.set_tail_call(true),
7878
)
79-
.transferred_value(self.env().transferred_balance())
79+
.transferred_value(self.env().transferred_value())
8080
.fire()
8181
.unwrap_or_else(|err| {
8282
panic!(

0 commit comments

Comments
 (0)