24
24
//! auth: Auth::Cookie {
25
25
//! file: "/home/user/.bitcoin/.cookie".into(),
26
26
//! },
27
+ //! proxy: None,
28
+ //! proxy_auth: None,
27
29
//! network: bdk::bitcoin::Network::Testnet,
28
30
//! wallet_name: "wallet_name".to_string(),
29
31
//! skip_blocks: None,
30
32
//! };
31
33
//! let blockchain = RpcBlockchain::from_config(&config);
32
34
//! ```
33
35
36
+ use super :: rpc_proxy:: ProxyTransport ;
34
37
use crate :: bitcoin:: consensus:: deserialize;
35
38
use crate :: bitcoin:: { Address , Network , OutPoint , Transaction , TxOut , Txid } ;
36
39
use crate :: blockchain:: { Blockchain , Capability , ConfigurableBlockchain , Progress } ;
@@ -60,7 +63,6 @@ pub struct RpcBlockchain {
60
63
capabilities : HashSet < Capability > ,
61
64
/// Skip this many blocks of the blockchain at the first rescan, if None the rescan is done from the genesis block
62
65
skip_blocks : Option < u32 > ,
63
-
64
66
/// This is a fixed Address used as a hack key to store information on the node
65
67
_storage_address : Address ,
66
68
}
@@ -72,6 +74,10 @@ pub struct RpcConfig {
72
74
pub url : String ,
73
75
/// The bitcoin node authentication mechanism
74
76
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 ) > ,
75
81
/// The network we are using (it will be checked the bitcoin node network matches this)
76
82
pub network : Network ,
77
83
/// 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 {
358
364
let wallet_url = format ! ( "{}/wallet/{}" , config. url, & wallet_name) ;
359
365
debug ! ( "connecting to {} auth:{:?}" , wallet_url, config. auth) ;
360
366
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
+
362
381
let loaded_wallets = client. list_wallets ( ) ?;
363
382
if loaded_wallets. contains ( & wallet_name) {
364
383
debug ! ( "wallet already loaded {:?}" , wallet_name) ;
@@ -437,6 +456,8 @@ crate::bdk_blockchain_tests! {
437
456
let config = RpcConfig {
438
457
url: test_client. bitcoind. rpc_url( ) ,
439
458
auth: Auth :: Cookie { file: test_client. bitcoind. params. cookie_file. clone( ) } ,
459
+ proxy: None ,
460
+ proxy_auth: None ,
440
461
network: Network :: Regtest ,
441
462
wallet_name: format!( "client-wallet-test-{:?}" , std:: time:: SystemTime :: now( ) ) ,
442
463
skip_blocks: None ,
0 commit comments