Trait hotshot_types::traits::block_contents::BlockPayload
source · pub trait BlockPayload<TYPES: NodeType>:
Serialize
+ Clone
+ Debug
+ Display
+ Hash
+ PartialEq
+ Eq
+ Send
+ Sync
+ DeserializeOwned
+ EncodeBytes {
type Error: Error + Debug + Send + Sync + Serialize + DeserializeOwned;
type Instance: InstanceState;
type Transaction: Transaction + Serialize + DeserializeOwned;
type ValidatedState: ValidatedState<TYPES>;
type Metadata: Clone + Debug + DeserializeOwned + Eq + Hash + Send + Sync + Serialize + EncodeBytes;
// Required methods
fn from_transactions<'life0, 'life1, 'async_trait>(
transactions: impl 'async_trait + IntoIterator<Item = Self::Transaction> + Send,
validated_state: &'life0 Self::ValidatedState,
instance_state: &'life1 Self::Instance,
) -> Pin<Box<dyn Future<Output = Result<(Self, Self::Metadata), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn from_bytes(
encoded_transactions: &[u8],
metadata: &Self::Metadata,
) -> Self;
fn empty() -> (Self, Self::Metadata);
fn builder_commitment(&self, metadata: &Self::Metadata) -> BuilderCommitment;
fn transactions<'a>(
&'a self,
metadata: &'a Self::Metadata,
) -> impl 'a + Iterator<Item = Self::Transaction>;
// Provided methods
fn transaction_commitments(
&self,
metadata: &Self::Metadata,
) -> Vec<Commitment<Self::Transaction>> { ... }
fn num_transactions(&self, metadata: &Self::Metadata) -> usize { ... }
}
Expand description
Abstraction over the full contents of a block
This trait encapsulates the behaviors that the transactions of a block must have in order to be used by consensus
- Must have a predefined error type (
BlockPayload::Error
) - Must have a transaction type that can be compared for equality, serialized and serialized, sent between threads, and can have a hash produced of it
- Must be hashable
Required Associated Types§
sourcetype Error: Error + Debug + Send + Sync + Serialize + DeserializeOwned
type Error: Error + Debug + Send + Sync + Serialize + DeserializeOwned
The error type for this type of block
sourcetype Instance: InstanceState
type Instance: InstanceState
The type of the instance-level state this state is associated with
sourcetype Transaction: Transaction + Serialize + DeserializeOwned
type Transaction: Transaction + Serialize + DeserializeOwned
The type of the transitions we are applying
sourcetype ValidatedState: ValidatedState<TYPES>
type ValidatedState: ValidatedState<TYPES>
Validated State
Required Methods§
sourcefn from_transactions<'life0, 'life1, 'async_trait>(
transactions: impl 'async_trait + IntoIterator<Item = Self::Transaction> + Send,
validated_state: &'life0 Self::ValidatedState,
instance_state: &'life1 Self::Instance,
) -> Pin<Box<dyn Future<Output = Result<(Self, Self::Metadata), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn from_transactions<'life0, 'life1, 'async_trait>(
transactions: impl 'async_trait + IntoIterator<Item = Self::Transaction> + Send,
validated_state: &'life0 Self::ValidatedState,
instance_state: &'life1 Self::Instance,
) -> Pin<Box<dyn Future<Output = Result<(Self, Self::Metadata), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Build a payload and associated metadata with the transactions. This function is asynchronous because it may need to request updated state from the peers via GET requests.
§Errors
If the transaction length conversion fails.
sourcefn from_bytes(encoded_transactions: &[u8], metadata: &Self::Metadata) -> Self
fn from_bytes(encoded_transactions: &[u8], metadata: &Self::Metadata) -> Self
Build a payload with the encoded transaction bytes, metadata, and the associated number of VID storage nodes
sourcefn builder_commitment(&self, metadata: &Self::Metadata) -> BuilderCommitment
fn builder_commitment(&self, metadata: &Self::Metadata) -> BuilderCommitment
Generate commitment that builders use to sign block options.
sourcefn transactions<'a>(
&'a self,
metadata: &'a Self::Metadata,
) -> impl 'a + Iterator<Item = Self::Transaction>
fn transactions<'a>( &'a self, metadata: &'a Self::Metadata, ) -> impl 'a + Iterator<Item = Self::Transaction>
Get the transactions in the payload.
Provided Methods§
sourcefn transaction_commitments(
&self,
metadata: &Self::Metadata,
) -> Vec<Commitment<Self::Transaction>>
fn transaction_commitments( &self, metadata: &Self::Metadata, ) -> Vec<Commitment<Self::Transaction>>
List of transaction commitments.
sourcefn num_transactions(&self, metadata: &Self::Metadata) -> usize
fn num_transactions(&self, metadata: &Self::Metadata) -> usize
Number of transactions in the block.