Skip to main content

Client

Struct Client 

Source
pub struct Client {
    pub(crate) baseurl: String,
    pub(crate) client: Client,
}
Expand description

Client for hoprd-api

API enabling developers to interact with a hoprd node programatically through HTTP REST API.

Version: 4.11.0

Fields§

§baseurl: String§client: Client

Implementations§

Source§

impl Client

Source

pub fn new(baseurl: &str) -> Self

Create a new client.

baseurl is the base URL provided to the internal reqwest::Client, and should include a scheme and hostname, as well as port and a path stem if applicable.

Source

pub fn new_with_client(baseurl: &str, client: Client) -> Self

Construct a new client with an existing reqwest::Client, allowing more control over its configuration.

baseurl is the base URL provided to the internal reqwest::Client, and should include a scheme and hostname, as well as port and a path stem if applicable.

Source§

impl Client

Source

pub async fn addresses<'a>( &'a self, ) -> Result<ResponseValue<AccountAddressesResponse>, Error<()>>

Get node’s native addresses

Sends a GET request to /api/v4/account/addresses

Source

pub async fn balances<'a>( &'a self, ) -> Result<ResponseValue<AccountBalancesResponse>, Error<()>>

Get node’s and associated Safe’s HOPR and native balances as the allowance for HOPR tokens to be drawn by HoprChannels from Safe

HOPR tokens from the Safe balance are used to fund the payment channels between this node and other nodes on the network. NATIVE balance of the Node is used to pay for the gas fees for the blockchain.

Sends a GET request to /api/v4/account/balances

Source

pub async fn withdraw<'a>( &'a self, body: &'a WithdrawBodyRequest, ) -> Result<ResponseValue<WithdrawResponse>, Error<()>>

Withdraw funds from this node to the ethereum wallet address

Withdraw funds from this node to the ethereum wallet address

Sends a POST request to /api/v4/account/withdraw

Arguments:

  • body: Request body for the withdraw endpoint
Source

pub async fn list_channels<'a>( &'a self, full_topology: Option<bool>, including_closed: Option<bool>, ) -> Result<ResponseValue<NodeChannelsResponse>, Error<()>>

Lists channels opened to/from this node. Alternatively, it can print all the channels in the network as this node sees them

List channels opened to/from this node. Alternatively, it can print all the channels in the network as this node sees them.

Sends a GET request to /api/v4/channels

Arguments:

  • full_topology: Should all channels (not only the ones concerning this node) be enumerated?
  • including_closed: Should be the closed channels included?
Source

pub async fn open_channel<'a>( &'a self, body: &'a OpenChannelBodyRequest, ) -> Result<ResponseValue<OpenChannelResponse>, Error<()>>

Opens a channel to the given on-chain address with the given initial stake of HOPR tokens

Opens a channel to the given on-chain address with the given initial stake of HOPR tokens.

Sends a POST request to /api/v4/channels

Arguments:

  • body: Open channel request specification: on-chain address of the counterparty and the initial HOPR token stake.
Source

pub async fn show_channel<'a>( &'a self, address: &'a str, direction: Option<ChannelDirection>, ) -> Result<ResponseValue<ChannelInfoResponse>, Error<()>>

Returns information about the channel with the given counterparty address in the given direction

Returns information about the channel with the given counterparty address. Use the direction query parameter to choose between the outgoing (this node → counterparty, default) and incoming (counterparty → this node) channel.

Sends a GET request to /api/v4/channels/{address}

Arguments:

  • address: On-chain address of the counterparty.
  • direction: Direction of the channel relative to this node. Defaults to outgoing.
Source

pub async fn close_channel<'a>( &'a self, address: &'a str, direction: Option<ChannelDirection>, ) -> Result<ResponseValue<CloseChannelResponse>, Error<()>>

Closes the channel with the given counterparty in the given direction

Closes the channel with the given counterparty. Use the direction query parameter to choose between the outgoing (this node → counterparty, default) and incoming (counterparty → this node) channel.

Sends a DELETE request to /api/v4/channels/{address}

Arguments:

  • address: On-chain address of the counterparty.
  • direction: Direction of the channel relative to this node. Defaults to outgoing.
Source

pub async fn fund_channel<'a>( &'a self, address: &'a str, body: &'a FundBodyRequest, ) -> Result<ResponseValue<FundChannelResponse>, Error<()>>

Funds the outgoing channel to the given counterparty with the given amount of HOPR tokens

Funds the outgoing channel to the given counterparty with the given amount of HOPR tokens.

Sends a POST request to /api/v4/channels/{address}/fund

Arguments:

  • address: On-chain address of the counterparty.
  • body: Specifies the amount of HOPR tokens to fund a channel with.
Source

pub async fn announced<'a>( &'a self, ) -> Result<ResponseValue<Vec<AnnouncedPeerResponse>>, Error<()>>

Lists all announced peers

List all announced peers

Sends a GET request to /api/v4/network/announced

Source

pub async fn connected<'a>( &'a self, ) -> Result<ResponseValue<Vec<ConnectedPeerResponse>>, Error<()>>

Lists peers with immediate observation data from the network graph

List connected peers with immediate observation data from the network graph

Sends a GET request to /api/v4/network/connected

Source

pub async fn graph<'a>( &'a self, reachable_only: Option<bool>, ) -> Result<ResponseValue<ByteStream>, Error<()>>

Returns the network graph in DOT (Graphviz) format

Get the network graph in DOT (Graphviz) format

Sends a GET request to /api/v4/network/graph

Arguments:

  • reachable_only: When true, only include edges reachable from this node via directed traversal. Disconnected subgraphs that cannot be routed through are excluded.
Source

pub async fn price<'a>( &'a self, ) -> Result<ResponseValue<TicketPriceResponse>, Error<()>>

Gets the current ticket price

Get the current ticket price

Sends a GET request to /api/v4/network/price

Source

pub async fn probability<'a>( &'a self, ) -> Result<ResponseValue<TicketProbabilityResponse>, Error<()>>

Gets the current minimum incoming ticket winning probability defined by the network

Get the current minimum incoming ticket winning probability defined by the network

Sends a GET request to /api/v4/network/probability

Source

pub async fn configuration<'a>( &'a self, ) -> Result<ResponseValue<HashMap<String, String>>, Error<()>>

Get the configuration of the running node

Get the configuration of the running node

Sends a GET request to /api/v4/node/configuration

Source

pub async fn info<'a>( &'a self, ) -> Result<ResponseValue<NodeInfoResponse>, Error<()>>

Get information about this HOPR Node

Get information about this HOPR Node

Sends a GET request to /api/v4/node/info

Source

pub async fn version<'a>( &'a self, ) -> Result<ResponseValue<NodeVersionResponse>, Error<()>>

Get the release version of the running node

Get the release version of the running node

Sends a GET request to /api/v4/node/version

Source

pub async fn show_peer_info<'a>( &'a self, address: &'a str, ) -> Result<ResponseValue<NodePeerInfoResponse>, Error<()>>

Returns comprehensive information about the given peer

Includes announced and observed multiaddresses, QoS observation data from the network graph, and the state of any channels between this node and the peer.

Sends a GET request to /api/v4/peers/{address}

Arguments:

  • address: On-chain address of the requested peer
Source

pub async fn ping_peer<'a>( &'a self, address: &'a str, ) -> Result<ResponseValue<PingResponse>, Error<()>>

Directly pings the given peer

Directly ping the given peer

Sends a POST request to /api/v4/peers/{address}/ping

Arguments:

  • address: On-chain address of the requested peer
Source

pub async fn session_config<'a>( &'a self, id: &'a str, ) -> Result<ResponseValue<SessionConfig>, Error<()>>

Gets configuration of an existing active session.

Sends a GET request to /api/v4/session/config/{id}

Arguments:

  • id: Session ID
Source

pub async fn adjust_session<'a>( &'a self, id: &'a str, body: &'a SessionConfig, ) -> Result<ResponseValue<ByteStream>, Error<ApiError>>

Updates configuration of an existing active session.

Sends a POST request to /api/v4/session/config/{id}

Arguments:

  • id: Session ID
  • body: Allows updating of several parameters of an existing active session.
Source

pub async fn list_clients<'a>( &'a self, protocol: &'a str, ) -> Result<ResponseValue<Vec<SessionClientResponse>>, Error<()>>

Lists existing Session listeners for the given IP protocol

Lists existing Session listeners for the given IP protocol.

Sends a GET request to /api/v4/session/{protocol}

Arguments:

  • protocol: IP transport protocol
Source

pub async fn create_client<'a>( &'a self, protocol: &'a str, body: &'a SessionClientRequest, ) -> Result<ResponseValue<SessionClientResponse>, Error<()>>

Creates a new client session returning the given session listening host and port over TCP or UDP. If no listening port is given in the request, the socket will be bound to a random free port and returned in the response. Different capabilities can be configured for the session, such as data segmentation or retransmission

Creates a new client HOPR session that will start listening on a dedicated port. Once the port is bound, it is possible to use the socket for bidirectional read and write communication.

Sends a POST request to /api/v4/session/{protocol}

Arguments:

  • protocol: IP transport protocol
  • body: Creates a new client HOPR session that will start listening on a dedicated port. Once the port is bound, it is possible to use the socket for bidirectional read and write communication.
Source

pub async fn close_client<'a>( &'a self, protocol: IpProtocol, ip: &'a str, port: i32, ) -> Result<ResponseValue<ByteStream>, Error<ApiError>>

Closes an existing Session listener. The listener must’ve been previously created and bound for the given IP protocol. Once a listener is closed, no more socket connections can be made to it. If the passed port number is 0, listeners on all ports of the given listening IP and protocol will be closed

Closes an existing Session listener.

Sends a DELETE request to /api/v4/session/{protocol}/{ip}/{port}

Arguments:

  • protocol: IP transport protocol
  • ip: Listening IP address of the Session.
  • port: Session port used for the listener.
Source

pub async fn redeem_tickets<'a>( &'a self, body: &'a RedeemTicketsRequest, ) -> Result<ResponseValue<ByteStream>, Error<ApiError>>

Starts redeeming tickets

Starts redeeming tickets. When a counterparty address is specified, only tickets from that counterparty are redeemed.

Sends a POST request to /api/v4/tickets/redeem

Arguments:

  • body: Optional counterparty address to scope ticket redemption.
Source

pub async fn show_ticket_statistics<'a>( &'a self, ) -> Result<ResponseValue<NodeTicketStatisticsResponse>, Error<()>>

Returns current complete statistics on tickets

Returns current complete statistics on tickets.

Sends a GET request to /api/v4/tickets/statistics

Source

pub async fn eligiblez<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>>

Check whether the node is eligible in the network

Check whether the node is eligible in the network

Sends a GET request to /eligiblez

Source

pub async fn healthyz<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>>

Check whether the node is healthy

Check whether the node is healthy

Sends a GET request to /healthyz

Source

pub async fn metrics<'a>( &'a self, ) -> Result<ResponseValue<ByteStream>, Error<()>>

Retrieve Prometheus metrics from the running node

Retrieve Prometheus metrics from the running node

Sends a GET request to /metrics

Source

pub async fn readyz<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>>

Check whether the node is ready to accept connections

Check whether the node is ready to accept connections

Sends a GET request to /readyz

Source

pub async fn startedz<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>>

Check whether the node is started

Check whether the node is started

Sends a GET request to /startedz

Trait Implementations§

Source§

impl ClientHooks for &Client

§

async fn pre<E>( &self, request: &mut Request, info: &OperationInfo, ) -> Result<(), Error<E>>

Runs prior to the execution of the request. This may be used to modify the request before it is transmitted.
§

async fn post<E>( &self, result: &Result<Response, Error>, info: &OperationInfo, ) -> Result<(), Error<E>>

Runs after completion of the request.
§

async fn exec( &self, request: Request, info: &OperationInfo, ) -> Result<Response, Error>

Execute the request. Note that for almost any reasonable implementation this will include code equivalent to this: Read more
Source§

impl ClientInfo<()> for Client

Source§

fn api_version() -> &'static str

Get the version of this API. Read more
Source§

fn baseurl(&self) -> &str

Get the base URL to which requests are made.
Source§

fn client(&self) -> &Client

Get the internal reqwest::Client used to make requests.
Source§

fn inner(&self) -> &()

Get the inner value of type T if one is specified.
Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

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 Client

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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> 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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