Skip to content

Commit

Permalink
Merge pull request #31 from mempool/mononaut/bulk-mempool-post-api
Browse files Browse the repository at this point in the history
Bulk mempool query by txid
  • Loading branch information
softsimon authored Aug 4, 2023
2 parents a21a958 + eed22ef commit 92eb65e
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 @@ -1128,6 +1128,29 @@ fn handle_request(

json_response(prepare_txs(txs, query, config), TTL_SHORT)
}
(&Method::POST, Some(&"mempool"), 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>)> = {
let mempool = query.mempool();
txids
.iter()
.filter_map(|txid| mempool.lookup_txn(txid).map(|tx| (tx, None)))
.collect()
};

json_response(prepare_txs(txs, query, config), 0)
}
Err(err) => http_message(StatusCode::BAD_REQUEST, err.to_string(), 0),
}
}
(&Method::GET, Some(&"mempool"), Some(&"txs"), last_seen_txid, None, None) => {
let last_seen_txid = last_seen_txid.and_then(|txid| Txid::from_hex(txid).ok());
let txs = query
Expand Down

0 comments on commit 92eb65e

Please sign in to comment.