Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl of calculate_fee_by_gas_usage method in GasPrice struct. #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
8 changes: 7 additions & 1 deletion src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -128,6 +128,12 @@ impl From<GasPrice> 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,
Expand Down