Apply suggestions from code review
Some checks are pending
Audit / audit (push) Waiting to run
Deny / audit (push) Waiting to run

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
This commit is contained in:
Boog900 2024-09-18 16:40:09 +01:00 committed by GitHub
parent fb592e3cda
commit 6aeb720dcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 48 additions and 8 deletions

View file

@ -21,7 +21,7 @@ num = []
map = ["cast", "dep:monero-serai"]
time = ["dep:chrono", "std"]
thread = ["std", "dep:target_os_lib"]
tx-utils = ["dep:monero-serai"]
tx = ["dep:monero-serai"]
[dependencies]
crossbeam = { workspace = true, optional = true }

View file

@ -31,7 +31,7 @@ pub mod thread;
#[cfg(feature = "time")]
pub mod time;
#[cfg(feature = "tx-utils")]
#[cfg(feature = "tx")]
pub mod tx;
//---------------------------------------------------------------------------------------------------- Private Usage

View file

@ -32,3 +32,39 @@ pub fn tx_fee(tx: &Transaction) -> u64 {
fee
}
#[cfg(test)]
mod test {
use curve25519_dalek::{edwards::CompressedEdwardsY, EdwardsPoint};
use monero_serai::transaction::{NotPruned, Output, Timelock, TransactionPrefix};
use super::*;
#[test]
#[should_panic(expected = "called `Option::unwrap()` on a `None` value")]
fn tx_fee_panic() {
let input = Input::ToKey {
amount: Some(u64::MAX),
key_offsets: vec![],
key_image: EdwardsPoint::default(),
};
let output = Output {
amount: Some(u64::MAX),
key: CompressedEdwardsY::default(),
view_tag: None,
};
let tx = Transaction::<NotPruned>::V1 {
prefix: TransactionPrefix {
additional_timelock: Timelock::None,
inputs: vec![input; 2],
outputs: vec![output],
extra: vec![],
},
signatures: vec![],
};
tx_fee(&tx);
}
}

View file

@ -46,14 +46,16 @@
//!
//! Although that would be easier, it makes getting a range of block extremely slow, as we have to build the weight cache to verify
//! blocks, roughly 100,000 block headers needed, this cost is too high.
pub use block::*;
pub use chain::*;
pub use tx::*;
mod block;
mod chain;
mod tx;
pub use block::{
add_alt_block, get_alt_block, get_alt_block_extended_header_from_height, get_alt_block_hash,
};
pub use chain::{get_alt_chain_history_ranges, update_alt_chain_info};
pub use tx::{add_alt_transaction_blob, get_alt_transaction};
/// Flush all alt-block data from all the alt-block tables.
///
/// This function completely empties the alt block tables.

View file

@ -40,7 +40,9 @@ pub fn add_alt_transaction_blob(
tables
.alt_transaction_blobs_mut()
.put(&tx.tx_hash, StorableVec::wrap_ref(&tx.tx_blob))
.put(&tx.tx_hash, StorableVec::wrap_ref(&tx.tx_blob))?;
Ok(())
}
/// Retrieve a [`VerifiedTransactionInformation`] from the database.

View file

@ -7,7 +7,7 @@ authors = ["Boog900", "hinto-janai"]
[dependencies]
cuprate-types = { path = "../types" }
cuprate-helper = { path = "../helper", features = ["map", "tx-utils"] }
cuprate-helper = { path = "../helper", features = ["map", "tx"] }
cuprate-wire = { path = "../net/wire" }
cuprate-p2p-core = { path = "../p2p/p2p-core", features = ["borsh"] }