From 0695ada6699907b33f5ec766e3d3e1204b97c32d Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sat, 5 Aug 2023 16:12:29 +0900 Subject: [PATCH 1/3] 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 6bc8cc8f..3a262656 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -1023,6 +1023,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)?; From 0301e4c60fc4fa486c8a11e2d1567f2b2e6c7b24 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sun, 6 Aug 2023 15:02:14 +0900 Subject: [PATCH 2/3] remove unnecessary scope --- src/rest.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/rest.rs b/src/rest.rs index 3a262656..320f5b51 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -1033,17 +1033,14 @@ fn handle_request( .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() - }; - + 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), From 59be24853631844e0b16fb101a2ae8411c9f5e38 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 16 Aug 2023 18:05:19 +0900 Subject: [PATCH 3/3] Protect POST /txs bulk query-by-txid endpoint --- src/rest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rest.rs b/src/rest.rs index 320f5b51..09daea0c 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -1023,7 +1023,7 @@ fn handle_request( json_response(tx.remove(0), ttl) } } - (&Method::POST, Some(&"txs"), None, None, None, None) => { + (&Method::POST, Some(&INTERNAL_PREFIX), Some(&"txs"), None, None, None) => { let txid_strings: Vec = serde_json::from_slice(&body).map_err(|err| HttpError::from(err.to_string()))?;