Skip to content

Commit

Permalink
Add a POST /txs bulk query-by-txid endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mononaut committed Aug 5, 2023
1 parent 92eb65e commit 6c4e12b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,32 @@ fn handle_request(

json_response(tx.remove(0), ttl)
}
(&Method::POST, Some(&"txs"), None, None, None, None) => {
let txid_strings: Vec<String> =
serde_json::from_slice(&body).map_err(|err| HttpError::from(err.to_string()))?;

match txid_strings
.into_iter()
.map(|txid| Txid::from_hex(&txid))
.collect::<Result<Vec<Txid>, _>>()
{
Ok(txids) => {
let txs: Vec<(Transaction, Option<BlockId>)> = {
txids
.iter()
.filter_map(|txid| {
query
.lookup_txn(txid)
.map(|tx| (tx, query.chain().tx_confirming_block(txid)))
})
.collect()
};

json_response(prepare_txs(txs, query, config), 0)
}
Err(err) => http_message(StatusCode::BAD_REQUEST, err.to_string(), 0),
}
}
(&Method::GET, Some(&"tx"), Some(hash), Some(out_type @ &"hex"), None, None)
| (&Method::GET, Some(&"tx"), Some(hash), Some(out_type @ &"raw"), None, None) => {
let hash = Txid::from_hex(hash)?;
Expand Down

0 comments on commit 6c4e12b

Please sign in to comment.