Skip to content

Commit 157dbf2

Browse files
authored
Merge pull request Blockstream#33 from mempool/mononaut/bulk-txs-post-api
Add a POST /txs bulk query-by-txid endpoint
2 parents e28f887 + 9ee9a5d commit 157dbf2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/rest.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,29 @@ fn handle_request(
10231023
json_response(tx.remove(0), ttl)
10241024
}
10251025
}
1026+
(&Method::POST, Some(&INTERNAL_PREFIX), Some(&"txs"), None, None, None) => {
1027+
let txid_strings: Vec<String> =
1028+
serde_json::from_slice(&body).map_err(|err| HttpError::from(err.to_string()))?;
1029+
1030+
match txid_strings
1031+
.into_iter()
1032+
.map(|txid| Txid::from_hex(&txid))
1033+
.collect::<Result<Vec<Txid>, _>>()
1034+
{
1035+
Ok(txids) => {
1036+
let txs: Vec<(Transaction, Option<BlockId>)> = txids
1037+
.iter()
1038+
.filter_map(|txid| {
1039+
query
1040+
.lookup_txn(txid)
1041+
.map(|tx| (tx, query.chain().tx_confirming_block(txid)))
1042+
})
1043+
.collect();
1044+
json_response(prepare_txs(txs, query, config), 0)
1045+
}
1046+
Err(err) => http_message(StatusCode::BAD_REQUEST, err.to_string(), 0),
1047+
}
1048+
}
10261049
(&Method::GET, Some(&"tx"), Some(hash), Some(out_type @ &"hex"), None, None)
10271050
| (&Method::GET, Some(&"tx"), Some(hash), Some(out_type @ &"raw"), None, None) => {
10281051
let hash = Txid::from_hex(hash)?;

0 commit comments

Comments
 (0)