Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

Generalized Electrum client that supports multiple backends. Can re-instantiate client_type if connections drops

Implementations§

Source§

impl Client

Source

pub fn new(url: &str) -> Result<Self, Error>

Default constructor supporting multiple backends by providing a prefix

Supported prefixes are:

  • tcp:// for a TCP plaintext client.
  • ssl:// for an SSL-encrypted client. The server certificate will be verified.

If no prefix is specified, then tcp:// is assumed.

See Client::from_config for more configuration options

Examples found in repository?
examples/plaintext.rs (line 4)
3fn main() {
4    let client = Client::new("tcp://electrum.blockstream.info:50001").unwrap();
5    let res = client.ping();
6    println!("{:#?}", res);
7}
More examples
Hide additional examples
examples/ssl.rs (line 4)
3fn main() {
4    let client = Client::new("ssl://electrum.blockstream.info:50002").unwrap();
5    let res = client.ping();
6    println!("{:#?}", res);
7}
Source

pub fn from_config(url: &str, config: Config) -> Result<Self, Error>

Generic constructor that supports multiple backends and allows configuration through the Config

Examples found in repository?
examples/tor.rs (line 9)
3fn main() {
4    // NOTE: This assumes Tor is running localy, with an unauthenticated Socks5 listening at
5    // localhost:9050
6    let proxy = Socks5Config::new("127.0.0.1:9050");
7    let config = ConfigBuilder::new().socks5(Some(proxy)).build();
8
9    let client = Client::from_config("tcp://explorernuoc63nb.onion:110", config.clone()).unwrap();
10    let res = client.ping();
11    println!("{:#?}", res);
12
13    // works both with onion v2/v3 (if your Tor supports them)
14    let client = Client::from_config(
15        "tcp://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion:110",
16        config,
17    )
18    .unwrap();
19    let res = client.ping();
20    println!("{:#?}", res);
21}

Trait Implementations§

Source§

impl ElectrumApi for Client

Source§

fn raw_call( &self, method_name: &str, params: impl IntoIterator<Item = Param>, ) -> Result<Value, Error>

Executes the requested API call returning the raw answer.
Source§

fn batch_call(&self, batch: &Batch) -> Result<Vec<Value>, Error>

Execute a queue of calls stored in a Batch struct. Returns Ok() only if all of the calls are successful. The order of the JSON Values returned reflects the order in which the calls were made on the Batch struct.
Source§

fn ping(&self) -> Result<(), Error>

Pings the server. This method can also be used as a “dummy” call to trigger the processing of incoming block header or script notifications.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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