diff --git a/processor/Cargo.toml b/processor/Cargo.toml index d9bab263..3de26e54 100644 --- a/processor/Cargo.toml +++ b/processor/Cargo.toml @@ -10,6 +10,7 @@ edition = "2021" async-trait = "0.1" thiserror = "1" +curve25519-dalek = { version = "3", features = ["std"] } monero = { version = "0.16", features = ["experimental"] } monero-serai = { path = "../coins/monero", features = ["multisig"] } diff --git a/processor/src/coins/monero.rs b/processor/src/coins/monero.rs index 88390795..e65cf1d9 100644 --- a/processor/src/coins/monero.rs +++ b/processor/src/coins/monero.rs @@ -1,5 +1,7 @@ use async_trait::async_trait; +use curve25519_dalek::{traits::Identity, scalar::Scalar, edwards::EdwardsPoint}; + use monero::util::address::Address; use monero_serai::{/*transaction::Output, */ rpc::Rpc, wallet::SpendableOutput}; @@ -28,11 +30,25 @@ impl OutputTrait for Output { } } -pub struct Monero(Rpc); +impl From for Output { + fn from(output: SpendableOutput) -> Output { + Output(output) + } +} + +pub struct Monero { + rpc: Rpc, + view: Scalar, + spend: EdwardsPoint +} impl Monero { pub fn new(url: String) -> Monero { - Monero(Rpc::new(url)) + Monero { + rpc: Rpc::new(url), + view: Scalar::zero(), + spend: EdwardsPoint::identity() + } } } @@ -46,11 +62,14 @@ impl Coin for Monero { async fn max_outputs() -> usize { 16 } async fn get_height(&self) -> Result { - self.0.get_height().await.map_err(|_| CoinError::ConnectionError) + self.rpc.get_height().await.map_err(|_| CoinError::ConnectionError) } - async fn get_outputs_in_block(&self) -> Result, CoinError> { - todo!() + async fn get_outputs_in_block(&self, height: usize) -> Result, CoinError> { + Ok( + self.rpc.get_block_transactions_possible(height).await.map_err(|_| CoinError::ConnectionError)? + .iter().flat_map(|tx| tx.scan(self.view, self.spend)).map(Output::from).collect() + ) } async fn send( diff --git a/processor/src/lib.rs b/processor/src/lib.rs index ac355340..41012af3 100644 --- a/processor/src/lib.rs +++ b/processor/src/lib.rs @@ -32,7 +32,7 @@ trait Coin { async fn max_outputs() -> usize; async fn get_height(&self) -> Result; - async fn get_outputs_in_block(&self) -> Result, CoinError>; + async fn get_outputs_in_block(&self, height: usize) -> Result, CoinError>; async fn send( &self, payments: &[(Self::Address, u64)]