use neptune_mutator_set::addition_record::AdditionRecord;
use neptune_mutator_set::commit;
use neptune_mutator_set::removal_record::absolute_index_set::AbsoluteIndexSet;
use rand::distr::Distribution;
use rand::distr::StandardUniform;
use rand::Rng;
use tasm_lib::prelude::Digest;
use tasm_lib::prelude::Tip5;
use tasm_lib::triton_vm::prelude::BFieldCodec;
use crate::transaction::utxo::Utxo;
#[derive(Debug, Clone, BFieldCodec)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct TransparentInput {
pub utxo: Utxo,
pub aocl_leaf_index: u64,
pub sender_randomness: Digest,
pub receiver_preimage: Digest,
}
impl TransparentInput {
pub fn absolute_index_set(&self) -> AbsoluteIndexSet {
let item = Tip5::hash(&self.utxo);
AbsoluteIndexSet::compute(
item,
self.sender_randomness,
self.receiver_preimage,
self.aocl_leaf_index,
)
}
pub fn addition_record(&self) -> AdditionRecord {
commit(
Tip5::hash(&self.utxo),
self.sender_randomness,
self.receiver_preimage.hash(),
)
}
}
impl Distribution<TransparentInput> for StandardUniform {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> TransparentInput {
let utxo = rng.random::<Utxo>();
let aocl_leaf_index = rng.random_range(0..(u64::MAX >> 1));
let sender_randomness = rng.random();
let receiver_preimage = rng.random();
TransparentInput {
utxo,
aocl_leaf_index,
sender_randomness,
receiver_preimage,
}
}
}