33#[ macro_use]
44mod common;
55
6- use std:: {
7- collections:: { BTreeSet , HashMap } ,
8- sync:: Arc ,
9- } ;
6+ use std:: { collections:: BTreeSet , str:: FromStr , sync:: Arc } ;
107
118use bdk_chain:: {
129 indexed_tx_graph:: { self , IndexedTxGraph } ,
@@ -18,8 +15,9 @@ use bdk_chain::{
1815} ;
1916use bdk_testenv:: {
2017 anyhow:: { self } ,
21- bitcoincore_rpc:: { json:: CreateRawTransactionInput , RpcApi } ,
22- block_id, hash,
18+ block_id,
19+ corepc_node:: { Input , Output } ,
20+ hash,
2321 utils:: { new_tx, DESCRIPTORS } ,
2422 TestEnv ,
2523} ;
@@ -67,6 +65,7 @@ fn relevant_conflicts() -> anyhow::Result<()> {
6765
6866 let sender_addr = client
6967 . get_new_address ( None , None ) ?
68+ . address ( ) ?
7069 . require_network ( Network :: Regtest ) ?;
7170
7271 let recv_spk = gen_spk ( ) ;
@@ -79,30 +78,37 @@ fn relevant_conflicts() -> anyhow::Result<()> {
7978 env. mine_blocks ( 101 , None ) ?;
8079
8180 let tx_input = client
82- . list_unspent ( None , None , None , None , None ) ?
81+ . list_unspent ( ) ?
82+ . 0
8383 . into_iter ( )
8484 . take ( 1 )
85- . map ( |r| CreateRawTransactionInput {
86- txid : r. txid ,
87- vout : r. vout ,
85+ . map ( |r| Input {
86+ txid : Txid :: from_str ( & r. txid ) . expect ( "should successfully parse the `Txid`" ) ,
87+ vout : r. vout as u64 ,
8888 sequence : None ,
8989 } )
9090 . collect :: < Vec < _ > > ( ) ;
9191 let tx_send = {
92- let outputs =
93- HashMap :: from ( [ ( recv_addr. to_string ( ) , Amount :: from_btc ( 49.999_99 ) ?) ] ) ;
94- let tx = client. create_raw_transaction ( & tx_input, & outputs, None , Some ( true ) ) ?;
92+ let outputs = [ Output :: new ( recv_addr, Amount :: from_btc ( 49.999_99 ) ?) ] ;
93+ let tx = client
94+ . create_raw_transaction ( & tx_input, & outputs) ?
95+ . into_model ( ) ?
96+ . 0 ;
9597 client
96- . sign_raw_transaction_with_wallet ( & tx, None , None ) ?
97- . transaction ( ) ?
98+ . sign_raw_transaction_with_wallet ( & tx) ?
99+ . into_model ( ) ?
100+ . tx
98101 } ;
99102 let tx_cancel = {
100- let outputs =
101- HashMap :: from ( [ ( sender_addr. to_string ( ) , Amount :: from_btc ( 49.999_98 ) ?) ] ) ;
102- let tx = client. create_raw_transaction ( & tx_input, & outputs, None , Some ( true ) ) ?;
103+ let outputs = [ Output :: new ( sender_addr, Amount :: from_btc ( 49.999_98 ) ?) ] ;
104+ let tx = client
105+ . create_raw_transaction ( & tx_input, & outputs) ?
106+ . into_model ( ) ?
107+ . 0 ;
103108 client
104- . sign_raw_transaction_with_wallet ( & tx, None , None ) ?
105- . transaction ( ) ?
109+ . sign_raw_transaction_with_wallet ( & tx) ?
110+ . into_model ( ) ?
111+ . tx
106112 } ;
107113
108114 Ok ( Self {
@@ -118,31 +124,40 @@ fn relevant_conflicts() -> anyhow::Result<()> {
118124 /// Scans through all transactions in the blockchain + mempool.
119125 fn sync ( & mut self ) -> anyhow:: Result < ( ) > {
120126 let client = self . env . rpc_client ( ) ;
121- for height in 0 ..=client. get_block_count ( ) ? {
122- let hash = client. get_block_hash ( height) ?;
123- let block = client. get_block ( & hash) ?;
127+ for height in 0 ..=client. get_block_count ( ) ?. into_model ( ) . 0 {
128+ let hash = client. get_block_hash ( height) ?. block_hash ( ) ? ;
129+ let block = client. get_block ( hash) ?;
124130 let _ = self . graph . apply_block_relevant ( & block, height as _ ) ;
125131 }
126- let _ = self . graph . batch_insert_relevant_unconfirmed (
127- client
128- . get_raw_mempool ( ) ?
129- . into_iter ( )
130- . map ( |txid| client. get_raw_transaction ( & txid, None ) . map ( |tx| ( tx, 0 ) ) )
131- . collect :: < Result < Vec < _ > , _ > > ( ) ?,
132- ) ;
132+
133+ let mempool_txids = client. get_raw_mempool ( ) ?. into_model ( ) ?. 0 ;
134+ let unconfirmed_txs = mempool_txids
135+ . iter ( )
136+ . map ( |txid| {
137+ client
138+ . get_raw_transaction ( * txid)
139+ . unwrap ( )
140+ . into_model ( )
141+ . unwrap ( )
142+ } )
143+ . map ( |get_raw_transaction| ( get_raw_transaction. 0 , 0 ) )
144+ . collect :: < Vec < _ > > ( ) ;
145+ let _ = self
146+ . graph
147+ . batch_insert_relevant_unconfirmed ( unconfirmed_txs) ;
133148 Ok ( ( ) )
134149 }
135150
136151 /// Broadcast the original sending transaction.
137152 fn broadcast_send ( & self ) -> anyhow:: Result < Txid > {
138153 let client = self . env . rpc_client ( ) ;
139- Ok ( client. send_raw_transaction ( & self . tx_send ) ?)
154+ Ok ( client. send_raw_transaction ( & self . tx_send ) ?. txid ( ) ? )
140155 }
141156
142157 /// Broadcast the cancellation transaction.
143158 fn broadcast_cancel ( & self ) -> anyhow:: Result < Txid > {
144159 let client = self . env . rpc_client ( ) ;
145- Ok ( client. send_raw_transaction ( & self . tx_cancel ) ?)
160+ Ok ( client. send_raw_transaction ( & self . tx_cancel ) ?. txid ( ) ? )
146161 }
147162 }
148163
0 commit comments