2024-09-13 00:48:57 -04:00
|
|
|
use monero_wallet::rpc::{RpcError, Rpc as RpcTrait};
|
|
|
|
|
use monero_simple_request_rpc::SimpleRequestRpc;
|
2024-09-12 18:40:10 -04:00
|
|
|
|
|
|
|
|
use serai_client::primitives::{NetworkId, Coin, Amount};
|
|
|
|
|
|
|
|
|
|
use scanner::ScannerFeed;
|
|
|
|
|
use signers::TransactionPublisher;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
transaction::Transaction,
|
|
|
|
|
block::{BlockHeader, Block},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
2024-09-13 00:48:57 -04:00
|
|
|
pub(crate) struct Rpc {
|
|
|
|
|
pub(crate) rpc: SimpleRequestRpc,
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
2024-09-13 00:48:57 -04:00
|
|
|
impl ScannerFeed for Rpc {
|
|
|
|
|
const NETWORK: NetworkId = NetworkId::Monero;
|
|
|
|
|
// Outputs aren't spendable until 10 blocks later due to the 10-block lock
|
|
|
|
|
// Since we assumed scanned outputs are spendable, that sets a minimum confirmation depth of 10
|
|
|
|
|
// A 10-block reorganization hasn't been observed in years and shouldn't occur
|
|
|
|
|
const CONFIRMATIONS: u64 = 10;
|
|
|
|
|
// The window length should be roughly an hour
|
|
|
|
|
const WINDOW_LENGTH: u64 = 30;
|
2024-09-12 18:40:10 -04:00
|
|
|
|
2024-09-13 00:48:57 -04:00
|
|
|
const TEN_MINUTES: u64 = 5;
|
2024-09-12 18:40:10 -04:00
|
|
|
|
2024-09-13 00:48:57 -04:00
|
|
|
type Block = Block;
|
2024-09-12 18:40:10 -04:00
|
|
|
|
|
|
|
|
type EphemeralError = RpcError;
|
|
|
|
|
|
|
|
|
|
async fn latest_finalized_block_number(&self) -> Result<u64, Self::EphemeralError> {
|
2024-09-13 00:48:57 -04:00
|
|
|
Ok(self.rpc.get_height().await?.checked_sub(1).expect("connected to an invalid Monero RPC").try_into().unwrap())
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn time_of_block(&self, number: u64) -> Result<u64, Self::EphemeralError> {
|
2024-09-13 00:48:57 -04:00
|
|
|
todo!("TODO")
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn unchecked_block_header_by_number(
|
|
|
|
|
&self,
|
|
|
|
|
number: u64,
|
|
|
|
|
) -> Result<<Self::Block as primitives::Block>::Header, Self::EphemeralError> {
|
|
|
|
|
Ok(BlockHeader(
|
2024-09-13 00:48:57 -04:00
|
|
|
self.rpc.get_block_by_number(number.try_into().unwrap()).await?
|
2024-09-12 18:40:10 -04:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn unchecked_block_by_number(
|
|
|
|
|
&self,
|
|
|
|
|
number: u64,
|
|
|
|
|
) -> Result<Self::Block, Self::EphemeralError> {
|
2024-09-13 00:48:57 -04:00
|
|
|
todo!("TODO")
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn dust(coin: Coin) -> Amount {
|
2024-09-13 00:48:57 -04:00
|
|
|
assert_eq!(coin, Coin::Monero);
|
2024-09-12 18:40:10 -04:00
|
|
|
|
2024-09-13 00:48:57 -04:00
|
|
|
todo!("TODO")
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn cost_to_aggregate(
|
|
|
|
|
&self,
|
|
|
|
|
coin: Coin,
|
|
|
|
|
_reference_block: &Self::Block,
|
|
|
|
|
) -> Result<Amount, Self::EphemeralError> {
|
|
|
|
|
assert_eq!(coin, Coin::Bitcoin);
|
|
|
|
|
// TODO
|
|
|
|
|
Ok(Amount(0))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
2024-09-13 00:48:57 -04:00
|
|
|
impl TransactionPublisher<Transaction> for Rpc {
|
2024-09-12 18:40:10 -04:00
|
|
|
type EphemeralError = RpcError;
|
|
|
|
|
|
|
|
|
|
async fn publish(&self, tx: Transaction) -> Result<(), Self::EphemeralError> {
|
2024-09-13 00:48:57 -04:00
|
|
|
self.rpc.publish_transaction(&tx.0).await
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
}
|