Split out BroadcastInterface, ChainWatchInterface monitors re-enter from called listeners
[rust-lightning] / src / chain / bitcoincorerpcchain.rs
1 use bitcoin::blockdata::transaction::Transaction;
2 use bitcoin::blockdata::script::Script;
3 use bitcoin::util::hash::Sha256dHash;
4
5 use chain::chaininterface::{ChainWatchInterface,ChainWatchInterfaceUtil,ChainListener, BroadcasterInterface};
6
7 use std::sync::Weak;
8
9 pub struct BitcoinCoreRPCClientChain {
10         util: ChainWatchInterfaceUtil
11 }
12
13 impl ChainWatchInterface for BitcoinCoreRPCClientChain {
14         fn install_watch_script(&self, spk: Script) {
15                 self.util.install_watch_script(spk)
16         }
17
18         fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32)) {
19                 self.util.install_watch_outpoint(outpoint)
20         }
21
22         fn watch_all_txn(&self) {
23                 self.util.watch_all_txn()
24         }
25
26         fn register_listener(&self, listener: Weak<ChainListener>) {
27                 self.util.register_listener(listener)
28         }
29 }
30
31 impl BroadcasterInterface for BitcoinCoreRPCClientChain {
32         fn broadcast_transaction(&self, _tx: &Transaction) {
33                 unimplemented!()
34         }
35 }
36
37 impl BitcoinCoreRPCClientChain {
38         pub fn new() -> BitcoinCoreRPCClientChain {
39                 BitcoinCoreRPCClientChain {
40                         util: ChainWatchInterfaceUtil::new(),
41                 }
42         }
43 }