Skip to content

Commit

Permalink
Merge branch 'storage-alt-blocks' into cuprated-blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
Boog900 committed Sep 9, 2024
2 parents da78cbd + c03065b commit b5f8475
Show file tree
Hide file tree
Showing 26 changed files with 1,401 additions and 115 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/consensus"


[features]
# TODO: I don't think this is a good idea
# All features on by default.
default = ["std", "atomic", "asynch", "cast", "fs", "num", "map", "time", "thread", "constants"]
default = ["std", "atomic", "asynch", "cast", "fs", "num", "map", "time", "thread", "constants", "tx-utils"]
std = []
atomic = ["dep:crossbeam"]
asynch = ["dep:futures", "dep:rayon"]
Expand All @@ -21,6 +22,7 @@ num = []
map = ["cast", "dep:monero-serai"]
time = ["dep:chrono", "std"]
thread = ["std", "dep:target_os_lib"]
tx-utils = ["dep:monero-serai"]

[dependencies]
crossbeam = { workspace = true, optional = true }
Expand Down
2 changes: 2 additions & 0 deletions helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub mod thread;
#[cfg(feature = "time")]
pub mod time;

#[cfg(feature = "tx-utils")]
pub mod tx_utils;
//---------------------------------------------------------------------------------------------------- Private Usage

//----------------------------------------------------------------------------------------------------
34 changes: 34 additions & 0 deletions helper/src/tx_utils.rs
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
}
3 changes: 2 additions & 1 deletion storage/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ cuprate-database = { path = "../database" }
cuprate-database-service = { path = "../service" }
cuprate-helper = { path = "../../helper", features = ["fs", "thread", "map"] }
cuprate-types = { path = "../../types", features = ["blockchain"] }
cuprate-pruning = { path = "../../pruning" }

bitflags = { workspace = true, features = ["std", "serde", "bytemuck"] }
bytemuck = { workspace = true, features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
curve25519-dalek = { workspace = true }
cuprate-pruning = { path = "../../pruning" }
rand = { workspace = true }
monero-serai = { workspace = true, features = ["std"] }
serde = { workspace = true, optional = true }

Expand Down
Loading

0 comments on commit b5f8475

Please sign in to comment.