@@ -8,12 +8,16 @@ use std::{
88} ;
99
1010use bdk_bitcoind_rpc:: {
11- bitcoincore_rpc :: { Auth , Client , RpcApi } ,
11+ bdk_bitcoind_client :: { jsonrpc :: serde_json :: json , Auth , Client } ,
1212 Emitter ,
1313} ;
14- use bdk_chain:: { bitcoin:: Block , local_chain, CanonicalizationParams , Merge } ;
14+
15+ use bdk_chain:: {
16+ bitcoin:: { Block , Txid } ,
17+ local_chain, CanonicalizationParams , Merge ,
18+ } ;
1519use example_cli:: {
16- anyhow,
20+ anyhow:: { self , Ok } ,
1721 clap:: { self , Args , Subcommand } ,
1822 ChangeSet , Keychain ,
1923} ;
@@ -70,16 +74,14 @@ impl From<RpcArgs> for Auth {
7074
7175impl RpcArgs {
7276 fn new_client ( & self ) -> anyhow:: Result < Client > {
73- Ok ( Client :: new (
74- & self . url ,
75- match ( & self . rpc_cookie , & self . rpc_user , & self . rpc_password ) {
76- ( None , None , None ) => Auth :: None ,
77- ( Some ( path) , _, _) => Auth :: CookieFile ( path. clone ( ) ) ,
78- ( _, Some ( user) , Some ( pass) ) => Auth :: UserPass ( user. clone ( ) , pass. clone ( ) ) ,
79- ( _, Some ( _) , None ) => panic ! ( "rpc auth: missing rpc_pass" ) ,
80- ( _, None , Some ( _) ) => panic ! ( "rpc auth: missing rpc_user" ) ,
81- } ,
82- ) ?)
77+ let auth = match ( & self . rpc_cookie , & self . rpc_user , & self . rpc_password ) {
78+ ( None , None , None ) => Auth :: None ,
79+ ( Some ( path) , _, _) => Auth :: CookieFile ( path. clone ( ) ) ,
80+ ( _, Some ( user) , Some ( pass) ) => Auth :: UserPass ( user. clone ( ) , pass. clone ( ) ) ,
81+ ( _, Some ( _) , None ) => panic ! ( "rpc auth: missing rpc_pass" ) ,
82+ ( _, None , Some ( _) ) => panic ! ( "rpc auth: missing rpc_user" ) ,
83+ } ;
84+ Ok ( Client :: with_auth ( & self . url , auth) ?)
8385 }
8486}
8587
@@ -122,7 +124,7 @@ fn main() -> anyhow::Result<()> {
122124 network,
123125 |rpc_args, tx| {
124126 let client = rpc_args. new_client ( ) ?;
125- client. send_raw_transaction ( tx ) ?;
127+ let _txid : Txid = client. call ( "sendrawtransaction" , & [ json ! ( tx ) ] ) ?;
126128 Ok ( ( ) )
127129 } ,
128130 general_cmd,
@@ -141,7 +143,7 @@ fn main() -> anyhow::Result<()> {
141143 let chain = chain. lock ( ) . unwrap ( ) ;
142144 let graph = graph. lock ( ) . unwrap ( ) ;
143145 Emitter :: new (
144- & rpc_client,
146+ rpc_client,
145147 chain. tip ( ) ,
146148 fallback_height,
147149 graph
@@ -241,12 +243,13 @@ fn main() -> anyhow::Result<()> {
241243 } = rpc_args;
242244 let sigterm_flag = start_ctrlc_handler ( ) ;
243245
244- let rpc_client = Arc :: new ( rpc_args. new_client ( ) ?) ;
246+ let emitter_rpc_client = rpc_args. new_client ( ) ?;
247+ let rpc_client = rpc_args. new_client ( ) ?;
245248 let mut emitter = {
246249 let chain = chain. lock ( ) . unwrap ( ) ;
247250 let graph = graph. lock ( ) . unwrap ( ) ;
248251 Emitter :: new (
249- rpc_client . clone ( ) ,
252+ emitter_rpc_client ,
250253 chain. tip ( ) ,
251254 fallback_height,
252255 graph
@@ -267,7 +270,7 @@ fn main() -> anyhow::Result<()> {
267270 ) ;
268271 let ( tx, rx) = std:: sync:: mpsc:: sync_channel :: < Emission > ( CHANNEL_BOUND ) ;
269272 let emission_jh = std:: thread:: spawn ( move || -> anyhow:: Result < ( ) > {
270- let mut block_count = rpc_client. get_block_count ( ) ? as u32 ;
273+ let mut block_count = rpc_client. get_block_count ( ) ?;
271274 tx. send ( Emission :: Tip ( block_count) ) ?;
272275
273276 loop {
@@ -278,7 +281,7 @@ fn main() -> anyhow::Result<()> {
278281 break ;
279282 }
280283 if height > block_count {
281- block_count = rpc_client. get_block_count ( ) ? as u32 ;
284+ block_count = rpc_client. get_block_count ( ) ?;
282285 tx. send ( Emission :: Tip ( block_count) ) ?;
283286 }
284287 tx. send ( Emission :: Block ( block_emission) ) ?;
0 commit comments