@@ -16,6 +16,8 @@ const DEFAULT_RELAY_PORT: &str = "8080";
1616const DEFAULT_DB_HOST : & str = "localhost:5432" ;
1717const DEFAULT_TIMEOUT_SECS : u64 = 30 ;
1818const MAX_BUFFER_SIZE : usize = 65536 ;
19+ const V1_REJECT_RES_JSON : & str =
20+ r#"{{"errorCode": "original-psbt-rejected ", "message": "Body is not a string"}}"# ;
1921const V1_UNAVAILABLE_RES_JSON : & str = r#"{{"errorCode": "unavailable", "message": "V2 receiver offline. V1 sends require synchronous communications."}}"# ;
2022
2123mod db;
@@ -86,6 +88,7 @@ async fn handle_ohttp_gateway(
8688 ohttp : Arc < Mutex < ohttp:: Server > > ,
8789) -> Result < Response < Body > > {
8890 let path = req. uri ( ) . path ( ) . to_string ( ) ;
91+ let query = req. uri ( ) . query ( ) . unwrap_or_default ( ) . to_string ( ) ;
8992 let ( parts, body) = req. into_parts ( ) ;
9093
9194 let path_segments: Vec < & str > = path. split ( '/' ) . collect ( ) ;
@@ -94,7 +97,7 @@ async fn handle_ohttp_gateway(
9497 ( Method :: POST , [ "" , "" ] ) => handle_ohttp ( body, pool, ohttp) . await ,
9598 ( Method :: GET , [ "" , "ohttp-config" ] ) =>
9699 Ok ( get_ohttp_config ( ohttp_config ( & ohttp) . await ?) . await ) ,
97- ( Method :: POST , [ "" , id] ) => post_fallback_v1 ( id, body, pool) . await ,
100+ ( Method :: POST , [ "" , id] ) => post_fallback_v1 ( id, query , body, pool) . await ,
98101 _ => Ok ( not_found ( ) ) ,
99102 }
100103 . unwrap_or_else ( |e| e. to_response ( ) ) ;
@@ -214,14 +217,29 @@ async fn post_enroll(body: Body) -> Result<Response<Body>, HandlerError> {
214217
215218async fn post_fallback_v1 (
216219 id : & str ,
220+ query : String ,
217221 body : Body ,
218222 pool : DbPool ,
219223) -> Result < Response < Body > , HandlerError > {
220224 trace ! ( "Post fallback v1" ) ;
221225 let none_response = Response :: builder ( )
222226 . status ( StatusCode :: SERVICE_UNAVAILABLE )
223227 . body ( Body :: from ( V1_UNAVAILABLE_RES_JSON ) ) ?;
224- post_fallback ( id, body, pool, none_response) . await
228+ let bad_request_body_res =
229+ Response :: builder ( ) . status ( StatusCode :: BAD_REQUEST ) . body ( Body :: from ( V1_REJECT_RES_JSON ) ) ?;
230+
231+ let body_bytes = match hyper:: body:: to_bytes ( body) . await {
232+ Ok ( bytes) => bytes. to_vec ( ) ,
233+ Err ( _) => return Ok ( bad_request_body_res) ,
234+ } ;
235+
236+ let body_str = match String :: from_utf8 ( body_bytes) {
237+ Ok ( body_str) => body_str,
238+ Err ( _) => return Ok ( bad_request_body_res) ,
239+ } ;
240+
241+ let v2_compat_body = Body :: from ( format ! ( "{}\n {}" , body_str, query) ) ;
242+ post_fallback ( id, v2_compat_body, pool, none_response) . await
225243}
226244
227245async fn post_fallback_v2 (
0 commit comments