reth_payload_builder_primitives/
traits.rsuse crate::{PayloadBuilderError, PayloadEvents};
use alloy_rpc_types_engine::PayloadId;
use reth_payload_primitives::{PayloadKind, PayloadTypes};
use std::fmt::Debug;
use tokio::sync::oneshot;
#[async_trait::async_trait]
pub trait PayloadStoreExt<T: PayloadTypes>: Debug + Send + Sync + Unpin {
async fn resolve_kind(
&self,
id: PayloadId,
kind: PayloadKind,
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>>;
async fn resolve(&self, id: PayloadId) -> Option<Result<T::BuiltPayload, PayloadBuilderError>> {
self.resolve_kind(id, PayloadKind::Earliest).await
}
async fn best_payload(
&self,
id: PayloadId,
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>>;
async fn payload_attributes(
&self,
id: PayloadId,
) -> Option<Result<T::PayloadBuilderAttributes, PayloadBuilderError>>;
}
#[async_trait::async_trait]
impl<T: PayloadTypes, P> PayloadStoreExt<T> for P
where
P: PayloadBuilder<PayloadType = T>,
{
async fn resolve_kind(
&self,
id: PayloadId,
kind: PayloadKind,
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>> {
Some(PayloadBuilder::resolve_kind(self, id, kind).await?.map_err(Into::into))
}
async fn best_payload(
&self,
id: PayloadId,
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>> {
Some(PayloadBuilder::best_payload(self, id).await?.map_err(Into::into))
}
async fn payload_attributes(
&self,
id: PayloadId,
) -> Option<Result<T::PayloadBuilderAttributes, PayloadBuilderError>> {
Some(PayloadBuilder::payload_attributes(self, id).await?.map_err(Into::into))
}
}
#[async_trait::async_trait]
pub trait PayloadBuilder: Debug + Send + Sync + Unpin {
type PayloadType: PayloadTypes;
type Error: Into<PayloadBuilderError>;
fn send_new_payload(
&self,
attr: <Self::PayloadType as PayloadTypes>::PayloadBuilderAttributes,
) -> oneshot::Receiver<Result<PayloadId, Self::Error>>;
async fn best_payload(
&self,
id: PayloadId,
) -> Option<Result<<Self::PayloadType as PayloadTypes>::BuiltPayload, Self::Error>>;
async fn resolve_kind(
&self,
id: PayloadId,
kind: PayloadKind,
) -> Option<Result<<Self::PayloadType as PayloadTypes>::BuiltPayload, Self::Error>>;
async fn resolve(
&self,
id: PayloadId,
) -> Option<Result<<Self::PayloadType as PayloadTypes>::BuiltPayload, Self::Error>> {
self.resolve_kind(id, PayloadKind::Earliest).await
}
async fn subscribe(&self) -> Result<PayloadEvents<Self::PayloadType>, Self::Error>;
async fn payload_attributes(
&self,
id: PayloadId,
) -> Option<Result<<Self::PayloadType as PayloadTypes>::PayloadBuilderAttributes, Self::Error>>;
}