Skip to content

Commit 333ad87

Browse files
authored
Merge pull request Blockstream#36 from mempool/mononaut/batch-outspends
Bulk txs outspends
2 parents 9a0383b + 3f877ad commit 333ad87

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/rest.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,38 @@ fn handle_request(
11221122
.map_err(|err| HttpError::from(err.description().to_string()))?;
11231123
http_message(StatusCode::OK, txid.to_hex(), 0)
11241124
}
1125+
(&Method::GET, Some(&"txs"), Some(&"outspends"), None, None, None) => {
1126+
let txid_strings: Vec<&str> = query_params
1127+
.get("txids")
1128+
.ok_or(HttpError::from("No txids specified".to_string()))?
1129+
.as_str()
1130+
.split(',')
1131+
.collect();
1132+
1133+
if txid_strings.len() > 50 {
1134+
return http_message(StatusCode::BAD_REQUEST, "Too many txids requested", 0);
1135+
}
1136+
1137+
let spends: Vec<Vec<SpendingValue>> = txid_strings
1138+
.into_iter()
1139+
.map(|txid_str| {
1140+
Txid::from_hex(txid_str)
1141+
.ok()
1142+
.and_then(|txid| query.lookup_txn(&txid))
1143+
.map_or_else(Vec::new, |tx| {
1144+
query
1145+
.lookup_tx_spends(tx)
1146+
.into_iter()
1147+
.map(|spend| {
1148+
spend.map_or_else(SpendingValue::default, SpendingValue::from)
1149+
})
1150+
.collect()
1151+
})
1152+
})
1153+
.collect();
1154+
1155+
json_response(spends, TTL_SHORT)
1156+
}
11251157

11261158
(&Method::GET, Some(&"mempool"), None, None, None, None) => {
11271159
json_response(query.mempool().backlog_stats(), TTL_SHORT)

0 commit comments

Comments
 (0)