pub struct BitcoinClient { /* private fields */ }Expand description
Bitcoin Core RPC client wrapper with automatic reconnection
§Examples
use kaccy_bitcoin::{BitcoinClient, BitcoinNetwork};
let client = BitcoinClient::new(
"http://localhost:8332",
"rpcuser",
"rpcpassword",
BitcoinNetwork::Testnet,
)?;
// Check connection health
let is_healthy = client.health_check()?;
println!("Bitcoin node healthy: {}", is_healthy);Implementations§
Source§impl BitcoinClient
impl BitcoinClient
Sourcepub fn new(
url: &str,
user: &str,
password: &str,
network: BitcoinNetwork,
) -> Result<Self>
pub fn new( url: &str, user: &str, password: &str, network: BitcoinNetwork, ) -> Result<Self>
Create a new Bitcoin RPC client
§Examples
use kaccy_bitcoin::{BitcoinClient, BitcoinNetwork};
let client = BitcoinClient::new(
"http://localhost:18443",
"user",
"pass",
BitcoinNetwork::Regtest,
)?;Sourcepub fn with_config(
url: &str,
user: &str,
password: &str,
network: BitcoinNetwork,
reconnect_config: ReconnectConfig,
) -> Result<Self>
pub fn with_config( url: &str, user: &str, password: &str, network: BitcoinNetwork, reconnect_config: ReconnectConfig, ) -> Result<Self>
Create a new Bitcoin RPC client with custom reconnection config
Sourcepub fn network(&self) -> BitcoinNetwork
pub fn network(&self) -> BitcoinNetwork
Get the configured network
Sourcepub fn health_check(&self) -> Result<bool>
pub fn health_check(&self) -> Result<bool>
Check if the connection is healthy
Sourcepub fn get_blockchain_info(&self) -> Result<GetBlockchainInfoResult>
pub fn get_blockchain_info(&self) -> Result<GetBlockchainInfoResult>
Get blockchain info
Sourcepub fn get_network_info(&self) -> Result<GetNetworkInfoResult>
pub fn get_network_info(&self) -> Result<GetNetworkInfoResult>
Get network info
Sourcepub fn get_block_height(&self) -> Result<u64>
pub fn get_block_height(&self) -> Result<u64>
Get current block height
Sourcepub fn get_best_block_hash(&self) -> Result<BlockHash>
pub fn get_best_block_hash(&self) -> Result<BlockHash>
Get best block hash
Sourcepub fn get_new_address(
&self,
label: Option<&str>,
) -> Result<Address<NetworkUnchecked>>
pub fn get_new_address( &self, label: Option<&str>, ) -> Result<Address<NetworkUnchecked>>
Generate a new address
Sourcepub fn get_received_by_address(
&self,
address: &Address,
min_confirmations: Option<u32>,
) -> Result<Amount>
pub fn get_received_by_address( &self, address: &Address, min_confirmations: Option<u32>, ) -> Result<Amount>
Get amount received by address
Sourcepub fn get_transaction(&self, txid: &Txid) -> Result<GetTransactionResult>
pub fn get_transaction(&self, txid: &Txid) -> Result<GetTransactionResult>
Get transaction by ID
Sourcepub fn get_raw_transaction(
&self,
txid: &Txid,
) -> Result<GetRawTransactionResult>
pub fn get_raw_transaction( &self, txid: &Txid, ) -> Result<GetRawTransactionResult>
Get raw transaction
Sourcepub fn list_unspent(
&self,
min_conf: Option<usize>,
max_conf: Option<usize>,
addresses: Option<&[&Address<NetworkChecked>]>,
) -> Result<Vec<ListUnspentResultEntry>>
pub fn list_unspent( &self, min_conf: Option<usize>, max_conf: Option<usize>, addresses: Option<&[&Address<NetworkChecked>]>, ) -> Result<Vec<ListUnspentResultEntry>>
Get unspent transactions for an address
Sourcepub fn get_balance(&self) -> Result<Amount>
pub fn get_balance(&self) -> Result<Amount>
Get wallet balance
Sourcepub fn validate_address(&self, address: &str) -> Result<AddressValidation>
pub fn validate_address(&self, address: &str) -> Result<AddressValidation>
Validate an address (basic validation without RPC)
Sourcepub fn get_mempool_info(&self) -> Result<GetMempoolInfoResult>
pub fn get_mempool_info(&self) -> Result<GetMempoolInfoResult>
Get mempool info
Source§impl BitcoinClient
impl BitcoinClient
Sourcepub fn get_node_status(&self) -> Result<NodeStatus>
pub fn get_node_status(&self) -> Result<NodeStatus>
Get comprehensive node status
Sourcepub fn list_since_block(
&self,
block_hash: Option<&BlockHash>,
target_confirmations: Option<usize>,
) -> Result<ListSinceBlockResult>
pub fn list_since_block( &self, block_hash: Option<&BlockHash>, target_confirmations: Option<usize>, ) -> Result<ListSinceBlockResult>
List transactions since a specific block
Sourcepub fn get_address_info(&self, address: &str) -> Result<AddressInfo>
pub fn get_address_info(&self, address: &str) -> Result<AddressInfo>
Get detailed address info including balance
Sourcepub fn send_raw_transaction(&self, tx_hex: &str) -> Result<Txid>
pub fn send_raw_transaction(&self, tx_hex: &str) -> Result<Txid>
Send raw transaction to the network
Sourcepub fn get_block_hash(&self, height: u64) -> Result<BlockHash>
pub fn get_block_hash(&self, height: u64) -> Result<BlockHash>
Get block by height
Sourcepub fn test_mempool_accept(&self, tx_hex: &str) -> Result<bool>
pub fn test_mempool_accept(&self, tx_hex: &str) -> Result<bool>
Test mempool accept for a transaction
Sourcepub fn generate_to_address(
&self,
blocks: u64,
address: &Address,
) -> Result<Vec<BlockHash>>
pub fn generate_to_address( &self, blocks: u64, address: &Address, ) -> Result<Vec<BlockHash>>
Generate blocks to an address (regtest only)
Sourcepub fn send_to_address(&self, address: &Address, amount: Amount) -> Result<Txid>
pub fn send_to_address(&self, address: &Address, amount: Amount) -> Result<Txid>
Send to an address
Sourcepub fn invalidate_block(&self, block_hash: &BlockHash) -> Result<()>
pub fn invalidate_block(&self, block_hash: &BlockHash) -> Result<()>
Invalidate a block (regtest only)
Sourcepub fn reconsider_block(&self, block_hash: &BlockHash) -> Result<()>
pub fn reconsider_block(&self, block_hash: &BlockHash) -> Result<()>
Reconsider a block (regtest only)