Differentiate BlockHeader from Block

This commit is contained in:
Luke Parker
2024-08-20 16:51:58 -04:00
parent 2b47feafed
commit 951872b026
5 changed files with 53 additions and 48 deletions

View File

@@ -5,7 +5,7 @@
use core::fmt::Debug;
use std::io;
use group::GroupEncoding;
use group::{Group, GroupEncoding};
use serai_primitives::Balance;
@@ -137,9 +137,8 @@ pub trait ReceivedOutput<K: GroupEncoding, A>:
fn read<R: io::Read>(reader: &mut R) -> io::Result<Self>;
}
/// A block from an external network.
#[async_trait::async_trait]
pub trait Block: Send + Sync + Sized + Clone + Debug {
/// A block header from an external network.
pub trait BlockHeader: Send + Sync + Sized + Clone + Debug {
/// The type used to identify blocks.
type Id: 'static + Id;
/// The ID of this block.
@@ -148,6 +147,31 @@ pub trait Block: Send + Sync + Sized + Clone + Debug {
fn parent(&self) -> Self::Id;
}
/// A block from an external network.
///
/// A block is defined as a consensus event associated with a set of transactions. It is not
/// necessary to literally define it as whatever the external network defines as a block. For
/// external networks which finalize block(s), this block type should be a representation of all
/// transactions within a period finalization (whether block or epoch).
#[async_trait::async_trait]
pub trait Block: Send + Sync + Sized + Clone + Debug {
/// The type used for this block's header.
type Header: BlockHeader;
/// The type used to represent keys on this external network.
type Key: Group + GroupEncoding;
/// The type used to represent addresses on this external network.
type Address;
/// The type used to represent received outputs on this external network.
type Output: ReceivedOutput<Self::Key, Self::Address>;
/// The ID of this block.
fn id(&self) -> <Self::Header as BlockHeader>::Id;
/// Scan all outputs within this block to find the outputs spendable by this key.
fn scan_for_outputs(&self, key: Self::Key) -> Vec<Self::Output>;
}
/// A wrapper for a group element which implements the borsh traits.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct BorshG<G: GroupEncoding>(pub G);