Skip to content

feat: add support for order-filtering as stream combinators#230

Merged
Fraser999 merged 3 commits into
mainfrom
fraser/eng-1789/stream-combinators
May 7, 2026
Merged

feat: add support for order-filtering as stream combinators#230
Fraser999 merged 3 commits into
mainfrom
fraser/eng-1789/stream-combinators

Conversation

@Fraser999
Copy link
Copy Markdown
Contributor

@Fraser999 Fraser999 commented May 5, 2026

[Claude Code]

Description

Adds stream combinators for filtering SignedOrder streams in signet-orders, plus a small supporting helper on SignedOrder itself.

  • New OrderStreamExt trait with filter_orders, implemented for any Stream<Item = Result<SignedOrder, E>>. Err items pass through unchanged; only Ok items are tested against the predicate. The predicate is FnMut, so stateful filtering (e.g. dedup by order_hash) is supported.
  • New stream::predicates module with ready-made predicate constructors: not_expired_at, has_output_chain, has_output_token, has_output_recipient, has_input_token, with_owner. Each returns impl Fn(&SignedOrder) -> bool and composes via boolean operators in a closure.
  • New SignedOrder::is_expired_at(timestamp) on signet-types, factored out of validate so the deadline check has a single source of truth and can be reused by not_expired_at. Boundary semantics are unchanged (timestamp == deadline is not expired; U256 deadlines saturate to u64::MAX).
  • Adds tokio (with macros, rt) as a [dev-dependencies] entry on signet-orders for the new #[tokio::test]s.
  • Bumps the version to 0.16.3 of all crates.

Test plan

  • cargo t -p signet-orders - new stream/predicate tests pass
  • cargo t -p signet-types - existing validate behavior preserved
  • cargo clippy -p signet-orders --all-features --all-targets
  • cargo clippy -p signet-orders --no-default-features --all-targets
  • cargo +nightly fmt -- --check
  • RUSTDOCFLAGS="-D warnings" cargo doc -p signet-orders --no-deps - verifies the predicates module-level doctest compiles

@Fraser999 Fraser999 requested a review from a team as a code owner May 5, 2026 23:36
Copy link
Copy Markdown
Contributor Author

Fraser999 commented May 5, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Fraser999 Fraser999 changed the title add support for order-filtering as stream combinators feat: add support for order-filtering as stream combinators May 5, 2026
Copy link
Copy Markdown
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one nit

Comment thread crates/orders/src/stream/predicates.rs Outdated
}

/// Match orders that have at least one [`Output`] paying `token`.
pub fn has_output_token(token: Address) -> impl Fn(&SignedOrder) -> bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be ambiguous if tokens on host and RU share an address. should we do a (chain_id, address) tuple here maybe?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slept on this. in extreme edge cases, an attacker can create this confusion. This should be caught downstream by additional filler quoting and pricing processes, but still better to do defense in depth here I think

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - addressed this in 6142c83.

@Fraser999 Fraser999 merged commit 191070c into main May 7, 2026
8 checks passed
@Fraser999 Fraser999 deleted the fraser/eng-1789/stream-combinators branch May 7, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants