Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,14 @@ impl AsyncClient {
}

/// Get the status of a [`Transaction`] given its [`Txid`].
pub async fn get_tx_status(&self, txid: &Txid) -> Result<Option<TxStatus>, Error> {
pub async fn get_tx_status(&self, txid: &Txid) -> Result<TxStatus, Error> {
let resp = self
.client
.get(&format!("{}/tx/{}/status", self.url, txid))
.send()
.await?;

if let StatusCode::NOT_FOUND = resp.status() {
return Ok(None);
}

Ok(Some(resp.error_for_status()?.json().await?))
Ok(resp.error_for_status()?.json().await?)
}

#[deprecated(
Expand Down
11 changes: 3 additions & 8 deletions src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,15 @@ impl BlockingClient {
}

/// Get the status of a [`Transaction`] given its [`Txid`].
pub fn get_tx_status(&self, txid: &Txid) -> Result<Option<TxStatus>, Error> {
pub fn get_tx_status(&self, txid: &Txid) -> Result<TxStatus, Error> {
let resp = self
.agent
.get(&format!("{}/tx/{}/status", self.url, txid))
.call();

match resp {
Ok(resp) => Ok(Some(resp.into_json()?)),
Err(ureq::Error::Status(code, _)) => {
if is_status_not_found(code) {
return Ok(None);
}
Err(Error::HttpResponse(code))
}
Ok(resp) => Ok(resp.into_json()?),
Err(ureq::Error::Status(code, _)) => Err(Error::HttpResponse(code)),
Err(e) => Err(Error::Ureq(e)),
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,20 @@ mod test {
let _miner = MINER.lock().await;
generate_blocks_and_wait(1);

let tx_status = blocking_client.get_tx_status(&txid).unwrap().unwrap();
let tx_status_async = async_client.get_tx_status(&txid).await.unwrap().unwrap();
let tx_status = blocking_client.get_tx_status(&txid).unwrap();
let tx_status_async = async_client.get_tx_status(&txid).await.unwrap();
assert_eq!(tx_status, tx_status_async);
assert!(tx_status.confirmed);

// Bogus txid returns a TxStatus with false, None, None, None
let txid = Txid::hash(b"ayyyy lmao");
let tx_status = blocking_client.get_tx_status(&txid).unwrap();
let tx_status_async = async_client.get_tx_status(&txid).await.unwrap();
assert_eq!(tx_status, tx_status_async);
assert!(!tx_status.confirmed);
assert!(tx_status.block_height.is_none());
assert!(tx_status.block_hash.is_none());
assert!(tx_status.block_time.is_none());
}

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