mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-01-21 03:21:08 +03:00
Remove double json encoding on http response (#114)
This commit is contained in:
parent
a45f8d3e9f
commit
db818ac8b7
1 changed files with 3 additions and 26 deletions
|
@ -766,7 +766,7 @@ where
|
||||||
&self,
|
&self,
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
api: Foreign<T, C, K>,
|
api: Foreign<T, C, K>,
|
||||||
) -> Box<dyn Future<Item = String, Error = Error> + Send> {
|
) -> Box<dyn Future<Item = Slate, Error = Error> + Send> {
|
||||||
Box::new(parse_body(req).and_then(
|
Box::new(parse_body(req).and_then(
|
||||||
//TODO: No way to insert a message from the params
|
//TODO: No way to insert a message from the params
|
||||||
move |slate_str: String| {
|
move |slate_str: String| {
|
||||||
|
@ -776,7 +776,7 @@ where
|
||||||
err(e)
|
err(e)
|
||||||
} else {
|
} else {
|
||||||
match api.receive_tx(&slate, None, None) {
|
match api.receive_tx(&slate, None, None) {
|
||||||
Ok(s) => ok(serde_json::to_string(&s).unwrap()),
|
Ok(s) => ok(s),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("receive_tx: failed with error: {}", e);
|
error!("receive_tx: failed with error: {}", e);
|
||||||
err(e)
|
err(e)
|
||||||
|
@ -803,7 +803,7 @@ where
|
||||||
),
|
),
|
||||||
"receive_tx" => Box::new(
|
"receive_tx" => Box::new(
|
||||||
self.receive_tx(req, api)
|
self.receive_tx(req, api)
|
||||||
.and_then(|res| ok(json_response_slate(&res))),
|
.and_then(|res| ok(json_response(&res))),
|
||||||
),
|
),
|
||||||
_ => Box::new(ok(response(StatusCode::BAD_REQUEST, "unknown action"))),
|
_ => Box::new(ok(response(StatusCode::BAD_REQUEST, "unknown action"))),
|
||||||
}
|
}
|
||||||
|
@ -915,29 +915,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// As above, dealing with stringified slate output
|
|
||||||
// from older versions.
|
|
||||||
// Older versions are expecting a slate objects, anything from
|
|
||||||
// 1.1.0 up is expecting a string
|
|
||||||
fn json_response_slate<T>(s: &T) -> Response<Body>
|
|
||||||
where
|
|
||||||
T: Serialize,
|
|
||||||
{
|
|
||||||
match serde_json::to_string(s) {
|
|
||||||
Ok(mut json) => {
|
|
||||||
if let None = json.find("version_info") {
|
|
||||||
let mut r = json.clone();
|
|
||||||
r.pop();
|
|
||||||
r.remove(0);
|
|
||||||
// again, for backwards slate compat
|
|
||||||
json = r.replace("\\\"", "\"")
|
|
||||||
}
|
|
||||||
response(StatusCode::OK, json)
|
|
||||||
}
|
|
||||||
Err(_) => response(StatusCode::INTERNAL_SERVER_ERROR, ""),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pretty-printed version of above
|
// pretty-printed version of above
|
||||||
fn json_response_pretty<T>(s: &T) -> Response<Body>
|
fn json_response_pretty<T>(s: &T) -> Response<Body>
|
||||||
where
|
where
|
||||||
|
|
Loading…
Reference in a new issue