2024-09-13 01:14:47 -04:00
|
|
|
use core::future::Future;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2024-09-13 01:14:47 -04:00
|
|
|
fn latest_finalized_block_number(
|
|
|
|
|
&self,
|
|
|
|
|
) -> impl Send + Future<Output = Result<u64, Self::EphemeralError>> {
|
|
|
|
|
async move {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-09-13 01:14:47 -04:00
|
|
|
fn time_of_block(
|
|
|
|
|
&self,
|
|
|
|
|
number: u64,
|
|
|
|
|
) -> impl Send + Future<Output = Result<u64, Self::EphemeralError>> {
|
2024-09-13 05:11:07 -04:00
|
|
|
async move { todo!("TODO") }
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
2024-09-13 01:14:47 -04:00
|
|
|
fn unchecked_block_header_by_number(
|
2024-09-12 18:40:10 -04:00
|
|
|
&self,
|
|
|
|
|
number: u64,
|
2024-09-13 01:14:47 -04:00
|
|
|
) -> impl Send
|
|
|
|
|
+ Future<Output = Result<<Self::Block as primitives::Block>::Header, Self::EphemeralError>>
|
|
|
|
|
{
|
|
|
|
|
async move { Ok(BlockHeader(self.rpc.get_block_by_number(number.try_into().unwrap()).await?)) }
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
|
2024-09-13 01:14:47 -04:00
|
|
|
fn unchecked_block_by_number(
|
2024-09-12 18:40:10 -04:00
|
|
|
&self,
|
|
|
|
|
number: u64,
|
2024-09-13 01:14:47 -04:00
|
|
|
) -> impl Send + Future<Output = Result<Self::Block, Self::EphemeralError>> {
|
|
|
|
|
async move { 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
|
|
|
}
|
|
|
|
|
|
2024-09-13 01:14:47 -04:00
|
|
|
fn cost_to_aggregate(
|
2024-09-12 18:40:10 -04:00
|
|
|
&self,
|
|
|
|
|
coin: Coin,
|
|
|
|
|
_reference_block: &Self::Block,
|
2024-09-13 01:14:47 -04:00
|
|
|
) -> impl Send + Future<Output = Result<Amount, Self::EphemeralError>> {
|
|
|
|
|
async move {
|
|
|
|
|
assert_eq!(coin, Coin::Bitcoin);
|
|
|
|
|
// TODO
|
|
|
|
|
Ok(Amount(0))
|
|
|
|
|
}
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-13 00:48:57 -04:00
|
|
|
impl TransactionPublisher<Transaction> for Rpc {
|
2024-09-12 18:40:10 -04:00
|
|
|
type EphemeralError = RpcError;
|
|
|
|
|
|
2024-09-13 01:14:47 -04:00
|
|
|
fn publish(
|
|
|
|
|
&self,
|
|
|
|
|
tx: Transaction,
|
|
|
|
|
) -> impl Send + Future<Output = Result<(), Self::EphemeralError>> {
|
|
|
|
|
async move { self.rpc.publish_transaction(&tx.0).await }
|
2024-09-12 18:40:10 -04:00
|
|
|
}
|
|
|
|
|
}
|