diff --git a/Cargo.lock b/Cargo.lock index 2c5222a96f..a08d082d9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1910,7 +1910,7 @@ dependencies = [ "lazy_static", "lazycell", "log", - "prettyplease 0.2.22", + "prettyplease", "proc-macro2", "quote", "regex", @@ -2390,7 +2390,7 @@ dependencies = [ "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.1)", "camino", - "prettyplease 0.2.22", + "prettyplease", "proc-macro2", "quote", "serde_json", @@ -2408,7 +2408,7 @@ dependencies = [ "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "camino", - "prettyplease 0.2.22", + "prettyplease", "proc-macro2", "quote", "serde_json", @@ -9519,12 +9519,6 @@ dependencies = [ "synstructure 0.12.6", ] -[[package]] -name = "multimap" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" - [[package]] name = "multimap" version = "0.10.0" @@ -10662,16 +10656,6 @@ dependencies = [ "yansi 1.0.1", ] -[[package]] -name = "prettyplease" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" -dependencies = [ - "proc-macro2", - "syn 1.0.109", -] - [[package]] name = "prettyplease" version = "0.2.22" @@ -10870,62 +10854,61 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.9" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" dependencies = [ "bytes", - "prost-derive 0.11.9", + "prost-derive 0.12.6", ] [[package]] name = "prost" -version = "0.12.6" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" +checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" dependencies = [ "bytes", - "prost-derive 0.12.6", + "prost-derive 0.13.3", ] [[package]] name = "prost-build" -version = "0.11.9" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" +checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", - "heck 0.4.1", - "itertools 0.10.5", - "lazy_static", + "heck 0.5.0", + "itertools 0.12.1", "log", - "multimap 0.8.3", + "multimap", + "once_cell", "petgraph", - "prettyplease 0.1.25", - "prost 0.11.9", - "prost-types 0.11.9", + "prettyplease", + "prost 0.12.6", + "prost-types 0.12.6", "regex", - "syn 1.0.109", + "syn 2.0.77", "tempfile", - "which 4.4.2", ] [[package]] name = "prost-build" -version = "0.12.6" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" +checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15" dependencies = [ "bytes", "heck 0.5.0", - "itertools 0.12.1", + "itertools 0.13.0", "log", - "multimap 0.10.0", + "multimap", "once_cell", "petgraph", - "prettyplease 0.2.22", - "prost 0.12.6", - "prost-types 0.12.6", + "prettyplease", + "prost 0.13.3", + "prost-types 0.13.3", "regex", "syn 2.0.77", "tempfile", @@ -10933,25 +10916,25 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.9" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.1", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.77", ] [[package]] name = "prost-derive" -version = "0.12.6" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" +checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" dependencies = [ "anyhow", - "itertools 0.12.1", + "itertools 0.13.0", "proc-macro2", "quote", "syn 2.0.77", @@ -10959,20 +10942,20 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.9" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" dependencies = [ - "prost 0.11.9", + "prost 0.12.6", ] [[package]] name = "prost-types" -version = "0.12.6" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" +checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670" dependencies = [ - "prost 0.12.6", + "prost 0.13.3", ] [[package]] @@ -11446,7 +11429,7 @@ dependencies = [ "url", "wasm-bindgen", "wasm-bindgen-futures", - "wasm-streams 0.4.0", + "wasm-streams", "web-sys", "webpki-roots 0.25.4", "winreg", @@ -11497,7 +11480,7 @@ dependencies = [ "url", "wasm-bindgen", "wasm-bindgen-futures", - "wasm-streams 0.4.0", + "wasm-streams", "web-sys", "webpki-roots 0.26.6", "windows-registry", @@ -14630,22 +14613,31 @@ dependencies = [ [[package]] name = "tonic" -version = "0.9.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" +checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" dependencies = [ + "async-stream", "async-trait", + "axum 0.6.20", "base64 0.21.7", "bytes", "flate2", - "futures-core", - "futures-util", + "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", + "hyper 0.14.30", + "hyper-timeout", "percent-encoding", "pin-project", - "prost 0.11.9", + "prost 0.12.6", + "rustls-native-certs 0.7.3", + "rustls-pemfile 2.1.3", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.25.0", "tokio-stream", + "tower 0.4.13", "tower-layer", "tower-service", "tracing", @@ -14653,30 +14645,21 @@ dependencies = [ [[package]] name = "tonic" -version = "0.11.0" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" +checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" dependencies = [ - "async-stream", "async-trait", - "axum 0.6.20", - "base64 0.21.7", + "base64 0.22.1", "bytes", - "h2 0.3.26", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.30", - "hyper-timeout", + "flate2", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", "percent-encoding", "pin-project", - "prost 0.12.6", - "rustls-native-certs 0.7.3", - "rustls-pemfile 2.1.3", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.25.0", + "prost 0.13.3", "tokio-stream", - "tower 0.4.13", "tower-layer", "tower-service", "tracing", @@ -14684,26 +14667,27 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.9.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6fdaae4c2c638bb70fe42803a26fbd6fc6ac8c72f5c59f67ecc2a2dcabf4b07" +checksum = "be4ef6dd70a610078cb4e338a0f79d06bc759ff1b22d2120c2ff02ae264ba9c2" dependencies = [ - "prettyplease 0.1.25", + "prettyplease", "proc-macro2", - "prost-build 0.11.9", + "prost-build 0.12.6", "quote", - "syn 1.0.109", + "syn 2.0.77", ] [[package]] name = "tonic-build" -version = "0.11.0" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4ef6dd70a610078cb4e338a0f79d06bc759ff1b22d2120c2ff02ae264ba9c2" +checksum = "9557ce109ea773b399c9b9e5dca39294110b74f1f342cb347a80d1fce8c26a11" dependencies = [ - "prettyplease 0.2.22", + "prettyplease", "proc-macro2", - "prost-build 0.12.6", + "prost-build 0.13.3", + "prost-types 0.13.3", "quote", "syn 2.0.77", ] @@ -14743,25 +14727,26 @@ dependencies = [ [[package]] name = "tonic-web-wasm-client" -version = "0.4.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac5987e92915a51a4b05e69a0ef903a7b76f16674f7ee66534f87fd3323e2d3a" +checksum = "ef5ca6e7bdd0042c440d36b6df97c1436f1d45871ce18298091f114004b1beb4" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "byteorder", "bytes", "futures-util", - "http 0.2.12", - "http-body 0.4.6", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", "httparse", "js-sys", "pin-project", "thiserror", - "tonic 0.9.2", + "tonic 0.12.3", "tower-service", "wasm-bindgen", "wasm-bindgen-futures", - "wasm-streams 0.3.0", + "wasm-streams", "web-sys", ] @@ -14830,8 +14815,8 @@ dependencies = [ "futures-util", "num-traits 0.2.19", "parking_lot 0.12.3", - "prost 0.11.9", "prost 0.12.6", + "prost 0.13.3", "serde", "serde_json", "starknet 0.12.0", @@ -14839,7 +14824,7 @@ dependencies = [ "thiserror", "tokio", "tonic 0.11.0", - "tonic 0.9.2", + "tonic 0.12.3", "torii-grpc", "torii-relay", "url", @@ -14935,11 +14920,12 @@ dependencies = [ "dojo-world", "futures", "futures-util", + "http 0.2.12", "hyper 0.14.30", "katana-runner", "num-traits 0.2.19", - "prost 0.11.9", "prost 0.12.6", + "prost 0.13.3", "rand 0.8.5", "rayon", "scarb", @@ -14955,14 +14941,15 @@ dependencies = [ "tokio", "tokio-stream", "tonic 0.11.0", - "tonic 0.9.2", + "tonic 0.12.3", "tonic-build 0.11.0", - "tonic-build 0.9.2", + "tonic-build 0.12.3", "tonic-reflection", "tonic-web", "tonic-web-wasm-client", "torii-core", "tower 0.4.13", + "tower-http 0.4.4", "tracing", ] @@ -15801,19 +15788,6 @@ dependencies = [ "syn 2.0.77", ] -[[package]] -name = "wasm-streams" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4609d447824375f43e1ffbc051b50ad8f4b3ae8219680c94452ea05eb240ac7" -dependencies = [ - "futures-util", - "js-sys", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "wasm-streams" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 99ab18cd48..e38f987188 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,16 +215,16 @@ warp = "0.3" # gRPC prost = "0.12" -tonic = { version = "0.11", features = [ "tls", "tls-roots" ] } +tonic = { version = "0.11", features = [ "tls", "tls-roots", "gzip" ] } tonic-build = "0.11" tonic-reflection = "0.11" tonic-web = "0.11" # WASM-compatible gRPC deps -tonic-web-wasm-client = "0.4.0" -wasm-prost = { version = "0.11.9", package = "prost" } -wasm-tonic = { version = "0.9.2", default-features = false, features = [ "codegen", "gzip", "prost" ], package = "tonic" } -wasm-tonic-build = { version = "0.9.2", default-features = false, features = [ "prost" ], package = "tonic-build" } +tonic-web-wasm-client = "0.6.0" +wasm-prost = { version = "0.13", package = "prost" } +wasm-tonic = { version = "0.12", default-features = false, features = [ "codegen", "gzip", "prost" ], package = "tonic" } +wasm-tonic-build = { version = "0.12", default-features = false, features = [ "prost" ], package = "tonic-build" } alloy-primitives = { version = "0.8.3", default-features = false } alloy-sol-types = { version = "0.8.3", default-features = false } diff --git a/crates/dojo-types/src/schema.rs b/crates/dojo-types/src/schema.rs index 810a73de58..943996d7ef 100644 --- a/crates/dojo-types/src/schema.rs +++ b/crates/dojo-types/src/schema.rs @@ -327,7 +327,7 @@ pub struct EnumOption { } impl Enum { - pub fn option(&self) -> Result { + pub fn option(&self) -> Result<&EnumOption, EnumError> { let option: usize = if let Some(option) = self.option { option as usize } else { @@ -338,7 +338,7 @@ impl Enum { return Err(EnumError::OptionInvalid); } - Ok(self.options[option].name.clone()) + Ok(&self.options[option]) } pub fn set_option(&mut self, name: &str) -> Result<(), EnumError> { @@ -352,7 +352,7 @@ impl Enum { } pub fn to_sql_value(&self) -> Result { - self.option() + self.option().map(|option| option.name.clone()) } } @@ -448,7 +448,7 @@ fn format_member(m: &Member) -> String { } } else if let Ty::Enum(e) = &m.ty { match e.option() { - Ok(option) => str.push_str(&format!(" = {option}")), + Ok(option) => str.push_str(&format!(" = {}", option.name)), Err(_) => str.push_str(" = Invalid Option"), } } diff --git a/crates/torii/grpc/Cargo.toml b/crates/torii/grpc/Cargo.toml index a9d4b00102..3734b9aee6 100644 --- a/crates/torii/grpc/Cargo.toml +++ b/crates/torii/grpc/Cargo.toml @@ -45,6 +45,8 @@ wasm-tonic.workspace = true [target.'cfg(not(target_arch = "wasm32"))'.dependencies] prost.workspace = true +tower-http.workspace = true +http.workspace = true sqlx.workspace = true tokio.workspace = true tokio-stream = "0.1.14" diff --git a/crates/torii/grpc/build.rs b/crates/torii/grpc/build.rs index b12cb0891b..b3f4a92d26 100644 --- a/crates/torii/grpc/build.rs +++ b/crates/torii/grpc/build.rs @@ -16,7 +16,7 @@ fn main() -> Result<(), Box> { .build_server(false) .build_client(feature_client.is_ok()) .file_descriptor_set_path(out_dir.join("world_descriptor.bin")) - .compile(&["proto/world.proto"], &["proto"])?; + .compile_protos(&["proto/world.proto"], &["proto"])?; } else { tonic_build::configure() .build_server(feature_server.is_ok()) diff --git a/crates/torii/grpc/proto/schema.proto b/crates/torii/grpc/proto/schema.proto index 764bfca5ce..0745d7c77f 100644 --- a/crates/torii/grpc/proto/schema.proto +++ b/crates/torii/grpc/proto/schema.proto @@ -1,25 +1,6 @@ syntax = "proto3"; package types; -enum PrimitiveType { - U8 = 0; - U16 = 1; - U32 = 2; - U64 = 3; - U128 = 4; - U256 = 5; - USIZE = 6; - BOOL = 7; - FELT252 = 8; - CLASS_HASH = 9; - CONTRACT_ADDRESS = 10; - I8 = 11; - I16 = 12; - I32 = 13; - I64 = 14; - I128 = 15; -} - message EnumOption { string name = 1; Ty ty = 2; @@ -32,8 +13,24 @@ message Enum { } message Primitive { - PrimitiveType type = 1; - Value value = 2; + oneof primitive_type { + int32 i8 = 1; + int32 i16 = 2; + int32 i32 = 3; + int64 i64 = 4; + bytes i128 = 5; + uint32 u8 = 6; + uint32 u16 = 7; + uint32 u32 = 8; + uint64 u64 = 9; + bytes u128 = 10; + bytes u256 = 11; + uint32 usize = 12; + bool bool = 13; + bytes felt252 = 14; + bytes class_hash = 15; + bytes contract_address = 16; + } } message Struct { @@ -61,13 +58,3 @@ message Member { Ty ty = 2; bool key = 3; } - -message Value { - oneof value_type { - string string_value = 2; - int64 int_value = 3; - uint64 uint_value = 4; - bool bool_value = 5; - bytes byte_value = 6; - } -} diff --git a/crates/torii/grpc/proto/types.proto b/crates/torii/grpc/proto/types.proto index deb84032cd..6b2abb2ba1 100644 --- a/crates/torii/grpc/proto/types.proto +++ b/crates/torii/grpc/proto/types.proto @@ -73,6 +73,7 @@ message Query { Clause clause = 1; uint32 limit = 2; uint32 offset = 3; + bool dont_include_hashed_keys = 4; } message EventQuery { diff --git a/crates/torii/grpc/proto/world.proto b/crates/torii/grpc/proto/world.proto index 49b8ad0742..dc0fa26deb 100644 --- a/crates/torii/grpc/proto/world.proto +++ b/crates/torii/grpc/proto/world.proto @@ -25,6 +25,9 @@ service World { // Retrieve entities rpc RetrieveEntities (RetrieveEntitiesRequest) returns (RetrieveEntitiesResponse); + // Retrieve entities as a stream + rpc RetrieveEntitiesStreaming (RetrieveEntitiesRequest) returns (stream RetrieveEntitiesStreamingResponse); + // Subscribe to entity updates. rpc SubscribeEventMessages (SubscribeEntitiesRequest) returns (stream SubscribeEntityResponse); @@ -98,6 +101,11 @@ message RetrieveEntitiesResponse { uint32 total_count = 2; } +message RetrieveEntitiesStreamingResponse { + types.Entity entity = 1; + uint32 remaining_count = 2; +} + message RetrieveEventsRequest { // The events to retrieve types.EventQuery query = 1; diff --git a/crates/torii/grpc/src/client.rs b/crates/torii/grpc/src/client.rs index d94eb2fa7a..cfaff960de 100644 --- a/crates/torii/grpc/src/client.rs +++ b/crates/torii/grpc/src/client.rs @@ -4,6 +4,7 @@ use std::num::ParseIntError; use futures_util::stream::MapOk; use futures_util::{Stream, StreamExt, TryStreamExt}; use starknet::core::types::{Felt, FromStrError, StateDiff, StateUpdate}; +use tonic::codec::CompressionEncoding; #[cfg(not(target_arch = "wasm32"))] use tonic::transport::Endpoint; @@ -55,7 +56,9 @@ impl WorldClient { let channel = endpoint.connect().await.map_err(Error::Transport)?; Ok(Self { _world_address: world_address, - inner: world_client::WorldClient::with_origin(channel, endpoint.uri().clone()), + inner: world_client::WorldClient::with_origin(channel, endpoint.uri().clone()) + .accept_compressed(CompressionEncoding::Gzip) + .send_compressed(CompressionEncoding::Gzip), }) } @@ -64,7 +67,9 @@ impl WorldClient { pub async fn new(endpoint: String, _world_address: Felt) -> Result { Ok(Self { _world_address, - inner: world_client::WorldClient::new(tonic_web_wasm_client::Client::new(endpoint)), + inner: world_client::WorldClient::new(tonic_web_wasm_client::Client::new(endpoint)) + .accept_compressed(CompressionEncoding::Gzip) + .send_compressed(CompressionEncoding::Gzip), }) } diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index 07d9607310..8ec0acaf5f 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -11,11 +11,13 @@ use std::pin::Pin; use std::str; use std::str::FromStr; use std::sync::Arc; +use std::time::Duration; use dojo_types::primitive::{Primitive, PrimitiveError}; use dojo_types::schema::Ty; use dojo_world::contracts::naming::compute_selector_from_names; use futures::Stream; +use http::HeaderName; use proto::world::{ RetrieveEntitiesRequest, RetrieveEntitiesResponse, RetrieveEventsRequest, RetrieveEventsResponse, SubscribeModelsRequest, SubscribeModelsResponse, @@ -31,13 +33,16 @@ use starknet::providers::JsonRpcClient; use subscriptions::event::EventManager; use subscriptions::indexer::IndexerManager; use tokio::net::TcpListener; -use tokio::sync::mpsc::Receiver; +use tokio::sync::mpsc::{channel, Receiver}; use tokio_stream::wrappers::{ReceiverStream, TcpListenerStream}; +use tonic::codec::CompressionEncoding; use tonic::transport::Server; use tonic::{Request, Response, Status}; +use tonic_web::GrpcWebLayer; use torii_core::error::{Error, ParseError, QueryError}; use torii_core::model::{build_sql_query, map_row_to_ty}; use torii_core::sql::cache::ModelCache; +use tower_http::cors::{AllowOrigin, CorsLayer}; use self::subscriptions::entity::EntityManager; use self::subscriptions::event_message::EventMessageManager; @@ -47,8 +52,9 @@ use crate::proto::types::member_value::ValueType; use crate::proto::types::LogicalOperator; use crate::proto::world::world_server::WorldServer; use crate::proto::world::{ - SubscribeEntitiesRequest, SubscribeEntityResponse, SubscribeEventsResponse, - SubscribeIndexerRequest, SubscribeIndexerResponse, WorldMetadataRequest, WorldMetadataResponse, + RetrieveEntitiesStreamingResponse, SubscribeEntitiesRequest, SubscribeEntityResponse, + SubscribeEventsResponse, SubscribeIndexerRequest, SubscribeIndexerResponse, + WorldMetadataRequest, WorldMetadataResponse, }; use crate::proto::{self}; use crate::types::schema::SchemaError; @@ -190,6 +196,7 @@ impl DojoWorld { entity_relation_column: &str, limit: u32, offset: u32, + dont_include_hashed_keys: bool, ) -> Result<(Vec, u32), Error> { self.query_by_hashed_keys( table, @@ -198,6 +205,7 @@ impl DojoWorld { None, Some(limit), Some(offset), + dont_include_hashed_keys, ) .await } @@ -221,6 +229,7 @@ impl DojoWorld { table: &str, entity_relation_column: &str, entities: Vec<(String, String)>, + dont_include_hashed_keys: bool, ) -> Result, Error> { // Group entities by their model combinations let mut model_groups: HashMap> = HashMap::new(); @@ -290,7 +299,7 @@ impl DojoWorld { let group_entities: Result, Error> = rows .par_iter() - .map(|row| map_row_to_entity(row, &arrays_rows, (*schemas).clone())) + .map(|row| map_row_to_entity(row, &arrays_rows, &schemas, dont_include_hashed_keys)) .collect(); all_entities.extend(group_entities?); @@ -303,6 +312,7 @@ impl DojoWorld { Ok(all_entities) } + #[allow(clippy::too_many_arguments)] pub(crate) async fn query_by_hashed_keys( &self, table: &str, @@ -311,6 +321,7 @@ impl DojoWorld { hashed_keys: Option, limit: Option, offset: Option, + dont_include_hashed_keys: bool, ) -> Result<(Vec, u32), Error> { // TODO: use prepared statement for where clause let filter_ids = match hashed_keys { @@ -364,10 +375,13 @@ impl DojoWorld { let db_entities: Vec<(String, String)> = sqlx::query_as(&query).bind(limit).bind(offset).fetch_all(&self.pool).await?; - let entities = self.fetch_entities(table, entity_relation_column, db_entities).await?; + let entities = self + .fetch_entities(table, entity_relation_column, db_entities, dont_include_hashed_keys) + .await?; Ok((entities, total_count)) } + #[allow(clippy::too_many_arguments)] pub(crate) async fn query_by_keys( &self, table: &str, @@ -376,6 +390,7 @@ impl DojoWorld { keys_clause: &proto::types::KeysClause, limit: Option, offset: Option, + dont_include_hashed_keys: bool, ) -> Result<(Vec, u32), Error> { let keys_pattern = build_keys_pattern(keys_clause)?; @@ -477,7 +492,9 @@ impl DojoWorld { .fetch_all(&self.pool) .await?; - let entities = self.fetch_entities(table, entity_relation_column, db_entities).await?; + let entities = self + .fetch_entities(table, entity_relation_column, db_entities, dont_include_hashed_keys) + .await?; Ok((entities, total_count)) } @@ -508,6 +525,7 @@ impl DojoWorld { row_events.iter().map(map_row_to_event).collect() } + #[allow(clippy::too_many_arguments)] pub(crate) async fn query_by_member( &self, table: &str, @@ -516,6 +534,7 @@ impl DojoWorld { member_clause: proto::types::MemberClause, limit: Option, offset: Option, + dont_include_hashed_keys: bool, ) -> Result<(Vec, u32), Error> { let comparison_operator = ComparisonOperator::from_repr(member_clause.operator as usize) .expect("invalid comparison operator"); @@ -598,18 +617,14 @@ impl DojoWorld { arrays_rows.insert(name, rows); } - let arrays_rows = Arc::new(arrays_rows); let entities_collection: Result, Error> = db_entities .par_iter() - .map(|row| { - let schemas_clone = schemas.clone(); - let arrays_rows_clone = arrays_rows.clone(); - map_row_to_entity(row, &arrays_rows_clone, schemas_clone) - }) + .map(|row| map_row_to_entity(row, &arrays_rows, &schemas, dont_include_hashed_keys)) .collect(); Ok((entities_collection?, total_count)) } + #[allow(clippy::too_many_arguments)] pub(crate) async fn query_by_composite( &self, table: &str, @@ -618,6 +633,7 @@ impl DojoWorld { composite: proto::types::CompositeClause, limit: Option, offset: Option, + dont_include_hashed_keys: bool, ) -> Result<(Vec, u32), Error> { let (where_clause, having_clause, join_clause, bind_values) = build_composite_clause(table, model_relation_table, &composite)?; @@ -665,7 +681,9 @@ impl DojoWorld { let db_entities: Vec<(String, String)> = db_query.fetch_all(&self.pool).await?; - let entities = self.fetch_entities(table, entity_relation_column, db_entities).await?; + let entities = self + .fetch_entities(table, entity_relation_column, db_entities, dont_include_hashed_keys) + .await?; Ok((entities, total_count)) } @@ -749,6 +767,7 @@ impl DojoWorld { entity_relation_column, query.limit, query.offset, + query.dont_include_hashed_keys, ) .await? } @@ -769,6 +788,7 @@ impl DojoWorld { }, Some(query.limit), Some(query.offset), + query.dont_include_hashed_keys, ) .await? } @@ -780,6 +800,7 @@ impl DojoWorld { &keys, Some(query.limit), Some(query.offset), + query.dont_include_hashed_keys, ) .await? } @@ -791,6 +812,7 @@ impl DojoWorld { member, Some(query.limit), Some(query.offset), + query.dont_include_hashed_keys, ) .await? } @@ -802,6 +824,7 @@ impl DojoWorld { composite, Some(query.limit), Some(query.offset), + query.dont_include_hashed_keys, ) .await? } @@ -860,18 +883,27 @@ fn map_row_to_event(row: &(String, String, String)) -> Result>, - mut schemas: Vec, + schemas: &[Ty], + dont_include_hashed_keys: bool, ) -> Result { let hashed_keys = Felt::from_str(&row.get::("id")).map_err(ParseError::FromStr)?; let models = schemas - .iter_mut() + .iter() .map(|schema| { - map_row_to_ty("", &schema.name(), schema, row, arrays_rows)?; - Ok(schema.as_struct().unwrap().clone().into()) + let mut ty = schema.clone(); + map_row_to_ty("", &schema.name(), &mut ty, row, arrays_rows)?; + Ok(ty.as_struct().unwrap().clone().into()) }) .collect::, Error>>()?; - Ok(proto::types::Entity { hashed_keys: hashed_keys.to_bytes_be().to_vec(), models }) + Ok(proto::types::Entity { + hashed_keys: if !dont_include_hashed_keys { + hashed_keys.to_bytes_be().to_vec() + } else { + vec![] + }, + models, + }) } // this builds a sql safe regex pattern to match against for keys @@ -1026,6 +1058,8 @@ type SubscribeEventsResponseStream = Pin> + Send>>; type SubscribeIndexerResponseStream = Pin> + Send>>; +type RetrieveEntitiesStreamingResponseStream = + Pin> + Send>>; #[tonic::async_trait] impl proto::world::world_server::World for DojoWorld { @@ -1034,6 +1068,7 @@ impl proto::world::world_server::World for DojoWorld { type SubscribeEventMessagesStream = SubscribeEntitiesResponseStream; type SubscribeEventsStream = SubscribeEventsResponseStream; type SubscribeIndexerStream = SubscribeIndexerResponseStream; + type RetrieveEntitiesStreamingStream = RetrieveEntitiesStreamingResponseStream; async fn world_metadata( &self, @@ -1119,6 +1154,43 @@ impl proto::world::world_server::World for DojoWorld { Ok(Response::new(entities)) } + async fn retrieve_entities_streaming( + &self, + request: Request, + ) -> ServiceResult { + let query = request + .into_inner() + .query + .ok_or_else(|| Status::invalid_argument("Missing query argument"))?; + + let (tx, rx) = channel(100); + let res = self + .retrieve_entities( + ENTITIES_TABLE, + ENTITIES_MODEL_RELATION_TABLE, + ENTITIES_ENTITY_RELATION_COLUMN, + query, + ) + .await + .map_err(|e| Status::internal(e.to_string()))?; + tokio::spawn(async move { + for (i, entity) in res.entities.iter().enumerate() { + tx.send(Ok(RetrieveEntitiesStreamingResponse { + entity: Some(entity.clone()), + remaining_count: (res.total_count - (i + 1) as u32), + })) + .await + .unwrap(); + } + }); + + Ok( + Response::new( + Box::pin(ReceiverStream::new(rx)) as Self::RetrieveEntitiesStreamingStream + ), + ) + } + async fn subscribe_event_messages( &self, request: Request, @@ -1196,6 +1268,18 @@ impl proto::world::world_server::World for DojoWorld { } } +const DEFAULT_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60); +const DEFAULT_EXPOSED_HEADERS: [&str; 4] = + ["grpc-status", "grpc-message", "grpc-status-details-bin", "grpc-encoding"]; +const DEFAULT_ALLOW_HEADERS: [&str; 6] = [ + "x-grpc-web", + "content-type", + "x-user-agent", + "grpc-timeout", + "grpc-accept-encoding", + "grpc-encoding", +]; + pub async fn new( mut shutdown_rx: tokio::sync::broadcast::Receiver<()>, pool: &Pool, @@ -1215,13 +1299,36 @@ pub async fn new( .unwrap(); let world = DojoWorld::new(pool.clone(), block_rx, world_address, provider); - let server = WorldServer::new(world); + let server = WorldServer::new(world) + .accept_compressed(CompressionEncoding::Gzip) + .send_compressed(CompressionEncoding::Gzip); let server_future = Server::builder() // GrpcWeb is over http1 so we must enable it. .accept_http1(true) + .layer( + CorsLayer::new() + .allow_origin(AllowOrigin::mirror_request()) + .allow_credentials(true) + .max_age(DEFAULT_MAX_AGE) + .expose_headers( + DEFAULT_EXPOSED_HEADERS + .iter() + .cloned() + .map(HeaderName::from_static) + .collect::>(), + ) + .allow_headers( + DEFAULT_ALLOW_HEADERS + .iter() + .cloned() + .map(HeaderName::from_static) + .collect::>(), + ), + ) + .layer(GrpcWebLayer::new()) .add_service(reflection) - .add_service(tonic_web::enable(server)) + .add_service(server) .serve_with_incoming_shutdown(TcpListenerStream::new(listener), async move { shutdown_rx.recv().await.map_or((), |_| ()) }); diff --git a/crates/torii/grpc/src/server/tests/entities_test.rs b/crates/torii/grpc/src/server/tests/entities_test.rs index 98388f466a..0bc8451919 100644 --- a/crates/torii/grpc/src/server/tests/entities_test.rs +++ b/crates/torii/grpc/src/server/tests/entities_test.rs @@ -145,6 +145,7 @@ async fn test_entities_queries(sequencer: &RunnerCtx) { }, Some(1), None, + false, ) .await .unwrap() diff --git a/crates/torii/grpc/src/types/mod.rs b/crates/torii/grpc/src/types/mod.rs index b47400d954..b4162f30b6 100644 --- a/crates/torii/grpc/src/types/mod.rs +++ b/crates/torii/grpc/src/types/mod.rs @@ -40,6 +40,7 @@ pub struct Query { pub clause: Option, pub limit: u32, pub offset: u32, + pub dont_include_hashed_keys: bool, } #[derive(Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Clone)] @@ -198,7 +199,12 @@ impl TryFrom for dojo_types::WorldMetadata { impl From for proto::types::Query { fn from(value: Query) -> Self { - Self { clause: value.clause.map(|c| c.into()), limit: value.limit, offset: value.offset } + Self { + clause: value.clause.map(|c| c.into()), + limit: value.limit, + offset: value.offset, + dont_include_hashed_keys: value.dont_include_hashed_keys, + } } } @@ -335,20 +341,6 @@ impl From for member_value::ValueType { } } -impl From for proto::types::Value { - fn from(value: Value) -> Self { - let value_type = match value.value_type { - ValueType::String(val) => Some(proto::types::value::ValueType::StringValue(val)), - ValueType::Int(val) => Some(proto::types::value::ValueType::IntValue(val)), - ValueType::UInt(val) => Some(proto::types::value::ValueType::UintValue(val)), - ValueType::Bool(val) => Some(proto::types::value::ValueType::BoolValue(val)), - ValueType::Bytes(val) => Some(proto::types::value::ValueType::ByteValue(val)), - }; - - Self { value_type } - } -} - impl TryFrom for StorageEntry { type Error = FromStrError; fn try_from(value: proto::types::StorageEntry) -> Result { diff --git a/crates/torii/grpc/src/types/schema.rs b/crates/torii/grpc/src/types/schema.rs index 42e03b51de..e31f9c2271 100644 --- a/crates/torii/grpc/src/types/schema.rs +++ b/crates/torii/grpc/src/types/schema.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use crypto_bigint::{Encoding, U256}; use dojo_types::primitive::Primitive; use dojo_types::schema::{Enum, EnumOption, Member, Struct, Ty}; @@ -144,133 +142,42 @@ impl From for proto::types::Struct { } } -// FIX: weird catch-22 issue - prost Enum has `try_from` trait we can use, however, using it results -// in wasm compile err about From missing. Implementing that trait results in clippy error -// about duplicate From... Workaround is to use deprecated `from_i32` and allow deprecation -// warning. -#[allow(deprecated)] impl TryFrom for Primitive { type Error = SchemaError; fn try_from(primitive: proto::types::Primitive) -> Result { - let primitive_type = primitive.r#type; - let value_type = primitive - .value - .ok_or(SchemaError::MissingExpectedData("value".to_string()))? - .value_type - .ok_or(SchemaError::MissingExpectedData("value_type".to_string()))?; + let value = primitive + .primitive_type + .ok_or(SchemaError::MissingExpectedData("primitive_type".to_string()))?; - let primitive = match &value_type { - proto::types::value::ValueType::BoolValue(bool) => Primitive::Bool(Some(*bool)), - proto::types::value::ValueType::UintValue(int) => { - match proto::types::PrimitiveType::from_i32(primitive_type) { - Some(proto::types::PrimitiveType::I8) => Primitive::I8(Some(*int as i8)), - Some(proto::types::PrimitiveType::I16) => Primitive::I16(Some(*int as i16)), - Some(proto::types::PrimitiveType::I32) => Primitive::I32(Some(*int as i32)), - Some(proto::types::PrimitiveType::I64) => Primitive::I64(Some(*int as i64)), - Some(proto::types::PrimitiveType::I128) => Primitive::I128(Some(*int as i128)), - Some(proto::types::PrimitiveType::U8) => Primitive::U8(Some(*int as u8)), - Some(proto::types::PrimitiveType::U16) => Primitive::U16(Some(*int as u16)), - Some(proto::types::PrimitiveType::U32) => Primitive::U32(Some(*int as u32)), - Some(proto::types::PrimitiveType::U64) => Primitive::U64(Some(*int)), - Some(proto::types::PrimitiveType::U128) => Primitive::U128(Some(*int as u128)), - Some(proto::types::PrimitiveType::Usize) => Primitive::USize(Some(*int as u32)), - _ => return Err(SchemaError::UnsupportedType("UintValue".to_string())), - } - } - proto::types::value::ValueType::IntValue(int) => { - match proto::types::PrimitiveType::from_i32(primitive_type) { - Some(proto::types::PrimitiveType::I8) => Primitive::I8(Some(*int as i8)), - Some(proto::types::PrimitiveType::I16) => Primitive::I16(Some(*int as i16)), - Some(proto::types::PrimitiveType::I32) => Primitive::I32(Some(*int as i32)), - Some(proto::types::PrimitiveType::I64) => Primitive::I64(Some(*int)), - Some(proto::types::PrimitiveType::I128) => Primitive::I128(Some(*int as i128)), - Some(proto::types::PrimitiveType::U8) => Primitive::U8(Some(*int as u8)), - Some(proto::types::PrimitiveType::U16) => Primitive::U16(Some(*int as u16)), - Some(proto::types::PrimitiveType::U32) => Primitive::U32(Some(*int as u32)), - Some(proto::types::PrimitiveType::U64) => Primitive::U64(Some(*int as u64)), - Some(proto::types::PrimitiveType::U128) => Primitive::U128(Some(*int as u128)), - Some(proto::types::PrimitiveType::Usize) => Primitive::USize(Some(*int as u32)), - _ => return Err(SchemaError::UnsupportedType("IntValue".to_string())), - } + let primitive = match &value { + proto::types::primitive::PrimitiveType::Bool(bool) => Primitive::Bool(Some(*bool)), + proto::types::primitive::PrimitiveType::I8(int) => Primitive::I8(Some(*int as i8)), + proto::types::primitive::PrimitiveType::I16(int) => Primitive::I16(Some(*int as i16)), + proto::types::primitive::PrimitiveType::I32(int) => Primitive::I32(Some(*int)), + proto::types::primitive::PrimitiveType::I64(int) => Primitive::I64(Some(*int)), + proto::types::primitive::PrimitiveType::I128(bytes) => Primitive::I128(Some( + i128::from_be_bytes(bytes.as_slice().try_into().map_err(SchemaError::FromSlice)?), + )), + proto::types::primitive::PrimitiveType::U8(int) => Primitive::U8(Some(*int as u8)), + proto::types::primitive::PrimitiveType::U16(int) => Primitive::U16(Some(*int as u16)), + proto::types::primitive::PrimitiveType::U32(int) => Primitive::U32(Some(*int)), + proto::types::primitive::PrimitiveType::U64(int) => Primitive::U64(Some(*int)), + proto::types::primitive::PrimitiveType::U128(bytes) => Primitive::U128(Some( + u128::from_be_bytes(bytes.as_slice().try_into().map_err(SchemaError::FromSlice)?), + )), + proto::types::primitive::PrimitiveType::Usize(int) => Primitive::USize(Some(*int)), + proto::types::primitive::PrimitiveType::Felt252(felt) => { + Primitive::Felt252(Some(Felt::from_bytes_be_slice(felt.as_slice()))) } - proto::types::value::ValueType::ByteValue(bytes) => { - match proto::types::PrimitiveType::from_i32(primitive_type) { - Some(proto::types::PrimitiveType::I128) => { - Primitive::I128(Some(i128::from_be_bytes( - bytes.as_slice().try_into().map_err(SchemaError::FromSlice)?, - ))) - } - Some(proto::types::PrimitiveType::U128) => { - Primitive::U128(Some(u128::from_be_bytes( - bytes.as_slice().try_into().map_err(SchemaError::FromSlice)?, - ))) - } - Some(proto::types::PrimitiveType::U256) => { - Primitive::U256(Some(U256::from_be_slice(bytes.as_slice()))) - } - Some(proto::types::PrimitiveType::Felt252) => { - Primitive::Felt252(Some(Felt::from_bytes_be_slice(bytes.as_slice()))) - } - Some(proto::types::PrimitiveType::ClassHash) => { - Primitive::ClassHash(Some(Felt::from_bytes_be_slice(bytes.as_slice()))) - } - Some(proto::types::PrimitiveType::ContractAddress) => { - Primitive::ContractAddress(Some(Felt::from_bytes_be_slice( - bytes.as_slice(), - ))) - } - _ => return Err(SchemaError::UnsupportedType("ByteValue".to_string())), - } + proto::types::primitive::PrimitiveType::ClassHash(felt) => { + Primitive::ClassHash(Some(Felt::from_bytes_be_slice(felt.as_slice()))) } - proto::types::value::ValueType::StringValue(str) => { - match proto::types::PrimitiveType::from_i32(primitive_type) { - Some(proto::types::PrimitiveType::I8) => { - Primitive::I8(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::I16) => { - Primitive::I16(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::I32) => { - Primitive::I32(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::I64) => { - Primitive::I64(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::I128) => { - Primitive::I128(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::U8) => { - Primitive::U8(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::U16) => { - Primitive::U16(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::U32) => { - Primitive::U32(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::U64) => { - Primitive::U64(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::U128) => { - Primitive::U128(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::Usize) => { - Primitive::USize(Some(str.parse().map_err(SchemaError::ParseIntError)?)) - } - Some(proto::types::PrimitiveType::Felt252) => { - Primitive::Felt252(Some(Felt::from_str(str).map_err(SchemaError::FromStr)?)) - } - Some(proto::types::PrimitiveType::ClassHash) => Primitive::ClassHash(Some( - Felt::from_str(str).map_err(SchemaError::FromStr)?, - )), - Some(proto::types::PrimitiveType::ContractAddress) => { - Primitive::ContractAddress(Some( - Felt::from_str(str).map_err(SchemaError::FromStr)?, - )) - } - _ => return Err(SchemaError::UnsupportedType("StringValue".to_string())), - } + proto::types::primitive::PrimitiveType::ContractAddress(felt) => { + Primitive::ContractAddress(Some(Felt::from_bytes_be_slice(felt.as_slice()))) } + proto::types::primitive::PrimitiveType::U256(bytes) => Primitive::U256(Some( + U256::from_be_bytes(bytes.as_slice().try_into().map_err(SchemaError::FromSlice)?), + )), }; Ok(primitive) @@ -279,39 +186,60 @@ impl TryFrom for Primitive { impl From for proto::types::Primitive { fn from(primitive: Primitive) -> Self { - use proto::types::value::ValueType; - - let value_type = match primitive { - Primitive::I8(i8) => ValueType::IntValue(i8.unwrap_or_default() as i64), - Primitive::I16(i16) => ValueType::IntValue(i16.unwrap_or_default() as i64), - Primitive::I32(i32) => ValueType::IntValue(i32.unwrap_or_default() as i64), - Primitive::I64(i64) => ValueType::IntValue(i64.unwrap_or_default()), - Primitive::I128(i128) => { - ValueType::ByteValue(i128.unwrap_or_default().to_be_bytes().to_vec()) + let value = match primitive { + Primitive::Bool(bool) => { + proto::types::primitive::PrimitiveType::Bool(bool.unwrap_or_default()) + } + Primitive::I8(i8) => { + proto::types::primitive::PrimitiveType::I8(i8.unwrap_or_default() as i32) } - Primitive::U8(u8) => ValueType::UintValue(u8.unwrap_or_default() as u64), - Primitive::U16(u16) => ValueType::UintValue(u16.unwrap_or_default() as u64), - Primitive::U32(u32) => ValueType::UintValue(u32.unwrap_or_default() as u64), - Primitive::U64(u64) => ValueType::UintValue(u64.unwrap_or_default()), - Primitive::U128(u128) => { - ValueType::ByteValue(u128.unwrap_or_default().to_be_bytes().to_vec()) + Primitive::I16(i16) => { + proto::types::primitive::PrimitiveType::I16(i16.unwrap_or_default() as i32) } - Primitive::U256(u256) => { - ValueType::ByteValue(u256.unwrap_or_default().to_be_bytes().to_vec()) + Primitive::I32(i32) => { + proto::types::primitive::PrimitiveType::I32(i32.unwrap_or_default()) } - Primitive::USize(usize) => ValueType::UintValue(usize.unwrap_or_default() as u64), - Primitive::Bool(bool) => ValueType::BoolValue(bool.unwrap_or_default()), - Primitive::Felt252(felt) - | Primitive::ClassHash(felt) - | Primitive::ContractAddress(felt) => { - ValueType::ByteValue(felt.unwrap_or_default().to_bytes_be().to_vec()) + Primitive::I64(i64) => { + proto::types::primitive::PrimitiveType::I64(i64.unwrap_or_default()) } + Primitive::I128(i128) => proto::types::primitive::PrimitiveType::I128( + i128.unwrap_or_default().to_be_bytes().to_vec(), + ), + Primitive::U8(u8) => { + proto::types::primitive::PrimitiveType::U8(u8.unwrap_or_default() as u32) + } + Primitive::U16(u16) => { + proto::types::primitive::PrimitiveType::U16(u16.unwrap_or_default() as u32) + } + Primitive::U32(u32) => { + proto::types::primitive::PrimitiveType::U32(u32.unwrap_or_default()) + } + Primitive::U64(u64) => { + proto::types::primitive::PrimitiveType::U64(u64.unwrap_or_default()) + } + Primitive::U128(u128) => proto::types::primitive::PrimitiveType::U128( + u128.unwrap_or_default().to_be_bytes().to_vec(), + ), + Primitive::USize(usize) => { + proto::types::primitive::PrimitiveType::Usize(usize.unwrap_or_default()) + } + Primitive::Felt252(felt) => proto::types::primitive::PrimitiveType::Felt252( + felt.unwrap_or_default().to_bytes_be().to_vec(), + ), + Primitive::ClassHash(felt) => proto::types::primitive::PrimitiveType::ClassHash( + felt.unwrap_or_default().to_bytes_be().to_vec(), + ), + Primitive::ContractAddress(felt) => { + proto::types::primitive::PrimitiveType::ContractAddress( + felt.unwrap_or_default().to_bytes_be().to_vec(), + ) + } + Primitive::U256(u256) => proto::types::primitive::PrimitiveType::U256( + u256.unwrap_or_default().to_be_bytes().to_vec(), + ), }; - proto::types::Primitive { - value: Some(proto::types::Value { value_type: Some(value_type) }), - r#type: primitive.to_numeric() as i32, - } + proto::types::Primitive { primitive_type: Some(value) } } } diff --git a/crates/torii/server/src/proxy.rs b/crates/torii/server/src/proxy.rs index 30ee956f79..4c759e8b1a 100644 --- a/crates/torii/server/src/proxy.rs +++ b/crates/torii/server/src/proxy.rs @@ -17,7 +17,7 @@ use tower::ServiceBuilder; use tower_http::cors::{AllowOrigin, CorsLayer}; use tracing::error; -const DEFAULT_ALLOW_HEADERS: [&str; 11] = [ +const DEFAULT_ALLOW_HEADERS: [&str; 13] = [ "accept", "origin", "content-type", @@ -29,9 +29,11 @@ const DEFAULT_ALLOW_HEADERS: [&str; 11] = [ "connection", "sec-websocket-key", "sec-websocket-version", + "grpc-accept-encoding", + "grpc-encoding", ]; -const DEFAULT_EXPOSED_HEADERS: [&str; 3] = - ["grpc-status", "grpc-message", "grpc-status-details-bin"]; +const DEFAULT_EXPOSED_HEADERS: [&str; 4] = + ["grpc-status", "grpc-message", "grpc-status-details-bin", "grpc-encoding"]; const DEFAULT_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60); lazy_static::lazy_static! {