Skip to content

Commit

Permalink
Merge pull request #33 from mempool/mononaut/bulk-txs-post-api
Browse files Browse the repository at this point in the history
Add a POST /txs bulk query-by-txid endpoint
  • Loading branch information
wiz authored Nov 12, 2023
2 parents e28f887 + 9ee9a5d commit 157dbf2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,29 @@ fn handle_request(
json_response(tx.remove(0), ttl)
}
}
(&Method::POST, Some(&INTERNAL_PREFIX), Some(&"txs"), 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 157dbf2

Please sign in to comment.