diff --git a/processor/src/coin/mod.rs b/processor/src/coin/mod.rs index 6cb19509..313dd2b3 100644 --- a/processor/src/coin/mod.rs +++ b/processor/src/coin/mod.rs @@ -19,6 +19,11 @@ pub enum CoinError { ConnectionError, } +pub trait Block: Sized + Clone { + type Id: Clone + Copy + AsRef<[u8]>; + fn id(&self) -> Self::Id; +} + #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum OutputType { External, @@ -27,7 +32,7 @@ pub enum OutputType { } pub trait Output: Sized + Clone { - type Id: AsRef<[u8]>; + type Id: Clone + Copy + AsRef<[u8]>; fn kind(&self) -> OutputType; @@ -44,7 +49,7 @@ pub trait Coin { type Fee: Copy; type Transaction; - type Block; + type Block: Block; type Output: Output; type SignableTransaction; diff --git a/processor/src/coin/monero.rs b/processor/src/coin/monero.rs index ca44ad2b..94f270c2 100644 --- a/processor/src/coin/monero.rs +++ b/processor/src/coin/monero.rs @@ -10,7 +10,7 @@ use frost::{curve::Ed25519, ThresholdKeys}; use monero_serai::{ transaction::Transaction, - block::Block, + block::Block as MBlock, rpc::Rpc, wallet::{ ViewPair, Scanner, @@ -21,9 +21,18 @@ use monero_serai::{ use crate::{ additional_key, - coin::{CoinError, OutputType, Output as OutputTrait, Coin}, + coin::{CoinError, Block as BlockTrait, OutputType, Output as OutputTrait, Coin}, }; +#[derive(Clone, Debug)] +pub struct Block([u8; 32], MBlock); +impl BlockTrait for Block { + type Id = [u8; 32]; + fn id(&self) -> Self::Id { + self.0 + } +} + #[derive(Clone, Debug)] pub struct Output(SpendableOutput); impl From for Output { @@ -162,7 +171,9 @@ impl Coin for Monero { } async fn get_block(&self, number: usize) -> Result { - self.rpc.get_block(number).await.map_err(|_| CoinError::ConnectionError) + let hash = self.rpc.get_block_hash(number).await.map_err(|_| CoinError::ConnectionError)?; + let block = self.rpc.get_block(hash).await.map_err(|_| CoinError::ConnectionError)?; + Ok(Block(hash, block)) } async fn get_outputs( @@ -172,7 +183,7 @@ impl Coin for Monero { ) -> Result, CoinError> { let mut transactions = self .scanner(key) - .scan(&self.rpc, block) + .scan(&self.rpc, &block.1) .await .map_err(|_| CoinError::ConnectionError)? .iter() @@ -288,7 +299,7 @@ impl Coin for Monero { } let outputs = Self::test_scanner() - .scan(&self.rpc, &self.rpc.get_block(new_block).await.unwrap()) + .scan(&self.rpc, &self.rpc.get_block_by_number(new_block).await.unwrap()) .await .unwrap() .swap_remove(0)