Skip to content

Commit 71ad00e

Browse files
impl of calculate_fee_by_gas_usage method in GasPrice struct.
1 parent a891109 commit 71ad00e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/block.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88
use crate::core::{ContractAddress, GlobalRoot};
99
use crate::hash::StarkHash;
1010
use crate::serde_utils::{BytesAsHex, PrefixedBytesAsHex};
11-
use crate::transaction::{Transaction, TransactionOutput};
11+
use crate::transaction::{Fee, Transaction, TransactionOutput};
1212

1313
/// A block.
1414
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
@@ -128,6 +128,12 @@ impl From<GasPrice> for PrefixedBytesAsHex<16_usize> {
128128
}
129129
}
130130

131+
impl GasPrice {
132+
pub fn calculate_fee_by_gas_usage(&self, gas_usage: f64) -> Fee {
133+
Fee((gas_usage.ceil() as u128) * self.0)
134+
}
135+
}
136+
131137
/// The timestamp of a [Block](`crate::block::Block`).
132138
#[derive(
133139
Debug, Default, Copy, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord,

0 commit comments

Comments
 (0)