Fill in various DB functions

This commit is contained in:
Luke Parker
2024-08-28 23:31:31 -04:00
parent 738636c238
commit 04a971a024
7 changed files with 77 additions and 19 deletions

View File

@@ -23,9 +23,9 @@ pub trait Eventuality: Sized + Send + Sync {
fn forwarded_output(&self) -> Option<Self::OutputId>;
/// Read an Eventuality.
fn read<R: io::Read>(reader: &mut R) -> io::Result<Self>;
/// Serialize an Eventuality to a `Vec<u8>`.
fn serialize(&self) -> Vec<u8>;
fn read(reader: &mut impl io::Read) -> io::Result<Self>;
/// Write an Eventuality.
fn write(&self, writer: &mut impl io::Write) -> io::Result<()>;
}
/// A tracker of unresolved Eventualities.
@@ -36,3 +36,16 @@ pub struct EventualityTracker<E: Eventuality> {
/// These are keyed by their lookups.
pub active_eventualities: HashMap<Vec<u8>, E>,
}
impl<E: Eventuality> Default for EventualityTracker<E> {
fn default() -> Self {
EventualityTracker { active_eventualities: HashMap::new() }
}
}
impl<E: Eventuality> EventualityTracker<E> {
/// Insert an Eventuality into the tracker.
pub fn insert(&mut self, eventuality: E) {
self.active_eventualities.insert(eventuality.lookup(), eventuality);
}
}

View File

@@ -8,7 +8,12 @@ use serai_primitives::{ExternalAddress, Balance};
use crate::Id;
/// An address on the external network.
pub trait Address: Send + Sync + TryFrom<ExternalAddress> {}
pub trait Address: Send + Sync + TryFrom<ExternalAddress> {
/// Write this address.
fn write(&self, writer: &mut impl io::Write) -> io::Result<()>;
/// Read an address.
fn read(reader: &mut impl io::Read) -> io::Result<Self>;
}
/// The type of the output.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]