Skip to content

Commit

Permalink
Merge 8b9b531 into d20ab71
Browse files Browse the repository at this point in the history
  • Loading branch information
aasseman committed Aug 9, 2023
2 parents d20ab71 + 8b9b531 commit b714e36
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
11 changes: 8 additions & 3 deletions service/src/graph_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ impl GraphNodeInstance {
.body(data.clone())
.header(header::CONTENT_TYPE, "application/json");

let response = request.send().await?.text().await?;
let response = request.send().await?;
let attestable = response
.headers()
.get("graph-attestable")
.map_or(false, |v| v == "true");

Ok(UnattestedQueryResult {
graphql_response: response,
attestable: true,
graphql_response: response.text().await?,
attestable,
})
}

Expand Down
11 changes: 8 additions & 3 deletions service/src/query_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,24 @@ impl ToString for SubgraphDeploymentID {
self.hex()
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Signature {
v: i64,
r: String,
s: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryResult {
graphql_response: String,
attestation: Option<Signature>,
#[serde(rename = "graphQLResponse")]
pub graphql_response: String,
pub attestation: Option<Signature>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnattestedQueryResult {
#[serde(rename = "graphQLResponse")]
pub graphql_response: String,
pub attestable: bool,
}
Expand Down
14 changes: 1 addition & 13 deletions service/src/server/routes/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use axum::{
response::IntoResponse,
Json,
};
use hyper::http::HeaderName;

use crate::server::ServerOptions;

Expand Down Expand Up @@ -46,18 +45,7 @@ pub async fn network_queries(
.expect("Failed to execute free network subgraph query");

match request.status {
200 => {
let response_body = request.result.graphql_response;
(
StatusCode::OK,
axum::response::AppendHeaders([(
HeaderName::from_static("graph-attestable"),
"false",
)]),
Json(response_body),
)
.into_response()
}
200 => (StatusCode::OK, Json(request.result)).into_response(),
_ => bad_request_response("Bad response from Graph node"),
}
}
16 changes: 2 additions & 14 deletions service/src/server/routes/subgraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use axum::{
extract::Extension,
http::{self, HeaderName, Request, StatusCode},
http::{self, Request, StatusCode},
response::IntoResponse,
Json,
};
Expand Down Expand Up @@ -72,19 +72,7 @@ pub async fn subgraph_queries(
.expect("Failed to execute free query");

match res.status {
200 => {
let response_body = res.result.graphql_response;
let attestable = res.result.attestable;
(
StatusCode::OK,
axum::response::AppendHeaders([(
HeaderName::from_static("graph-attestable"),
if attestable { "true" } else { "false" },
)]),
Json(response_body),
)
.into_response()
}
200 => (StatusCode::OK, Json(res.result)).into_response(),
_ => bad_request_response("Bad response from Graph node"),
}
} else {
Expand Down

0 comments on commit b714e36

Please sign in to comment.