mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(payload builder): transaction pool filter (#10542)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -11913,4 +11913,4 @@ checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
]
|
||||
@ -208,7 +208,7 @@ pub struct BestTransactionFilter<I, P> {
|
||||
|
||||
impl<I, P> BestTransactionFilter<I, P> {
|
||||
/// Create a new [`BestTransactionFilter`] with the given predicate.
|
||||
pub(crate) const fn new(best: I, predicate: P) -> Self {
|
||||
pub const fn new(best: I, predicate: P) -> Self {
|
||||
Self { best, predicate }
|
||||
}
|
||||
}
|
||||
|
||||
@ -814,6 +814,36 @@ impl<T> BestTransactions for std::iter::Empty<T> {
|
||||
fn set_skip_blobs(&mut self, _skip_blobs: bool) {}
|
||||
}
|
||||
|
||||
/// A filter that allows to check if a transaction satisfies a set of conditions
|
||||
pub trait TransactionFilter {
|
||||
/// The type of the transaction to check.
|
||||
type Transaction;
|
||||
|
||||
/// Returns true if the transaction satisfies the conditions.
|
||||
fn is_valid(&self, transaction: &Self::Transaction) -> bool;
|
||||
}
|
||||
|
||||
/// A no-op implementation of [`TransactionFilter`] which
|
||||
/// marks all transactions as valid.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NoopTransactionFilter<T>(std::marker::PhantomData<T>);
|
||||
|
||||
// We can't derive Default because this forces T to be
|
||||
// Default as well, which isn't necessary.
|
||||
impl<T> Default for NoopTransactionFilter<T> {
|
||||
fn default() -> Self {
|
||||
Self(std::marker::PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TransactionFilter for NoopTransactionFilter<T> {
|
||||
type Transaction = T;
|
||||
|
||||
fn is_valid(&self, _transaction: &Self::Transaction) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// A Helper type that bundles the best transactions attributes together.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct BestTransactionsAttributes {
|
||||
|
||||
Reference in New Issue
Block a user