PathData

Struct PathData 

Source
pub struct PathData {
    pub flow_vertices: Vec<Address>,
    pub flow_edges: Vec<FlowEdge>,
    pub streams: Vec<Stream>,
    pub packed_coordinates: Vec<u8>,
    pub source_coordinate: U256,
}
Expand description

Simplified pathfinding result data structure

This struct contains the raw pathfinding results in a format that can be easily converted to contract-compatible types. It eliminates the need for manual field-by-field conversion between different type layers.

Fields§

§flow_vertices: Vec<Address>

Sorted list of all addresses involved in the flow

§flow_edges: Vec<FlowEdge>

Flow edges as (stream_sink_id, amount) tuples

§streams: Vec<Stream>

Streams as (source_coordinate, flow_edge_ids, data) tuples

§packed_coordinates: Vec<u8>

Packed coordinates as raw bytes

§source_coordinate: U256

Source coordinate index

Implementations§

Source§

impl PathData

Source

pub fn from_transfers( transfers: &[TransferStep], from: Address, to: Address, target_flow: U192, ) -> Result<Self, PathfinderError>

Create PathData from transfer steps

This is the main constructor that takes the output from pathfinding and creates a PathData structure ready for contract conversion.

§Arguments
  • transfers - Vector of transfer steps from pathfinding
  • from - Source address
  • to - Destination address
  • target_flow - Target flow amount
§Returns

A PathData structure ready for contract conversion

§Errors

Returns PathfinderError if flow matrix creation fails

Source

pub fn to_flow_edges(&self) -> Vec<FlowEdge>

Convert to standard Circles Hub FlowEdge types

Returns a vector of FlowEdge structs with the exact field names and types expected by the Circles Hub smart contract.

§Example
let edges = path_data.to_flow_edges();
assert_eq!(edges[0].streamSinkId, 1);
assert_eq!(edges[0].amount, U192::from(1000u64));
Source

pub fn to_streams(&self) -> Vec<Stream>

Convert to standard Circles Hub Stream types

Returns a vector of Stream structs with the exact field names and types expected by the Circles Hub smart contract.

§Example
let streams = path_data.to_streams();
assert_eq!(streams[0].sourceCoordinate, 0);
assert_eq!(streams[0].flowEdgeIds, vec![1, 2]);
Source

pub fn to_contract_params( &self, ) -> (Vec<Address>, Vec<FlowEdge>, Vec<Stream>, Bytes)

Get all contract call parameters in one tuple

This convenience method returns all the parameters needed for most Circles Hub contract calls in the correct order and format.

§Returns

A tuple of (flow_vertices, flow_edges, streams, packed_coordinates) ready to use in contract function calls.

§Example
let (vertices, edges, streams, coords) = path_data.to_contract_params();

// Ready for contract calls:
// contract.transferFlow(vertices, edges, streams, coords).send().await?;
Examples found in repository?
examples/contract_integration.rs (line 94)
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Example addresses (replace with real addresses)
9    let sender = Address::from_str("0x52e14be00d5acff4424ad625662c6262b4fd1a58")?;
10    let receiver = Address::from_str("0xcf6dc192dc292d5f2789da2db02d6dd4f41f4214")?;
11    let amount = U192::from_str("1000000000000000000")?; // 1 CRC in wei
12    let rpc_url = "https://rpc.aboutcircles.com/";
13
14    println!("Finding path and preparing contract data...");
15    println!("From: {sender}");
16    println!("To: {receiver}");
17    println!("Amount: {amount} wei");
18
19    let params = FindPathParams {
20        from: sender,
21        to: receiver,
22        target_flow: U256::from(amount),
23        use_wrapped_balances: Some(true),
24        from_tokens: None,
25        to_tokens: None,
26        exclude_from_tokens: None,
27        exclude_to_tokens: None,
28        simulated_balances: None,
29        max_transfers: None,
30    };
31
32    // NEW API: One function call does everything
33    let path_data: PathData = prepare_flow_for_contract(rpc_url, params).await?;
34
35    println!("\nFlow matrix prepared for contract calls:");
36    println!("Flow vertices: {} addresses", path_data.flow_vertices.len());
37    println!("Flow edges: {} transfers", path_data.flow_edges.len());
38    println!("Streams: {} streams", path_data.streams.len());
39    println!(
40        "Packed coordinates: {} bytes",
41        path_data.packed_coordinates.len()
42    );
43    println!("Source coordinate: {}", path_data.source_coordinate);
44
45    // Demonstrate contract-ready data
46    println!("\nContract-ready data:");
47
48    // Flow vertices (already Address types)
49    println!(
50        "Vertices (first 3): {:?}",
51        &path_data.flow_vertices[..3.min(path_data.flow_vertices.len())]
52    );
53
54    // Flow edges (raw tuples - convert to contract types)
55    for (i, flow_edge) in path_data.flow_edges.iter().take(3).enumerate() {
56        println!(
57            "Edge {i}: stream_sink_id={}, amount={amount}",
58            flow_edge.streamSinkId
59        );
60    }
61
62    // Streams (raw tuples - convert to contract types)
63    for (i, stream) in path_data.streams.iter().enumerate() {
64        println!(
65            "Stream {i}: source_coordinate={}, flow_edge_ids={:?}",
66            stream.sourceCoordinate, stream.flowEdgeIds
67        );
68    }
69
70    // Packed coordinates (raw bytes - convert to Bytes for contracts)
71    println!(
72        "Packed coordinates length: {} bytes",
73        path_data.packed_coordinates.len()
74    );
75
76    // Example: How you would use this in a smart contract call
77    println!("\nExample smart contract usage:");
78    println!("```rust");
79    println!("let contract = MyContract::new(contract_address, provider);");
80    println!("let tx = contract");
81    println!("    .redeemPayment(");
82    println!("        module_address,");
83    println!("        subscription_id,");
84    println!("        path_data.flow_vertices,           // Vec<Address>");
85    println!("        path_data.to_flow_edges(),         // Vec<FlowEdge>");
86    println!("        path_data.to_streams(),            // Vec<Stream>");
87    println!("        path_data.to_packed_coordinates()  // Bytes");
88    println!("    )");
89    println!("    .send()");
90    println!("    .await?;");
91    println!("```");
92
93    // Demonstrate decomposition for tuple-based contract calls
94    let (vertices, edges, streams, packed_coords) = path_data.to_contract_params();
95    println!("\nFor tuple-based contract calls:");
96    println!("Decomposed into {} components ready for contract", 4);
97    println!("- {} vertices", vertices.len());
98    println!("- {} edges", edges.len());
99    println!("- {} streams", streams.len());
100    println!("- {} bytes of coordinates", packed_coords.len());
101
102    Ok(())
103}
Source

pub fn to_packed_coordinates(&self) -> Bytes

Get packed coordinates as Bytes

Convenience method to get the packed coordinates in the Bytes format expected by contract calls.

Trait Implementations§

Source§

impl Clone for PathData

Source§

fn clone(&self) -> PathData

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 PathData

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, 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