Skip to main content

Multiplexer

Struct Multiplexer 

Source
pub struct Multiplexer { /* private fields */ }
Expand description

Manages a set of conditional orders and computes their Merkle root.

The Merkle tree follows the OpenZeppelin MerkleTree standard used by the ComposableCow contract:

  • Leaf = keccak256(keccak256(abi.encode(params)))
  • Node = keccak256(min(left, right) ++ max(left, right))
  • Root is verified on-chain by ComposableCow::setRoot.

Implementations§

Source§

impl Multiplexer

Source

pub const fn new(proof_location: ProofLocation) -> Self

Create an empty multiplexer with the given proof location.

§Arguments
§Returns

A new, empty Multiplexer configured with the specified proof location.

Source

pub fn add(&mut self, params: ConditionalOrderParams)

Add a conditional order to the managed set.

The order is appended to the end; its position index can be used with proof or get_by_index.

§Arguments
Source

pub fn remove(&mut self, id: B256)

Remove the first conditional order whose order_id matches id.

If no order matches, this is a no-op.

§Arguments
  • id — the keccak256-based order identifier to match against.
Source

pub fn update( &mut self, index: usize, params: ConditionalOrderParams, ) -> Result<(), CowError>

Update the order at index with new params.

§Errors

Returns CowError::AppData if index is out of range.

Source

pub fn get_by_index(&self, index: usize) -> Option<&ConditionalOrderParams>

Retrieve the order at index.

§Arguments
  • index — zero-based position of the order in the managed set.
§Returns

Some(&ConditionalOrderParams) if the index is valid, or None if out of range.

Source

pub fn get_by_id(&self, id: B256) -> Option<&ConditionalOrderParams>

Retrieve the first order matching id.

§Arguments
  • id — the keccak256-based order identifier to search for.
§Returns

Some(&ConditionalOrderParams) for the first order whose computed order_id equals id, or None if no order matches.

Source

pub const fn len(&self) -> usize

Number of orders currently managed.

§Returns

The count of conditional orders in the managed set.

Source

pub const fn is_empty(&self) -> bool

True if no orders are managed.

§Returns

true when the multiplexer contains zero orders, false otherwise.

Source

pub fn root(&self) -> Result<Option<B256>, CowError>

Compute the Merkle root of all managed orders.

The root is computed using the OpenZeppelin MerkleTree algorithm: each leaf is keccak256(keccak256(abi.encode(params))) and internal nodes are keccak256(min(left, right) ++ max(left, right)).

Returns None if there are no orders.

§Errors

Returns CowError::AppData if ABI encoding of any order fails.

Source

pub fn proof(&self, index: usize) -> Result<OrderProof, CowError>

Generate a Merkle inclusion proof for the order at position index.

Returns the sibling hashes needed to verify membership against the root computed by root.

§Errors

Returns CowError::AppData if index is out of range.

Source

pub fn dump_proofs_and_params(&self) -> Result<Vec<ProofWithParams>, CowError>

Export all orders with their Merkle proofs — useful for watchtower services.

§Errors

Returns CowError::AppData if proof generation fails.

Source

pub fn order_ids(&self) -> impl Iterator<Item = B256> + '_

Iterate over the order IDs of all managed conditional orders.

Each ID is the keccak256 hash of the ABI-encoded ConditionalOrderParams as computed by order_id.

§Returns

An iterator yielding the B256 identifier for each managed order.

Source

pub fn iter(&self) -> impl Iterator<Item = &ConditionalOrderParams>

Iterate over all managed conditional orders.

§Returns

An iterator yielding shared references to each ConditionalOrderParams in insertion order.

Source

pub fn as_slice(&self) -> &[ConditionalOrderParams]

View all managed orders as a slice.

§Returns

A borrowed slice of all ConditionalOrderParams in insertion order.

Source

pub fn clear(&mut self)

Remove all managed orders.

Source

pub const fn proof_location(&self) -> ProofLocation

The configured proof location.

§Returns

The ProofLocation variant that was set at construction or via with_proof_location.

Source

pub const fn with_proof_location(self, location: ProofLocation) -> Self

Override the proof location and return self (builder style).

§Arguments
§Returns

The same Multiplexer with its proof location updated, enabling builder-style chaining.

Source

pub fn into_vec(self) -> Vec<ConditionalOrderParams>

Consume the multiplexer and return the managed orders as a Vec.

§Returns

A Vec<ConditionalOrderParams> containing all orders that were managed by this multiplexer, in insertion order.

Source

pub fn to_json(&self) -> Result<String, CowError>

Serialise the multiplexer to a JSON string.

The output is a JSON object with proof_location (integer) and orders (array of { handler, salt, static_input } hex strings). Deserialise with Multiplexer::from_json.

§Errors

Returns CowError::AppData if serialisation fails.

Source

pub fn decode_proofs_from_json( json: &str, ) -> Result<Vec<ProofWithParams>, CowError>

Decode a watchtower proof array from the JSON format used by the CoW Protocol watchtower service.

The input must be a JSON array of { "proof": ["0x...", ...], "params": { "handler": "0x...", "salt": "0x...", "staticInput": "0x..." } } objects.

§Errors

Returns CowError::AppData on parse or hex-decode failure.

Source

pub fn from_json(json: &str) -> Result<Self, CowError>

Deserialise a Multiplexer from a JSON string produced by Multiplexer::to_json.

§Errors

Returns CowError::AppData on parse or decode failure.

Trait Implementations§

Source§

impl Clone for Multiplexer

Source§

fn clone(&self) -> Multiplexer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Multiplexer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Multiplexer

Source§

fn default() -> Multiplexer

Returns the “default value” for a type. Read more
Source§

impl Display for Multiplexer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more