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,14 +15,15 @@ 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} ;
2624use bitcoin:: {
27- secp256k1:: Secp256k1 , Address , Amount , BlockHash , Network , OutPoint , ScriptBuf , Transaction ,
28- TxIn , TxOut , Txid ,
25+ secp256k1:: Secp256k1 , Address , Amount , BlockHash , Network ,
26+ OutPoint , ScriptBuf , Transaction , TxIn , TxOut , Txid ,
2927} ;
3028use miniscript:: Descriptor ;
3129
@@ -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 ( ) ;
@@ -78,31 +77,39 @@ fn relevant_conflicts() -> anyhow::Result<()> {
7877 env. mine_blocks ( 1 , Some ( sender_addr. clone ( ) ) ) ?;
7978 env. mine_blocks ( 101 , None ) ?;
8079
80+ // TODO: (@oleonardolima) remove unwraps
8181 let tx_input = client
82- . list_unspent ( None , None , None , None , None ) ?
82+ . list_unspent ( ) ?
83+ . 0
8384 . into_iter ( )
8485 . take ( 1 )
85- . map ( |r| CreateRawTransactionInput {
86- txid : r. txid ,
87- vout : r. vout ,
86+ . map ( |r| Input {
87+ txid : Txid :: from_str ( & r. txid ) . unwrap ( ) ,
88+ vout : r. vout as u64 ,
8889 sequence : None ,
8990 } )
9091 . collect :: < Vec < _ > > ( ) ;
9192 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 ) ) ?;
93+ let outputs = [ Output :: new ( recv_addr, Amount :: from_btc ( 49.999_99 ) ?) ] ;
94+ let tx = client
95+ . create_raw_transaction ( & tx_input, & outputs) ?
96+ . into_model ( ) ?
97+ . 0 ;
9598 client
96- . sign_raw_transaction_with_wallet ( & tx, None , None ) ?
97- . transaction ( ) ?
99+ . sign_raw_transaction_with_wallet ( & tx) ?
100+ . into_model ( ) ?
101+ . tx
98102 } ;
99103 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 ) ) ?;
104+ let outputs = [ Output :: new ( sender_addr, Amount :: from_btc ( 49.999_98 ) ?) ] ;
105+ let tx = client
106+ . create_raw_transaction ( & tx_input, & outputs) ?
107+ . into_model ( ) ?
108+ . 0 ;
103109 client
104- . sign_raw_transaction_with_wallet ( & tx, None , None ) ?
105- . transaction ( ) ?
110+ . sign_raw_transaction_with_wallet ( & tx) ?
111+ . into_model ( ) ?
112+ . tx
106113 } ;
107114
108115 Ok ( Self {
@@ -118,31 +125,53 @@ fn relevant_conflicts() -> anyhow::Result<()> {
118125 /// Scans through all transactions in the blockchain + mempool.
119126 fn sync ( & mut self ) -> anyhow:: Result < ( ) > {
120127 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) ?;
128+ for height in 0 ..=client. get_block_count ( ) ?. into_model ( ) . 0 {
129+ let hash = client. get_block_hash ( height) ?. block_hash ( ) ? ;
130+ let block = client. get_block ( hash) ?;
124131 let _ = self . graph . apply_block_relevant ( & block, height as _ ) ;
125132 }
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- ) ;
133+
134+ let mempool_txids = client. get_raw_mempool ( ) ?. into_model ( ) ?. 0 ;
135+ let unconfirmed_txs = mempool_txids
136+ . iter ( )
137+ . map ( |txid| {
138+ client
139+ . get_raw_transaction ( * txid)
140+ . unwrap ( )
141+ . into_model ( )
142+ . unwrap ( )
143+ } )
144+ . map ( |get_raw_transaction| ( get_raw_transaction. 0 , 0 ) )
145+ . collect :: < Vec < _ > > ( ) ;
146+ // let unconfirmed_txs = mempool_txids
147+ // .iter()
148+ // // .map(|txid| -> Result<_, _> { client.get_raw_transaction(*txid)?.into_model() })?
149+ // .map(
150+ // |txid| -> Result<
151+ // GetRawTransaction,
152+ // bdk_testenv::corepc_client::client_sync::Error,
153+ // > { client.get_raw_transaction(*txid) },
154+ // )
155+ // .collect::<Vec<Result<_, _>>>()
156+ // .map(|get_raw_tx| get_raw_tx.into_model())
157+ // .map(|tx| (tx.0, 0))
158+ // .collect::<Vec<(Transaction, u64)>>();
159+ let _ = self
160+ . graph
161+ . batch_insert_relevant_unconfirmed ( unconfirmed_txs) ;
133162 Ok ( ( ) )
134163 }
135164
136165 /// Broadcast the original sending transaction.
137166 fn broadcast_send ( & self ) -> anyhow:: Result < Txid > {
138167 let client = self . env . rpc_client ( ) ;
139- Ok ( client. send_raw_transaction ( & self . tx_send ) ?)
168+ Ok ( client. send_raw_transaction ( & self . tx_send ) ?. txid ( ) ? )
140169 }
141170
142171 /// Broadcast the cancellation transaction.
143172 fn broadcast_cancel ( & self ) -> anyhow:: Result < Txid > {
144173 let client = self . env . rpc_client ( ) ;
145- Ok ( client. send_raw_transaction ( & self . tx_cancel ) ?)
174+ Ok ( client. send_raw_transaction ( & self . tx_cancel ) ?. txid ( ) ? )
146175 }
147176 }
148177
0 commit comments