66//! [0]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
77//! [1]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
88
9+ use bdk_bitcoind_client:: corepc_types:: model:: GetBlockHeaderVerbose ;
10+ use bdk_bitcoind_client:: Client ;
911use bdk_core:: bitcoin;
1012use bdk_core:: CheckPoint ;
1113use bitcoin:: BlockHash ;
1214use bitcoin:: { bip158:: BlockFilter , Block , ScriptBuf } ;
13- use bitcoincore_rpc;
14- use bitcoincore_rpc:: { json:: GetBlockHeaderResult , RpcApi } ;
1515
1616/// Type that returns Bitcoin blocks by matching a list of script pubkeys (SPKs) against a
1717/// [`bip158::BlockFilter`](bitcoin::bip158::BlockFilter).
1818///
1919/// * `FilterIter` talks to bitcoind via JSON-RPC interface, which is handled by the
20- /// [`bitcoincore_rpc ::Client`].
20+ /// [`bdk_bitcoind_client ::Client`].
2121/// * Collect the script pubkeys (SPKs) you want to watch. These will usually correspond to wallet
2222/// addresses that have been handed out for receiving payments.
2323/// * Construct `FilterIter` with the RPC client, SPKs, and [`CheckPoint`]. The checkpoint tip
@@ -31,19 +31,19 @@ use bitcoincore_rpc::{json::GetBlockHeaderResult, RpcApi};
3131#[ derive( Debug ) ]
3232pub struct FilterIter < ' a > {
3333 /// RPC client
34- client : & ' a bitcoincore_rpc :: Client ,
34+ client : & ' a Client ,
3535 /// SPK inventory
3636 spks : Vec < ScriptBuf > ,
3737 /// checkpoint
3838 cp : CheckPoint < BlockHash > ,
3939 /// Header info, contains the prev and next hashes for each header.
40- header : Option < GetBlockHeaderResult > ,
40+ header : Option < GetBlockHeaderVerbose > ,
4141}
4242
4343impl < ' a > FilterIter < ' a > {
4444 /// Construct [`FilterIter`] with checkpoint, RPC client and SPKs.
4545 pub fn new (
46- client : & ' a bitcoincore_rpc :: Client ,
46+ client : & ' a Client ,
4747 cp : CheckPoint ,
4848 spks : impl IntoIterator < Item = ScriptBuf > ,
4949 ) -> Self {
@@ -58,9 +58,9 @@ impl<'a> FilterIter<'a> {
5858 /// Return the agreement header with the remote node.
5959 ///
6060 /// Error if no agreement header is found.
61- fn find_base ( & self ) -> Result < GetBlockHeaderResult , Error > {
61+ fn find_base ( & self ) -> Result < GetBlockHeaderVerbose , Error > {
6262 for cp in self . cp . iter ( ) {
63- match self . client . get_block_header_info ( & cp. hash ( ) ) {
63+ match self . client . get_block_header_verbose ( & cp. hash ( ) ) {
6464 Err ( e) if is_not_found ( & e) => continue ,
6565 Ok ( header) if header. confirmations <= 0 => continue ,
6666 Ok ( header) => return Ok ( header) ,
@@ -111,20 +111,20 @@ impl Iterator for FilterIter<'_> {
111111 None => return Ok ( None ) ,
112112 } ;
113113
114- let mut next_header = self . client . get_block_header_info ( & next_hash) ?;
114+ let mut next_header = self . client . get_block_header_verbose ( & next_hash) ?;
115115
116116 // In case of a reorg, rewind by fetching headers of previous hashes until we find
117117 // one with enough confirmations.
118118 while next_header. confirmations < 0 {
119119 let prev_hash = next_header
120120 . previous_block_hash
121121 . ok_or ( Error :: ReorgDepthExceeded ) ?;
122- let prev_header = self . client . get_block_header_info ( & prev_hash) ?;
122+ let prev_header = self . client . get_block_header_verbose ( & prev_hash) ?;
123123 next_header = prev_header;
124124 }
125125
126126 next_hash = next_header. hash ;
127- let next_height: u32 = next_header. height . try_into ( ) ? ;
127+ let next_height: u32 = next_header. height ;
128128
129129 cp = cp. insert ( next_height, next_hash) ;
130130
@@ -153,7 +153,7 @@ impl Iterator for FilterIter<'_> {
153153#[ derive( Debug ) ]
154154pub enum Error {
155155 /// RPC error
156- Rpc ( bitcoincore_rpc :: Error ) ,
156+ Rpc ( bdk_bitcoind_client :: Error ) ,
157157 /// `bitcoin::bip158` error
158158 Bip158 ( bitcoin:: bip158:: Error ) ,
159159 /// Max reorg depth exceeded.
@@ -176,8 +176,8 @@ impl core::fmt::Display for Error {
176176#[ cfg( feature = "std" ) ]
177177impl std:: error:: Error for Error { }
178178
179- impl From < bitcoincore_rpc :: Error > for Error {
180- fn from ( e : bitcoincore_rpc :: Error ) -> Self {
179+ impl From < bdk_bitcoind_client :: Error > for Error {
180+ fn from ( e : bdk_bitcoind_client :: Error ) -> Self {
181181 Self :: Rpc ( e)
182182 }
183183}
@@ -189,10 +189,12 @@ impl From<core::num::TryFromIntError> for Error {
189189}
190190
191191/// Whether the RPC error is a "not found" error (code: `-5`).
192- fn is_not_found ( e : & bitcoincore_rpc:: Error ) -> bool {
193- matches ! (
194- e,
195- bitcoincore_rpc:: Error :: JsonRpc ( bitcoincore_rpc:: jsonrpc:: Error :: Rpc ( e) )
196- if e. code == -5
197- )
192+ fn is_not_found ( e : & bdk_bitcoind_client:: Error ) -> bool {
193+ if let bdk_bitcoind_client:: Error :: JsonRpc ( bdk_bitcoind_client:: jsonrpc:: Error :: Rpc ( rpc_err) ) =
194+ e
195+ {
196+ rpc_err. code == -5
197+ } else {
198+ false
199+ }
198200}
0 commit comments