-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
254 additions
and
138 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.