mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-23 03:59:31 +00:00
read: move Output
mapping to crate::free
it's needed in tests too
This commit is contained in:
parent
0e4ec3958d
commit
a347f7fd9d
3 changed files with 44 additions and 29 deletions
|
@ -1,10 +1,48 @@
|
|||
//! General free functions (related to the database).
|
||||
//!
|
||||
//! TODO.
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
|
||||
use cuprate_types::OutputOnChain;
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_POINT, edwards::CompressedEdwardsY, Scalar};
|
||||
use monero_serai::{transaction::Timelock, H};
|
||||
|
||||
use crate::{
|
||||
tables::{Tables, TxUnlockTime},
|
||||
types::{Amount, Output, OutputFlags},
|
||||
DatabaseRo, RuntimeError,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Free functions
|
||||
/// Map a [`crate::types::Output`] to a [`cuprate_types::OutputOnChain`].
|
||||
pub(crate) fn output_to_output_on_chain(
|
||||
output: &Output,
|
||||
amount: Amount,
|
||||
table_tx_unlock_time: &impl DatabaseRo<TxUnlockTime>,
|
||||
) -> Result<OutputOnChain, RuntimeError> {
|
||||
// FIXME: implement lookup table for common values:
|
||||
// <https://github.com/monero-project/monero/blob/c8214782fb2a769c57382a999eaf099691c836e7/src/ringct/rctOps.cpp#L322>
|
||||
let commitment = ED25519_BASEPOINT_POINT + H() * Scalar::from(amount);
|
||||
|
||||
let time_lock = if output
|
||||
.output_flags
|
||||
.contains(OutputFlags::NON_ZERO_UNLOCK_TIME)
|
||||
{
|
||||
Timelock::Time(table_tx_unlock_time.get(&output.tx_idx)?)
|
||||
} else {
|
||||
Timelock::None
|
||||
};
|
||||
|
||||
let key = CompressedEdwardsY::from_slice(&output.key)
|
||||
.map(|y| y.decompress())
|
||||
.unwrap_or(None);
|
||||
|
||||
Ok(OutputOnChain {
|
||||
height: u64::from(output.height),
|
||||
time_lock,
|
||||
key,
|
||||
commitment,
|
||||
})
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -242,7 +242,7 @@ pub use env::{Env, EnvInner};
|
|||
mod error;
|
||||
pub use error::{InitError, RuntimeError};
|
||||
|
||||
mod free;
|
||||
pub(crate) mod free;
|
||||
|
||||
pub mod resize;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ use crate::{
|
|||
config::ReaderThreads,
|
||||
constants::DATABASE_CORRUPT_MSG,
|
||||
error::RuntimeError,
|
||||
free::output_to_output_on_chain,
|
||||
ops::{
|
||||
block::{get_block_extended_header_from_height, get_block_info},
|
||||
blockchain::{cumulative_generated_coins, top_block_height},
|
||||
|
@ -434,33 +435,9 @@ fn outputs(env: &ConcreteEnv, map: HashMap<Amount, HashSet<AmountIndex>>) -> Res
|
|||
amount,
|
||||
amount_index,
|
||||
};
|
||||
|
||||
let output = get_output(&pre_rct_output_id, tables.outputs())?;
|
||||
|
||||
//--- Map `Output` -> `OutputOnChain`
|
||||
|
||||
// FIXME: implement lookup table for common values:
|
||||
// <https://github.com/monero-project/monero/blob/c8214782fb2a769c57382a999eaf099691c836e7/src/ringct/rctOps.cpp#L322>
|
||||
let commitment = ED25519_BASEPOINT_POINT + H() * Scalar::from(amount);
|
||||
|
||||
let time_lock = if output
|
||||
.output_flags
|
||||
.contains(OutputFlags::NON_ZERO_UNLOCK_TIME)
|
||||
{
|
||||
Timelock::Time(tables.tx_unlock_time().get(&output.tx_idx)?)
|
||||
} else {
|
||||
Timelock::None
|
||||
};
|
||||
|
||||
let key = CompressedEdwardsY::from_slice(&output.key)
|
||||
.map(|y| y.decompress())
|
||||
.unwrap_or(None);
|
||||
|
||||
let output_on_chain = OutputOnChain {
|
||||
height: u64::from(output.height),
|
||||
time_lock,
|
||||
key,
|
||||
commitment,
|
||||
};
|
||||
let output_on_chain = output_to_output_on_chain(&output, amount, tables.tx_unlock_time())?;
|
||||
|
||||
Ok((amount_index, output_on_chain))
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue