Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Sep 12, 2023
1 parent 041eb78 commit 920fc6a
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 88 deletions.
1 change: 1 addition & 0 deletions 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 crates/torii/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tokio.workspace = true
tonic = "0.9"
tracing.workspace = true
url.workspace = true
parking_lot.workspace = true

[build-dependencies]
tonic-build = "0.9"
33 changes: 18 additions & 15 deletions crates/torii/grpc/proto/world.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ message GetEntitiesResponse {

message SubscribeEntitiesRequest {

// The list of entities to subscribe to.
message Entity {
string component = 1;
repeated string keys = 2;
}

repeated Entity entities = 1;
// The address of the World whose entities to subscribe to.
string world = 1;
// The list of entities to subscribe to.
repeated Entity entities = 2;
}

message SubscribeEntitiesResponse {
// // List of entities that have been updated.
// EntityUpdate entity_update = 1;

string message = 1;
// List of entities that have been updated.
EntityUpdate entity_update = 1;
}

/*
Expand All @@ -90,15 +90,18 @@ message SubscribeEntitiesResponse {
*/
message EntityUpdate {

message DiffItem {
// A mapping of storage address to its value
map<string, string> slots = 1;
}
// message DiffItem {
// // A mapping of storage address to its value
// map<string, string> slots = 1;
// }

// The block hash of the update.
string block_hash = 1;
// The block number of the update.
string block_number = 2;
// Map of component names to the diff items.
map<string, DiffItem> entity_diffs = 3;
// string block_hash = 1;
// The address of the world.
string world = 1;

map<string, string> storage_addresses = 2;

// // Map of component names to the diff items.
// map<string, DiffItem> entity_diffs = 3;
}
16 changes: 6 additions & 10 deletions crates/torii/grpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use std::pin::Pin;

use futures::Stream;
use sqlx::{Pool, Sqlite};
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
use tokio::sync::mpsc;
use tokio::sync::mpsc::Receiver;
use tonic::transport::Server;
use tonic::{Request, Response, Status, Streaming};

pub mod server;

Expand All @@ -18,15 +14,15 @@ use url::Url;
/// channel to communicate with the indexer, in order to receive the block number that the indexer
/// engine is processing at any moment. This way, we can sync with the indexer and request the state
/// update of the current block that the indexer is currently processing.
// TODO: get a receiver channel as param
pub async fn start(pool: Pool<Sqlite>) -> Result<(), Box<dyn std::error::Error>> {
let (_tx, rx) = mpsc::channel(1);

pub async fn start(
pool: Pool<Sqlite>,
block_receiver: Receiver<u64>,
) -> Result<(), Box<dyn std::error::Error>> {
let provider =
JsonRpcClient::new(HttpTransport::new(Url::parse("http://localhost:5050").unwrap()));

let addr = "[::1]:50051".parse()?;
let world = DojoWorld::new(pool, provider, rx);
let world = DojoWorld::new(pool, provider, block_receiver);

Server::builder().add_service(WorldServer::new(world)).serve(addr).await?;

Expand Down
Loading

0 comments on commit 920fc6a

Please sign in to comment.