100 * u64::pow(2, retries), )) .await; retries += 1; continue; } }; break; } // Return early on any error, because we need all results to proceed if let Some(err) = results.iter().find_map(|res| res.error.as_ref()) { return Err(anyhow!( "failed to fetch raw transaction: code {} message {}", err.code, err.message )); } // Results from batched JSON-RPC requests can come back in any order, so we must sort them by id results.sort_by(|a, b| a.id.cmp(&b.id)); let txs = results .into_iter() .map(|res| { res .result .ok_or_else(|| anyhow!("Missing result for batched JSON-RPC response")) .and_then(|str| { hex::decode(str) .map_err(|e| anyhow!("Result for batched JSON-RPC response not valid hex: {e}")) }) .and_then(|hex| { bitcoin::consensus::deserialize(&hex).map_err(|e| { anyhow!("Result for batched JSON-RPC response not valid bitcoin tx: {e}")