pub struct HttpClient { /* private fields */ }Expand description
HTTP client for the AnySwap server API. See the module docs for swap flows.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(base_url: &str, wallet: Option<&Wallet>) -> Result<Self, WalletError>
pub fn new(base_url: &str, wallet: Option<&Wallet>) -> Result<Self, WalletError>
A client for the server at base_url. It signs protected requests with
wallet’s identity key; without a wallet, only the public endpoints
work.
Sourcepub fn subscribe_url(&self) -> Result<String, ClientError>
pub fn subscribe_url(&self) -> Result<String, ClientError>
The signed /v1/subscribe/{user_id} WebSocket URL, auth in the query.
Sourcepub async fn get_info(&self) -> Result<InfoResponse, ClientError>
pub async fn get_info(&self) -> Result<InfoResponse, ClientError>
Fetches server info: protocol version, network, and per-chain policies (amount limits, confirmation requirements, swap_fee rates).
Sourcepub async fn create_swap(
&self,
req: &CreateSwapRequest,
) -> Result<(), ClientError>
pub async fn create_swap( &self, req: &CreateSwapRequest, ) -> Result<(), ClientError>
Initiates a swap. The server may cancel the swap right after creation;
the actual state is discovered via HttpClient::get_swap.
Sourcepub async fn list_swaps(
&self,
query: &SwapListQuery,
) -> Result<SwapListResponse, ClientError>
pub async fn list_swaps( &self, query: &SwapListQuery, ) -> Result<SwapListResponse, ClientError>
Fetches the paginated swap history for a user.
Sourcepub async fn cancel(
&self,
swap_id: Uuid,
req: &CancelRequest,
) -> Result<(), ClientError>
pub async fn cancel( &self, swap_id: Uuid, req: &CancelRequest, ) -> Result<(), ClientError>
Requests swap cancellation. The outcome is observed via
HttpClient::get_swap: Canceled reveals the server’s claim privkey
for an immediate keypath refund of any deposit.
Sourcepub async fn reveal_claim(
&self,
swap_id: Uuid,
req: &RevealClaimRequest,
) -> Result<(), ClientError>
pub async fn reveal_claim( &self, swap_id: Uuid, req: &RevealClaimRequest, ) -> Result<(), ClientError>
Reveals the user’s refund privkey after the claim invoice was paid (swap-in only), letting the server claim cooperatively via the keypath instead of the preimage script path.
Sourcepub async fn reveal_preimage(
&self,
swap_id: Uuid,
req: &RevealPreimageRequest,
) -> Result<(), ClientError>
pub async fn reveal_preimage( &self, swap_id: Uuid, req: &RevealPreimageRequest, ) -> Result<(), ClientError>
Reveals the preimage off-chain (swap-out only) instead of claiming via the script path. The server settles the held invoice and exposes its refund privkey, letting the user finish with a cheap cooperative keypath claim. Reveal only after the opening tx has the required confirmations.