Stub out Scheduler in the Monero processor

This commit is contained in:
Luke Parker
2024-09-14 01:38:31 -04:00
parent e1ad897f7e
commit a2d9aeaed7
6 changed files with 178 additions and 72 deletions

View File

@@ -1,21 +1,17 @@
use std::collections::HashMap;
use zeroize::Zeroizing;
use ciphersuite::{Ciphersuite, Ed25519};
use monero_wallet::{
block::Block as MBlock, rpc::ScannableBlock as MScannableBlock, ViewPairError,
GuaranteedViewPair, ScanError, GuaranteedScanner,
block::Block as MBlock, rpc::ScannableBlock as MScannableBlock, ScanError, GuaranteedScanner,
};
use serai_client::networks::monero::Address;
use primitives::{ReceivedOutput, EventualityTracker};
use view_keys::view_key;
use crate::{
EXTERNAL_SUBADDRESS, BRANCH_SUBADDRESS, CHANGE_SUBADDRESS, FORWARDED_SUBADDRESS, output::Output,
transaction::Eventuality,
EXTERNAL_SUBADDRESS, BRANCH_SUBADDRESS, CHANGE_SUBADDRESS, FORWARDED_SUBADDRESS, view_pair,
output::Output, transaction::Eventuality,
};
#[derive(Clone, Debug)]
@@ -45,17 +41,11 @@ impl primitives::Block for Block {
}
fn scan_for_outputs_unordered(&self, key: Self::Key) -> Vec<Self::Output> {
let view_pair = match GuaranteedViewPair::new(key.0, Zeroizing::new(*view_key::<Ed25519>(0))) {
Ok(view_pair) => view_pair,
Err(ViewPairError::TorsionedSpendKey) => {
unreachable!("dalek_ff_group::EdwardsPoint had torsion")
}
};
let mut scanner = GuaranteedScanner::new(view_pair);
scanner.register_subaddress(EXTERNAL_SUBADDRESS.unwrap());
scanner.register_subaddress(BRANCH_SUBADDRESS.unwrap());
scanner.register_subaddress(CHANGE_SUBADDRESS.unwrap());
scanner.register_subaddress(FORWARDED_SUBADDRESS.unwrap());
let mut scanner = GuaranteedScanner::new(view_pair(key));
scanner.register_subaddress(EXTERNAL_SUBADDRESS);
scanner.register_subaddress(BRANCH_SUBADDRESS);
scanner.register_subaddress(CHANGE_SUBADDRESS);
scanner.register_subaddress(FORWARDED_SUBADDRESS);
match scanner.scan(self.0.clone()) {
Ok(outputs) => outputs.not_additionally_locked().into_iter().map(Output).collect(),
Err(ScanError::UnsupportedProtocol(version)) => {

View File

@@ -1,10 +1,37 @@
use monero_wallet::address::SubaddressIndex;
use zeroize::Zeroizing;
use ciphersuite::{Ciphersuite, Ed25519};
use monero_wallet::{address::SubaddressIndex, ViewPairError, GuaranteedViewPair};
use view_keys::view_key;
pub(crate) mod output;
pub(crate) mod transaction;
pub(crate) mod block;
pub(crate) const EXTERNAL_SUBADDRESS: Option<SubaddressIndex> = SubaddressIndex::new(1, 0);
pub(crate) const BRANCH_SUBADDRESS: Option<SubaddressIndex> = SubaddressIndex::new(2, 0);
pub(crate) const CHANGE_SUBADDRESS: Option<SubaddressIndex> = SubaddressIndex::new(2, 1);
pub(crate) const FORWARDED_SUBADDRESS: Option<SubaddressIndex> = SubaddressIndex::new(2, 2);
pub(crate) const EXTERNAL_SUBADDRESS: SubaddressIndex = match SubaddressIndex::new(1, 0) {
Some(index) => index,
None => panic!("SubaddressIndex for EXTERNAL_SUBADDRESS was None"),
};
pub(crate) const BRANCH_SUBADDRESS: SubaddressIndex = match SubaddressIndex::new(2, 0) {
Some(index) => index,
None => panic!("SubaddressIndex for BRANCH_SUBADDRESS was None"),
};
pub(crate) const CHANGE_SUBADDRESS: SubaddressIndex = match SubaddressIndex::new(2, 1) {
Some(index) => index,
None => panic!("SubaddressIndex for CHANGE_SUBADDRESS was None"),
};
pub(crate) const FORWARDED_SUBADDRESS: SubaddressIndex = match SubaddressIndex::new(2, 2) {
Some(index) => index,
None => panic!("SubaddressIndex for FORWARDED_SUBADDRESS was None"),
};
pub(crate) fn view_pair(key: <Ed25519 as Ciphersuite>::G) -> GuaranteedViewPair {
match GuaranteedViewPair::new(key.0, Zeroizing::new(*view_key::<Ed25519>(0))) {
Ok(view_pair) => view_pair,
Err(ViewPairError::TorsionedSpendKey) => {
unreachable!("dalek_ff_group::EdwardsPoint had torsion")
}
}
}

View File

@@ -46,16 +46,17 @@ impl ReceivedOutput<<Ed25519 as Ciphersuite>::G, Address> for Output {
type TransactionId = [u8; 32];
fn kind(&self) -> OutputType {
if self.0.subaddress() == EXTERNAL_SUBADDRESS {
let subaddress = self.0.subaddress().unwrap();
if subaddress == EXTERNAL_SUBADDRESS {
return OutputType::External;
}
if self.0.subaddress() == BRANCH_SUBADDRESS {
if subaddress == BRANCH_SUBADDRESS {
return OutputType::Branch;
}
if self.0.subaddress() == CHANGE_SUBADDRESS {
if subaddress == CHANGE_SUBADDRESS {
return OutputType::Change;
}
if self.0.subaddress() == FORWARDED_SUBADDRESS {
if subaddress == FORWARDED_SUBADDRESS {
return OutputType::Forwarded;
}
unreachable!("scanned output to unknown subaddress");