Skip to content

Commit

Permalink
feat: send query request to value check
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Apr 19, 2024
1 parent ee51bb6 commit 02dc7f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
31 changes: 29 additions & 2 deletions common/src/indexer_service/http/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ use axum::{
};
use axum_extra::TypedHeader;
use reqwest::StatusCode;
use serde_json::value::RawValue;
use thegraph::types::DeploymentId;
use tracing::trace;

use crate::{indexer_service::http::IndexerServiceResponse, prelude::AttestationSigner};
use crate::{
indexer_service::http::IndexerServiceResponse, prelude::AttestationSigner, tap::AgoraQuery,
};

use super::{
indexer_service::{IndexerServiceError, IndexerServiceState},
Expand All @@ -41,16 +44,40 @@ where
.with_label_values(&[&manifest_id.to_string()])
.inc();

#[derive(Debug, serde::Deserialize)]
pub struct QueryBody {
pub query: String,
pub variables: Option<Box<RawValue>>,
}

let request =
serde_json::from_slice(&body).map_err(|e| IndexerServiceError::InvalidRequest(e.into()))?;

let mut attestation_signer: Option<AttestationSigner> = None;

if let Some(receipt) = receipt.into_signed_receipt() {
let allocation_id = receipt.message.allocation_id;
let signature = receipt.signature;

let request: QueryBody = serde_json::from_slice(&body)
.map_err(|e| IndexerServiceError::InvalidRequest(e.into()))?;
let variables = request
.variables
.as_ref()
.map(ToString::to_string)
.unwrap_or_default();
let _ = state
.value_check_sender
.tx_query
.send(AgoraQuery {
signature,
deployment_id: manifest_id,
query: request.query.clone(),
variables,
})
.await;

// Verify the receipt and store it in the database
// TODO update checks
state
.tap_manager
.verify_and_store_receipt(receipt)
Expand Down
2 changes: 1 addition & 1 deletion common/src/tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod checks;
mod receipt_store;

pub use checks::value_check::{
create_value_check, CostModelSource, ValueCheckReceiver, ValueCheckSender,
create_value_check, AgoraQuery, CostModelSource, ValueCheckReceiver, ValueCheckSender,
};

#[derive(Clone)]
Expand Down
8 changes: 4 additions & 4 deletions common/src/tap/checks/value_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ fn compile_cost_model(src: CostModelSource) -> anyhow::Result<CostModel> {
}

pub struct AgoraQuery {
signature: Signature,
deployment_id: DeploymentId,
query: String,
variables: String,
pub signature: Signature,
pub deployment_id: DeploymentId,
pub query: String,
pub variables: String,
}

#[derive(Clone, Eq, Hash, PartialEq)]
Expand Down

0 comments on commit 02dc7f2

Please sign in to comment.