-
Notifications
You must be signed in to change notification settings - Fork 204
refactor(types): schema json sql value #3257
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
Conversation
WalkthroughOhayo sensei! This change refactors the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Ty
participant Primitive
Caller->>Ty: to_json_value()
alt Ty::Primitive variant (numeric types)
Ty->>Primitive: to_sql_value()
Primitive-->>Ty: SQL/JSON value
Ty-->>Caller: JSON value
else Other variants
Ty-->>Caller: JSON value (other logic)
end
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/dojo/types/src/schema.rs
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/dojo/types/src/schema.rs (1)
crates/dojo/types/src/primitive.rs (1)
to_sql_value
(196-219)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: fmt
🔇 Additional comments (5)
crates/dojo/types/src/schema.rs (5)
345-345
: Ohayo sensei! LGTM - Clean refactor for I64.The change to use
primitive.to_sql_value()
for I64 maintains decimal formatting and is compatible with the correspondingfrom_json_value
parsing logic.
352-352
: Ohayo sensei! U256 refactor looks good.The U256 change is compatible since
from_json_value
usesU256::from_be_hex()
which properly handles the hex format fromto_sql_value()
.
353-354
: Ohayo sensei! Felt252 and ClassHash changes look good.These changes are compatible since
Felt::from_str()
used infrom_json_value
can handle the hex format output fromto_sql_value()
.
356-356
: Ohayo sensei! EthAddress change is compatible.The EthAddress refactor looks good since
Felt::from_str()
used infrom_json_value
can handle the hex format.
345-356
: Ohayo sensei! Verify round-trip serialization compatibility.The format changes from decimal to hex for I128, U64, U128 may break round-trip serialization. Let's verify this concern with a test.
#!/bin/bash # Description: Search for existing tests that verify round-trip serialization of these primitive types # Expected: Find tests that create primitives, serialize to JSON, then deserialize back echo "=== Searching for round-trip serialization tests ===" rg -A 10 -B 5 "to_json_value.*from_json_value|from_json_value.*to_json_value" echo "=== Searching for tests involving I128, U64, U128 JSON serialization ===" rg -A 15 -B 5 "I128.*json|U64.*json|U128.*json" echo "=== Searching for test files that might contain primitive serialization tests ===" fd -e rs -x grep -l "to_json_value\|from_json_value" {} \;
crates/dojo/types/src/schema.rs
Outdated
Primitive::ContractAddress(Some(v)) => Ok(json!(format!("{:#x}", v))), | ||
Primitive::EthAddress(Some(v)) => Ok(json!(format!("{:#x}", v))), | ||
Primitive::U64(Some(v)) => Ok(json!(primitive.to_sql_value())), | ||
Primitive::U128(Some(v)) => Ok(json!(primitive.to_sql_value())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo sensei! U128 has the same hex parsing issue.
U128 follows the same problematic pattern - hex output from to_sql_value()
but decimal parsing in from_json_value
(line 440).
Apply similar fix:
Primitive::U128(v) => {
if let JsonValue::String(s) = value {
- *v = s.parse().ok();
+ if s.starts_with("0x") {
+ *v = u128::from_str_radix(&s[2..], 16).ok();
+ } else {
+ *v = s.parse().ok();
+ }
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Primitive::U128(Some(v)) => Ok(json!(primitive.to_sql_value())), | |
Primitive::U128(v) => { | |
if let JsonValue::String(s) = value { | |
- *v = s.parse().ok(); | |
+ if s.starts_with("0x") { | |
+ *v = u128::from_str_radix(&s[2..], 16).ok(); | |
+ } else { | |
+ *v = s.parse().ok(); | |
+ } | |
} | |
} |
🤖 Prompt for AI Agents
In crates/dojo/types/src/schema.rs at line 351, the Primitive::U128 variant uses
to_sql_value() which outputs hex, but from_json_value at line 440 expects
decimal, causing inconsistency. Modify the to_sql_value() call for U128 to
output a decimal string instead of hex, matching the decimal parsing logic in
from_json_value. This ensures consistent serialization and deserialization of
U128 values.
crates/dojo/types/src/schema.rs
Outdated
Primitive::ClassHash(Some(v)) => Ok(json!(format!("{:#x}", v))), | ||
Primitive::ContractAddress(Some(v)) => Ok(json!(format!("{:#x}", v))), | ||
Primitive::EthAddress(Some(v)) => Ok(json!(format!("{:#x}", v))), | ||
Primitive::U64(Some(v)) => Ok(json!(primitive.to_sql_value())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo sensei! Same hex compatibility issue with U64.
Similar to I128, U64's to_sql_value()
returns hex format but from_json_value
(line 435) uses s.parse().ok()
which doesn't handle hex strings for u64.
Consider updating the from_json_value
method:
Primitive::U64(v) => {
if let JsonValue::String(s) = value {
- *v = s.parse().ok();
+ if s.starts_with("0x") {
+ *v = u64::from_str_radix(&s[2..], 16).ok();
+ } else {
+ *v = s.parse().ok();
+ }
}
}
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In crates/dojo/types/src/schema.rs at line 350 and around line 435, the U64
primitive's to_sql_value method returns a hex string, but from_json_value uses
s.parse().ok() which cannot parse hex strings. Update from_json_value to detect
hex strings for U64 and parse them accordingly, converting the hex string to a
u64 value instead of using direct parse().
crates/dojo/types/src/schema.rs
Outdated
Primitive::I64(Some(v)) => Ok(json!(v.to_string())), | ||
Primitive::I128(Some(v)) => Ok(json!(v.to_string())), | ||
Primitive::I64(Some(v)) => Ok(json!(primitive.to_sql_value())), | ||
Primitive::I128(Some(v)) => Ok(json!(primitive.to_sql_value())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo sensei! Potential compatibility issue with I128 hex formatting.
The to_sql_value()
method formats I128 as hexadecimal (0x{:064x}
), but the corresponding from_json_value
method (line 415) uses s.parse().ok()
which doesn't handle hex strings by default for i128. This could break round-trip serialization.
Consider updating the from_json_value
method to handle hex parsing:
Primitive::I128(v) => {
if let JsonValue::String(s) = value {
- *v = s.parse().ok();
+ if s.starts_with("0x") {
+ *v = i128::from_str_radix(&s[2..], 16).ok();
+ } else {
+ *v = s.parse().ok();
+ }
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Primitive::I128(Some(v)) => Ok(json!(primitive.to_sql_value())), | |
// In your `from_json_value` implementation: | |
Primitive::I128(v) => { | |
if let JsonValue::String(s) = value { | |
if s.starts_with("0x") { | |
*v = i128::from_str_radix(&s[2..], 16).ok(); | |
} else { | |
*v = s.parse().ok(); | |
} | |
} | |
} |
🤖 Prompt for AI Agents
In crates/dojo/types/src/schema.rs around line 346, the to_sql_value() method
formats I128 values as hexadecimal strings, but the from_json_value method at
line 415 currently parses these strings as decimal, causing incompatibility. To
fix this, update from_json_value to detect and correctly parse hex-formatted
strings (starting with "0x") into i128 values, ensuring proper round-trip
serialization between to_sql_value and from_json_value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you @Larkooo. Will be more homogeneous in the DB with the same formatting everywhere. 👍
* Fix broken getting started link in README (#3235) * chore(versions): add torii 1.5.6 * Update DEVELOPMENT.md (#3236) * Update DEVELOPMENT.md with new instructions * Update scripts/rebuild_test_artifacts.sh with Rabbit suggestion Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Respond to review comments * Respond to review comments II * Respond to review comments III --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * feat: update rpc spec to 0.8 (#3179) * release(prepare): v1.6.0-alpha.0 (#3241) Prepare release: v1.6.0-alpha.0 Co-authored-by: glihm <glihm@users.noreply.github.com> * chore(versions): bump katana to 1.6.0-alpha.0 * fix(dojoup): remove new line in the source cmd (#3244) fix: fixed new line in the source cmd * chore: edited the build badge and its link (#3221) Co-authored-by: Ammar Arif <evergreenkary@gmail.com> * chore(devcontainer): update image: v1.6.0-alpha.0 (#3242) Update devcontainer image: v1.6.0-alpha.0 Co-authored-by: glihm <glihm@users.noreply.github.com> * chore: add katana 1.5.4 (#3245) * chore: add the missing backticks in the comments (#3243) Signed-off-by: one230six <723682061@qq.com> * fix(bindgen): use world namespace for imported models in TypeScript S… (#3249) * fix(bindgen): filter out Value models (#3248) * fix(bindgen): fix ts bytearray type mapping (#3247) * chore: update katana versions (#3253) add katana versions * sozo(unrealengine): handle UE5.6 and Dojo 1.5 (#3252) * fix(sozo): assert caller permission with match (#3254) * handle call_contract_syscall() result for better panic trace * avoid using 0 as caller address * remove temporarly the RPC version check. Currently, Katana uses the new RPC types, without bumping the spec version. To ensure we can still use sozo with sepolia/mainnet and Katana, Sozo will not check the RPC version for now * update test dbs --------- Co-authored-by: glihm <dev@glihm.net> * feat(sozo): create standalone bindgen command (#3246) * feat: create standalone bindgen command * cleanup unused inputs * remove dbg * add meaningful error if project is not built --------- Co-authored-by: glihm <dev@glihm.net> * feat(sozo): add MCP sever (#3256) * feat(sozo): add mvp for mcp server * refacto: restructure MCP server * evaluate changes using official rust sdk * feat(mcp): add stdio support * refacto with rmcp crate * wip * bump rmcp * add testing support * wip * refacto * cleanup * add instructions * add instructions * wip test * refacto tests * add debugging * ignore test with katana at the moment * fix typos and sozo path * refacto uri parsing * remove dbg * disable test that should be run with katana * fix test, windows fails because of new reqwest version * refactor(types): schema json sql value (#3257) * refactor(types): schema json sql value * remove excess comma * fix clippy --------- Co-authored-by: glihm <dev@glihm.net> * chore: bump cairo packages to 1.6.0-alpha.0 * fix(mcp): ensure test is using latest version * split scarb metadata ext in a different crate for dependencies * wip: controller issue * wip * wip: resolve conflicts and update deps * cleanup * lint * wip * wip tests * fix all tests * rebuild test db * fix: run linter * fix slot dep with github commit * fix clippy * fix inspect by adding missing json format * fix mcp formatting * fix stdio_test * use sozo from path --------- Signed-off-by: one230six <723682061@qq.com> Co-authored-by: Ritik <ritikverma0050@gmail.com> Co-authored-by: Daniel Kronovet <kronovet@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ammar Arif <evergreenkary@gmail.com> Co-authored-by: Tarrence van As <tarrencev@users.noreply.github.com> Co-authored-by: glihm <glihm@users.noreply.github.com> Co-authored-by: Benjamin <158306087+bengineer42@users.noreply.github.com> Co-authored-by: braveocheretovych <braveocheretovych@gmail.com> Co-authored-by: one230six <163239332+one230six@users.noreply.github.com> Co-authored-by: Brother MartianGreed <valentin@pupucecorp.com> Co-authored-by: Corentin Cailleaud <corentin.cailleaud@caillef.com> Co-authored-by: Rémy Baranx <remy.baranx@gmail.com> Co-authored-by: Larko <59736843+Larkooo@users.noreply.github.com>
…3266) * feat: add external contract registering in the world (#3195) * Use the world as external contract reference and manage upgrades with sozo * update spawn-and-move with new external contract features * update test artifacts + world_address in dojo_dev.toml * export entrypoints + fix tests + remove TODO RBA * restore test_metadata_updated_event test * fix tests * rabbit improvements * fix test * feat: add proc macros (#3212) * WIP * add macros + core-tests crates + update them from 1.6.0 * update scripts/cairo_fmt.sh + fix fmt * update CI + Scarb.toml files * fix fmt * change from 2.11.2 to 2.11.4 * fix scarb issue + fmt * one testing library for each test runner (cairo, snfoundry) + update examples * fix fmt * update comment * chore: apply patches to sync exact same commits than scarb * fix(ci): update rust-toolchain version * fix(ci): bump clippy to use nightly compatible with 1.86 * fix: clippy and fmt * update spawn-and-move to use dojo-snf-test * update world address --------- Co-authored-by: glihm <dev@glihm.net> * Scarb crate removing (#3223) * introduce scarb_interop crate * handle missing scarb * introduce metadata instead of workspace to manage dojo related paths and config * add stats back and ensure profile is propagated until build not only metadata * cleanup and add error message if SCARB is not set correctly * add features + packages to build command * update scarb build/test command * refactor packages/features * fix utils.rs + enable auth command * fix rust fmt * re-enable sozo commands * re-enable the last sozo commands + new version command * fix issue with conflicts_with_all * check if manifest_path does not exist * set run() functions as async instead of using tokio * update init command management * refactor metadata loading + dead code cleaning * add build_simple_dev() function to be used to easily build spawn-and-move for tests/benches * update tests + fmt + clippy * remove dojo/lang * remove useless sozo files * tiny change * fix CI * use scarb nightly in CI * fix manifest_path/manifest_dir issue * fix fmt * update snfoundry version + update tests accordingly + add cairo-profiler to .tool-versions --------- Co-authored-by: glihm <dev@glihm.net> * feat: add DojoStore trait to handle storage serialization (#3219) * add DojoStore management * fix rust fmt after abigen * fix ModelReader * fix fmt * set DojoStore functions as inline(always) * update test artifacts * fix fmt * remove dojo-core test from CI as all tests are now in core-tests * feat: add block number for external contract events (#3224) * add block_number to ExternalContractRegistered/ExternalContractUpgraded events * remove useless println * restore external_contracts tests + update with block_number * update test artifacts * fix clippy * rework: handle block_number * fix world.dns for external contract + update tests * update sozo events with missing events * add a self-managed external contract called from spawn-and-move * update manifest_dev.json * use dns_address * fix fmt + abigen * update test artifacts * fix fmt * update starkli path * update policies * rebuild test db * fix: restore resource order to avoid storage conflict (#3238) * Resource enum variant order should not change as it is used in the world storage * fix fmt * fix world address and test db * fix fmt --------- Co-authored-by: glihm <dev@glihm.net> * fix(lang): remove warning with unit type (#3255) fix warning with unit type for enumerations serialization generated code. * dev: merge main in dev 1.6.0 (#3263) * Fix broken getting started link in README (#3235) * chore(versions): add torii 1.5.6 * Update DEVELOPMENT.md (#3236) * Update DEVELOPMENT.md with new instructions * Update scripts/rebuild_test_artifacts.sh with Rabbit suggestion Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Respond to review comments * Respond to review comments II * Respond to review comments III --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * feat: update rpc spec to 0.8 (#3179) * release(prepare): v1.6.0-alpha.0 (#3241) Prepare release: v1.6.0-alpha.0 Co-authored-by: glihm <glihm@users.noreply.github.com> * chore(versions): bump katana to 1.6.0-alpha.0 * fix(dojoup): remove new line in the source cmd (#3244) fix: fixed new line in the source cmd * chore: edited the build badge and its link (#3221) Co-authored-by: Ammar Arif <evergreenkary@gmail.com> * chore(devcontainer): update image: v1.6.0-alpha.0 (#3242) Update devcontainer image: v1.6.0-alpha.0 Co-authored-by: glihm <glihm@users.noreply.github.com> * chore: add katana 1.5.4 (#3245) * chore: add the missing backticks in the comments (#3243) Signed-off-by: one230six <723682061@qq.com> * fix(bindgen): use world namespace for imported models in TypeScript S… (#3249) * fix(bindgen): filter out Value models (#3248) * fix(bindgen): fix ts bytearray type mapping (#3247) * chore: update katana versions (#3253) add katana versions * sozo(unrealengine): handle UE5.6 and Dojo 1.5 (#3252) * fix(sozo): assert caller permission with match (#3254) * handle call_contract_syscall() result for better panic trace * avoid using 0 as caller address * remove temporarly the RPC version check. Currently, Katana uses the new RPC types, without bumping the spec version. To ensure we can still use sozo with sepolia/mainnet and Katana, Sozo will not check the RPC version for now * update test dbs --------- Co-authored-by: glihm <dev@glihm.net> * feat(sozo): create standalone bindgen command (#3246) * feat: create standalone bindgen command * cleanup unused inputs * remove dbg * add meaningful error if project is not built --------- Co-authored-by: glihm <dev@glihm.net> * feat(sozo): add MCP sever (#3256) * feat(sozo): add mvp for mcp server * refacto: restructure MCP server * evaluate changes using official rust sdk * feat(mcp): add stdio support * refacto with rmcp crate * wip * bump rmcp * add testing support * wip * refacto * cleanup * add instructions * add instructions * wip test * refacto tests * add debugging * ignore test with katana at the moment * fix typos and sozo path * refacto uri parsing * remove dbg * disable test that should be run with katana * fix test, windows fails because of new reqwest version * refactor(types): schema json sql value (#3257) * refactor(types): schema json sql value * remove excess comma * fix clippy --------- Co-authored-by: glihm <dev@glihm.net> * chore: bump cairo packages to 1.6.0-alpha.0 * fix(mcp): ensure test is using latest version * split scarb metadata ext in a different crate for dependencies * wip: controller issue * wip * wip: resolve conflicts and update deps * cleanup * lint * wip * wip tests * fix all tests * rebuild test db * fix: run linter * fix slot dep with github commit * fix clippy * fix inspect by adding missing json format * fix mcp formatting * fix stdio_test * use sozo from path --------- Signed-off-by: one230six <723682061@qq.com> Co-authored-by: Ritik <ritikverma0050@gmail.com> Co-authored-by: Daniel Kronovet <kronovet@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ammar Arif <evergreenkary@gmail.com> Co-authored-by: Tarrence van As <tarrencev@users.noreply.github.com> Co-authored-by: glihm <glihm@users.noreply.github.com> Co-authored-by: Benjamin <158306087+bengineer42@users.noreply.github.com> Co-authored-by: braveocheretovych <braveocheretovych@gmail.com> Co-authored-by: one230six <163239332+one230six@users.noreply.github.com> Co-authored-by: Brother MartianGreed <valentin@pupucecorp.com> Co-authored-by: Corentin Cailleaud <corentin.cailleaud@caillef.com> Co-authored-by: Rémy Baranx <remy.baranx@gmail.com> Co-authored-by: Larko <59736843+Larkooo@users.noreply.github.com> * feat(core): use metaprogramming for tuple and fixed size array Introspect and DojoStore (#3260) * reuse Starkware metaprogramming stuff to manage tuples * fix fmt + clippy + artifacts * use metaprogramming to handle tuple introspect * fix fmt + clippy + artifacts * add fixed size array support * update dojo-world * update abigen + artifacts after rebase * add a sum_sizes function * update artifacts * tooling: add cairo-bench tool + bench tests (#3240) * add cairo-bench tool * add bench tests * first optimisation batch * fix fmt * add license info * update artifacts after rebase * fix cairo-bench tests * update artifacts * update artifacts * update scarb lock --------- Co-authored-by: glihm <dev@glihm.net> * fix(cairo-bench): use write and threshold + refactor fixed size array (#3267) * remove update-ref-test-list argument * add threshold parameter to cairo-bench (set to 3% by default) * max_fee_raw and fee_estimate_multiplier don't exist anymore * update sozo model commands for fixed size arrays * fix fmt + clippy * rename --update-ref to --write * fix some tests * fix fmt * fix(ci): update katana to 1.6.2 for compatible db --------- Signed-off-by: one230six <723682061@qq.com> Co-authored-by: Rémy Baranx <remy.baranx@gmail.com> Co-authored-by: Ritik <ritikverma0050@gmail.com> Co-authored-by: Daniel Kronovet <kronovet@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ammar Arif <evergreenkary@gmail.com> Co-authored-by: Tarrence van As <tarrencev@users.noreply.github.com> Co-authored-by: glihm <glihm@users.noreply.github.com> Co-authored-by: Benjamin <158306087+bengineer42@users.noreply.github.com> Co-authored-by: braveocheretovych <braveocheretovych@gmail.com> Co-authored-by: one230six <163239332+one230six@users.noreply.github.com> Co-authored-by: Brother MartianGreed <valentin@pupucecorp.com> Co-authored-by: Corentin Cailleaud <corentin.cailleaud@caillef.com> Co-authored-by: Larko <59736843+Larkooo@users.noreply.github.com>
Summary by CodeRabbit