From 6c4e12bf12778b924bd18d376fadd83ebb5d6521 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sat, 5 Aug 2023 16:12:29 +0900 Subject: [PATCH] Add a POST /txs bulk query-by-txid endpoint --- src/rest.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/rest.rs b/src/rest.rs index 625f7643..51a77323 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -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 = + 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::, _>>() + { + Ok(txids) => { + let txs: Vec<(Transaction, Option)> = { + 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)?;