monero_interface/
provides_outputs.rs1use core::future::Future;
2use alloc::{format, vec::Vec};
3
4use monero_oxide::ed25519::{Point, CompressedPoint};
5
6use crate::InterfaceError;
7
8#[derive(Clone, Copy, PartialEq, Eq, Debug)]
10pub struct RingCtOutputInformation {
11 pub block_number: usize,
13 pub unlocked: bool,
15 pub key: CompressedPoint,
20 pub commitment: Point,
22 pub transaction: [u8; 32],
24}
25
26pub trait ProvidesUnvalidatedOutputs: Sync {
28 fn output_indexes(
32 &self,
33 hash: [u8; 32],
34 ) -> impl Send + Future<Output = Result<Vec<u64>, InterfaceError>>;
35
36 fn ringct_outputs(
41 &self,
42 indexes: &[u64],
43 ) -> impl Send + Future<Output = Result<Vec<RingCtOutputInformation>, InterfaceError>>;
44}
45
46pub trait ProvidesOutputs: Sync {
48 fn output_indexes(
53 &self,
54 hash: [u8; 32],
55 ) -> impl Send + Future<Output = Result<Vec<u64>, InterfaceError>>;
56
57 fn ringct_outputs(
62 &self,
63 indexes: &[u64],
64 ) -> impl Send + Future<Output = Result<Vec<RingCtOutputInformation>, InterfaceError>>;
65}
66
67impl<P: ProvidesUnvalidatedOutputs> ProvidesOutputs for P {
68 fn output_indexes(
69 &self,
70 hash: [u8; 32],
71 ) -> impl Send + Future<Output = Result<Vec<u64>, InterfaceError>> {
72 <P as ProvidesUnvalidatedOutputs>::output_indexes(self, hash)
73 }
74
75 fn ringct_outputs(
80 &self,
81 indexes: &[u64],
82 ) -> impl Send + Future<Output = Result<Vec<RingCtOutputInformation>, InterfaceError>> {
83 async move {
84 let outputs = <P as ProvidesUnvalidatedOutputs>::ringct_outputs(self, indexes).await?;
85 if outputs.len() != indexes.len() {
86 Err(InterfaceError::InternalError(format!(
87 "`{}` returned {} outputs, expected {}",
88 "ProvidesUnvalidatedOutputs::ringct_outputs",
89 outputs.len(),
90 indexes.len(),
91 )))?;
92 }
93 Ok(outputs)
94 }
95 }
96}