Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add gas parameter to ext_gas_price
  • Loading branch information
ascjones committed Jun 25, 2020
commit 3f829b15a1b005f034f954562f780132911f2cd4
6 changes: 3 additions & 3 deletions core/src/env/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ where
})
}

/// Returns the current price for gas.
/// Returns the price for the specified amount of weight.
///
/// # Errors
///
/// If the returned value cannot be properly decoded.
pub fn gas_price<T>() -> Result<T::Balance>
pub fn gas_price<T>(gas: u64) -> Result<T::Balance>
where
T: EnvTypes,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::gas_price::<T>(instance)
TypedEnv::gas_price::<T>(instance, gas)
})
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/env/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ pub trait TypedEnv: Env {
/// For more details visit: [`ink_core::env::transferred_balance`]
fn transferred_balance<T: EnvTypes>(&mut self) -> Result<T::Balance>;

/// Returns the current price for gas.
/// Returns the price for the specified amount of weight.
///
/// # Note
///
/// For more details visit: [`ink_core::env::gas_price`]
fn gas_price<T: EnvTypes>(&mut self) -> Result<T::Balance>;
fn gas_price<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance>;

/// Returns the amount of gas left for the contract execution.
///
Expand Down
5 changes: 4 additions & 1 deletion core/src/env/engine/on_chain/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ impl_ext_wrapper_for! {
(block_number => ext_block_number),
(address => ext_address),
(balance => ext_balance),
(gas_price => ext_gas_price),
(gas_left => ext_gas_left),
(value_transferred => ext_value_transferred),
(now => ext_now),
Expand All @@ -294,6 +293,10 @@ impl_ext_wrapper_for! {
(tombstone_deposit => ext_tombstone_deposit),
}

pub fn gas_price(gas: u64) {
unsafe { sys::ext_gas_price(gas) }
}

pub fn set_rent_allowance(value: &[u8]) {
unsafe { sys::ext_set_rent_allowance(value.as_ptr() as u32, value.len() as u32) }
}
Expand Down
9 changes: 5 additions & 4 deletions core/src/env/engine/on_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ impl TypedEnv for EnvInstance {
self.get_property::<T::Balance>(ext::value_transferred)
}

fn gas_price<T: EnvTypes>(&mut self) -> Result<T::Balance> {
self.get_property::<T::Balance>(ext::gas_price)
}

fn gas_left<T: EnvTypes>(&mut self) -> Result<T::Balance> {
self.get_property::<T::Balance>(ext::gas_left)
}
Expand Down Expand Up @@ -380,6 +376,11 @@ impl TypedEnv for EnvInstance {
ext::transfer(destination, value)
}

fn gas_price<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance> {
ext::gas_price(gas);
self.decode_scratch_buffer().map_err(Into::into)
}

fn random<T>(&mut self, subject: &[u8]) -> Result<T::Hash>
where
T: EnvTypes,
Expand Down