diff --git a/sdk/src/fee.rs b/sdk/src/fee.rs index 2fb045aba5d73e..bd3af75e70da18 100644 --- a/sdk/src/fee.rs +++ b/sdk/src/fee.rs @@ -31,6 +31,19 @@ pub struct FeeStructure { pub compute_fee_bins: Vec, } +/// Return type of calculate_fee(...) +#[derive(Debug, Default, Clone, Eq, PartialEq)] +pub struct FeeDetails { + transaction_fee: u64, + prioritization_fee: u64, +} + +impl FeeDetails { + pub fn total_fee(&self) -> u64 { + self.transaction_fee.saturating_add(self.prioritization_fee) + } +} + pub const ACCOUNT_DATA_COST_PAGE_SIZE: u64 = 32_u64.saturating_mul(1024); impl FeeStructure { @@ -75,15 +88,32 @@ impl FeeStructure { .saturating_mul(heap_cost) } - /// Calculate fee for `SanitizedMessage` #[cfg(not(target_os = "solana"))] pub fn calculate_fee( &self, message: &SanitizedMessage, - _lamports_per_signature: u64, + lamports_per_signature: u64, budget_limits: &FeeBudgetLimits, include_loaded_account_data_size_in_fee: bool, ) -> u64 { + self.calculate_fee_details( + message, + lamports_per_signature, + budget_limits, + include_loaded_account_data_size_in_fee, + ) + .total_fee() + } + + /// Calculate fee details for `SanitizedMessage` + #[cfg(not(target_os = "solana"))] + pub fn calculate_fee_details( + &self, + message: &SanitizedMessage, + _lamports_per_signature: u64, + budget_limits: &FeeBudgetLimits, + include_loaded_account_data_size_in_fee: bool, + ) -> FeeDetails { let signature_fee = message .num_signatures() .saturating_mul(self.lamports_per_signature); @@ -115,12 +145,13 @@ impl FeeStructure { .unwrap_or_default() }); - (budget_limits - .prioritization_fee - .saturating_add(signature_fee) - .saturating_add(write_lock_fee) - .saturating_add(compute_fee) as f64) - .round() as u64 + FeeDetails { + transaction_fee: (signature_fee + .saturating_add(write_lock_fee) + .saturating_add(compute_fee) as f64) + .round() as u64, + prioritization_fee: budget_limits.prioritization_fee, + } } }