2424//! auth: Auth::Cookie {
2525//! file: "/home/user/.bitcoin/.cookie".into(),
2626//! },
27+ //! proxy: None,
28+ //! proxy_auth: None,
2729//! network: bdk::bitcoin::Network::Testnet,
2830//! wallet_name: "wallet_name".to_string(),
2931//! skip_blocks: None,
3032//! };
3133//! let blockchain = RpcBlockchain::from_config(&config);
3234//! ```
3335
36+ use super :: rpc_proxy:: ProxyTransport ;
3437use crate :: bitcoin:: consensus:: deserialize;
3538use crate :: bitcoin:: { Address , Network , OutPoint , Transaction , TxOut , Txid } ;
3639use crate :: blockchain:: { Blockchain , Capability , ConfigurableBlockchain , Progress } ;
@@ -60,7 +63,6 @@ pub struct RpcBlockchain {
6063 capabilities : HashSet < Capability > ,
6164 /// Skip this many blocks of the blockchain at the first rescan, if None the rescan is done from the genesis block
6265 skip_blocks : Option < u32 > ,
63-
6466 /// This is a fixed Address used as a hack key to store information on the node
6567 _storage_address : Address ,
6668}
@@ -72,6 +74,10 @@ pub struct RpcConfig {
7274 pub url : String ,
7375 /// The bitcoin node authentication mechanism
7476 pub auth : Auth ,
77+ /// A proxy (like Tor) can be used to connect Bitcoin Core RPC
78+ pub proxy : Option < String > ,
79+ /// Authentication for proxy server
80+ pub proxy_auth : Option < ( String , String ) > ,
7581 /// The network we are using (it will be checked the bitcoin node network matches this)
7682 pub network : Network ,
7783 /// The wallet name in the bitcoin node, consider using [crate::wallet::wallet_name_from_descriptor] for this
@@ -358,7 +364,20 @@ impl ConfigurableBlockchain for RpcBlockchain {
358364 let wallet_url = format ! ( "{}/wallet/{}" , config. url, & wallet_name) ;
359365 debug ! ( "connecting to {} auth:{:?}" , wallet_url, config. auth) ;
360366
361- let client = Client :: new ( wallet_url. as_str ( ) , config. auth . clone ( ) . into ( ) ) ?;
367+ let client = if let Some ( proxy) = & config. proxy {
368+ let proxy_transport = ProxyTransport :: new (
369+ proxy,
370+ wallet_url. as_str ( ) ,
371+ config. proxy_auth . clone ( ) ,
372+ & config. auth ,
373+ ) ?;
374+ Client :: from_jsonrpc ( bitcoincore_rpc:: jsonrpc:: Client :: with_transport (
375+ proxy_transport,
376+ ) )
377+ } else {
378+ Client :: new ( wallet_url. as_str ( ) , config. auth . clone ( ) . into ( ) ) ?
379+ } ;
380+
362381 let loaded_wallets = client. list_wallets ( ) ?;
363382 if loaded_wallets. contains ( & wallet_name) {
364383 debug ! ( "wallet already loaded {:?}" , wallet_name) ;
@@ -437,6 +456,8 @@ crate::bdk_blockchain_tests! {
437456 let config = RpcConfig {
438457 url: test_client. bitcoind. rpc_url( ) ,
439458 auth: Auth :: Cookie { file: test_client. bitcoind. params. cookie_file. clone( ) } ,
459+ proxy: None ,
460+ proxy_auth: None ,
440461 network: Network :: Regtest ,
441462 wallet_name: format!( "client-wallet-test-{:?}" , std:: time:: SystemTime :: now( ) ) ,
442463 skip_blocks: None ,
0 commit comments