Skip to content

Commit

Permalink
Merge #94: Add Batch::raw and improve docs
Browse files Browse the repository at this point in the history
adb0c74 Add `Batch::raw` and improve docs (志宇)

Pull request description:

  Being able to add raw requests to `Batch` makes sense from an API standpoint because we already allow raw non-batched requests. This is also useful when the electrum server API gets an updated version and our client is unable to keep up.

  Additional to this, I have improved the documentation and made `Call` private (since `Call` is never used externally).

ACKs for top commit:
  notmandatory:
    ACK adb0c74

Tree-SHA512: 808dccf1152b750881e45a9709fb4127835ecff3da5ecccffcb9f03e62171192c58154860195db7d3d3467ae8e3e450bba845ff4e8d4dffb302c3d8d6eb837fd
  • Loading branch information
notmandatory committed Dec 7, 2023
2 parents 5ecb26f + adb0c74 commit 8b31e5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub struct Batch {
}

impl Batch {
/// Add a raw request to the batch queue
pub fn raw(&mut self, method: String, params: Vec<Param>) {
self.calls.push((method, params));
}

/// Add one `blockchain.scripthash.listunspent` request to the batch queue
pub fn script_list_unspent(&mut self, script: &Script) {
let params = vec![Param::String(script.to_electrum_scripthash().to_hex())];
Expand Down
22 changes: 22 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use std::time::Duration;

/// Configuration for an electrum client
///
/// Refer to [`Client::from_config`] and [`ClientType::from_config`].
///
/// [`Client::from_config`]: crate::Client::from_config
/// [`ClientType::from_config`]: crate::ClientType::from_config
#[derive(Debug, Clone)]
pub struct Config {
/// Proxy socks5 configuration, default None
Expand Down Expand Up @@ -97,19 +103,35 @@ impl Socks5Config {
}

impl Config {
/// Get the configuration for `socks5`
///
/// Set this with [`ConfigBuilder::socks5`]
pub fn socks5(&self) -> &Option<Socks5Config> {
&self.socks5
}

/// Get the configuration for `retry`
///
/// Set this with [`ConfigBuilder::retry`]
pub fn retry(&self) -> u8 {
self.retry
}

/// Get the configuration for `timeout`
///
/// Set this with [`ConfigBuilder::timeout`]
pub fn timeout(&self) -> Option<Duration> {
self.timeout
}

/// Get the configuration for `validate_domain`
///
/// Set this with [`ConfigBuilder::validate_domain`]
pub fn validate_domain(&self) -> bool {
self.validate_domain
}

/// Convenience method for calling [`ConfigBuilder::new`]
pub fn builder() -> ConfigBuilder {
ConfigBuilder::new()
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde::{de, Deserialize, Serialize};

static JSONRPC_2_0: &str = "2.0";

pub type Call = (String, Vec<Param>);
pub(crate) type Call = (String, Vec<Param>);

#[derive(Serialize, Clone)]
#[serde(untagged)]
Expand Down

0 comments on commit 8b31e5f

Please sign in to comment.