Skip to content

Commit c3b72ec

Browse files
Merge #46: bugfix: GET /tx/:txid/status is not Option
e20b701 bugfix: `GET /tx/:txid/status` is not `Option` (Max Fang) Pull request description: See the [server-side handler](https://github.com/Blockstream/electrs/blob/adedee15f1fe460398a7045b292604df2161adc0/src/rest.rs#L941) - unlike the other `tx` endpoints, this one doesn't first check if the tx is known. Also added a test that confirms this behavior. Top commit has no ACKs. Tree-SHA512: f0f59ceae998fb3b237eda3466e3f8c77d2951ea332838fcf01c93b60a8ea5eacdb21f71bac89fdb37f8c354953377e9710673cd2040886834da02f3a7fef2bb
2 parents 54de811 + e20b701 commit c3b72ec

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/async.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,14 @@ impl AsyncClient {
9999
}
100100

101101
/// 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> {
103103
let resp = self
104104
.client
105105
.get(&format!("{}/tx/{}/status", self.url, txid))
106106
.send()
107107
.await?;
108108

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?)
114110
}
115111

116112
#[deprecated(

src/blocking.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,15 @@ impl BlockingClient {
108108
}
109109

110110
/// 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> {
112112
let resp = self
113113
.agent
114114
.get(&format!("{}/tx/{}/status", self.url, txid))
115115
.call();
116116

117117
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)),
125120
Err(e) => Err(Error::Ureq(e)),
126121
}
127122
}

src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,20 @@ mod test {
460460
let _miner = MINER.lock().await;
461461
generate_blocks_and_wait(1);
462462

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();
465465
assert_eq!(tx_status, tx_status_async);
466466
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());
467477
}
468478

469479
#[cfg(all(feature = "blocking", feature = "async"))]

0 commit comments

Comments
 (0)