pub fn buy_gas<T: Trait>(
	transactor: &T::AccountId,
	gas_limit: T::Gas,
) -> Result<(GasMeter<T>, NegativeImbalanceOf<T>), &'static str> {
	// Check if the specified amount of gas is available in the current block.
	// This cannot underflow since `gas_spent` is never greater than `block_gas_limit`.
	let gas_available = <Module<T>>::block_gas_limit() - <Module<T>>::gas_spent();
	if gas_limit > gas_available {
		// gas limit reached, revert the transaction and retry again in the future
		return Err(BLOCK_FULL);
	}

	// Buy the specified amount of gas.
	let gas_price = <Module<T>>::gas_price();
	let cost = <T::Gas as As<BalanceOf<T>>>::as_(gas_limit.clone())
		.checked_mul(&gas_price)
		.ok_or("overflow multiplying gas limit by price")?;

	let imbalance = T::Currency::withdraw(
		transactor,
		cost,
		WithdrawReason::Fee,
		ExistenceRequirement::KeepAlive
	)?;

	Ok((GasMeter {
		limit: gas_limit,
		gas_left: gas_limit,
		gas_price,

		#[cfg(test)]
		tokens: Vec::new(),
	}, imbalance))
}
/// Buy the given amount of gas.
///
/// Cost is calculated by multiplying the gas cost (taken from the storage) by the `gas_limit`.
/// The funds are deducted from `transactor`.
Buy the given amount of gas.
Cost is calculated by multiplying the gas cost (taken from the storage) by the `gas_limit`.
The funds are deducted from `transactor`.
Buy the given amount of gas . Cost is calculated by multiplying the gas cost ( taken from the storage ) by the ` gas_limit ` . The funds are deducted from ` transactor ` .
pub fn buy_gas<T: Trait>(
	transactor: &T::AccountId,
	gas_limit: T::Gas,
) -> Result<(GasMeter<T>, NegativeImbalanceOf<T>), &'static str> {
	// Check if the specified amount of gas is available in the current block.
	// This cannot underflow since `gas_spent` is never greater than `block_gas_limit`.
	let gas_available = <Module<T>>::block_gas_limit() - <Module<T>>::gas_spent();
	if gas_limit > gas_available {
		// gas limit reached, revert the transaction and retry again in the future
		return Err(BLOCK_FULL);
	}
	// Buy the specified amount of gas.
	let gas_price = <Module<T>>::gas_price();
	let cost = <T::Gas as As<BalanceOf<T>>>::as_(gas_limit.clone())
		.checked_mul(&gas_price)
		.ok_or("overflow multiplying gas limit by price")?;
	let imbalance = T::Currency::withdraw(
		transactor,
		cost,
		WithdrawReason::Fee,
		ExistenceRequirement::KeepAlive
	)?;
	Ok((GasMeter {
		limit: gas_limit,
		gas_left: gas_limit,
		gas_price,
		#[cfg(test)]
		tokens: Vec::new(),
	}, imbalance))
}
pub fn buy_gas < T : Trait > ( transactor : & T :: AccountId , gas_limit : T :: Gas , ) -> Result < ( GasMeter < T > , NegativeImbalanceOf < T > ) , & ' static str > { // Check if the specified amount of gas is available in the current block. // This cannot underflow since `gas_spent` is never greater than `block_gas_limit`. let gas_available = < Module < T > > :: block_gas_limit ( ) - < Module < T > > :: gas_spent ( ) ; if gas_limit > gas_available { // gas limit reached, revert the transaction and retry again in the future return Err ( BLOCK_FULL ) ; } // Buy the specified amount of gas. let gas_price = < Module < T > > :: gas_price ( ) ; let cost = < T :: Gas as As < BalanceOf < T > > > :: as_ ( gas_limit . clone ( ) ) . checked_mul ( & gas_price ) . ok_or ( " " ) ? ; let imbalance = T :: Currency :: withdraw ( transactor , cost , WithdrawReason :: Fee , ExistenceRequirement :: KeepAlive ) ? ; Ok ( ( GasMeter { limit : gas_limit , gas_left : gas_limit , gas_price , # [ cfg ( test ) ] tokens : Vec :: new ( ) , } , imbalance ) ) }
Buy the given amount of gas.
Buy the given amount of gas .
transactor
&T::AccountId
gas_limit
T::Gas
transactor
&T::AccountId
gas_limit
T::Gas