ethos-bitcoind 30.2.11

Generated client for ethos-bitcoind.
Documentation
use std::fmt;
use std::sync::Arc;

use crate::transport::core::{TransportError, TransportTrait};
use crate::transport::DefaultTransport;

/// Thin wrapper around a transport for making RPC calls
pub struct RpcClient {
    transport: Arc<dyn TransportTrait>,
}

impl fmt::Debug for RpcClient {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("RpcClient").field("transport", &"<dyn TransportTrait>").finish()
    }
}

impl RpcClient {
    /// Wrap an existing transport (no URL+auth dance)
    pub fn from_transport(inner: Arc<dyn TransportTrait>) -> Self { Self { transport: inner } }

    /// Create a new RPC client with the given RPC endpoint URL.
    ///
    /// The argument must be the full RPC endpoint URL (e.g. `http://127.0.0.1:8332/`),
    /// not a filesystem path. This constructor is for HTTP/URL-based transport.
    pub fn new(url: &str) -> Self {
        let transport = DefaultTransport::new(url, None);
        Self { transport: Arc::new(transport) }
    }

    /// Call a JSON-RPC method
    pub async fn call_method(
        &self,
        method: &str,
        params: &[serde_json::Value],
    ) -> Result<serde_json::Value, TransportError> {
        self.transport.send_request(method, params).await
    }
}