Skip to content

Commit

Permalink
feat: Theoros validators stuff (#24)
Browse files Browse the repository at this point in the history
* feat(theoros_validators): Theoros validators stuff

* feat(theoros_validators): theoros storage

* feat(theoros_validators): Som docssss

* feat(theoros_validators): Hyperlane rpc stuff

* feat(theoros_validators): Storage stuff

* feat(theoros_validators): Stufff

* feat(theoros_validators): docs

* feat(theoros_validators): Storages -> Storage

* feat(theoros_validators): latest toolchain

* feat(theoros_validators): Docs'

* feat(theoros_validators):
  • Loading branch information
akhercha authored Sep 9, 2024
1 parent ea8ac52 commit 13e5c0d
Show file tree
Hide file tree
Showing 36 changed files with 667 additions and 297 deletions.
3 changes: 0 additions & 3 deletions rust/.env.example

This file was deleted.

1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ axum-macros = { version = "0.4.1" }
ya-gcp = { version = "0.11.3", features = ["storage"] }
rusoto_s3 = "0.48.0"
rusoto_core = "0.48.0"
lazy_static = "1.5.0"

# Apibara DNA (indexing)
apibara-core = { git = "https://github.com/apibara/dna", rev = "9caa385" }
Expand Down
2 changes: 1 addition & 1 deletion rust/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.80.0"
channel = "1.81.0"
components = ["rustfmt", "clippy", "rust-analyzer"]
targets = ["wasm32-unknown-unknown"]
profile = "minimal"
1 change: 1 addition & 0 deletions rust/theoros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ ya-gcp = { workspace = true }
rusoto_s3 = { workspace = true }
rusoto_core = { workspace = true }
alloy = { workspace = true }
lazy_static = { workspace = true }

pragma-utils = { path = "../pragma-utils" }
142 changes: 141 additions & 1 deletion rust/theoros/openapi.json
Original file line number Diff line number Diff line change
@@ -1 +1,141 @@
{"openapi":"3.0.3","info":{"title":"theoros","description":"","license":{"name":""},"version":"0.1.0"},"paths":{"/v1/calldata":{"get":{"tags":["crate::handlers::get_calldata"],"operationId":"get_calldata","parameters":[],"responses":{"200":{"description":"Get the calldata","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/GetCalldataResponse"}}}}}}}}},"components":{"schemas":{"GetCalldataError":{"type":"string","enum":["InternalServerError","DatabaseConnection"]},"GetCalldataQuery":{"type":"object"},"GetCalldataResponse":{"type":"object","required":["hash"],"properties":{"hash":{"type":"string"}}}},"responses":{"GetCalldataResponse":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["hash"],"properties":{"hash":{"type":"string"}}}}}}}},"tags":[{"name":"theoros","description":"Theoros - the Pragma Consultant"}]}
{
"openapi": "3.0.3",
"info": {
"title": "theoros",
"description": "",
"license": {
"name": ""
},
"version": "0.1.0"
},
"paths": {
"/v1/calldata": {
"get": {
"tags": [
"crate::handlers::get_data_feeds"
],
"operationId": "get_data_feeds",
"parameters": [],
"responses": {
"200": {
"description": "Get all the available data feeds",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/GetDataFeedsResponse"
}
}
}
}
}
}
}
},
"/v1/calldata/{data_feed_id}": {
"get": {
"tags": [
"crate::handlers::get_calldata"
],
"operationId": "get_calldata",
"parameters": [],
"responses": {
"200": {
"description": "Constructs the calldata used to update the data feed id specified",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/GetCalldataResponse"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"GetCalldataError": {
"type": "string",
"enum": [
"InternalServerError",
"DatabaseConnection"
]
},
"GetCalldataQuery": {
"type": "object"
},
"GetCalldataResponse": {
"type": "object",
"required": [
"hash"
],
"properties": {
"hash": {
"type": "string"
}
}
},
"GetDataFeedsError": {
"type": "string",
"enum": [
"InternalServerError",
"DatabaseConnection"
]
},
"GetDataFeedsQuery": {
"type": "object"
},
"GetDataFeedsResponse": {
"type": "array",
"items": {
"type": "string"
}
}
},
"responses": {
"GetCalldataResponse": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"hash"
],
"properties": {
"hash": {
"type": "string"
}
}
}
}
}
},
"GetDataFeedsResponse": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
},
"tags": [
{
"name": "theoros",
"description": "Theoros - the Pragma Consultant"
}
]
}
60 changes: 0 additions & 60 deletions rust/theoros/src/config.rs

This file was deleted.

25 changes: 25 additions & 0 deletions rust/theoros/src/errors/data_feeds_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use axum::{http::StatusCode, response::IntoResponse, Json};
use serde_json::json;
use utoipa::ToSchema;

#[derive(Debug, thiserror::Error, ToSchema)]
#[allow(unused)]
pub enum GetDataFeedsError {
#[error("internal server error")]
InternalServerError,
#[error("could not establish a connection with the database")]
DatabaseConnection,
}

impl IntoResponse for GetDataFeedsError {
fn into_response(self) -> axum::response::Response {
let (status, err_msg) = match self {
Self::DatabaseConnection => {
(StatusCode::SERVICE_UNAVAILABLE, "Could not establish a connection with the Database".to_string())
}
_ => (StatusCode::INTERNAL_SERVER_ERROR, String::from("Internal server error")),
};
(status, Json(json!({"resource":"Calldata", "message": err_msg, "happened_at" : chrono::Utc::now() })))
.into_response()
}
}
2 changes: 2 additions & 0 deletions rust/theoros/src/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod app_error;
pub mod calldata_error;
pub mod data_feeds_error;

pub use app_error::AppError;
pub use calldata_error::GetCalldataError;
pub use data_feeds_error::GetDataFeedsError;
13 changes: 9 additions & 4 deletions rust/theoros/src/handlers/get_calldata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToResponse, ToSchema};

use crate::errors::GetCalldataError;
use crate::extractors::PathExtractor;
use crate::AppState;

#[derive(Default, Deserialize, IntoParams, ToSchema)]
Expand All @@ -16,19 +17,23 @@ pub struct GetCalldataResponse {

#[utoipa::path(
get,
// TODO: path
path = "/v1/calldata",
path = "/v1/calldata/{data_feed_id}",
responses(
(status = 200, description = "Get the calldata", body = [GetCalldataResponse])
(
status = 200,
description = "Constructs the calldata used to update the data feed id specified",
body = [GetCalldataResponse]
)
),
params(
GetCalldataQuery
),
)]
pub async fn get_calldata(
State(_state): State<AppState>,
PathExtractor(data_feed_id): PathExtractor<String>,
Query(_params): Query<GetCalldataQuery>,
) -> Result<Json<GetCalldataResponse>, GetCalldataError> {
tracing::info!("Received get calldata request");
tracing::info!("Received get calldata request for feed: {data_feed_id}");
Ok(Json(GetCalldataResponse::default()))
}
32 changes: 32 additions & 0 deletions rust/theoros/src/handlers/get_data_feeds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use axum::extract::{Query, State};
use axum::Json;
use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToResponse, ToSchema};

use crate::errors::GetDataFeedsError;
use crate::AppState;

#[derive(Default, Deserialize, IntoParams, ToSchema)]
pub struct GetDataFeedsQuery {}

#[derive(Debug, Default, Serialize, Deserialize, ToResponse, ToSchema)]
pub struct GetDataFeedsResponse(pub Vec<String>);

#[utoipa::path(
get,
// TODO: path
path = "/v1/calldata",
responses(
(status = 200, description = "Get all the available data feeds", body = [GetDataFeedsResponse])
),
params(
GetDataFeedsQuery
),
)]
pub async fn get_data_feeds(
State(_state): State<AppState>,
Query(_params): Query<GetDataFeedsQuery>,
) -> Result<Json<GetDataFeedsResponse>, GetDataFeedsError> {
tracing::info!("Received get calldata request");
Ok(Json(GetDataFeedsResponse::default()))
}
1 change: 1 addition & 0 deletions rust/theoros/src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod get_calldata;
pub mod get_data_feeds;
pub mod subscribe_to_calldata;
Loading

0 comments on commit 13e5c0d

Please sign in to comment.