Skip to main content

circles_rpc/methods/
pathfinder.rs

1use crate::client::RpcClient;
2use crate::error::Result;
3use circles_types::{FindPathParams, PathfindingResult, SimulatedBalance, SimulatedTrust};
4
5/// Methods for invoking the pathfinder (max-flow) RPC.
6///
7/// Mirrors `circlesV2_findPath` and accepts the full `FindPathParams`, including
8/// simulated balances, simulated trusts, and token overrides.
9#[derive(Clone, Debug)]
10pub struct PathfinderMethods {
11    client: RpcClient,
12}
13
14impl PathfinderMethods {
15    /// Create a new accessor for pathfinder RPCs.
16    pub fn new(client: RpcClient) -> Self {
17        Self { client }
18    }
19
20    /// circlesV2_findPath — accepts full FindPathParams
21    pub async fn find_path(&self, params: FindPathParams) -> Result<PathfindingResult> {
22        self.client.call("circlesV2_findPath", (params,)).await
23    }
24
25    /// Compatibility variant that lets callers overlay simulated balance/trust inputs.
26    pub async fn find_path_with_simulation(
27        &self,
28        mut params: FindPathParams,
29        simulated_balances: Option<Vec<SimulatedBalance>>,
30        simulated_trusts: Option<Vec<SimulatedTrust>>,
31    ) -> Result<PathfindingResult> {
32        if simulated_balances.is_some() {
33            params.simulated_balances = simulated_balances;
34        }
35        if simulated_trusts.is_some() {
36            params.simulated_trusts = simulated_trusts;
37        }
38        self.find_path(params).await
39    }
40}