Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(torii-server): combine tonic and warp #926

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 48 additions & 24 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@ toml = "0.7.4"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.16", features = [ "env-filter" ] }
url = "2.4.0"

# server
hyper = "0.14.27"
warp = "0.3"

# gRPC
prost = "0.12"
tonic = "0.10"
tonic-build = "0.10"
tonic-web = "0.10.1"

[patch."https://github.com/starkware-libs/blockifier"]
blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "f7df9ba" }

Expand Down
1 change: 0 additions & 1 deletion crates/torii/client/src/contract/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ pub fn unpack<P: Provider>(
}

fn parse_ty<P: Provider>(data: &[FieldElement]) -> Result<Ty, ComponentError<P::Error>> {
println!("{:#?}", data);
let member_type: u8 = data[0].try_into().unwrap();
match member_type {
0 => parse_simple::<P>(&data[1..]),
Expand Down
7 changes: 3 additions & 4 deletions crates/torii/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ repository.workspace = true
version.workspace = true

[dependencies]
bytes = "1.0"
prost = "0.11"
prost.workspace = true
sqlx = { version = "0.6.2", features = [ "chrono", "macros", "offline", "runtime-actix-rustls", "sqlite", "uuid" ] }
tonic = "0.9"
tonic.workspace = true
warp.workspace = true

[build-dependencies]
tonic-build = "0.9"
tonic-build.workspace = true
56 changes: 55 additions & 1 deletion crates/torii/grpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
pub mod route;
use sqlx::{Pool, Sqlite};
use tonic::{Request, Response, Status};
use world::world_server::World;
use world::{MetaReply, MetaRequest};

pub mod world {
tonic::include_proto!("world");
}

#[derive(Clone, Debug)]
pub struct DojoWorld {
pool: Pool<Sqlite>,
}

impl DojoWorld {
pub fn new(pool: Pool<Sqlite>) -> Self {
Self { pool }
}
}

#[tonic::async_trait]
impl World for DojoWorld {
async fn meta(
&self,
request: Request<MetaRequest>, // Accept request of type MetaRequest
) -> Result<Response<MetaReply>, Status> {
let id = request.into_inner().id;

let (world_address, world_class_hash, executor_address, executor_class_hash): (
String,
String,
String,
String,
) = sqlx::query_as(
"SELECT world_address, world_class_hash, executor_address, executor_class_hash FROM \
worlds WHERE id = ?",
)
.bind(id)
.fetch_one(&self.pool)
.await
.map_err(|e| match e {
sqlx::Error::RowNotFound => Status::not_found("World not found"),
_ => Status::internal("Internal error"),
})?;

let reply = world::MetaReply {
world_address,
world_class_hash,
executor_address,
executor_class_hash,
};

Ok(Response::new(reply)) // Send back our formatted greeting
}
}
90 changes: 0 additions & 90 deletions crates/torii/grpc/src/route.rs

This file was deleted.

Loading