[][src]Struct electrum_client::client::Client

pub struct Client<S> where
    S: Read + Write
{ /* fields omitted */ }

Instance of an Electrum client

A Client maintains a constant connection with an Electrum server and exposes methods to interact with it. It can also subscribe and receive notifictations from the server about new blocks or activity on a specific scriptPubKey.

The Client is modeled in such a way that allows the external caller to have full control over its functionality: no threads or tasks are spawned internally to monitor the state of the connection. This allows the caller to control its behavior through some polling functions, and ultimately makes the library more lightweight and easier to embed into existing projects.

More transport methods can be used by manually creating an instance of this struct with an arbitray S type.

Methods

impl Client<ElectrumPlaintextStream>[src]

pub fn new<A: ToSocketAddrs>(socket_addr: A) -> Result<Self, Error>[src]

Creates a new plaintext client and tries to connect to socket_addr.

impl Client<ElectrumSslStream>[src]

pub fn new_ssl<A: ToSocketAddrsDomain>(
    socket_addr: A,
    validate_domain: bool
) -> Result<Self, Error>
[src]

Creates a new SSL client and tries to connect to socket_addr. Optionally, if validate_domain is true, validate the server's certificate.

impl Client<ElectrumProxyStream>[src]

pub fn new_proxy<A: ToSocketAddrs, T: ToTargetAddr>(
    target_addr: T,
    proxy_addr: A
) -> Result<Self, Error>
[src]

Creates a new socks client and tries to connect to target_addr using proxy_addr as an unauthenticated socks proxy server. The DNS resolution of target_addr, if required, is done through the proxy. This allows to specify, for instance, .onion addresses.

impl<S: Read + Write> Client<S>[src]

pub fn batch_call(&mut self, batch: Batch) -> Result<Vec<Value>, Error>[src]

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.

pub fn poll(&mut self) -> Result<(), Error>[src]

Tries to read from the read buffer if any notifications were received since the last call or poll, and processes them

pub fn block_headers_subscribe(&mut self) -> Result<HeaderNotification, Error>[src]

Subscribes to notifications for new block headers, by sending a blockchain.headers.subscribe call.

pub fn block_headers_poll(
    &mut self
) -> Result<Option<HeaderNotification>, Error>
[src]

Tries to pop one queued notification for a new block header that we might have received. Returns None if there are no items in the queue.

pub fn block_header(&mut self, height: usize) -> Result<BlockHeader, Error>[src]

Gets the block header for height height.

pub fn block_headers(
    &mut self,
    start_height: usize,
    count: usize
) -> Result<GetHeadersRes, Error>
[src]

Tries to fetch count block headers starting from start_height.

pub fn estimate_fee(&mut self, number: usize) -> Result<f64, Error>[src]

Estimates the fee required in Satoshis per kilobyte to confirm a transaction in number blocks.

pub fn relay_fee(&mut self) -> Result<f64, Error>[src]

Returns the minimum accepted fee by the server's node in Bitcoin, not Satoshi.

pub fn script_subscribe(
    &mut self,
    script: &Script
) -> Result<ScriptStatus, Error>
[src]

Subscribes to notifications for activity on a specific scriptPubKey.

Returns a ScriptStatus when successful that represents the current status for the requested script.

Returns Error::AlreadySubscribed if already subscribed to the same script.

pub fn script_unsubscribe(&mut self, script: &Script) -> Result<bool, Error>[src]

Subscribes to notifications for activity on a specific scriptPubKey.

Returns a bool with the server response when successful.

Returns Error::NotSubscribed if not subscribed to the script.

pub fn script_poll(
    &mut self,
    script: &Script
) -> Result<Option<ScriptStatus>, Error>
[src]

Tries to pop one queued notification for a the requested script. Returns None if there are no items in the queue.

pub fn script_get_balance(
    &mut self,
    script: &Script
) -> Result<GetBalanceRes, Error>
[src]

Returns the balance for a scriptPubKey

pub fn batch_script_get_balance<'s, I>(
    &mut self,
    scripts: I
) -> Result<Vec<GetBalanceRes>, Error> where
    I: IntoIterator<Item = &'s Script>, 
[src]

Batch version of script_get_balance.

Takes a list of scripts and returns a list of balance responses.

pub fn script_get_history(
    &mut self,
    script: &Script
) -> Result<Vec<GetHistoryRes>, Error>
[src]

Returns the history for a scriptPubKey

pub fn batch_script_get_history<'s, I>(
    &mut self,
    scripts: I
) -> Result<Vec<Vec<GetHistoryRes>>, Error> where
    I: IntoIterator<Item = &'s Script>, 
[src]

Batch version of script_get_history.

Takes a list of scripts and returns a list of history responses.

pub fn script_list_unspent(
    &mut self,
    script: &Script
) -> Result<Vec<ListUnspentRes>, Error>
[src]

Returns the list of unspent outputs for a scriptPubKey

pub fn batch_script_list_unspent<'s, I>(
    &mut self,
    scripts: I
) -> Result<Vec<Vec<ListUnspentRes>>, Error> where
    I: IntoIterator<Item = &'s Script>, 
[src]

Batch version of script_list_unspent.

Takes a list of scripts and returns a list of a list of utxos.

pub fn transaction_get(&mut self, txid: &Txid) -> Result<Transaction, Error>[src]

Gets the raw transaction with txid. Returns an error if not found.

pub fn batch_transaction_get<'t, I>(
    &mut self,
    txids: Vec<&Txid>
) -> Result<Vec<Transaction>, Error> where
    I: IntoIterator<Item = &'t Txid>, 
[src]

Batch version of transaction_get.

Takes a list of txids and returns a list of transactions.

pub fn transaction_broadcast(&mut self, tx: &Transaction) -> Result<Txid, Error>[src]

Broadcasts a transaction to the network.

pub fn transaction_get_merkle(
    &mut self,
    txid: &Txid,
    height: usize
) -> Result<GetMerkleRes, Error>
[src]

Returns the merkle path for the transaction txid confirmed in the block at height.

pub fn server_features(&mut self) -> Result<ServerFeaturesRes, Error>[src]

Returns the capabilities of the server.

Trait Implementations

impl<S: Debug> Debug for Client<S> where
    S: Read + Write
[src]

impl<S> From<S> for Client<S> where
    S: Read + Write
[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for Client<S>

impl<S> Send for Client<S> where
    S: Send

impl<S> Sync for Client<S> where
    S: Send

impl<S> Unpin for Client<S>

impl<S> UnwindSafe for Client<S>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.