File tree Expand file tree Collapse file tree 3 files changed +17
-16
lines changed Expand file tree Collapse file tree 3 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -99,18 +99,14 @@ impl AsyncClient {
99
99
}
100
100
101
101
/// Get the status of a [`Transaction`] given its [`Txid`].
102
- pub async fn get_tx_status ( & self , txid : & Txid ) -> Result < Option < TxStatus > , Error > {
102
+ pub async fn get_tx_status ( & self , txid : & Txid ) -> Result < TxStatus , Error > {
103
103
let resp = self
104
104
. client
105
105
. get ( & format ! ( "{}/tx/{}/status" , self . url, txid) )
106
106
. send ( )
107
107
. await ?;
108
108
109
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
110
- return Ok ( None ) ;
111
- }
112
-
113
- Ok ( Some ( resp. error_for_status ( ) ?. json ( ) . await ?) )
109
+ Ok ( resp. error_for_status ( ) ?. json ( ) . await ?)
114
110
}
115
111
116
112
#[ deprecated(
Original file line number Diff line number Diff line change @@ -108,20 +108,15 @@ impl BlockingClient {
108
108
}
109
109
110
110
/// Get the status of a [`Transaction`] given its [`Txid`].
111
- pub fn get_tx_status ( & self , txid : & Txid ) -> Result < Option < TxStatus > , Error > {
111
+ pub fn get_tx_status ( & self , txid : & Txid ) -> Result < TxStatus , Error > {
112
112
let resp = self
113
113
. agent
114
114
. get ( & format ! ( "{}/tx/{}/status" , self . url, txid) )
115
115
. call ( ) ;
116
116
117
117
match resp {
118
- Ok ( resp) => Ok ( Some ( resp. into_json ( ) ?) ) ,
119
- Err ( ureq:: Error :: Status ( code, _) ) => {
120
- if is_status_not_found ( code) {
121
- return Ok ( None ) ;
122
- }
123
- Err ( Error :: HttpResponse ( code) )
124
- }
118
+ Ok ( resp) => Ok ( resp. into_json ( ) ?) ,
119
+ Err ( ureq:: Error :: Status ( code, _) ) => Err ( Error :: HttpResponse ( code) ) ,
125
120
Err ( e) => Err ( Error :: Ureq ( e) ) ,
126
121
}
127
122
}
Original file line number Diff line number Diff line change @@ -460,10 +460,20 @@ mod test {
460
460
let _miner = MINER . lock ( ) . await ;
461
461
generate_blocks_and_wait ( 1 ) ;
462
462
463
- let tx_status = blocking_client. get_tx_status ( & txid) . unwrap ( ) . unwrap ( ) ;
464
- let tx_status_async = async_client. get_tx_status ( & txid) . await . unwrap ( ) . unwrap ( ) ;
463
+ let tx_status = blocking_client. get_tx_status ( & txid) . unwrap ( ) ;
464
+ let tx_status_async = async_client. get_tx_status ( & txid) . await . unwrap ( ) ;
465
465
assert_eq ! ( tx_status, tx_status_async) ;
466
466
assert ! ( tx_status. confirmed) ;
467
+
468
+ // Bogus txid returns a TxStatus with false, None, None, None
469
+ let txid = Txid :: hash ( b"ayyyy lmao" ) ;
470
+ let tx_status = blocking_client. get_tx_status ( & txid) . unwrap ( ) ;
471
+ let tx_status_async = async_client. get_tx_status ( & txid) . await . unwrap ( ) ;
472
+ assert_eq ! ( tx_status, tx_status_async) ;
473
+ assert ! ( !tx_status. confirmed) ;
474
+ assert ! ( tx_status. block_height. is_none( ) ) ;
475
+ assert ! ( tx_status. block_hash. is_none( ) ) ;
476
+ assert ! ( tx_status. block_time. is_none( ) ) ;
467
477
}
468
478
469
479
#[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
You can’t perform that action at this time.
0 commit comments