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
impl Client
Sourcepub fn new(url: &str) -> Result<Self, Error>
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?
More examples
Sourcepub fn from_config(url: &str, config: Config) -> Result<Self, Error>
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 11)
5fn main() {
6 // NOTE: This assumes Tor is running localy, with an unauthenticated Socks5 listening at
7 // localhost:9050
8 let proxy = Socks5Config::new("127.0.0.1:9050");
9 let config = ConfigBuilder::new().socks5(Some(proxy)).build();
10
11 let client = Client::from_config("tcp://explorernuoc63nb.onion:110", config.clone()).unwrap();
12 let res = client.server_features();
13 println!("{:#?}", res);
14
15 // works both with onion v2/v3 (if your Tor supports them)
16 let client = Client::from_config(
17 "tcp://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion:110",
18 config,
19 )
20 .unwrap();
21 let res = client.server_features();
22 println!("{:#?}", res);
23}
Trait Implementations§
Source§impl ElectrumApi for Client
impl ElectrumApi for Client
Source§fn raw_call(
&self,
method_name: &str,
params: impl IntoIterator<Item = Param>,
) -> Result<Value, Error>
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>
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 Value
s returned
reflects the order in which the calls were made on the Batch
struct.Source§fn block_headers_subscribe_raw(&self) -> Result<RawHeaderNotification, Error>
fn block_headers_subscribe_raw(&self) -> Result<RawHeaderNotification, Error>
Subscribes to notifications for new block headers, by sending a
blockchain.headers.subscribe
call and
returns the current tip as raw bytes instead of deserializing them.Source§fn block_headers_pop_raw(&self) -> Result<Option<RawHeaderNotification>, Error>
fn block_headers_pop_raw(&self) -> Result<Option<RawHeaderNotification>, Error>
Tries to pop one queued notification for a new block header that we might have received.
Returns a the header in raw bytes if a notification is found in the queue, None otherwise.
Source§fn block_header_raw(&self, height: usize) -> Result<Vec<u8>, Error>
fn block_header_raw(&self, height: usize) -> Result<Vec<u8>, Error>
Gets the raw bytes of block header for height
height
.Source§fn block_headers(
&self,
start_height: usize,
count: usize,
) -> Result<GetHeadersRes, Error>
fn block_headers( &self, start_height: usize, count: usize, ) -> Result<GetHeadersRes, Error>
Tries to fetch
count
block headers starting from start_height
.Source§fn estimate_fee(&self, number: usize) -> Result<f64, Error>
fn estimate_fee(&self, number: usize) -> Result<f64, Error>
Estimates the fee required in Bitcoin per kilobyte to confirm a transaction in
number
blocks.Source§fn relay_fee(&self) -> Result<f64, Error>
fn relay_fee(&self) -> Result<f64, Error>
Returns the minimum accepted fee by the server’s node in Bitcoin, not Satoshi.
Source§fn script_subscribe(
&self,
script: &Script,
) -> Result<Option<ScriptStatus>, Error>
fn script_subscribe( &self, script: &Script, ) -> Result<Option<ScriptStatus>, Error>
Subscribes to notifications for activity on a specific scriptPubKey. Read more
Source§fn batch_script_subscribe<'s, I>(
&self,
scripts: I,
) -> Result<Vec<Option<ScriptStatus>>, Error>
fn batch_script_subscribe<'s, I>( &self, scripts: I, ) -> Result<Vec<Option<ScriptStatus>>, Error>
Batch version of
script_subscribe
. Read moreSource§fn script_unsubscribe(&self, script: &Script) -> Result<bool, Error>
fn script_unsubscribe(&self, script: &Script) -> Result<bool, Error>
Subscribes to notifications for activity on a specific scriptPubKey. Read more
Source§fn script_pop(&self, script: &Script) -> Result<Option<ScriptStatus>, Error>
fn script_pop(&self, script: &Script) -> Result<Option<ScriptStatus>, Error>
Tries to pop one queued notification for a the requested script. Returns
None
if there are no items in the queue.Source§fn script_get_balance(&self, script: &Script) -> Result<GetBalanceRes, Error>
fn script_get_balance(&self, script: &Script) -> Result<GetBalanceRes, Error>
Returns the balance for a scriptPubKey.
Source§fn batch_script_get_balance<'s, I>(
&self,
scripts: I,
) -> Result<Vec<GetBalanceRes>, Error>
fn batch_script_get_balance<'s, I>( &self, scripts: I, ) -> Result<Vec<GetBalanceRes>, Error>
Batch version of
script_get_balance
. Read moreSource§fn script_get_history(
&self,
script: &Script,
) -> Result<Vec<GetHistoryRes>, Error>
fn script_get_history( &self, script: &Script, ) -> Result<Vec<GetHistoryRes>, Error>
Returns the history for a scriptPubKey
Source§fn batch_script_get_history<'s, I>(
&self,
scripts: I,
) -> Result<Vec<Vec<GetHistoryRes>>, Error>
fn batch_script_get_history<'s, I>( &self, scripts: I, ) -> Result<Vec<Vec<GetHistoryRes>>, Error>
Batch version of
script_get_history
. Read moreSource§fn script_list_unspent(
&self,
script: &Script,
) -> Result<Vec<ListUnspentRes>, Error>
fn script_list_unspent( &self, script: &Script, ) -> Result<Vec<ListUnspentRes>, Error>
Returns the list of unspent outputs for a scriptPubKey
Source§fn batch_script_list_unspent<'s, I>(
&self,
scripts: I,
) -> Result<Vec<Vec<ListUnspentRes>>, Error>
fn batch_script_list_unspent<'s, I>( &self, scripts: I, ) -> Result<Vec<Vec<ListUnspentRes>>, Error>
Batch version of
script_list_unspent
. Read moreSource§fn transaction_get_raw(&self, txid: &Txid) -> Result<Vec<u8>, Error>
fn transaction_get_raw(&self, txid: &Txid) -> Result<Vec<u8>, Error>
Gets the raw bytes of a transaction with
txid
. Returns an error if not found.Source§fn batch_transaction_get_raw<'t, I>(
&self,
txids: I,
) -> Result<Vec<Vec<u8>>, Error>
fn batch_transaction_get_raw<'t, I>( &self, txids: I, ) -> Result<Vec<Vec<u8>>, Error>
Batch version of
transaction_get_raw
. Read moreSource§fn batch_block_header_raw<'s, I>(
&self,
heights: I,
) -> Result<Vec<Vec<u8>>, Error>
fn batch_block_header_raw<'s, I>( &self, heights: I, ) -> Result<Vec<Vec<u8>>, Error>
Batch version of
block_header_raw
. Read moreSource§fn batch_estimate_fee<'s, I>(&self, numbers: I) -> Result<Vec<f64>, Error>
fn batch_estimate_fee<'s, I>(&self, numbers: I) -> Result<Vec<f64>, Error>
Batch version of
estimate_fee
. Read moreSource§fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<Txid, Error>
fn transaction_broadcast_raw(&self, raw_tx: &[u8]) -> Result<Txid, Error>
Broadcasts the raw bytes of a transaction to the network.
Source§fn transaction_get_merkle(
&self,
txid: &Txid,
height: usize,
) -> Result<GetMerkleRes, Error>
fn transaction_get_merkle( &self, txid: &Txid, height: usize, ) -> Result<GetMerkleRes, Error>
Returns the merkle path for the transaction
txid
confirmed in the block at height
.Source§fn txid_from_pos(&self, height: usize, tx_pos: usize) -> Result<Txid, Error>
fn txid_from_pos(&self, height: usize, tx_pos: usize) -> Result<Txid, Error>
Returns a transaction hash, given a block
height
and a tx_pos
in the block.Source§fn txid_from_pos_with_merkle(
&self,
height: usize,
tx_pos: usize,
) -> Result<TxidFromPosRes, Error>
fn txid_from_pos_with_merkle( &self, height: usize, tx_pos: usize, ) -> Result<TxidFromPosRes, Error>
Returns a transaction hash and a merkle path, given a block
height
and a tx_pos
in the
block.Source§fn server_features(&self) -> Result<ServerFeaturesRes, Error>
fn server_features(&self) -> Result<ServerFeaturesRes, Error>
Returns the capabilities of the server.
Source§fn ping(&self) -> Result<(), Error>
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.
Source§fn block_header(&self, height: usize) -> Result<Header, Error>
fn block_header(&self, height: usize) -> Result<Header, Error>
Gets the block header for height
height
.Source§fn block_headers_subscribe(&self) -> Result<HeaderNotification, Error>
fn block_headers_subscribe(&self) -> Result<HeaderNotification, Error>
Subscribes to notifications for new block headers, by sending a
blockchain.headers.subscribe
call.Source§fn block_headers_pop(&self) -> Result<Option<HeaderNotification>, Error>
fn block_headers_pop(&self) -> Result<Option<HeaderNotification>, Error>
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.Source§fn transaction_get(&self, txid: &Txid) -> Result<Transaction, Error>
fn transaction_get(&self, txid: &Txid) -> Result<Transaction, Error>
Gets the transaction with
txid
. Returns an error if not found.Source§fn batch_transaction_get<'t, I>(
&self,
txids: I,
) -> Result<Vec<Transaction>, Error>
fn batch_transaction_get<'t, I>( &self, txids: I, ) -> Result<Vec<Transaction>, Error>
Batch version of
transaction_get
. Read moreSource§fn batch_block_header<I>(&self, heights: I) -> Result<Vec<Header>, Error>
fn batch_block_header<I>(&self, heights: I) -> Result<Vec<Header>, Error>
Batch version of
block_header
. Read moreSource§fn transaction_broadcast(&self, tx: &Transaction) -> Result<Txid, Error>
fn transaction_broadcast(&self, tx: &Transaction) -> Result<Txid, Error>
Broadcasts a transaction to the network.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more