pub struct BitcoinRpcClient { /* private fields */ }Expand description
Minimal async JSON-RPC client for Bitcoin Core regtest nodes.
Implementations§
Source§impl BitcoinRpcClient
impl BitcoinRpcClient
Sourcepub fn new(
host: impl AsRef<str>,
port: u16,
user: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn new( host: impl AsRef<str>, port: u16, user: impl Into<String>, password: impl Into<String>, ) -> Self
Create a client for a host, port, and RPC credentials.
Sourcepub fn wallet(&self, wallet_name: &str) -> Self
pub fn wallet(&self, wallet_name: &str) -> Self
Return a client scoped to a named Bitcoin Core wallet.
Sourcepub async fn get_blockchain_info(
&self,
) -> Result<BlockchainInfo, BitcoinRpcError>
pub async fn get_blockchain_info( &self, ) -> Result<BlockchainInfo, BitcoinRpcError>
Call getblockchaininfo.
Sourcepub async fn list_wallets(&self) -> Result<Vec<String>, BitcoinRpcError>
pub async fn list_wallets(&self) -> Result<Vec<String>, BitcoinRpcError>
Call listwallets.
Sourcepub async fn create_wallet(
&self,
wallet_name: &str,
) -> Result<CreateWallet, BitcoinRpcError>
pub async fn create_wallet( &self, wallet_name: &str, ) -> Result<CreateWallet, BitcoinRpcError>
Call createwallet.
Sourcepub async fn load_wallet(
&self,
wallet_name: &str,
) -> Result<LoadWallet, BitcoinRpcError>
pub async fn load_wallet( &self, wallet_name: &str, ) -> Result<LoadWallet, BitcoinRpcError>
Call loadwallet.
Sourcepub async fn ensure_wallet(
&self,
wallet_name: &str,
) -> Result<(), BitcoinRpcError>
pub async fn ensure_wallet( &self, wallet_name: &str, ) -> Result<(), BitcoinRpcError>
Ensure a wallet is loaded, creating it if it does not already exist.
Sourcepub async fn get_new_address(&self) -> Result<String, BitcoinRpcError>
pub async fn get_new_address(&self) -> Result<String, BitcoinRpcError>
Call getnewaddress.
Sourcepub async fn generate_to_address(
&self,
count: u64,
address: &str,
) -> Result<Vec<String>, BitcoinRpcError>
pub async fn generate_to_address( &self, count: u64, address: &str, ) -> Result<Vec<String>, BitcoinRpcError>
Mine count regtest blocks to address.
Sourcepub async fn get_block(&self, hash: &str) -> Result<BlockInfo, BitcoinRpcError>
pub async fn get_block(&self, hash: &str) -> Result<BlockInfo, BitcoinRpcError>
Call getblock with verbosity 1.
Sourcepub async fn add_node(&self, socket: &str) -> Result<(), BitcoinRpcError>
pub async fn add_node(&self, socket: &str) -> Result<(), BitcoinRpcError>
Call addnode <socket> add.
Sourcepub async fn send_to_address(
&self,
address: &str,
amount_btc: f64,
) -> Result<String, BitcoinRpcError>
pub async fn send_to_address( &self, address: &str, amount_btc: f64, ) -> Result<String, BitcoinRpcError>
Call sendtoaddress and return the transaction id.
Sourcepub async fn send_many(
&self,
amounts: &HashMap<String, f64>,
) -> Result<String, BitcoinRpcError>
pub async fn send_many( &self, amounts: &HashMap<String, f64>, ) -> Result<String, BitcoinRpcError>
Call sendmany and return the transaction id.
Sourcepub async fn call<T>(
&self,
method: &str,
params: Value,
) -> Result<T, BitcoinRpcError>where
T: DeserializeOwned,
pub async fn call<T>(
&self,
method: &str,
params: Value,
) -> Result<T, BitcoinRpcError>where
T: DeserializeOwned,
Call a JSON-RPC method and deserialize the result field.
Sourcepub async fn call_value(
&self,
method: &str,
params: Value,
) -> Result<Value, BitcoinRpcError>
pub async fn call_value( &self, method: &str, params: Value, ) -> Result<Value, BitcoinRpcError>
Call a JSON-RPC method and return the raw JSON result field.
Trait Implementations§
Source§impl Clone for BitcoinRpcClient
impl Clone for BitcoinRpcClient
Source§fn clone(&self) -> BitcoinRpcClient
fn clone(&self) -> BitcoinRpcClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BitcoinRpcClient
impl !RefUnwindSafe for BitcoinRpcClient
impl Send for BitcoinRpcClient
impl Sync for BitcoinRpcClient
impl Unpin for BitcoinRpcClient
impl UnsafeUnpin for BitcoinRpcClient
impl !UnwindSafe for BitcoinRpcClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request