@@ -502,7 +502,7 @@ fn prepare_txs(
502502 txs : Vec < ( Transaction , Option < BlockId > ) > ,
503503 query : & Query ,
504504 config : & Config ,
505- ) -> Result < Vec < TransactionValue > , errors :: Error > {
505+ ) -> Vec < TransactionValue > {
506506 let outpoints = txs
507507 . iter ( )
508508 . flat_map ( |( tx, _) | {
@@ -513,12 +513,11 @@ fn prepare_txs(
513513 } )
514514 . collect ( ) ;
515515
516- let prevouts = query. lookup_txos ( & outpoints) ? ;
516+ let prevouts = query. lookup_txos ( & outpoints) ;
517517
518- Ok ( txs
519- . into_iter ( )
518+ txs. into_iter ( )
520519 . map ( |( tx, blockid) | TransactionValue :: new ( tx, blockid, & prevouts, config) )
521- . collect ( ) )
520+ . collect ( )
522521}
523522
524523#[ tokio:: main]
@@ -709,7 +708,7 @@ fn handle_request(
709708 . map ( |tx| ( tx, None ) )
710709 . collect ( ) ;
711710
712- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
711+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
713712 }
714713 ( & Method :: GET , Some ( & "block" ) , Some ( hash) , Some ( & "header" ) , None , None ) => {
715714 let hash = BlockHash :: from_hex ( hash) ?;
@@ -786,7 +785,7 @@ fn handle_request(
786785 // XXX orphraned blocks alway get TTL_SHORT
787786 let ttl = ttl_by_depth ( confirmed_blockid. map ( |b| b. height ) , query) ;
788787
789- json_maybe_error_response ( prepare_txs ( txs, query, config) , ttl)
788+ json_response ( prepare_txs ( txs, query, config) , ttl)
790789 }
791790 ( & Method :: GET , Some ( script_type @ & "address" ) , Some ( script_str) , None , None , None )
792791 | ( & Method :: GET , Some ( script_type @ & "scripthash" ) , Some ( script_str) , None , None , None ) => {
@@ -874,7 +873,7 @@ fn handle_request(
874873 ) ;
875874 }
876875
877- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
876+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
878877 }
879878
880879 (
@@ -907,7 +906,7 @@ fn handle_request(
907906 . map ( |( tx, blockid) | ( tx, Some ( blockid) ) )
908907 . collect ( ) ;
909908
910- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
909+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
911910 }
912911 (
913912 & Method :: GET ,
@@ -938,7 +937,7 @@ fn handle_request(
938937 . map ( |tx| ( tx, None ) )
939938 . collect ( ) ;
940939
941- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
940+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
942941 }
943942
944943 (
@@ -981,9 +980,9 @@ fn handle_request(
981980 let blockid = query. chain ( ) . tx_confirming_block ( & hash) ;
982981 let ttl = ttl_by_depth ( blockid. as_ref ( ) . map ( |b| b. height ) , query) ;
983982
984- let tx = prepare_txs ( vec ! [ ( tx, blockid) ] , query, config) . map ( | mut v| v . remove ( 0 ) ) ;
983+ let mut tx = prepare_txs ( vec ! [ ( tx, blockid) ] , query, config) ;
985984
986- json_maybe_error_response ( tx, ttl)
985+ json_response ( tx. remove ( 0 ) , ttl)
987986 }
988987 ( & Method :: GET , Some ( & "tx" ) , Some ( hash) , Some ( out_type @ & "hex" ) , None , None )
989988 | ( & Method :: GET , Some ( & "tx" ) , Some ( hash) , Some ( out_type @ & "raw" ) , None , None ) => {
@@ -1106,7 +1105,7 @@ fn handle_request(
11061105 . map ( |tx| ( tx, None ) )
11071106 . collect ( ) ;
11081107
1109- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
1108+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
11101109 }
11111110 ( & Method :: GET , Some ( & "mempool" ) , Some ( & "txs" ) , last_seen_txid, None , None ) => {
11121111 let last_seen_txid = last_seen_txid. and_then ( |txid| Txid :: from_hex ( txid) . ok ( ) ) ;
@@ -1117,7 +1116,7 @@ fn handle_request(
11171116 . map ( |tx| ( tx, None ) )
11181117 . collect ( ) ;
11191118
1120- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
1119+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
11211120 }
11221121 ( & Method :: GET , Some ( & "mempool" ) , Some ( & "recent" ) , None , None , None ) => {
11231122 let mempool = query. mempool ( ) ;
@@ -1188,7 +1187,7 @@ fn handle_request(
11881187 . map ( |( tx, blockid) | ( tx, Some ( blockid) ) ) ,
11891188 ) ;
11901189
1191- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
1190+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
11921191 }
11931192
11941193 #[ cfg( feature = "liquid" ) ]
@@ -1214,7 +1213,7 @@ fn handle_request(
12141213 . map ( |( tx, blockid) | ( tx, Some ( blockid) ) )
12151214 . collect ( ) ;
12161215
1217- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
1216+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
12181217 }
12191218
12201219 #[ cfg( feature = "liquid" ) ]
@@ -1228,7 +1227,7 @@ fn handle_request(
12281227 . map ( |tx| ( tx, None ) )
12291228 . collect ( ) ;
12301229
1231- json_maybe_error_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
1230+ json_response ( prepare_txs ( txs, query, config) , TTL_SHORT )
12321231 }
12331232
12341233 #[ cfg( feature = "liquid" ) ]
@@ -1281,26 +1280,26 @@ fn json_response<T: Serialize>(value: T, ttl: u32) -> Result<Response<Body>, Htt
12811280 . unwrap ( ) )
12821281}
12831282
1284- fn json_maybe_error_response < T : Serialize > (
1285- value : Result < T , errors:: Error > ,
1286- ttl : u32 ,
1287- ) -> Result < Response < Body > , HttpError > {
1288- let response = Response :: builder ( )
1289- . header ( "Content-Type" , "application/json" )
1290- . header ( "Cache-Control" , format ! ( "public, max-age={:}" , ttl) )
1291- . header ( "X-Powered-By" , & * * VERSION_STRING ) ;
1292- Ok ( match value {
1293- Ok ( v) => response
1294- . body ( Body :: from ( serde_json:: to_string ( & v) ?) )
1295- . expect ( "Valid http response" ) ,
1296- Err ( e) => response
1297- . status ( 500 )
1298- . body ( Body :: from ( serde_json:: to_string (
1299- & json ! ( { "error" : e. to_string( ) } ) ,
1300- ) ?) )
1301- . expect ( "Valid http response" ) ,
1302- } )
1303- }
1283+ // fn json_maybe_error_response<T: Serialize>(
1284+ // value: Result<T, errors::Error>,
1285+ // ttl: u32,
1286+ // ) -> Result<Response<Body>, HttpError> {
1287+ // let response = Response::builder()
1288+ // .header("Content-Type", "application/json")
1289+ // .header("Cache-Control", format!("public, max-age={:}", ttl))
1290+ // .header("X-Powered-By", &**VERSION_STRING);
1291+ // Ok(match value {
1292+ // Ok(v) => response
1293+ // .body(Body::from(serde_json::to_string(&v)?))
1294+ // .expect("Valid http response"),
1295+ // Err(e) => response
1296+ // .status(500)
1297+ // .body(Body::from(serde_json::to_string(
1298+ // &json!({ "error": e.to_string() }),
1299+ // )?))
1300+ // .expect("Valid http response"),
1301+ // })
1302+ // }
13041303
13051304fn blocks (
13061305 query : & Query ,
0 commit comments