From 68c307328e1a338a60ce931d1c2115e3c177c582 Mon Sep 17 00:00:00 2001 From: Nir Levi Date: Mon, 12 Jun 2023 13:10:07 +0300 Subject: [PATCH] impl of calculate_fee_by_gas_usage method in GasPrice struct. --- src/block.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/block.rs b/src/block.rs index 574f90cd..2a2f9489 100644 --- a/src/block.rs +++ b/src/block.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::core::{ContractAddress, GlobalRoot}; use crate::hash::StarkHash; use crate::serde_utils::{BytesAsHex, PrefixedBytesAsHex}; -use crate::transaction::{Transaction, TransactionOutput}; +use crate::transaction::{Fee, Transaction, TransactionOutput}; /// A block. #[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] @@ -128,6 +128,12 @@ impl From for PrefixedBytesAsHex<16_usize> { } } +impl GasPrice { + pub fn calculate_fee_by_gas_usage(&self, gas_usage: f64) -> Fee { + Fee((gas_usage.ceil() as u128) * self.0) + } +} + /// The timestamp of a [Block](`crate::block::Block`). #[derive( Debug, Default, Copy, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord,