66// accordance with one or both of these licenses.
77
88mod bitcoind_rpc;
9+ mod electrum;
910
1011use crate :: chain:: bitcoind_rpc:: {
1112 BitcoindRpcClient , BoundedHeaderCache , ChainListener , FeeRateEstimationMode ,
1213} ;
14+ use crate :: chain:: electrum:: ElectrumRuntimeClient ;
1315use crate :: config:: {
14- Config , EsploraSyncConfig , BDK_CLIENT_CONCURRENCY , BDK_CLIENT_STOP_GAP ,
16+ Config , ElectrumSyncConfig , EsploraSyncConfig , BDK_CLIENT_CONCURRENCY , BDK_CLIENT_STOP_GAP ,
1517 BDK_WALLET_SYNC_TIMEOUT_SECS , FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS , LDK_WALLET_SYNC_TIMEOUT_SECS ,
1618 RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL , TX_BROADCAST_TIMEOUT_SECS ,
1719 WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
@@ -122,6 +124,20 @@ pub(crate) enum ChainSource {
122124 logger : Arc < Logger > ,
123125 node_metrics : Arc < RwLock < NodeMetrics > > ,
124126 } ,
127+ Electrum {
128+ server_url : String ,
129+ sync_config : ElectrumSyncConfig ,
130+ electrum_runtime_client : RwLock < Option < ElectrumRuntimeClient > > ,
131+ onchain_wallet : Arc < Wallet > ,
132+ onchain_wallet_sync_status : Mutex < WalletSyncStatus > ,
133+ lightning_wallet_sync_status : Mutex < WalletSyncStatus > ,
134+ fee_estimator : Arc < OnchainFeeEstimator > ,
135+ tx_broadcaster : Arc < Broadcaster > ,
136+ kv_store : Arc < DynStore > ,
137+ config : Arc < Config > ,
138+ logger : Arc < Logger > ,
139+ node_metrics : Arc < RwLock < NodeMetrics > > ,
140+ } ,
125141 BitcoindRpc {
126142 bitcoind_rpc_client : Arc < BitcoindRpcClient > ,
127143 header_cache : tokio:: sync:: Mutex < BoundedHeaderCache > ,
@@ -167,6 +183,31 @@ impl ChainSource {
167183 }
168184 }
169185
186+ pub ( crate ) fn new_electrum (
187+ server_url : String , sync_config : ElectrumSyncConfig , onchain_wallet : Arc < Wallet > ,
188+ fee_estimator : Arc < OnchainFeeEstimator > , tx_broadcaster : Arc < Broadcaster > ,
189+ kv_store : Arc < DynStore > , config : Arc < Config > , logger : Arc < Logger > ,
190+ node_metrics : Arc < RwLock < NodeMetrics > > ,
191+ ) -> Self {
192+ let electrum_runtime_client = RwLock :: new ( None ) ;
193+ let onchain_wallet_sync_status = Mutex :: new ( WalletSyncStatus :: Completed ) ;
194+ let lightning_wallet_sync_status = Mutex :: new ( WalletSyncStatus :: Completed ) ;
195+ Self :: Electrum {
196+ server_url,
197+ sync_config,
198+ electrum_runtime_client,
199+ onchain_wallet,
200+ onchain_wallet_sync_status,
201+ lightning_wallet_sync_status,
202+ fee_estimator,
203+ tx_broadcaster,
204+ kv_store,
205+ config,
206+ logger,
207+ node_metrics,
208+ }
209+ }
210+
170211 pub ( crate ) fn new_bitcoind_rpc (
171212 host : String , port : u16 , rpc_user : String , rpc_password : String ,
172213 onchain_wallet : Arc < Wallet > , fee_estimator : Arc < OnchainFeeEstimator > ,
@@ -193,6 +234,35 @@ impl ChainSource {
193234 }
194235 }
195236
237+ pub ( crate ) fn start ( & self , runtime : Arc < tokio:: runtime:: Runtime > ) -> Result < ( ) , Error > {
238+ match self {
239+ Self :: Electrum { server_url, electrum_runtime_client, logger, .. } => {
240+ let mut locked_client = electrum_runtime_client. write ( ) . unwrap ( ) ;
241+ * locked_client = Some ( ElectrumRuntimeClient :: new (
242+ server_url. clone ( ) ,
243+ runtime,
244+ Arc :: clone ( & logger) ,
245+ ) ?) ;
246+ } ,
247+ _ => {
248+ // Nothing to do for other chain sources.
249+ } ,
250+ }
251+ Ok ( ( ) )
252+ }
253+
254+ pub ( crate ) fn stop ( & self ) {
255+ match self {
256+ Self :: Electrum { electrum_runtime_client, .. } => {
257+ let mut locked_client = electrum_runtime_client. write ( ) . unwrap ( ) ;
258+ * locked_client = None ;
259+ } ,
260+ _ => {
261+ // Nothing to do for other chain sources.
262+ } ,
263+ }
264+ }
265+
196266 pub ( crate ) fn as_utxo_source ( & self ) -> Option < Arc < dyn UtxoSource > > {
197267 match self {
198268 Self :: BitcoindRpc { bitcoind_rpc_client, .. } => Some ( bitcoind_rpc_client. rpc_client ( ) ) ,
@@ -260,6 +330,7 @@ impl ChainSource {
260330 }
261331 }
262332 } ,
333+ Self :: Electrum { .. } => todo ! ( ) ,
263334 Self :: BitcoindRpc {
264335 bitcoind_rpc_client,
265336 header_cache,
@@ -527,6 +598,7 @@ impl ChainSource {
527598
528599 res
529600 } ,
601+ Self :: Electrum { .. } => todo ! ( ) ,
530602 Self :: BitcoindRpc { .. } => {
531603 // In BitcoindRpc mode we sync lightning and onchain wallet in one go by via
532604 // `ChainPoller`. So nothing to do here.
@@ -626,6 +698,7 @@ impl ChainSource {
626698
627699 res
628700 } ,
701+ Self :: Electrum { .. } => todo ! ( ) ,
629702 Self :: BitcoindRpc { .. } => {
630703 // In BitcoindRpc mode we sync lightning and onchain wallet in one go by via
631704 // `ChainPoller`. So nothing to do here.
@@ -644,6 +717,11 @@ impl ChainSource {
644717 // `sync_onchain_wallet` and `sync_lightning_wallet`. So nothing to do here.
645718 unreachable ! ( "Listeners will be synced via transction-based syncing" )
646719 } ,
720+ Self :: Electrum { .. } => {
721+ // In Electrum mode we sync lightning and onchain wallets via
722+ // `sync_onchain_wallet` and `sync_lightning_wallet`. So nothing to do here.
723+ unreachable ! ( "Listeners will be synced via transction-based syncing" )
724+ } ,
647725 Self :: BitcoindRpc {
648726 bitcoind_rpc_client,
649727 header_cache,
@@ -864,6 +942,7 @@ impl ChainSource {
864942
865943 Ok ( ( ) )
866944 } ,
945+ Self :: Electrum { .. } => todo ! ( ) ,
867946 Self :: BitcoindRpc {
868947 bitcoind_rpc_client,
869948 fee_estimator,
@@ -1074,6 +1153,7 @@ impl ChainSource {
10741153 }
10751154 }
10761155 } ,
1156+ Self :: Electrum { .. } => todo ! ( ) ,
10771157 Self :: BitcoindRpc { bitcoind_rpc_client, tx_broadcaster, logger, .. } => {
10781158 // While it's a bit unclear when we'd be able to lean on Bitcoin Core >v28
10791159 // features, we should eventually switch to use `submitpackage` via the
@@ -1136,12 +1216,14 @@ impl Filter for ChainSource {
11361216 fn register_tx ( & self , txid : & bitcoin:: Txid , script_pubkey : & bitcoin:: Script ) {
11371217 match self {
11381218 Self :: Esplora { tx_sync, .. } => tx_sync. register_tx ( txid, script_pubkey) ,
1219+ Self :: Electrum { .. } => todo ! ( ) ,
11391220 Self :: BitcoindRpc { .. } => ( ) ,
11401221 }
11411222 }
11421223 fn register_output ( & self , output : lightning:: chain:: WatchedOutput ) {
11431224 match self {
11441225 Self :: Esplora { tx_sync, .. } => tx_sync. register_output ( output) ,
1226+ Self :: Electrum { .. } => todo ! ( ) ,
11451227 Self :: BitcoindRpc { .. } => ( ) ,
11461228 }
11471229 }
0 commit comments