-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'storage-alt-blocks' into cuprated-blockchain
- Loading branch information
Showing
26 changed files
with
1,401 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Utils for working with [`Transaction`] | ||
|
||
use monero_serai::transaction::{Input, Transaction}; | ||
|
||
/// Calculates the fee of the [`Transaction`]. | ||
/// | ||
/// # Panics | ||
/// This will panic if the inputs overflow or the transaction outputs too much, so should only | ||
/// be used on known to be valid txs. | ||
pub fn tx_fee(tx: &Transaction) -> u64 { | ||
let mut fee = 0_u64; | ||
|
||
match &tx { | ||
Transaction::V1 { prefix, .. } => { | ||
for input in &prefix.inputs { | ||
match input { | ||
Input::Gen(_) => return 0, | ||
Input::ToKey { amount, .. } => { | ||
fee = fee.checked_add(amount.unwrap_or(0)).unwrap(); | ||
} | ||
} | ||
} | ||
|
||
for output in &prefix.outputs { | ||
fee.checked_sub(output.amount.unwrap_or(0)).unwrap(); | ||
} | ||
} | ||
Transaction::V2 { proofs, .. } => { | ||
fee = proofs.as_ref().unwrap().base.fee; | ||
} | ||
}; | ||
|
||
fee | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.