mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-10 21:05:01 +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).
|
//! General free functions (related to the database).
|
||||||
//!
|
|
||||||
//! TODO.
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- 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
|
//---------------------------------------------------------------------------------------------------- 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
|
//---------------------------------------------------------------------------------------------------- Tests
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -242,7 +242,7 @@ pub use env::{Env, EnvInner};
|
||||||
mod error;
|
mod error;
|
||||||
pub use error::{InitError, RuntimeError};
|
pub use error::{InitError, RuntimeError};
|
||||||
|
|
||||||
mod free;
|
pub(crate) mod free;
|
||||||
|
|
||||||
pub mod resize;
|
pub mod resize;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ use crate::{
|
||||||
config::ReaderThreads,
|
config::ReaderThreads,
|
||||||
constants::DATABASE_CORRUPT_MSG,
|
constants::DATABASE_CORRUPT_MSG,
|
||||||
error::RuntimeError,
|
error::RuntimeError,
|
||||||
|
free::output_to_output_on_chain,
|
||||||
ops::{
|
ops::{
|
||||||
block::{get_block_extended_header_from_height, get_block_info},
|
block::{get_block_extended_header_from_height, get_block_info},
|
||||||
blockchain::{cumulative_generated_coins, top_block_height},
|
blockchain::{cumulative_generated_coins, top_block_height},
|
||||||
|
@ -434,33 +435,9 @@ fn outputs(env: &ConcreteEnv, map: HashMap<Amount, HashSet<AmountIndex>>) -> Res
|
||||||
amount,
|
amount,
|
||||||
amount_index,
|
amount_index,
|
||||||
};
|
};
|
||||||
|
|
||||||
let output = get_output(&pre_rct_output_id, tables.outputs())?;
|
let output = get_output(&pre_rct_output_id, tables.outputs())?;
|
||||||
|
let output_on_chain = output_to_output_on_chain(&output, amount, tables.tx_unlock_time())?;
|
||||||
//--- 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,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((amount_index, output_on_chain))
|
Ok((amount_index, output_on_chain))
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue