Expand description
§electrum_streaming_client
A streaming, sans-IO Electrum client for asynchronous and blocking Rust applications.
This crate provides low-level primitives and high-level clients for communicating with Electrum
servers over JSON-RPC. It supports both asynchronous (futures
/tokio
) and blocking transport
models.
§Features
- Streaming protocol support: Handles both server-initiated notifications and responses.
- Transport agnostic: Works with any I/O type implementing the appropriate
Read
/Write
traits. - Sans-IO core: The
State
struct tracks pending requests and processes server messages. - Typed request/response system: Strongly typed Electrum method wrappers with minimal overhead.
§Example (async with Tokio)
use electrum_streaming_client::{AsyncClient, AsyncBatchRequest, Event};
use tokio::net::TcpStream;
use futures::StreamExt;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let stream = TcpStream::connect("127.0.0.1:50001").await?;
let (reader, writer) = stream.into_split();
let (client, mut events, worker) = AsyncClient::new_tokio(reader, writer);
tokio::spawn(worker); // spawn the client worker task
let mut batch = AsyncBatchRequest::new();
let fut = batch.request(electrum_streaming_client::request::RelayFee);
client.send_batch(batch)?;
let relay_fee = fut.await?;
println!("Relay fee: {relay_fee:?}");
while let Some(event) = events.next().await {
println!("Event: {event:?}");
}
Ok(())
}
§Optional Features
tokio
: EnablesAsyncClient::new_tokio
for use with Tokio-compatible streams.
§License
MIT
Re-exports§
pub use request::Request;
Modules§
- io
- Low-level I/O utilities for reading and writing Electrum JSON-RPC messages.
- notification
- Defines parsed Electrum server notifications.
- request
- Defines the request abstraction used to interact with the Electrum server.
- response
- Types representing structured responses returned by the Electrum server.
Structs§
- Async
Batch Request - A builder for batching multiple asynchronous requests to the Electrum server.
- Async
Client - An asynchronous Electrum client built on the
futures
I/O ecosystem. - Blocking
Batch Request - A builder for batching multiple blocking requests to the Electrum server.
- Blocking
Client - A blocking Electrum client built on standard I/O.
- Electrum
Script Hash - A script hash used by Electrum to identify wallet outputs.
- Electrum
Script Status - Represents the Electrum server’s status hash for a specific script.
- RawNotification
- A raw server-initiated JSON-RPC notification.
- RawRequest
- A raw JSON-RPC request to be sent to the Electrum server.
- RawResponse
- A raw JSON-RPC response from the Electrum server.
- Response
Error - Electrum server responds with an error.
- State
- A sans-io structure that manages the state of an Electrum client.
- Version
- Represents the
jsonrpc
version field in JSON-RPC messages.
Enums§
- Async
Pending Request - An internal representation of a pending asynchronous Electrum request.
- Batch
Request Error - An error that can occur when adding a request to a batch or polling its result.
- Blocking
Pending Request - An internal representation of a pending blocking Electrum request.
- Errored
Request - A request that received an error response from the Electrum server.
- Event
- Represents a high-level event produced after processing a server notification or response.
- Maybe
Batch - Represents either a single item or a batch of items.
- Process
Error - An error that occurred while processing an incoming server response or notification.
- RawNotification
OrResponse - A raw incoming message from the Electrum server.
- Satisfied
Request - A successfully handled request and its decoded server response.
Constants§
- JSONRPC_
VERSION_ 2_ 0 - The JSON-RPC protocol version supported by this client.
Traits§
- Pending
Request - A trait representing a request that has been sent to the Electrum server and is awaiting a response.
Type Aliases§
- Async
Event Receiver - The receiving half of the internal event stream, returned to users of
AsyncClient
. - Async
Event Sender - The sending half of the internal event stream, used to emit
Event
s from the client worker loop. - Async
Pending Request Tuple - A tracked or untracked asynchronous request, paired with an optional response sender.
- Async
Request Error - The error returned by
AsyncClient::send_request
when a request fails. - Async
Request Receiver - The receiving half of the request channel used internally by the async client.
- Async
Request Send Error - The error that occurs when a request cannot be sent into the async request channel.
- Async
Request Sender - The sending half of the channel used to enqueue one or more requests from
AsyncClient
. - Async
Response Receiver - A oneshot receiver used to await the result of a tracked async request.
- Async
Response Sender - A oneshot sender used to deliver the result of a tracked async request.
- Async
State - Internal
State
instance specialized for tracking asynchronous requests. - Blocking
Event Receiver - Channel receiver used to receive
Event
s from the Electrum server. - Blocking
Event Sender - Channel sender used by the read thread to emit
Event
s. - Blocking
Pending Request Tuple - A tracked or untracked blocking request, paired with an optional response sender.
- Blocking
Request Error - Error returned by
BlockingClient::send_request
if the request fails or is canceled. - Blocking
Request Receiver - Channel receiver used by the write thread to dequeue pending requests.
- Blocking
Request Send Error - Error that occurs when a blocking request cannot be sent to the internal request channel.
- Blocking
Request Sender - Channel sender for sending blocking requests from
BlockingClient
to the write thread. - Blocking
Response Receiver - One-shot receiver used to block and wait for a response to a tracked request.
- Blocking
Response Sender - One-shot sender used to deliver the result of a tracked blocking request.
- Blocking
State - Internal
State
specialized for tracking blocking requests. - CowStr
- An owned or borrowed static string.
- DoubleSHA
- A double SHA256 hash (
sha256d
) used for Merkle branches and header proofs. - Method
AndParams - A method name and its corresponding parameters, as used in a JSON-RPC request.
- Response
Result - A server response that is either a success (
Ok
) or a JSON-RPC error (Err
).