1
1
use crate :: tests:: test_utils:: expect_event;
2
2
use crate :: { Builder , Config , Error , Event } ;
3
3
4
- use bitcoin:: { Address , Amount } ;
4
+ use bitcoin:: { Address , Amount , Txid } ;
5
5
use bitcoind:: bitcoincore_rpc:: RpcApi ;
6
6
use electrsd:: bitcoind:: bitcoincore_rpc:: bitcoincore_rpc_json:: AddressType ;
7
7
use electrsd:: { bitcoind, bitcoind:: BitcoinD , ElectrsD } ;
@@ -69,6 +69,20 @@ fn wait_for_block(min_height: usize) {
69
69
}
70
70
}
71
71
72
+ fn wait_for_tx ( txid : Txid ) {
73
+ let mut tx_res = get_electrsd ( ) . client . transaction_get ( & txid) ;
74
+ loop {
75
+ if tx_res. is_ok ( ) {
76
+ break ;
77
+ }
78
+ tx_res = exponential_backoff_poll ( || {
79
+ get_electrsd ( ) . trigger ( ) . unwrap ( ) ;
80
+ get_electrsd ( ) . client . ping ( ) . unwrap ( ) ;
81
+ Some ( get_electrsd ( ) . client . transaction_get ( & txid) )
82
+ } ) ;
83
+ }
84
+ }
85
+
72
86
fn exponential_backoff_poll < T , F > ( mut poll : F ) -> T
73
87
where
74
88
F : FnMut ( ) -> Option < T > ,
@@ -91,10 +105,11 @@ fn premine_and_distribute_funds(addrs: Vec<Address>, amount: Amount) {
91
105
} ) ;
92
106
93
107
for addr in addrs {
94
- get_bitcoind ( )
108
+ let txid = get_bitcoind ( )
95
109
. client
96
110
. send_to_address ( & addr, amount, None , None , None , None , None , None )
97
111
. unwrap ( ) ;
112
+ wait_for_tx ( txid) ;
98
113
}
99
114
100
115
generate_blocks_and_wait ( 1 ) ;
@@ -147,8 +162,17 @@ fn channel_full_cycle() {
147
162
format ! ( "{}@{}" , node_b. node_id( ) . unwrap( ) , node_b. listening_address( ) . unwrap( ) ) ;
148
163
node_a. connect_open_channel ( & node_b_addr, 50000 , true ) . unwrap ( ) ;
149
164
150
- // Wait a sec so the funding tx can 'propagate' via EsploraD to BitcoinD.
151
- std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
165
+ let funding_txo = loop {
166
+ let details = node_a. list_channels ( ) ;
167
+
168
+ if details. is_empty ( ) || details[ 0 ] . funding_txo . is_none ( ) {
169
+ std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
170
+ } else {
171
+ break details[ 0 ] . funding_txo . unwrap ( ) ;
172
+ }
173
+ } ;
174
+
175
+ wait_for_tx ( funding_txo. txid ) ;
152
176
153
177
println ! ( "\n .. generating blocks, syncing wallets .. " ) ;
154
178
generate_blocks_and_wait ( 6 ) ;
0 commit comments