From 0085a79e45d06accd67e141982af2afba20d02cf Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 28 Nov 2024 10:48:06 +0700 Subject: [PATCH 01/10] feat(torii-core): json value for ty for efficient json ser --- Cargo.lock | 1 + crates/dojo/types/Cargo.toml | 1 + crates/dojo/types/src/schema.rs | 194 +++++++++++++++++++++++++++++++- 3 files changed, 195 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d6f8d6883f..2adfe23f00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4875,6 +4875,7 @@ dependencies = [ "cainome 0.4.6", "crypto-bigint", "hex", + "indexmap 2.5.0", "itertools 0.12.1", "num-traits 0.2.19", "regex", diff --git a/crates/dojo/types/Cargo.toml b/crates/dojo/types/Cargo.toml index 88d725071c..58815c875d 100644 --- a/crates/dojo/types/Cargo.toml +++ b/crates/dojo/types/Cargo.toml @@ -20,3 +20,4 @@ starknet-crypto.workspace = true strum.workspace = true strum_macros.workspace = true thiserror.workspace = true +indexmap.workspace = true \ No newline at end of file diff --git a/crates/dojo/types/src/schema.rs b/crates/dojo/types/src/schema.rs index 5ebaea0d42..49fed70b7a 100644 --- a/crates/dojo/types/src/schema.rs +++ b/crates/dojo/types/src/schema.rs @@ -1,11 +1,14 @@ -use std::any::type_name; +use std::{any::type_name, str::FromStr}; use cainome::cairo_serde::{ByteArray, CairoSerde}; +use crypto_bigint::{Encoding, U256}; use itertools::Itertools; use num_traits::ToPrimitive; use serde::{Deserialize, Serialize}; use starknet::core::types::Felt; use strum_macros::AsRefStr; +use serde_json::{Number, Value as JsonValue}; +use indexmap::IndexMap; use crate::primitive::{Primitive, PrimitiveError}; @@ -308,6 +311,195 @@ impl Ty { } } } + + /// Convert a Ty to a JSON Value + pub fn to_json_value(&self) -> Result { + match self { + Ty::Primitive(primitive) => match primitive { + Primitive::Bool(Some(v)) => Ok(JsonValue::Bool(*v)), + Primitive::I8(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::I16(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::I32(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::I64(Some(v)) => Ok(JsonValue::String(v.to_string())), + Primitive::I128(Some(v)) => Ok(JsonValue::String(v.to_string())), + Primitive::U8(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::U16(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::U32(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::U64(Some(v)) => Ok(JsonValue::String(v.to_string())), + Primitive::U128(Some(v)) => Ok(JsonValue::String(v.to_string())), + Primitive::USize(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::U256(Some(v)) => { + let bytes = v.to_be_bytes(); + let high = u128::from_be_bytes(bytes[..16].try_into().unwrap()); + let low = u128::from_be_bytes(bytes[16..].try_into().unwrap()); + + let mut obj = IndexMap::new(); + obj.insert("high".to_string(), JsonValue::String(high.to_string())); + obj.insert("low".to_string(), JsonValue::String(low.to_string())); + Ok(JsonValue::Object(obj.into_iter().collect())) + } + Primitive::Felt252(Some(v)) => Ok(JsonValue::String(v.to_string())), + Primitive::ClassHash(Some(v)) => Ok(JsonValue::String(v.to_string())), + Primitive::ContractAddress(Some(v)) => Ok(JsonValue::String(v.to_string())), + _ => Err(PrimitiveError::MissingFieldElement), + }, + Ty::Struct(s) => { + let mut obj = IndexMap::new(); + for member in &s.children { + obj.insert(member.name.clone(), member.ty.to_json_value()?); + } + Ok(JsonValue::Object(obj.into_iter().collect())) + }, + Ty::Enum(e) => { + let option = e.option().map_err(|_| PrimitiveError::MissingFieldElement)?; + let mut obj = IndexMap::new(); + obj.insert(option.name.clone(), option.ty.to_json_value()?); + Ok(JsonValue::Object(obj.into_iter().collect())) + }, + Ty::Array(items) => { + let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); + Ok(JsonValue::Array(values?)) + }, + Ty::Tuple(items) => { + let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); + Ok(JsonValue::Array(values?)) + }, + Ty::ByteArray(bytes) => Ok(JsonValue::String(bytes.clone())), + } + } + + /// Parse a JSON Value into a Ty + pub fn from_json_value(&mut self, value: JsonValue) -> Result<(), PrimitiveError> { + match (self, value) { + (Ty::Primitive(primitive), value) => match primitive { + Primitive::Bool(v) => { + if let JsonValue::Bool(b) = value { + *v = Some(b); + } + }, + Primitive::I8(v) => { + if let JsonValue::Number(n) = value { + *v = n.as_i64().map(|n| n as i8); + } + }, + Primitive::I16(v) => { + if let JsonValue::Number(n) = value { + *v = n.as_i64().map(|n| n as i16); + } + }, + Primitive::I32(v) => { + if let JsonValue::Number(n) = value { + *v = n.as_i64().map(|n| n as i32); + } + }, + Primitive::I64(v) => { + if let JsonValue::String(s) = value { + *v = s.parse().ok(); + } + }, + Primitive::I128(v) => { + if let JsonValue::String(s) = value { + *v = s.parse().ok(); + } + }, + Primitive::U8(v) => { + if let JsonValue::Number(n) = value { + *v = n.as_u64().map(|n| n as u8); + } + }, + Primitive::U16(v) => { + if let JsonValue::Number(n) = value { + *v = n.as_u64().map(|n| n as u16); + } + }, + Primitive::U32(v) => { + if let JsonValue::Number(n) = value { + *v = n.as_u64().map(|n| n as u32); + } + }, + Primitive::U64(v) => { + if let JsonValue::String(s) = value { + *v = s.parse().ok(); + } + }, + Primitive::U128(v) => { + if let JsonValue::String(s) = value { + *v = s.parse().ok(); + } + }, + Primitive::USize(v) => { + if let JsonValue::Number(n) = value { + *v = n.as_u64().map(|n| n as u32); + } + }, + Primitive::U256(v) => { + if let JsonValue::Object(obj) = value { + if let (Some(JsonValue::String(high)), Some(JsonValue::String(low))) = + (obj.get("high"), obj.get("low")) { + if let (Ok(high), Ok(low)) = (high.parse::(), low.parse::()) { + let mut bytes = [0u8; 32]; + bytes[..16].copy_from_slice(&high.to_be_bytes()); + bytes[16..].copy_from_slice(&low.to_be_bytes()); + *v = Some(U256::from_be_slice(&bytes)); + } + } + } + }, + Primitive::Felt252(v) => { + if let JsonValue::String(s) = value { + *v = Felt::from_str(&s).ok(); + } + }, + Primitive::ClassHash(v) => { + if let JsonValue::String(s) = value { + *v = Felt::from_str(&s).ok(); + } + }, + Primitive::ContractAddress(v) => { + if let JsonValue::String(s) = value { + *v = Felt::from_str(&s).ok(); + } + }, + }, + (Ty::Struct(s), JsonValue::Object(obj)) => { + for member in &mut s.children { + if let Some(value) = obj.get(&member.name) { + member.ty.from_json_value(value.clone())?; + } + } + }, + (Ty::Enum(e), JsonValue::Object(obj)) => { + if let Some((name, value)) = obj.into_iter().next() { + e.set_option(&name).map_err(|_| PrimitiveError::TypeMismatch)?; + if let Some(option) = e.option { + e.options[option as usize].ty.from_json_value(value)?; + } + } + }, + (Ty::Array(items), JsonValue::Array(values)) => { + items.clear(); + let template = items.first().cloned().unwrap_or_else(|| Ty::Primitive(Primitive::Felt252(None))); + for value in values { + let mut item = template.clone(); + item.from_json_value(value)?; + items.push(item); + } + }, + (Ty::Tuple(items), JsonValue::Array(values)) => { + if items.len() != values.len() { + return Err(PrimitiveError::TypeMismatch); + } + for (item, value) in items.iter_mut().zip(values) { + item.from_json_value(value)?; + } + }, + (Ty::ByteArray(bytes), JsonValue::String(s)) => { + *bytes = s; + }, + _ => return Err(PrimitiveError::TypeMismatch), + } + Ok(()) + } } #[derive(Debug)] From 5b8c77cdebfdba253df0faf299d362473ad42a28 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 28 Nov 2024 11:04:47 +0700 Subject: [PATCH 02/10] histoircal event message json value --- crates/dojo/types/src/schema.rs | 63 +++++++++++++-------------- crates/torii/core/src/executor/mod.rs | 9 +--- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/crates/dojo/types/src/schema.rs b/crates/dojo/types/src/schema.rs index 49fed70b7a..8c51b240f3 100644 --- a/crates/dojo/types/src/schema.rs +++ b/crates/dojo/types/src/schema.rs @@ -7,7 +7,7 @@ use num_traits::ToPrimitive; use serde::{Deserialize, Serialize}; use starknet::core::types::Felt; use strum_macros::AsRefStr; -use serde_json::{Number, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; use indexmap::IndexMap; use crate::primitive::{Primitive, PrimitiveError}; @@ -316,31 +316,30 @@ impl Ty { pub fn to_json_value(&self) -> Result { match self { Ty::Primitive(primitive) => match primitive { - Primitive::Bool(Some(v)) => Ok(JsonValue::Bool(*v)), - Primitive::I8(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), - Primitive::I16(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), - Primitive::I32(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), - Primitive::I64(Some(v)) => Ok(JsonValue::String(v.to_string())), - Primitive::I128(Some(v)) => Ok(JsonValue::String(v.to_string())), - Primitive::U8(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), - Primitive::U16(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), - Primitive::U32(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), - Primitive::U64(Some(v)) => Ok(JsonValue::String(v.to_string())), - Primitive::U128(Some(v)) => Ok(JsonValue::String(v.to_string())), - Primitive::USize(Some(v)) => Ok(JsonValue::Number(Number::from(*v))), + Primitive::Bool(Some(v)) => Ok(json!(*v)), + Primitive::I8(Some(v)) => Ok(json!(*v)), + Primitive::I16(Some(v)) => Ok(json!(*v)), + Primitive::I32(Some(v)) => Ok(json!(*v)), + Primitive::I64(Some(v)) => Ok(json!(v.to_string())), + Primitive::I128(Some(v)) => Ok(json!(v.to_string())), + Primitive::U8(Some(v)) => Ok(json!(*v)), + Primitive::U16(Some(v)) => Ok(json!(*v)), + Primitive::U32(Some(v)) => Ok(json!(*v)), + Primitive::U64(Some(v)) => Ok(json!(v.to_string())), + Primitive::U128(Some(v)) => Ok(json!(v.to_string())), + Primitive::USize(Some(v)) => Ok(json!(*v)), Primitive::U256(Some(v)) => { let bytes = v.to_be_bytes(); let high = u128::from_be_bytes(bytes[..16].try_into().unwrap()); let low = u128::from_be_bytes(bytes[16..].try_into().unwrap()); - - let mut obj = IndexMap::new(); - obj.insert("high".to_string(), JsonValue::String(high.to_string())); - obj.insert("low".to_string(), JsonValue::String(low.to_string())); - Ok(JsonValue::Object(obj.into_iter().collect())) - } - Primitive::Felt252(Some(v)) => Ok(JsonValue::String(v.to_string())), - Primitive::ClassHash(Some(v)) => Ok(JsonValue::String(v.to_string())), - Primitive::ContractAddress(Some(v)) => Ok(JsonValue::String(v.to_string())), + Ok(json!({ + "high": high.to_string(), + "low": low.to_string() + })) + } + Primitive::Felt252(Some(v)) => Ok(json!(v.to_string())), + Primitive::ClassHash(Some(v)) => Ok(json!(v.to_string())), + Primitive::ContractAddress(Some(v)) => Ok(json!(v.to_string())), _ => Err(PrimitiveError::MissingFieldElement), }, Ty::Struct(s) => { @@ -348,23 +347,23 @@ impl Ty { for member in &s.children { obj.insert(member.name.clone(), member.ty.to_json_value()?); } - Ok(JsonValue::Object(obj.into_iter().collect())) + Ok(json!(obj)) }, Ty::Enum(e) => { let option = e.option().map_err(|_| PrimitiveError::MissingFieldElement)?; - let mut obj = IndexMap::new(); - obj.insert(option.name.clone(), option.ty.to_json_value()?); - Ok(JsonValue::Object(obj.into_iter().collect())) + Ok(json!({ + option.name.clone(): option.ty.to_json_value()? + })) }, Ty::Array(items) => { - let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); - Ok(JsonValue::Array(values?)) + let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); + Ok(json!(values?)) }, Ty::Tuple(items) => { - let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); - Ok(JsonValue::Array(values?)) + let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); + Ok(json!(values?)) }, - Ty::ByteArray(bytes) => Ok(JsonValue::String(bytes.clone())), + Ty::ByteArray(bytes) => Ok(json!(bytes.clone())), } } @@ -477,8 +476,8 @@ impl Ty { } }, (Ty::Array(items), JsonValue::Array(values)) => { + let template = items[0].clone(); items.clear(); - let template = items.first().cloned().unwrap_or_else(|| Ty::Primitive(Primitive::Felt252(None))); for value in values { let mut item = template.clone(); item.from_json_value(value)?; diff --git a/crates/torii/core/src/executor/mod.rs b/crates/torii/core/src/executor/mod.rs index 18c76f6d64..006d942efd 100644 --- a/crates/torii/core/src/executor/mod.rs +++ b/crates/torii/core/src/executor/mod.rs @@ -548,14 +548,7 @@ impl<'c, P: Provider + Sync + Send + 'static> Executor<'c, P> { if em_query.is_historical { event_counter += 1; - let data = em_query - .ty - .serialize()? - .iter() - .map(|felt| format!("{:#x}", felt)) - .collect::>() - .join("/"); - + let data = serde_json::to_string(&em_query.ty.to_json_value()?)?; sqlx::query( "INSERT INTO event_messages_historical (id, keys, event_id, data, \ model_id, executed_at) VALUES (?, ?, ?, ?, ?, ?) RETURNING *", From bc56e52dcf4a122b2cb58a346ea0f344f54b3f0a Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 28 Nov 2024 12:20:07 +0700 Subject: [PATCH 03/10] fmt --- crates/dojo/types/src/schema.rs | 65 +++++++++++++++++---------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/crates/dojo/types/src/schema.rs b/crates/dojo/types/src/schema.rs index 8c51b240f3..19d229abc4 100644 --- a/crates/dojo/types/src/schema.rs +++ b/crates/dojo/types/src/schema.rs @@ -1,14 +1,15 @@ -use std::{any::type_name, str::FromStr}; +use std::any::type_name; +use std::str::FromStr; use cainome::cairo_serde::{ByteArray, CairoSerde}; use crypto_bigint::{Encoding, U256}; +use indexmap::IndexMap; use itertools::Itertools; use num_traits::ToPrimitive; use serde::{Deserialize, Serialize}; +use serde_json::{json, Value as JsonValue}; use starknet::core::types::Felt; use strum_macros::AsRefStr; -use serde_json::{Value as JsonValue, json}; -use indexmap::IndexMap; use crate::primitive::{Primitive, PrimitiveError}; @@ -348,21 +349,21 @@ impl Ty { obj.insert(member.name.clone(), member.ty.to_json_value()?); } Ok(json!(obj)) - }, + } Ty::Enum(e) => { let option = e.option().map_err(|_| PrimitiveError::MissingFieldElement)?; Ok(json!({ option.name.clone(): option.ty.to_json_value()? })) - }, + } Ty::Array(items) => { let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); Ok(json!(values?)) - }, + } Ty::Tuple(items) => { let values: Result, _> = items.iter().map(|ty| ty.to_json_value()).collect(); Ok(json!(values?)) - }, + } Ty::ByteArray(bytes) => Ok(json!(bytes.clone())), } } @@ -375,67 +376,69 @@ impl Ty { if let JsonValue::Bool(b) = value { *v = Some(b); } - }, + } Primitive::I8(v) => { if let JsonValue::Number(n) = value { *v = n.as_i64().map(|n| n as i8); } - }, + } Primitive::I16(v) => { if let JsonValue::Number(n) = value { *v = n.as_i64().map(|n| n as i16); } - }, + } Primitive::I32(v) => { if let JsonValue::Number(n) = value { *v = n.as_i64().map(|n| n as i32); } - }, + } Primitive::I64(v) => { if let JsonValue::String(s) = value { *v = s.parse().ok(); } - }, + } Primitive::I128(v) => { if let JsonValue::String(s) = value { *v = s.parse().ok(); } - }, + } Primitive::U8(v) => { if let JsonValue::Number(n) = value { *v = n.as_u64().map(|n| n as u8); } - }, + } Primitive::U16(v) => { if let JsonValue::Number(n) = value { *v = n.as_u64().map(|n| n as u16); } - }, + } Primitive::U32(v) => { if let JsonValue::Number(n) = value { *v = n.as_u64().map(|n| n as u32); } - }, + } Primitive::U64(v) => { if let JsonValue::String(s) = value { *v = s.parse().ok(); } - }, + } Primitive::U128(v) => { if let JsonValue::String(s) = value { *v = s.parse().ok(); } - }, + } Primitive::USize(v) => { if let JsonValue::Number(n) = value { *v = n.as_u64().map(|n| n as u32); } - }, + } Primitive::U256(v) => { if let JsonValue::Object(obj) = value { - if let (Some(JsonValue::String(high)), Some(JsonValue::String(low))) = - (obj.get("high"), obj.get("low")) { - if let (Ok(high), Ok(low)) = (high.parse::(), low.parse::()) { + if let (Some(JsonValue::String(high)), Some(JsonValue::String(low))) = + (obj.get("high"), obj.get("low")) + { + if let (Ok(high), Ok(low)) = (high.parse::(), low.parse::()) + { let mut bytes = [0u8; 32]; bytes[..16].copy_from_slice(&high.to_be_bytes()); bytes[16..].copy_from_slice(&low.to_be_bytes()); @@ -443,22 +446,22 @@ impl Ty { } } } - }, + } Primitive::Felt252(v) => { if let JsonValue::String(s) = value { *v = Felt::from_str(&s).ok(); } - }, + } Primitive::ClassHash(v) => { if let JsonValue::String(s) = value { *v = Felt::from_str(&s).ok(); } - }, + } Primitive::ContractAddress(v) => { if let JsonValue::String(s) = value { *v = Felt::from_str(&s).ok(); } - }, + } }, (Ty::Struct(s), JsonValue::Object(obj)) => { for member in &mut s.children { @@ -466,7 +469,7 @@ impl Ty { member.ty.from_json_value(value.clone())?; } } - }, + } (Ty::Enum(e), JsonValue::Object(obj)) => { if let Some((name, value)) = obj.into_iter().next() { e.set_option(&name).map_err(|_| PrimitiveError::TypeMismatch)?; @@ -474,7 +477,7 @@ impl Ty { e.options[option as usize].ty.from_json_value(value)?; } } - }, + } (Ty::Array(items), JsonValue::Array(values)) => { let template = items[0].clone(); items.clear(); @@ -483,7 +486,7 @@ impl Ty { item.from_json_value(value)?; items.push(item); } - }, + } (Ty::Tuple(items), JsonValue::Array(values)) => { if items.len() != values.len() { return Err(PrimitiveError::TypeMismatch); @@ -491,10 +494,10 @@ impl Ty { for (item, value) in items.iter_mut().zip(values) { item.from_json_value(value)?; } - }, + } (Ty::ByteArray(bytes), JsonValue::String(s)) => { *bytes = s; - }, + } _ => return Err(PrimitiveError::TypeMismatch), } Ok(()) From 22fe5e44083377355279769ec028925e8d1bfd0b Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 28 Nov 2024 12:21:57 +0700 Subject: [PATCH 04/10] update grpc --- crates/torii/grpc/src/server/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index a0dee77df9..711874f770 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -368,7 +368,7 @@ impl DojoWorld { .model(&Felt::from_str(&model_id).map_err(ParseError::FromStr)?) .await?; let mut schema = model.schema; - schema.deserialize(&mut sql_string_to_felts(&data))?; + schema.from_json_value(serde_json::from_str(&data).unwrap())?; let entity = entities .entry(id) From fd49da8e858bfeafbe581b913ed7bec45948efc3 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 28 Nov 2024 12:28:28 +0700 Subject: [PATCH 05/10] unused import --- crates/torii/grpc/src/server/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index 711874f770..ae6a7068ae 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -42,7 +42,6 @@ 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 torii_core::sql::utils::sql_string_to_felts; use torii_core::types::{Token, TokenBalance}; use tower_http::cors::{AllowOrigin, CorsLayer}; From 30938be7f85936e1c37c3112126d1b34c6cae381 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 28 Nov 2024 12:34:34 +0700 Subject: [PATCH 06/10] no unwrap --- crates/torii/grpc/src/server/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index ae6a7068ae..a6ca4460fa 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -367,7 +367,9 @@ impl DojoWorld { .model(&Felt::from_str(&model_id).map_err(ParseError::FromStr)?) .await?; let mut schema = model.schema; - schema.from_json_value(serde_json::from_str(&data).unwrap())?; + schema.from_json_value( + serde_json::from_str(&data).map_err(|e| ParseError::FromJsonStr(e))?, + )?; let entity = entities .entry(id) From 2487b192db422e64c8d894c745098800da044e81 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 28 Nov 2024 13:32:40 +0700 Subject: [PATCH 07/10] hex for felt --- crates/dojo/types/src/schema.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/dojo/types/src/schema.rs b/crates/dojo/types/src/schema.rs index 19d229abc4..712f102225 100644 --- a/crates/dojo/types/src/schema.rs +++ b/crates/dojo/types/src/schema.rs @@ -338,9 +338,9 @@ impl Ty { "low": low.to_string() })) } - Primitive::Felt252(Some(v)) => Ok(json!(v.to_string())), - Primitive::ClassHash(Some(v)) => Ok(json!(v.to_string())), - Primitive::ContractAddress(Some(v)) => Ok(json!(v.to_string())), + Primitive::Felt252(Some(v)) => Ok(json!(format!("{:#x}", v))), + Primitive::ClassHash(Some(v)) => Ok(json!(format!("{:#x}", v))), + Primitive::ContractAddress(Some(v)) => Ok(json!(format!("{:#x}", v))), _ => Err(PrimitiveError::MissingFieldElement), }, Ty::Struct(s) => { From 8362198211e7785553fc645eced0fca020679f0d Mon Sep 17 00:00:00 2001 From: Larko <59736843+Larkooo@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:53:58 +0700 Subject: [PATCH 08/10] Update mod.rs --- crates/torii/grpc/src/server/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index a6ca4460fa..2d4d156b1e 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -368,7 +368,7 @@ impl DojoWorld { .await?; let mut schema = model.schema; schema.from_json_value( - serde_json::from_str(&data).map_err(|e| ParseError::FromJsonStr(e))?, + serde_json::from_str(&data).map_err(ParseError::FromJsonStr)?, )?; let entity = entities From c7a37084bf1877ed4aba0924507bb87bc36a89dc Mon Sep 17 00:00:00 2001 From: Larko <59736843+Larkooo@users.noreply.github.com> Date: Fri, 29 Nov 2024 01:43:00 +0700 Subject: [PATCH 09/10] Update mod.rs --- crates/torii/grpc/src/server/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index 2d4d156b1e..d4541dc00a 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -367,9 +367,8 @@ impl DojoWorld { .model(&Felt::from_str(&model_id).map_err(ParseError::FromStr)?) .await?; let mut schema = model.schema; - schema.from_json_value( - serde_json::from_str(&data).map_err(ParseError::FromJsonStr)?, - )?; + schema + .from_json_value(serde_json::from_str(&data).map_err(ParseError::FromJsonStr)?)?; let entity = entities .entry(id) From d4ecbb913603627202de46be2a8a49872349ae4f Mon Sep 17 00:00:00 2001 From: Larko <59736843+Larkooo@users.noreply.github.com> Date: Fri, 29 Nov 2024 01:47:25 +0700 Subject: [PATCH 10/10] Update mod.rs --- crates/torii/grpc/src/server/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index d4541dc00a..67084230df 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -367,8 +367,8 @@ impl DojoWorld { .model(&Felt::from_str(&model_id).map_err(ParseError::FromStr)?) .await?; let mut schema = model.schema; - schema - .from_json_value(serde_json::from_str(&data).map_err(ParseError::FromJsonStr)?)?; + schema + .from_json_value(serde_json::from_str(&data).map_err(ParseError::FromJsonStr)?)?; let entity = entities .entry(id)