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
impl Multiplexer
Sourcepub const fn new(proof_location: ProofLocation) -> Self
pub const fn new(proof_location: ProofLocation) -> Self
Create an empty multiplexer with the given proof location.
§Arguments
proof_location— where the Merkle proofs will be stored or published (e.g.ProofLocation::Emitted,ProofLocation::Ipfs).
§Returns
A new, empty Multiplexer configured with the specified proof location.
Sourcepub fn add(&mut self, params: ConditionalOrderParams)
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
params— theConditionalOrderParamsdescribing the order to add.
Sourcepub fn update(
&mut self,
index: usize,
params: ConditionalOrderParams,
) -> Result<(), CowError>
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.
Sourcepub fn get_by_index(&self, index: usize) -> Option<&ConditionalOrderParams>
pub fn get_by_index(&self, index: usize) -> Option<&ConditionalOrderParams>
Sourcepub fn get_by_id(&self, id: B256) -> Option<&ConditionalOrderParams>
pub fn get_by_id(&self, id: B256) -> Option<&ConditionalOrderParams>
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
True if no orders are managed.
§Returns
true when the multiplexer contains zero orders, false otherwise.
Sourcepub fn root(&self) -> Result<Option<B256>, CowError>
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.
Sourcepub fn proof(&self, index: usize) -> Result<OrderProof, CowError>
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.
Sourcepub fn dump_proofs_and_params(&self) -> Result<Vec<ProofWithParams>, CowError>
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.
Sourcepub fn order_ids(&self) -> impl Iterator<Item = B256> + '_
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.
Sourcepub fn iter(&self) -> impl Iterator<Item = &ConditionalOrderParams>
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.
Sourcepub fn as_slice(&self) -> &[ConditionalOrderParams]
pub fn as_slice(&self) -> &[ConditionalOrderParams]
View all managed orders as a slice.
§Returns
A borrowed slice of all ConditionalOrderParams in insertion order.
Sourcepub const fn proof_location(&self) -> ProofLocation
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.
Sourcepub const fn with_proof_location(self, location: ProofLocation) -> Self
pub const fn with_proof_location(self, location: ProofLocation) -> Self
Override the proof location and return self (builder style).
§Arguments
location— the newProofLocationto use.
§Returns
The same Multiplexer with its proof location updated, enabling
builder-style chaining.
Sourcepub fn into_vec(self) -> Vec<ConditionalOrderParams>
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.
Sourcepub fn to_json(&self) -> Result<String, CowError>
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.
Sourcepub fn decode_proofs_from_json(
json: &str,
) -> Result<Vec<ProofWithParams>, CowError>
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.
Sourcepub fn from_json(json: &str) -> Result<Self, CowError>
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
impl Clone for Multiplexer
Source§fn clone(&self) -> Multiplexer
fn clone(&self) -> Multiplexer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Multiplexer
impl Debug for Multiplexer
Source§impl Default for Multiplexer
impl Default for Multiplexer
Source§fn default() -> Multiplexer
fn default() -> Multiplexer
Auto Trait Implementations§
impl Freeze for Multiplexer
impl RefUnwindSafe for Multiplexer
impl Send for Multiplexer
impl Sync for Multiplexer
impl Unpin for Multiplexer
impl UnsafeUnpin for Multiplexer
impl UnwindSafe for Multiplexer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.