Skip to content

Commit b5f8475

Browse files
committed
Merge branch 'storage-alt-blocks' into cuprated-blockchain
2 parents da78cbd + c03065b commit b5f8475

File tree

26 files changed

+1401
-115
lines changed

26 files changed

+1401
-115
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helper/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/consensus"
99

1010

1111
[features]
12+
# TODO: I don't think this is a good idea
1213
# All features on by default.
13-
default = ["std", "atomic", "asynch", "cast", "fs", "num", "map", "time", "thread", "constants"]
14+
default = ["std", "atomic", "asynch", "cast", "fs", "num", "map", "time", "thread", "constants", "tx-utils"]
1415
std = []
1516
atomic = ["dep:crossbeam"]
1617
asynch = ["dep:futures", "dep:rayon"]
@@ -21,6 +22,7 @@ num = []
2122
map = ["cast", "dep:monero-serai"]
2223
time = ["dep:chrono", "std"]
2324
thread = ["std", "dep:target_os_lib"]
25+
tx-utils = ["dep:monero-serai"]
2426

2527
[dependencies]
2628
crossbeam = { workspace = true, optional = true }

helper/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub mod thread;
3131
#[cfg(feature = "time")]
3232
pub mod time;
3333

34+
#[cfg(feature = "tx-utils")]
35+
pub mod tx_utils;
3436
//---------------------------------------------------------------------------------------------------- Private Usage
3537

3638
//----------------------------------------------------------------------------------------------------

helper/src/tx_utils.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Utils for working with [`Transaction`]
2+
3+
use monero_serai::transaction::{Input, Transaction};
4+
5+
/// Calculates the fee of the [`Transaction`].
6+
///
7+
/// # Panics
8+
/// This will panic if the inputs overflow or the transaction outputs too much, so should only
9+
/// be used on known to be valid txs.
10+
pub fn tx_fee(tx: &Transaction) -> u64 {
11+
let mut fee = 0_u64;
12+
13+
match &tx {
14+
Transaction::V1 { prefix, .. } => {
15+
for input in &prefix.inputs {
16+
match input {
17+
Input::Gen(_) => return 0,
18+
Input::ToKey { amount, .. } => {
19+
fee = fee.checked_add(amount.unwrap_or(0)).unwrap();
20+
}
21+
}
22+
}
23+
24+
for output in &prefix.outputs {
25+
fee.checked_sub(output.amount.unwrap_or(0)).unwrap();
26+
}
27+
}
28+
Transaction::V2 { proofs, .. } => {
29+
fee = proofs.as_ref().unwrap().base.fee;
30+
}
31+
};
32+
33+
fee
34+
}

storage/blockchain/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ cuprate-database = { path = "../database" }
2525
cuprate-database-service = { path = "../service" }
2626
cuprate-helper = { path = "../../helper", features = ["fs", "thread", "map"] }
2727
cuprate-types = { path = "../../types", features = ["blockchain"] }
28+
cuprate-pruning = { path = "../../pruning" }
2829

2930
bitflags = { workspace = true, features = ["std", "serde", "bytemuck"] }
3031
bytemuck = { workspace = true, features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
3132
curve25519-dalek = { workspace = true }
32-
cuprate-pruning = { path = "../../pruning" }
33+
rand = { workspace = true }
3334
monero-serai = { workspace = true, features = ["std"] }
3435
serde = { workspace = true, optional = true }
3536

0 commit comments

Comments
 (0)