From 5db3cacb2333e3fb1821762fe1bbe57008ed2bdd Mon Sep 17 00:00:00 2001 From: Nasr Date: Wed, 7 Aug 2024 17:25:06 -0400 Subject: [PATCH 1/8] feat: fix starknet & big refactor on bindings --- Cargo.lock | 38 +- Cargo.toml | 4 +- build.rs | 35 ++ dojo.hpp | 1345 ++++++++++++++------------------------------- src/c/mod.rs | 4 +- src/lib.rs | 2 +- src/types.rs | 13 + src/wasm/mod.rs | 470 ++-------------- src/wasm/types.rs | 455 +++++++++++++++ src/wasm/utils.rs | 179 +++--- 10 files changed, 1052 insertions(+), 1493 deletions(-) create mode 100644 src/wasm/types.rs diff --git a/Cargo.lock b/Cargo.lock index 970578e..556eb1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2315,7 +2315,7 @@ dependencies = [ "torii-client", "torii-grpc", "torii-relay", - "tsify", + "tsify-next", "url", "wasm-bindgen", "wasm-bindgen-futures", @@ -3916,9 +3916,9 @@ dependencies = [ [[package]] name = "gloo-utils" -version = "0.1.7" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e" +checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa" dependencies = [ "js-sys", "serde", @@ -4908,7 +4908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -7750,7 +7750,7 @@ checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ "proc-macro2", "quote", - "serde_derive_internals 0.29.1", + "serde_derive_internals", "syn 2.0.71", ] @@ -7913,17 +7913,6 @@ dependencies = [ "syn 2.0.71", ] -[[package]] -name = "serde_derive_internals" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.71", -] - [[package]] name = "serde_derive_internals" version = "0.29.1" @@ -9599,27 +9588,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] -name = "tsify" -version = "0.4.5" +name = "tsify-next" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6b26cf145f2f3b9ff84e182c448eaf05468e247f148cf3d2a7d67d78ff023a0" +checksum = "2f4a645dca4ee0800f5ab60ce166deba2db6a0315de795a2691e138a3d55d756" dependencies = [ "gloo-utils", "serde", + "serde-wasm-bindgen", "serde_json", - "tsify-macros", + "tsify-next-macros", "wasm-bindgen", ] [[package]] -name = "tsify-macros" -version = "0.4.5" +name = "tsify-next-macros" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a94b0f0954b3e59bfc2c246b4c8574390d94a4ad4ad246aaf2fb07d7dfd3b47" +checksum = "0d5c06f8a51d759bb58129e30b2631739e7e1e4579fad1f30ac09a6c88e488a6" dependencies = [ "proc-macro2", "quote", - "serde_derive_internals 0.28.0", + "serde_derive_internals", "syn 2.0.71", ] diff --git a/Cargo.toml b/Cargo.toml index 51d7c66..c4f8499 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,10 +33,9 @@ cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.3.0" } # WASM -[target.'cfg(target_arch = "wasm32")'.dependencies] +# [target.'cfg(target_arch = "wasm32")'.dependencies] serde-wasm-bindgen = "0.6.3" wasm-bindgen-futures = "0.4.39" -tsify = "0.4.5" js-sys = "0.3.66" web-sys = { version = "0.3.4", features = [ 'MessageEvent', @@ -46,6 +45,7 @@ web-sys = { version = "0.3.4", features = [ 'console', ] } crypto-bigint = "0.5.5" +tsify-next = { version = "0.5.4", features = ["js"] } [build-dependencies] cbindgen = "0.26.0" diff --git a/build.rs b/build.rs index 4d1630d..72676ec 100644 --- a/build.rs +++ b/build.rs @@ -73,6 +73,41 @@ fn main() { .expect("Unable to generate bindings") .write_to_file("dojo.hpp"); + cbindgen::Builder::new() + .with_config({ + let mut config = cbindgen::Config::default(); + + config.language = cbindgen::Language::Cython; + config.braces = cbindgen::Braces::SameLine; + config.style = cbindgen::Style::Both; + config.layout = cbindgen::LayoutConfig { ..Default::default() }; + config.enumeration = cbindgen::EnumConfig { + derive_helper_methods: true, + // prefix_with_name: true, + ..Default::default() + }; + config.export = cbindgen::ExportConfig { + mangle: cbindgen::MangleConfig { remove_underscores: true, ..Default::default() }, + ..Default::default() + }; + + // config.structure.derive_constructor = true; + // config.structure.derive_eq = true; + config.namespace = Some("dojo_bindings".to_string()); + + config.defines = HashMap::new(); + config.defines.insert( + "target_pointer_width = 32".to_string(), + "TARGET_POINTER_WIDTH_32".to_string(), + ); + + config + }) + .with_crate(crate_dir.clone()) + .generate() + .expect("Unable to generate bindings") + .write_to_file("dojo.hpp"); + // NOTE: disable for now. use c2cs to generate csharp bindings // generics not supported // csbindgen::Builder::default() diff --git a/dojo.hpp b/dojo.hpp index f056ac6..0c33d6e 100644 --- a/dojo.hpp +++ b/dojo.hpp @@ -1,110 +1,78 @@ -#include -#include -#include -#include -#include - -namespace dojo_bindings { - -enum class BlockTag { - Latest, - Pending, -}; - -enum class ComparisonOperator { - Eq, - Neq, - Gt, - Gte, - Lt, - Lte, -}; - -enum class LogicalOperator { - And, - Or, -}; - -enum class PatternMatching { - FixedLen = 0, - VariableLen = 1, -}; - -struct Account; - -struct Provider; - -struct Subscription; - -struct ToriiClient; - -struct Error { - char *message; -}; - -template -struct Result { - enum class Tag { - Ok, - Err, - }; - - struct Ok_Body { - T _0; - }; - - struct Err_Body { - Error _0; - }; - - Tag tag; - union { - Ok_Body ok; - Err_Body err; - }; - - static Result Ok(const T &_0) { - Result result; - ::new (&result.ok._0) (T)(_0); - result.tag = Tag::Ok; - return result; - } - - bool IsOk() const { - return tag == Tag::Ok; - } - - static Result Err(const Error &_0) { - Result result; - ::new (&result.err._0) (Error)(_0); - result.tag = Tag::Err; - return result; - } - - bool IsErr() const { - return tag == Tag::Err; - } -}; - -struct FieldElement { - uint8_t data[32]; -}; - -template -struct CArray { - T *data; - uintptr_t data_len; -}; - -struct Signature { - /// The `r` value of a signature - FieldElement r; - /// The `s` value of a signature - FieldElement s; -}; - -struct Primitive { - enum class Tag { +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t +cdef extern from *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum BlockTag: + Latest, + Pending, + + cdef enum ComparisonOperator: + Eq, + Neq, + Gt, + Gte, + Lt, + Lte, + + cdef enum LogicalOperator: + And, + Or, + + cdef enum PatternMatching: + FixedLen # = 0, + VariableLen # = 1, + + cdef struct Account: + pass + + cdef struct Provider: + pass + + cdef struct Subscription: + pass + + cdef struct ToriiClient: + pass + + cdef struct Error: + char *message; + + cdef enum ResultToriiClient_Tag: + OkToriiClient, + ErrToriiClient, + + cdef struct ResultToriiClient: + ResultToriiClient_Tag tag; + ToriiClient *ok; + Error err; + + cdef struct FieldElement: + uint8_t data[32]; + + cdef struct CArrayu8: + uint8_t *data; + uintptr_t data_len; + + cdef enum ResultCArrayu8_Tag: + OkCArrayu8, + ErrCArrayu8, + + cdef struct ResultCArrayu8: + ResultCArrayu8_Tag tag; + CArrayu8 ok; + Error err; + + cdef struct Signature: + # The `r` value of a signature + FieldElement r; + # The `s` value of a signature + FieldElement s; + + cdef enum Primitive_Tag: I8, I16, I32, @@ -115,915 +83,406 @@ struct Primitive { U32, U64, U128, -#if !defined(TARGET_POINTER_WIDTH_32) U256, -#endif -#if defined(TARGET_POINTER_WIDTH_32) U256, -#endif USize, Bool, Felt252, ClassHash, ContractAddress, - }; - - struct I8_Body { - int8_t _0; - }; - - struct I16_Body { - int16_t _0; - }; - - struct I32_Body { - int32_t _0; - }; - - struct I64_Body { - int64_t _0; - }; - - struct I128_Body { - uint8_t _0[16]; - }; - - struct U8_Body { - uint8_t _0; - }; - - struct U16_Body { - uint16_t _0; - }; - - struct U32_Body { - uint32_t _0; - }; - - struct U64_Body { - uint64_t _0; - }; - - struct U128_Body { - uint8_t _0[16]; - }; - -#if !defined(TARGET_POINTER_WIDTH_32) - struct U256_Body { - uint64_t _0[4]; - }; -#endif - -#if defined(TARGET_POINTER_WIDTH_32) - struct U256_Body { - uint32_t _0[8]; - }; -#endif - - struct USize_Body { - uint32_t _0; - }; - - struct Bool_Body { - bool _0; - }; - - struct Felt252_Body { - FieldElement _0; - }; - - struct ClassHash_Body { - FieldElement _0; - }; - - struct ContractAddress_Body { - FieldElement _0; - }; - - Tag tag; - union { - I8_Body i8; - I16_Body i16; - I32_Body i32; - I64_Body i64; - I128_Body i128; - U8_Body u8; - U16_Body u16; - U32_Body u32; - U64_Body u64; - U128_Body u128; -#if !defined(TARGET_POINTER_WIDTH_32) - U256_Body u256; -#endif -#if defined(TARGET_POINTER_WIDTH_32) - U256_Body u256; -#endif - USize_Body u_size; - Bool_Body bool_; - Felt252_Body felt252; - ClassHash_Body class_hash; - ContractAddress_Body contract_address; - }; - - static Primitive I8(const int8_t &_0) { - Primitive result; - ::new (&result.i8._0) (int8_t)(_0); - result.tag = Tag::I8; - return result; - } - - bool IsI8() const { - return tag == Tag::I8; - } - - static Primitive I16(const int16_t &_0) { - Primitive result; - ::new (&result.i16._0) (int16_t)(_0); - result.tag = Tag::I16; - return result; - } - - bool IsI16() const { - return tag == Tag::I16; - } - - static Primitive I32(const int32_t &_0) { - Primitive result; - ::new (&result.i32._0) (int32_t)(_0); - result.tag = Tag::I32; - return result; - } - - bool IsI32() const { - return tag == Tag::I32; - } - - static Primitive I64(const int64_t &_0) { - Primitive result; - ::new (&result.i64._0) (int64_t)(_0); - result.tag = Tag::I64; - return result; - } - - bool IsI64() const { - return tag == Tag::I64; - } - - static Primitive I128(const uint8_t (&_0)[16]) { - Primitive result; - for (int i = 0; i < 16; i++) { - ::new (&result.i128._0[i]) (uint8_t)(_0[i]); - } - result.tag = Tag::I128; - return result; - } - - bool IsI128() const { - return tag == Tag::I128; - } - - static Primitive U8(const uint8_t &_0) { - Primitive result; - ::new (&result.u8._0) (uint8_t)(_0); - result.tag = Tag::U8; - return result; - } - - bool IsU8() const { - return tag == Tag::U8; - } - - static Primitive U16(const uint16_t &_0) { - Primitive result; - ::new (&result.u16._0) (uint16_t)(_0); - result.tag = Tag::U16; - return result; - } - - bool IsU16() const { - return tag == Tag::U16; - } - - static Primitive U32(const uint32_t &_0) { - Primitive result; - ::new (&result.u32._0) (uint32_t)(_0); - result.tag = Tag::U32; - return result; - } - - bool IsU32() const { - return tag == Tag::U32; - } - - static Primitive U64(const uint64_t &_0) { - Primitive result; - ::new (&result.u64._0) (uint64_t)(_0); - result.tag = Tag::U64; - return result; - } - - bool IsU64() const { - return tag == Tag::U64; - } - - static Primitive U128(const uint8_t (&_0)[16]) { - Primitive result; - for (int i = 0; i < 16; i++) { - ::new (&result.u128._0[i]) (uint8_t)(_0[i]); - } - result.tag = Tag::U128; - return result; - } - - bool IsU128() const { - return tag == Tag::U128; - } - -#if !defined(TARGET_POINTER_WIDTH_32) - static Primitive U256(const uint64_t (&_0)[4]) { - Primitive result; - for (int i = 0; i < 4; i++) { - ::new (&result.u256._0[i]) (uint64_t)(_0[i]); - } - result.tag = Tag::U256; - return result; - } - - bool IsU256() const { - return tag == Tag::U256; - } -#endif - -#if defined(TARGET_POINTER_WIDTH_32) - static Primitive U256(const uint32_t (&_0)[8]) { - Primitive result; - for (int i = 0; i < 8; i++) { - ::new (&result.u256._0[i]) (uint32_t)(_0[i]); - } - result.tag = Tag::U256; - return result; - } - - bool IsU256() const { - return tag == Tag::U256; - } -#endif - - static Primitive USize(const uint32_t &_0) { - Primitive result; - ::new (&result.u_size._0) (uint32_t)(_0); - result.tag = Tag::USize; - return result; - } - - bool IsUSize() const { - return tag == Tag::USize; - } - - static Primitive Bool(const bool &_0) { - Primitive result; - ::new (&result.bool_._0) (bool)(_0); - result.tag = Tag::Bool; - return result; - } - - bool IsBool() const { - return tag == Tag::Bool; - } - - static Primitive Felt252(const FieldElement &_0) { - Primitive result; - ::new (&result.felt252._0) (FieldElement)(_0); - result.tag = Tag::Felt252; - return result; - } - - bool IsFelt252() const { - return tag == Tag::Felt252; - } - - static Primitive ClassHash(const FieldElement &_0) { - Primitive result; - ::new (&result.class_hash._0) (FieldElement)(_0); - result.tag = Tag::ClassHash; - return result; - } - - bool IsClassHash() const { - return tag == Tag::ClassHash; - } - - static Primitive ContractAddress(const FieldElement &_0) { - Primitive result; - ::new (&result.contract_address._0) (FieldElement)(_0); - result.tag = Tag::ContractAddress; - return result; - } - - bool IsContractAddress() const { - return tag == Tag::ContractAddress; - } -}; - -struct EnumOption { - const char *name; - Ty *ty; -}; - -struct Enum { - const char *name; - uint8_t option; - CArray options; -}; - -struct Ty { - enum class Tag { + + cdef struct Primitive: + Primitive_Tag tag; + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + uint8_t i128[16]; + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + uint8_t u128[16]; + uint64_t u256[4]; + uint32_t u256[8]; + uint32_t u_size; + bool bool_; + FieldElement felt252; + FieldElement class_hash; + FieldElement contract_address; + + cdef struct EnumOption: + const char *name; + Ty *ty; + + cdef struct CArrayEnumOption: + EnumOption *data; + uintptr_t data_len; + + cdef struct Enum: + const char *name; + uint8_t option; + CArrayEnumOption options; + + cdef struct CArrayTy: + Ty *data; + uintptr_t data_len; + + cdef enum Ty_Tag: Primitive_, Struct_, Enum_, Tuple_, Array_, ByteArray, - }; - - struct Primitive__Body { - Primitive _0; - }; - - struct Struct__Body { - Struct _0; - }; - - struct Enum__Body { - Enum _0; - }; - - struct Tuple__Body { - CArray _0; - }; - - struct Array__Body { - CArray _0; - }; - - struct ByteArray_Body { - const char *_0; - }; - - Tag tag; - union { - Primitive__Body primitive; - Struct__Body struct_; - Enum__Body enum_; - Tuple__Body tuple; - Array__Body array; - ByteArray_Body byte_array; - }; - - static Ty Primitive_(const Primitive &_0) { - Ty result; - ::new (&result.primitive._0) (Primitive)(_0); - result.tag = Tag::Primitive_; - return result; - } - - bool IsPrimitive_() const { - return tag == Tag::Primitive_; - } - - static Ty Struct_(const Struct &_0) { - Ty result; - ::new (&result.struct_._0) (Struct)(_0); - result.tag = Tag::Struct_; - return result; - } - - bool IsStruct_() const { - return tag == Tag::Struct_; - } - - static Ty Enum_(const Enum &_0) { - Ty result; - ::new (&result.enum_._0) (Enum)(_0); - result.tag = Tag::Enum_; - return result; - } - - bool IsEnum_() const { - return tag == Tag::Enum_; - } - - static Ty Tuple_(const CArray &_0) { - Ty result; - ::new (&result.tuple._0) (CArray)(_0); - result.tag = Tag::Tuple_; - return result; - } - - bool IsTuple_() const { - return tag == Tag::Tuple_; - } - - static Ty Array_(const CArray &_0) { - Ty result; - ::new (&result.array._0) (CArray)(_0); - result.tag = Tag::Array_; - return result; - } - - bool IsArray_() const { - return tag == Tag::Array_; - } - - static Ty ByteArray(const char *const &_0) { - Ty result; - ::new (&result.byte_array._0) (const char*)(_0); - result.tag = Tag::ByteArray; - return result; - } - - bool IsByteArray() const { - return tag == Tag::ByteArray; - } -}; - -struct Member { - const char *name; - Ty *ty; - bool key; -}; - -struct Struct { - const char *name; - CArray children; -}; - -struct Entity { - FieldElement hashed_keys; - CArray models; -}; - -template -struct COption { - enum class Tag { - Some, - None, - }; - - struct Some_Body { - T _0; - }; - - Tag tag; - union { - Some_Body some; - }; - - static COption Some(const T &_0) { - COption result; - ::new (&result.some._0) (T)(_0); - result.tag = Tag::Some; - return result; - } - - bool IsSome() const { - return tag == Tag::Some; - } - - static COption None() { - COption result; - result.tag = Tag::None; - return result; - } - - bool IsNone() const { - return tag == Tag::None; - } -}; - -struct KeysClause { - CArray> keys; - PatternMatching pattern_matching; - CArray models; -}; - -struct ValueType { - enum class Tag { + + cdef struct Ty: + Ty_Tag tag; + Primitive primitive; + Struct struct_; + Enum enum_; + CArrayTy tuple; + CArrayTy array; + const char *byte_array; + + cdef struct Member: + const char *name; + Ty *ty; + bool key; + + cdef struct CArrayMember: + Member *data; + uintptr_t data_len; + + cdef struct Struct: + const char *name; + CArrayMember children; + + cdef struct CArrayStruct: + Struct *data; + uintptr_t data_len; + + cdef struct Entity: + FieldElement hashed_keys; + CArrayStruct models; + + cdef struct CArrayEntity: + Entity *data; + uintptr_t data_len; + + cdef enum ResultCArrayEntity_Tag: + OkCArrayEntity, + ErrCArrayEntity, + + cdef struct ResultCArrayEntity: + ResultCArrayEntity_Tag tag; + CArrayEntity ok; + Error err; + + cdef enum COptionFieldElement_Tag: + SomeFieldElement, + NoneFieldElement, + + cdef struct COptionFieldElement: + COptionFieldElement_Tag tag; + FieldElement some; + + cdef struct CArrayCOptionFieldElement: + COptionFieldElement *data; + uintptr_t data_len; + + cdef struct CArrayc_char: + const char **data; + uintptr_t data_len; + + cdef struct KeysClause: + CArrayCOptionFieldElement keys; + PatternMatching pattern_matching; + CArrayc_char models; + + cdef enum ValueType_Tag: String, Int, UInt, VBool, Bytes, - }; - - struct String_Body { - const char *_0; - }; - - struct Int_Body { - int64_t _0; - }; - - struct UInt_Body { - uint64_t _0; - }; - - struct VBool_Body { - bool _0; - }; - - struct Bytes_Body { - CArray _0; - }; - - Tag tag; - union { - String_Body string; - Int_Body int_; - UInt_Body u_int; - VBool_Body v_bool; - Bytes_Body bytes; - }; - - static ValueType String(const char *const &_0) { - ValueType result; - ::new (&result.string._0) (const char*)(_0); - result.tag = Tag::String; - return result; - } - - bool IsString() const { - return tag == Tag::String; - } - - static ValueType Int(const int64_t &_0) { - ValueType result; - ::new (&result.int_._0) (int64_t)(_0); - result.tag = Tag::Int; - return result; - } - - bool IsInt() const { - return tag == Tag::Int; - } - - static ValueType UInt(const uint64_t &_0) { - ValueType result; - ::new (&result.u_int._0) (uint64_t)(_0); - result.tag = Tag::UInt; - return result; - } - - bool IsUInt() const { - return tag == Tag::UInt; - } - - static ValueType VBool(const bool &_0) { - ValueType result; - ::new (&result.v_bool._0) (bool)(_0); - result.tag = Tag::VBool; - return result; - } - - bool IsVBool() const { - return tag == Tag::VBool; - } - - static ValueType Bytes(const CArray &_0) { - ValueType result; - ::new (&result.bytes._0) (CArray)(_0); - result.tag = Tag::Bytes; - return result; - } - - bool IsBytes() const { - return tag == Tag::Bytes; - } -}; - -struct Value { - Primitive primitive_type; - ValueType value_type; -}; - -struct MemberClause { - const char *model; - const char *member; - ComparisonOperator operator_; - Value value; -}; - -struct CompositeClause { - LogicalOperator operator_; - CArray clauses; -}; - -struct Clause { - enum class Tag { + + cdef struct ValueType: + ValueType_Tag tag; + const char *string; + int64_t int_; + uint64_t u_int; + bool v_bool; + CArrayu8 bytes; + + cdef struct Value: + Primitive primitive_type; + ValueType value_type; + + cdef struct MemberClause: + const char *model; + const char *member; + ComparisonOperator operator_; + Value value; + + cdef struct CArrayClause: + Clause *data; + uintptr_t data_len; + + cdef struct CompositeClause: + LogicalOperator operator_; + CArrayClause clauses; + + cdef enum Clause_Tag: Keys, CMember, Composite, - }; - - struct Keys_Body { - KeysClause _0; - }; - - struct CMember_Body { - MemberClause _0; - }; - - struct Composite_Body { - CompositeClause _0; - }; - - Tag tag; - union { - Keys_Body keys; - CMember_Body c_member; - Composite_Body composite; - }; - - static Clause Keys(const KeysClause &_0) { - Clause result; - ::new (&result.keys._0) (KeysClause)(_0); - result.tag = Tag::Keys; - return result; - } - - bool IsKeys() const { - return tag == Tag::Keys; - } - - static Clause CMember(const MemberClause &_0) { - Clause result; - ::new (&result.c_member._0) (MemberClause)(_0); - result.tag = Tag::CMember; - return result; - } - - bool IsCMember() const { - return tag == Tag::CMember; - } - - static Clause Composite(const CompositeClause &_0) { - Clause result; - ::new (&result.composite._0) (CompositeClause)(_0); - result.tag = Tag::Composite; - return result; - } - - bool IsComposite() const { - return tag == Tag::Composite; - } -}; - -struct Query { - uint32_t limit; - uint32_t offset; - COption clause; -}; - -struct ModelMetadata { - Ty schema; - const char *namespace_; - const char *name; - uint32_t packed_size; - uint32_t unpacked_size; - FieldElement class_hash; - FieldElement contract_address; - CArray layout; -}; - -template -struct CHashItem { - K key; - V value; -}; - -struct WorldMetadata { - FieldElement world_address; - FieldElement world_class_hash; - CArray> models; -}; - -struct EntityKeysClause { - enum class Tag { + + cdef struct Clause: + Clause_Tag tag; + KeysClause keys; + MemberClause c_member; + CompositeClause composite; + + cdef enum COptionClause_Tag: + SomeClause, + NoneClause, + + cdef struct COptionClause: + COptionClause_Tag tag; + Clause some; + + cdef struct Query: + uint32_t limit; + uint32_t offset; + COptionClause clause; + + cdef struct CArrayFieldElement: + FieldElement *data; + uintptr_t data_len; + + cdef struct ModelMetadata: + Ty schema; + const char *namespace_; + const char *name; + uint32_t packed_size; + uint32_t unpacked_size; + FieldElement class_hash; + FieldElement contract_address; + CArrayFieldElement layout; + + cdef struct CHashItemFieldElementModelMetadata: + FieldElement key; + ModelMetadata value; + + cdef struct CArrayCHashItemFieldElementModelMetadata: + CHashItemFieldElementModelMetadata *data; + uintptr_t data_len; + + cdef struct WorldMetadata: + FieldElement world_address; + FieldElement world_class_hash; + CArrayCHashItemFieldElementModelMetadata models; + + cdef enum ResultSubscription_Tag: + OkSubscription, + ErrSubscription, + + cdef struct ResultSubscription: + ResultSubscription_Tag tag; + Subscription *ok; + Error err; + + cdef enum EntityKeysClause_Tag: HashedKeys, EntityKeys, - }; - - struct HashedKeys_Body { - CArray _0; - }; - - struct EntityKeys_Body { - KeysClause _0; - }; - - Tag tag; - union { - HashedKeys_Body hashed_keys; - EntityKeys_Body entity_keys; - }; - - static EntityKeysClause HashedKeys(const CArray &_0) { - EntityKeysClause result; - ::new (&result.hashed_keys._0) (CArray)(_0); - result.tag = Tag::HashedKeys; - return result; - } - - bool IsHashedKeys() const { - return tag == Tag::HashedKeys; - } - - static EntityKeysClause EntityKeys(const KeysClause &_0) { - EntityKeysClause result; - ::new (&result.entity_keys._0) (KeysClause)(_0); - result.tag = Tag::EntityKeys; - return result; - } - - bool IsEntityKeys() const { - return tag == Tag::EntityKeys; - } -}; - -struct Call { - FieldElement to; - const char *selector; - CArray calldata; -}; - -/// Block hash, number or tag -struct BlockId { - enum class Tag { + + cdef struct EntityKeysClause: + EntityKeysClause_Tag tag; + CArrayFieldElement hashed_keys; + KeysClause entity_keys; + + cdef enum Resultbool_Tag: + Okbool, + Errbool, + + cdef struct Resultbool: + Resultbool_Tag tag; + bool ok; + Error err; + + cdef enum ResultCArrayFieldElement_Tag: + OkCArrayFieldElement, + ErrCArrayFieldElement, + + cdef struct ResultCArrayFieldElement: + ResultCArrayFieldElement_Tag tag; + CArrayFieldElement ok; + Error err; + + cdef enum Resultc_char_Tag: + Okc_char, + Errc_char, + + cdef struct Resultc_char: + Resultc_char_Tag tag; + const char *ok; + Error err; + + cdef enum ResultFieldElement_Tag: + OkFieldElement, + ErrFieldElement, + + cdef struct ResultFieldElement: + ResultFieldElement_Tag tag; + FieldElement ok; + Error err; + + cdef enum ResultSignature_Tag: + OkSignature, + ErrSignature, + + cdef struct ResultSignature: + ResultSignature_Tag tag; + Signature ok; + Error err; + + cdef enum ResultProvider_Tag: + OkProvider, + ErrProvider, + + cdef struct ResultProvider: + ResultProvider_Tag tag; + Provider *ok; + Error err; + + cdef enum ResultAccount_Tag: + OkAccount, + ErrAccount, + + cdef struct ResultAccount: + ResultAccount_Tag tag; + Account *ok; + Error err; + + cdef struct Call: + FieldElement to; + const char *selector; + CArrayFieldElement calldata; + + # Block hash, number or tag + cdef enum BlockId_Tag: Hash, Number, BlockTag_, - }; - - struct Hash_Body { - FieldElement _0; - }; - - struct Number_Body { - uint64_t _0; - }; - - struct BlockTag__Body { - BlockTag _0; - }; - - Tag tag; - union { - Hash_Body hash; - Number_Body number; - BlockTag__Body block_tag; - }; - - static BlockId Hash(const FieldElement &_0) { - BlockId result; - ::new (&result.hash._0) (FieldElement)(_0); - result.tag = Tag::Hash; - return result; - } - - bool IsHash() const { - return tag == Tag::Hash; - } - - static BlockId Number(const uint64_t &_0) { - BlockId result; - ::new (&result.number._0) (uint64_t)(_0); - result.tag = Tag::Number; - return result; - } - bool IsNumber() const { - return tag == Tag::Number; - } + cdef struct BlockId: + BlockId_Tag tag; + FieldElement hash; + uint64_t number; + BlockTag block_tag; - static BlockId BlockTag_(const BlockTag &_0) { - BlockId result; - ::new (&result.block_tag._0) (BlockTag)(_0); - result.tag = Tag::BlockTag_; - return result; - } + ResultToriiClient client_new(const char *torii_url, + const char *rpc_url, + const char *libp2p_relay_url, + FieldElement world); - bool IsBlockTag_() const { - return tag == Tag::BlockTag_; - } -}; + void client_set_logger(ToriiClient *client, void (*logger)(const char*)); -extern "C" { + ResultCArrayu8 client_publish_message(ToriiClient *client, + const char *message, + Signature signature); -Result client_new(const char *torii_url, - const char *rpc_url, - const char *libp2p_relay_url, - FieldElement world); + ResultCArrayEntity client_entities(ToriiClient *client, const Query *query); -void client_set_logger(ToriiClient *client, void (*logger)(const char*)); + ResultCArrayEntity client_event_messages(ToriiClient *client, const Query *query); -Result> client_publish_message(ToriiClient *client, - const char *message, - Signature signature); + WorldMetadata client_metadata(ToriiClient *client); -Result> client_entities(ToriiClient *client, const Query *query); + ResultSubscription client_on_entity_state_update(ToriiClient *client, + const EntityKeysClause *clauses, + uintptr_t clauses_len, + void (*callback)(FieldElement, CArrayStruct)); -Result> client_event_messages(ToriiClient *client, const Query *query); - -WorldMetadata client_metadata(ToriiClient *client); - -Result client_on_entity_state_update(ToriiClient *client, - const EntityKeysClause *clauses, - uintptr_t clauses_len, - void (*callback)(FieldElement, CArray)); - -Result client_update_entity_subscription(ToriiClient *client, + Resultbool client_update_entity_subscription(ToriiClient *client, Subscription *subscription, const EntityKeysClause *clauses, uintptr_t clauses_len); -Result client_on_event_message_update(ToriiClient *client, - const EntityKeysClause *clauses, - uintptr_t clauses_len, - void (*callback)(FieldElement, CArray)); + ResultSubscription client_on_event_message_update(ToriiClient *client, + const EntityKeysClause *clauses, + uintptr_t clauses_len, + void (*callback)(FieldElement, CArrayStruct)); -Result client_update_event_message_subscription(ToriiClient *client, + Resultbool client_update_event_message_subscription(ToriiClient *client, Subscription *subscription, const EntityKeysClause *clauses, uintptr_t clauses_len); -Result> bytearray_serialize(const char *str); + ResultCArrayFieldElement bytearray_serialize(const char *str); -Result bytearray_deserialize(const FieldElement *felts, uintptr_t felts_len); + Resultc_char bytearray_deserialize(const FieldElement *felts, uintptr_t felts_len); -FieldElement poseidon_hash(const FieldElement *felts, uintptr_t felts_len); + FieldElement poseidon_hash(const FieldElement *felts, uintptr_t felts_len); -Result typed_data_encode(const char *typed_data, FieldElement address); + ResultFieldElement typed_data_encode(const char *typed_data, FieldElement address); -FieldElement signing_key_new(); + FieldElement signing_key_new(); -Result signing_key_sign(FieldElement private_key, FieldElement hash); + ResultSignature signing_key_sign(FieldElement private_key, FieldElement hash); -FieldElement verifying_key_new(FieldElement signing_key); + FieldElement verifying_key_new(FieldElement signing_key); -Result verifying_key_verify(FieldElement verifying_key, + Resultbool verifying_key_verify(FieldElement verifying_key, FieldElement hash, Signature signature); -Result provider_new(const char *rpc_url); + ResultProvider provider_new(const char *rpc_url); -Result account_new(Provider *rpc, FieldElement private_key, const char *address); + ResultAccount account_new(Provider *rpc, FieldElement private_key, const char *address); -Result> starknet_call(Provider *provider, Call call, BlockId block_id); + ResultCArrayFieldElement starknet_call(Provider *provider, Call call, BlockId block_id); -Result account_deploy_burner(Provider *provider, - Account *master_account, - FieldElement signing_key); + ResultAccount account_deploy_burner(Provider *provider, + Account *master_account, + FieldElement signing_key); -FieldElement account_address(Account *account); + FieldElement account_address(Account *account); -FieldElement account_chain_id(Account *account); + FieldElement account_chain_id(Account *account); -void account_set_block_id(Account *account, BlockId block_id); + void account_set_block_id(Account *account, BlockId block_id); -Result account_execute_raw(Account *account, + ResultFieldElement account_execute_raw(Account *account, const Call *calldata, uintptr_t calldata_len); -Result wait_for_transaction(Provider *rpc, FieldElement txn_hash); - -FieldElement hash_get_contract_address(FieldElement class_hash, - FieldElement salt, - const FieldElement *constructor_calldata, - uintptr_t constructor_calldata_len, - FieldElement deployer_address); - -void subscription_cancel(Subscription *subscription); + Resultbool wait_for_transaction(Provider *rpc, FieldElement txn_hash); -void client_free(ToriiClient *t); + FieldElement hash_get_contract_address(FieldElement class_hash, + FieldElement salt, + const FieldElement *constructor_calldata, + uintptr_t constructor_calldata_len, + FieldElement deployer_address); -void provider_free(Provider *rpc); + void subscription_cancel(Subscription *subscription); -void model_free(Struct *model); + void client_free(ToriiClient *t); -void account_free(Account *account); + void provider_free(Provider *rpc); -void ty_free(Ty *ty); + void model_free(Struct *model); -void entity_free(Entity *entity); + void account_free(Account *account); -void error_free(Error *error); + void ty_free(Ty *ty); -void world_metadata_free(WorldMetadata *metadata); + void entity_free(Entity *entity); -void carray_free(void *data, uintptr_t data_len); + void error_free(Error *error); -void string_free(char *string); + void world_metadata_free(WorldMetadata *metadata); -} // extern "C" + void carray_free(void *data, uintptr_t data_len); -} // namespace dojo_bindings + void string_free(char *string); diff --git a/src/c/mod.rs b/src/c/mod.rs index 9ca70b8..47ce3b8 100644 --- a/src/c/mod.rs +++ b/src/c/mod.rs @@ -482,7 +482,7 @@ pub unsafe extern "C" fn account_deploy_burner( ); // deploy the burner - let exec = (*master_account).0.execute_v3(vec![starknet::accounts::Call { + let exec = (*master_account).0.execute_v1(vec![starknet::accounts::Call { to: constants::UDC_ADDRESS, calldata: vec![ constants::KATANA_ACCOUNT_CLASS_HASH, // class_hash @@ -539,7 +539,7 @@ pub unsafe extern "C" fn account_execute_raw( let calldata = unsafe { std::slice::from_raw_parts(calldata, calldata_len).to_vec() }; let calldata = calldata.into_iter().map(|c| (&c).into()).collect::>(); - let call = (*account).0.execute_v3(calldata); + let call = (*account).0.execute_v1(calldata); match tokio::runtime::Runtime::new() { Ok(runtime) => match runtime.block_on(call.send()) { diff --git a/src/lib.rs b/src/lib.rs index fd7abea..61ff93e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,6 @@ mod utils; #[cfg(not(target_arch = "wasm32"))] mod c; -#[cfg(target_arch = "wasm32")] +// #[cfg(target_arch = "wasm32")] /// cbindgen:ignore mod wasm; diff --git a/src/types.rs b/src/types.rs index 5c7868a..4bfd3d5 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,3 +1,4 @@ +use std::ffi::c_char; use std::sync::Arc; use starknet::accounts::SingleOwnerAccount; @@ -5,8 +6,20 @@ use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use starknet::signers::LocalWallet; use stream_cancel::Trigger; +use torii_client::client::Client; use wasm_bindgen::prelude::*; +#[wasm_bindgen] +pub struct ToriiClient { + #[wasm_bindgen(skip)] + pub inner: Client, + #[cfg(not(target_arch = "wasm32"))] + #[wasm_bindgen(skip)] + pub runtime: tokio::runtime::Runtime, + #[cfg(not(target_arch = "wasm32"))] + #[wasm_bindgen(skip)] + pub logger: Option, +} #[wasm_bindgen] pub struct Provider(pub(crate) Arc>); #[wasm_bindgen] diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index b6def64..6121a21 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -1,5 +1,6 @@ mod utils; +use std::collections::HashMap; use std::str::FromStr; use std::sync::Arc; @@ -11,7 +12,6 @@ use serde::{Deserialize, Serialize}; use starknet::accounts::{ Account as _, ConnectedAccount as _, ExecutionEncoding, SingleOwnerAccount, }; -use starknet::core::crypto::Signature; use starknet::core::types::{Felt, FunctionCall}; use starknet::core::utils::{get_contract_address, get_selector_from_name}; use starknet::providers::jsonrpc::HttpTransport; @@ -21,408 +21,16 @@ use starknet_crypto::poseidon_hash_many; use stream_cancel::{StreamExt as _, Tripwire}; use torii_relay::typed_data::TypedData; use torii_relay::types::Message; -use tsify::Tsify; +use tsify_next::Tsify; use wasm_bindgen::prelude::*; use crate::constants; -use crate::types::{Account, Provider, Subscription}; +use crate::types::{Account, Provider, Subscription, ToriiClient}; use crate::utils::watch_tx; -use crate::wasm::utils::parse_entities_as_json_str; - -#[derive(Tsify, Serialize, Deserialize)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct ClientConfig { - #[serde(rename = "rpcUrl")] - pub rpc_url: String, - #[serde(rename = "toriiUrl")] - pub torii_url: String, - #[serde(rename = "relayUrl")] - pub relay_url: String, - #[serde(rename = "worldAddress")] - pub world_address: String, -} - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(js_namespace = console)] - fn log(s: &str); - - #[wasm_bindgen(js_namespace = console)] - fn error(s: &str); -} - -#[wasm_bindgen] -pub struct Client { - inner: torii_client::client::Client, -} - -#[derive(Tsify, Serialize, Deserialize)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct JsSignature { - pub r: String, - pub s: String, -} - -impl From<&Signature> for JsSignature { - fn from(value: &Signature) -> Self { - Self { r: format!("{:#x}", value.r), s: format!("{:#x}", value.s) } - } -} - -impl From<&JsSignature> for Signature { - fn from(value: &JsSignature) -> Self { - Self { - r: Felt::from_str(value.r.as_str()).unwrap(), - s: Felt::from_str(value.s.as_str()).unwrap(), - } - } -} -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct Calls(Vec); - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct Call { - pub to: String, - pub selector: String, - pub calldata: Vec, -} - -impl From<&Call> for starknet::accounts::Call { - fn from(value: &Call) -> Self { - Self { - to: Felt::from_str(value.to.as_str()).unwrap(), - selector: get_selector_from_name(value.selector.as_str()).unwrap(), - calldata: value.calldata.iter().map(|c| Felt::from_str(c.as_str()).unwrap()).collect(), - } - } -} - -impl From<&Call> for FunctionCall { - fn from(value: &Call) -> Self { - Self { - contract_address: Felt::from_str(value.to.as_str()).unwrap(), - entry_point_selector: get_selector_from_name(value.selector.as_str()).unwrap(), - calldata: value.calldata.iter().map(|c| Felt::from_str(c.as_str()).unwrap()).collect(), - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum BlockTag { - Latest, - Pending, -} -impl From<&BlockTag> for starknet::core::types::BlockTag { - fn from(value: &BlockTag) -> Self { - match value { - BlockTag::Latest => starknet::core::types::BlockTag::Latest, - BlockTag::Pending => starknet::core::types::BlockTag::Pending, - } - } -} +mod types; -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum BlockId { - Hash(String), - Number(u64), - BlockTag(BlockTag), -} - -impl From<&BlockId> for starknet::core::types::BlockId { - fn from(value: &BlockId) -> Self { - match value { - BlockId::Hash(hash) => { - starknet::core::types::BlockId::Hash(Felt::from_str(hash.as_str()).unwrap()) - } - BlockId::Number(number) => starknet::core::types::BlockId::Number(*number), - BlockId::BlockTag(tag) => starknet::core::types::BlockId::Tag(tag.into()), - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct Query { - pub limit: u32, - pub offset: u32, - pub clause: Option, -} - -impl From<&Query> for torii_grpc::types::Query { - fn from(value: &Query) -> Self { - Self { - limit: value.limit, - offset: value.offset, - clause: value.clause.as_ref().map(|c| c.into()), - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum Clause { - Keys(KeysClause), - Member(MemberClause), - Composite(CompositeClause), -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct KeysClauses(pub Vec); - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct ModelKeysClauses(pub Vec); - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct ModelKeysClause { - pub model: String, - pub keys: Vec, -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum PatternMatching { - FixedLen = 0, - VariableLen = 1, -} - -impl From<&PatternMatching> for torii_grpc::types::PatternMatching { - fn from(value: &PatternMatching) -> Self { - match value { - PatternMatching::FixedLen => Self::FixedLen, - PatternMatching::VariableLen => Self::VariableLen, - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum EntityKeysClause { - HashedKeys(Vec), - Keys(KeysClause), -} - -impl From<&EntityKeysClause> for torii_grpc::types::EntityKeysClause { - fn from(value: &EntityKeysClause) -> Self { - match value { - EntityKeysClause::HashedKeys(keys) => { - Self::HashedKeys(keys.iter().map(|k| Felt::from_str(k.as_str()).unwrap()).collect()) - } - EntityKeysClause::Keys(keys) => Self::Keys(keys.into()), - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct KeysClause { - pub keys: Vec>, - pub pattern_matching: PatternMatching, - pub models: Vec, -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct MemberClause { - pub model: String, - pub member: String, - pub operator: ComparisonOperator, - pub value: Value, -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct CompositeClause { - pub operator: LogicalOperator, - pub clauses: Vec, -} - -impl From<&ModelKeysClause> for torii_grpc::types::ModelKeysClause { - fn from(value: &ModelKeysClause) -> Self { - Self { - model: value.model.to_string(), - keys: value.keys.iter().map(|k| Felt::from_str(k.as_str()).unwrap()).collect(), - } - } -} - -impl From<&KeysClause> for torii_grpc::types::KeysClause { - fn from(value: &KeysClause) -> Self { - Self { - keys: value - .keys - .iter() - .map(|o| o.as_ref().map(|k| Felt::from_str(k.as_str()).unwrap())) - .collect(), - models: value.models.iter().map(|m| m.to_string()).collect(), - pattern_matching: (&value.pattern_matching).into(), - } - } -} - -impl From<&MemberClause> for torii_grpc::types::MemberClause { - fn from(value: &MemberClause) -> Self { - Self { - model: value.model.to_string(), - member: value.member.to_string(), - operator: (&value.operator).into(), - value: (&value.value).into(), - } - } -} - -impl From<&CompositeClause> for torii_grpc::types::CompositeClause { - fn from(value: &CompositeClause) -> Self { - Self { - operator: (&value.operator).into(), - clauses: value.clauses.iter().map(|c| c.into()).collect(), - } - } -} - -impl From<&Clause> for torii_grpc::types::Clause { - fn from(value: &Clause) -> Self { - match value { - Clause::Keys(keys) => Self::Keys(keys.into()), - Clause::Member(member) => Self::Member(member.into()), - Clause::Composite(composite) => Self::Composite(composite.into()), - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum LogicalOperator { - And, - Or, -} - -impl From<&LogicalOperator> for torii_grpc::types::LogicalOperator { - fn from(value: &LogicalOperator) -> Self { - match value { - LogicalOperator::And => Self::And, - LogicalOperator::Or => Self::Or, - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum ComparisonOperator { - Eq, - Neq, - Gt, - Gte, - Lt, - Lte, -} - -impl From<&ComparisonOperator> for torii_grpc::types::ComparisonOperator { - fn from(value: &ComparisonOperator) -> Self { - match value { - ComparisonOperator::Eq => Self::Eq, - ComparisonOperator::Neq => Self::Neq, - ComparisonOperator::Gt => Self::Gt, - ComparisonOperator::Gte => Self::Gte, - ComparisonOperator::Lt => Self::Lt, - ComparisonOperator::Lte => Self::Lte, - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub struct Value { - pub primitive_type: Primitive, - pub value_type: ValueType, -} - -impl From<&Value> for torii_grpc::types::Value { - fn from(value: &Value) -> Self { - Self { - primitive_type: (&value.primitive_type).into(), - value_type: (&value.value_type).into(), - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum ValueType { - String(String), - Int(i64), - UInt(u64), - VBool(bool), - Bytes(Vec), -} - -impl From<&ValueType> for torii_grpc::types::ValueType { - fn from(value: &ValueType) -> Self { - match &value { - ValueType::String(s) => Self::String(s.to_string()), - ValueType::Int(i) => Self::Int(*i), - ValueType::UInt(u) => Self::UInt(*u), - ValueType::VBool(b) => Self::Bool(*b), - ValueType::Bytes(b) => Self::Bytes(b.to_vec()), - } - } -} - -#[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] -pub enum Primitive { - I8(Option), - I16(Option), - I32(Option), - I64(Option), - I128(Option), - U8(Option), - U16(Option), - U32(Option), - U64(Option), - U128(Option), - U256(Option), - USize(Option), - Bool(Option), - Felt252(Option), - ClassHash(Option), - ContractAddress(Option), -} - -impl From<&Primitive> for dojo_types::primitive::Primitive { - fn from(value: &Primitive) -> Self { - match value { - Primitive::I8(Some(value)) => Self::I8(Some(*value)), - Primitive::I16(Some(value)) => Self::I16(Some(*value)), - Primitive::I32(Some(value)) => Self::I32(Some(*value)), - Primitive::I64(Some(value)) => Self::I64(Some(*value)), - Primitive::I128(Some(value)) => Self::I128(Some(i128::from_str(value).unwrap())), - Primitive::U8(Some(value)) => Self::U8(Some(*value)), - Primitive::U16(Some(value)) => Self::U16(Some(*value)), - Primitive::U32(Some(value)) => Self::U32(Some(*value)), - Primitive::U64(Some(value)) => Self::U64(Some(*value)), - Primitive::U128(Some(value)) => Self::U128(Some(u128::from_str(value).unwrap())), - Primitive::U256(Some(value)) => Self::U256(Some(U256::from_be_hex(value.as_str()))), - Primitive::USize(Some(value)) => Self::USize(Some(*value)), - Primitive::Bool(Some(value)) => Self::Bool(Some(*value)), - Primitive::Felt252(Some(value)) => Self::Felt252(Some(Felt::from_str(value).unwrap())), - Primitive::ClassHash(Some(value)) => { - Self::ClassHash(Some(Felt::from_str(value).unwrap())) - } - Primitive::ContractAddress(Some(value)) => { - Self::ContractAddress(Some(Felt::from_str(value).unwrap())) - } - _ => unimplemented!(), - } - } -} +use types::{BlockId, Call, Calls, ClientConfig, Entities, KeysClauses, Model, Query, Signature}; #[wasm_bindgen(js_name = typedDataEncode)] pub fn typed_data_encode(typed_data: &str, address: &str) -> Result { @@ -446,7 +54,7 @@ pub fn signing_key_new() -> String { } #[wasm_bindgen(js_name = signingKeySign)] -pub fn signing_key_sign(private_key: &str, hash: &str) -> Result { +pub fn signing_key_sign(private_key: &str, hash: &str) -> Result { let private_key = Felt::from_str(private_key); if let Err(e) = private_key { return Err(JsValue::from(format!("failed to parse private key: {e}"))); @@ -461,7 +69,7 @@ pub fn signing_key_sign(private_key: &str, hash: &str) -> Result Result::Ok(JsSignature::from(&sig)), + Ok(sig) => Result::Ok(Signature::from(&sig)), Err(e) => Err(JsValue::from(format!("failed to sign: {e}"))), } } @@ -482,7 +90,7 @@ pub fn verifying_key_new(signing_key: &str) -> Result { pub fn verifying_key_verify( verifying_key: &str, hash: &str, - signature: JsSignature, + signature: Signature, ) -> Result { let verifying_key = Felt::from_str(verifying_key); if let Err(e) = verifying_key { @@ -498,7 +106,7 @@ pub fn verifying_key_verify( let hash = &hash.unwrap(); - let signature = &Signature::from(&signature); + let signature = &starknet::core::crypto::Signature::from(&signature); match verifying_key.verify(hash, signature) { Ok(result) => Result::Ok(result), @@ -613,9 +221,9 @@ impl Account { #[wasm_bindgen(js_name = executeRaw)] pub async unsafe fn execute_raw(&self, calldata: Calls) -> Result { - let calldata = calldata.0.iter().map(|c| c.into()).collect(); + let calldata = calldata.iter().map(|c| c.into()).collect(); - let call = self.0.execute_v3(calldata); + let call = self.0.execute_v1(calldata); let result = call.send().await; @@ -649,7 +257,7 @@ impl Account { SingleOwnerAccount::new(provider, signer, address, chain_id, ExecutionEncoding::New); // deploy the burner - let exec = self.0.execute_v3(vec![starknet::accounts::Call { + let exec = self.0.execute_v1(vec![starknet::accounts::Call { to: constants::UDC_ADDRESS, calldata: vec![ constants::KATANA_ACCOUNT_CLASS_HASH, // class_hash @@ -664,9 +272,7 @@ impl Account { let result = exec.send().await; if let Err(e) = result { - return Err(JsValue::from(format!( - "failed to start torii client subscription service: {e}" - ))); + return Err(JsValue::from(format!("failed to deploy burner: {e}",))); } let result = result.unwrap(); @@ -747,24 +353,22 @@ pub fn poseidon_hash(inputs: Vec) -> Result { } #[wasm_bindgen] -impl Client { +impl ToriiClient { #[wasm_bindgen(js_name = getEntities)] - pub async fn get_entities(&self, query: Query) -> Result { + pub async fn get_entities(&self, query: Query) -> Result { #[cfg(feature = "console-error-panic")] console_error_panic_hook::set_once(); let results = self.inner.entities((&query).into()).await; match results { - Ok(entities) => { - Ok(js_sys::JSON::parse(&parse_entities_as_json_str(entities).to_string())?) - } + Ok(entities) => Ok((&entities).into()), Err(err) => Err(JsValue::from(format!("failed to get entities: {err}"))), } } #[wasm_bindgen(js_name = getAllEntities)] - pub async fn get_all_entities(&self, limit: u32, offset: u32) -> Result { + pub async fn get_all_entities(&self, limit: u32, offset: u32) -> Result { #[cfg(feature = "console-error-panic")] console_error_panic_hook::set_once(); @@ -772,24 +376,20 @@ impl Client { self.inner.entities(torii_grpc::types::Query { limit, offset, clause: None }).await; match results { - Ok(entities) => { - Ok(js_sys::JSON::parse(&parse_entities_as_json_str(entities).to_string())?) - } + Ok(entities) => Ok((&entities).into()), Err(err) => Err(JsValue::from(format!("failed to get entities: {err}"))), } } #[wasm_bindgen(js_name = getEventMessages)] - pub async fn get_event_messages(&self, query: Query) -> Result { + pub async fn get_event_messages(&self, query: Query) -> Result { #[cfg(feature = "console-error-panic")] console_error_panic_hook::set_once(); let results = self.inner.event_messages((&query).into()).await; match results { - Ok(event_messages) => { - Ok(js_sys::JSON::parse(&parse_entities_as_json_str(event_messages).to_string())?) - } + Ok(event_messages) => Ok((&event_messages).into()), Err(err) => Err(JsValue::from(format!("failed to get event_messages: {err}"))), } } @@ -803,7 +403,7 @@ impl Client { #[cfg(feature = "console-error-panic")] console_error_panic_hook::set_once(); - let clauses = clauses.0.iter().map(|c| c.into()).collect(); + let clauses = clauses.iter().map(|c| c.into()).collect(); let mut stream = self.inner.on_entity_updated(clauses).await.unwrap(); let subscription_id = match stream.next().await { @@ -816,10 +416,12 @@ impl Client { let mut stream = stream.take_until_if(tripwire); while let Some(Ok((_, entity))) = stream.next().await { - let json_str = parse_entities_as_json_str(vec![entity]).to_string(); - let _ = callback.call1( + let models = entity.models.iter().map(|m| m.into()).collect::>(); + + let _ = callback.call2( &JsValue::null(), - &js_sys::JSON::parse(&json_str).expect("json parse failed"), + &JsValue::from_str(&format!("{:#x}", entity.hashed_keys)), + &serde_wasm_bindgen::to_value(&models).unwrap(), ); } }); @@ -833,7 +435,7 @@ impl Client { subscription: &Subscription, clauses: KeysClauses, ) -> Result<(), JsValue> { - let clauses = clauses.0.iter().map(|c| c.into()).collect(); + let clauses = clauses.iter().map(|c| c.into()).collect(); self.inner .update_entity_subscription(subscription.id, clauses) .await @@ -849,7 +451,7 @@ impl Client { #[cfg(feature = "console-error-panic")] console_error_panic_hook::set_once(); - let clauses = clauses.0.iter().map(|c| c.into()).collect(); + let clauses = clauses.iter().map(|c| c.into()).collect(); let mut stream = self.inner.on_event_message_updated(clauses).await.unwrap(); let subscription_id = match stream.next().await { @@ -862,10 +464,12 @@ impl Client { let mut stream = stream.take_until_if(tripwire); while let Some(Ok((_, entity))) = stream.next().await { - let json_str = parse_entities_as_json_str(vec![entity]).to_string(); - let _ = callback.call1( + let models = entity.models.iter().map(|m| m.into()).collect::>(); + + let _ = callback.call2( &JsValue::null(), - &js_sys::JSON::parse(&json_str).expect("json parse failed"), + &JsValue::from_str(&format!("{:#x}", entity.hashed_keys)), + &serde_wasm_bindgen::to_value(&models).unwrap(), ); } }); @@ -879,7 +483,7 @@ impl Client { subscription: &Subscription, clauses: KeysClauses, ) -> Result<(), JsValue> { - let clauses = clauses.0.iter().map(|c| c.into()).collect(); + let clauses = clauses.iter().map(|c| c.into()).collect(); self.inner .update_event_message_subscription(subscription.id, clauses) .await @@ -890,7 +494,7 @@ impl Client { pub async fn publish_message( &mut self, message: &str, - signature: JsSignature, + signature: Signature, ) -> Result { #[cfg(feature = "console-error-panic")] console_error_panic_hook::set_once(); @@ -924,7 +528,7 @@ impl Subscription { /// Create the a client with the given configurations. #[wasm_bindgen(js_name = createClient)] #[allow(non_snake_case)] -pub async fn create_client(config: ClientConfig) -> Result { +pub async fn create_client(config: ClientConfig) -> Result { #[cfg(feature = "console-error-panic")] console_error_panic_hook::set_once(); @@ -942,5 +546,5 @@ pub async fn create_client(config: ClientConfig) -> Result { relay_runner.lock().await.run().await; }); - Ok(Client { inner: client }) + Ok(ToriiClient { inner: client }) } diff --git a/src/wasm/types.rs b/src/wasm/types.rs new file mode 100644 index 0000000..7f5601e --- /dev/null +++ b/src/wasm/types.rs @@ -0,0 +1,455 @@ +use std::collections::HashMap; +use std::str::FromStr; + +use crypto_bigint::U256; +use dojo_types::schema::Struct; +use serde::{Deserialize, Serialize}; +use starknet::core::{types::FunctionCall, utils::get_selector_from_name}; +use starknet_crypto::Felt; + +use tsify_next::declare; +use tsify_next::Tsify; +use wasm_bindgen::prelude::*; + +use super::utils::parse_ty_as_json_str; + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct ClientConfig { + #[serde(rename = "rpcUrl")] + pub rpc_url: String, + #[serde(rename = "toriiUrl")] + pub torii_url: String, + #[serde(rename = "relayUrl")] + pub relay_url: String, + #[serde(rename = "worldAddress")] + pub world_address: String, +} + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_namespace = console)] + fn log(s: &str); + + #[wasm_bindgen(js_namespace = console)] + fn error(s: &str); +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Ty { + pub r#type: String, + pub type_name: String, + #[tsify(type = "any")] + pub value: serde_json::Value, + pub key: bool, +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct EnumValue { + pub option: String, + pub value: Ty, +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Signature { + pub r: String, + pub s: String, +} + +impl From<&starknet::core::crypto::Signature> for Signature { + fn from(value: &starknet::core::crypto::Signature) -> Self { + Self { r: format!("{:#x}", value.r), s: format!("{:#x}", value.s) } + } +} + +impl From<&Signature> for starknet::core::crypto::Signature { + fn from(value: &Signature) -> Self { + Self { + r: Felt::from_str(value.r.as_str()).unwrap(), + s: Felt::from_str(value.s.as_str()).unwrap(), + } + } +} + +#[declare] +pub type Calls = Vec; + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Model(pub HashMap); + +impl From<&Struct> for Model { + fn from(value: &Struct) -> Self { + Self( + value + .children + .iter() + .map(|c| (c.name.clone(), parse_ty_as_json_str(&c.ty, c.key))) + .collect(), + ) + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Entity(pub HashMap); + +impl From<&torii_grpc::types::schema::Entity> for Entity { + fn from(value: &torii_grpc::types::schema::Entity) -> Self { + Self(value.models.iter().map(|m| (m.name.clone(), m.into())).collect()) + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Entities(pub HashMap); + +impl From<&Vec> for Entities { + fn from(value: &Vec) -> Self { + Self(value.iter().map(|e| (format!("{:#x}", e.hashed_keys), e.into())).collect()) + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Call { + pub to: String, + pub selector: String, + pub calldata: Vec, +} + +impl From<&Call> for starknet::accounts::Call { + fn from(value: &Call) -> Self { + Self { + to: Felt::from_str(value.to.as_str()).unwrap(), + selector: get_selector_from_name(value.selector.as_str()).unwrap(), + calldata: value.calldata.iter().map(|c| Felt::from_str(c.as_str()).unwrap()).collect(), + } + } +} + +impl From<&Call> for FunctionCall { + fn from(value: &Call) -> Self { + Self { + contract_address: Felt::from_str(value.to.as_str()).unwrap(), + entry_point_selector: get_selector_from_name(value.selector.as_str()).unwrap(), + calldata: value.calldata.iter().map(|c| Felt::from_str(c.as_str()).unwrap()).collect(), + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum BlockTag { + Latest, + Pending, +} + +impl From<&BlockTag> for starknet::core::types::BlockTag { + fn from(value: &BlockTag) -> Self { + match value { + BlockTag::Latest => starknet::core::types::BlockTag::Latest, + BlockTag::Pending => starknet::core::types::BlockTag::Pending, + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum BlockId { + Hash(String), + Number(u64), + BlockTag(BlockTag), +} + +impl From<&BlockId> for starknet::core::types::BlockId { + fn from(value: &BlockId) -> Self { + match value { + BlockId::Hash(hash) => { + starknet::core::types::BlockId::Hash(Felt::from_str(hash.as_str()).unwrap()) + } + BlockId::Number(number) => starknet::core::types::BlockId::Number(*number), + BlockId::BlockTag(tag) => starknet::core::types::BlockId::Tag(tag.into()), + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Query { + pub limit: u32, + pub offset: u32, + pub clause: Option, +} + +impl From<&Query> for torii_grpc::types::Query { + fn from(value: &Query) -> Self { + Self { + limit: value.limit, + offset: value.offset, + clause: value.clause.as_ref().map(|c| c.into()), + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum Clause { + Keys(KeysClause), + Member(MemberClause), + Composite(CompositeClause), +} + +#[declare] +pub type KeysClauses = Vec; + +#[declare] +pub type ModelKeysClauses = Vec; + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct ModelKeysClause { + pub model: String, + pub keys: Vec, +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum PatternMatching { + FixedLen = 0, + VariableLen = 1, +} + +impl From<&PatternMatching> for torii_grpc::types::PatternMatching { + fn from(value: &PatternMatching) -> Self { + match value { + PatternMatching::FixedLen => Self::FixedLen, + PatternMatching::VariableLen => Self::VariableLen, + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum EntityKeysClause { + HashedKeys(Vec), + Keys(KeysClause), +} + +impl From<&EntityKeysClause> for torii_grpc::types::EntityKeysClause { + fn from(value: &EntityKeysClause) -> Self { + match value { + EntityKeysClause::HashedKeys(keys) => { + Self::HashedKeys(keys.iter().map(|k| Felt::from_str(k.as_str()).unwrap()).collect()) + } + EntityKeysClause::Keys(keys) => Self::Keys(keys.into()), + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct KeysClause { + pub keys: Vec>, + pub pattern_matching: PatternMatching, + pub models: Vec, +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct MemberClause { + pub model: String, + pub member: String, + pub operator: ComparisonOperator, + pub value: Value, +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct CompositeClause { + pub operator: LogicalOperator, + pub clauses: Vec, +} + +impl From<&ModelKeysClause> for torii_grpc::types::ModelKeysClause { + fn from(value: &ModelKeysClause) -> Self { + Self { + model: value.model.to_string(), + keys: value.keys.iter().map(|k| Felt::from_str(k.as_str()).unwrap()).collect(), + } + } +} + +impl From<&KeysClause> for torii_grpc::types::KeysClause { + fn from(value: &KeysClause) -> Self { + Self { + keys: value + .keys + .iter() + .map(|o| o.as_ref().map(|k| Felt::from_str(k.as_str()).unwrap())) + .collect(), + models: value.models.iter().map(|m| m.to_string()).collect(), + pattern_matching: (&value.pattern_matching).into(), + } + } +} + +impl From<&MemberClause> for torii_grpc::types::MemberClause { + fn from(value: &MemberClause) -> Self { + Self { + model: value.model.to_string(), + member: value.member.to_string(), + operator: (&value.operator).into(), + value: (&value.value).into(), + } + } +} + +impl From<&CompositeClause> for torii_grpc::types::CompositeClause { + fn from(value: &CompositeClause) -> Self { + Self { + operator: (&value.operator).into(), + clauses: value.clauses.iter().map(|c| c.into()).collect(), + } + } +} + +impl From<&Clause> for torii_grpc::types::Clause { + fn from(value: &Clause) -> Self { + match value { + Clause::Keys(keys) => Self::Keys(keys.into()), + Clause::Member(member) => Self::Member(member.into()), + Clause::Composite(composite) => Self::Composite(composite.into()), + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum LogicalOperator { + And, + Or, +} + +impl From<&LogicalOperator> for torii_grpc::types::LogicalOperator { + fn from(value: &LogicalOperator) -> Self { + match value { + LogicalOperator::And => Self::And, + LogicalOperator::Or => Self::Or, + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum ComparisonOperator { + Eq, + Neq, + Gt, + Gte, + Lt, + Lte, +} + +impl From<&ComparisonOperator> for torii_grpc::types::ComparisonOperator { + fn from(value: &ComparisonOperator) -> Self { + match value { + ComparisonOperator::Eq => Self::Eq, + ComparisonOperator::Neq => Self::Neq, + ComparisonOperator::Gt => Self::Gt, + ComparisonOperator::Gte => Self::Gte, + ComparisonOperator::Lt => Self::Lt, + ComparisonOperator::Lte => Self::Lte, + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Value { + pub primitive_type: Primitive, + pub value_type: ValueType, +} + +impl From<&Value> for torii_grpc::types::Value { + fn from(value: &Value) -> Self { + Self { + primitive_type: (&value.primitive_type).into(), + value_type: (&value.value_type).into(), + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum ValueType { + String(String), + Int(i64), + UInt(u64), + VBool(bool), + Bytes(Vec), +} + +impl From<&ValueType> for torii_grpc::types::ValueType { + fn from(value: &ValueType) -> Self { + match &value { + ValueType::String(s) => Self::String(s.to_string()), + ValueType::Int(i) => Self::Int(*i), + ValueType::UInt(u) => Self::UInt(*u), + ValueType::VBool(b) => Self::Bool(*b), + ValueType::Bytes(b) => Self::Bytes(b.to_vec()), + } + } +} + +#[derive(Tsify, Serialize, Deserialize, Debug)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub enum Primitive { + I8(Option), + I16(Option), + I32(Option), + I64(Option), + I128(Option), + U8(Option), + U16(Option), + U32(Option), + U64(Option), + U128(Option), + U256(Option), + USize(Option), + Bool(Option), + Felt252(Option), + ClassHash(Option), + ContractAddress(Option), +} + +impl From<&Primitive> for dojo_types::primitive::Primitive { + fn from(value: &Primitive) -> Self { + match value { + Primitive::I8(Some(value)) => Self::I8(Some(*value)), + Primitive::I16(Some(value)) => Self::I16(Some(*value)), + Primitive::I32(Some(value)) => Self::I32(Some(*value)), + Primitive::I64(Some(value)) => Self::I64(Some(*value)), + Primitive::I128(Some(value)) => Self::I128(Some(i128::from_str(value).unwrap())), + Primitive::U8(Some(value)) => Self::U8(Some(*value)), + Primitive::U16(Some(value)) => Self::U16(Some(*value)), + Primitive::U32(Some(value)) => Self::U32(Some(*value)), + Primitive::U64(Some(value)) => Self::U64(Some(*value)), + Primitive::U128(Some(value)) => Self::U128(Some(u128::from_str(value).unwrap())), + Primitive::U256(Some(value)) => Self::U256(Some(U256::from_be_hex(value.as_str()))), + Primitive::USize(Some(value)) => Self::USize(Some(*value)), + Primitive::Bool(Some(value)) => Self::Bool(Some(*value)), + Primitive::Felt252(Some(value)) => Self::Felt252(Some(Felt::from_str(value).unwrap())), + Primitive::ClassHash(Some(value)) => { + Self::ClassHash(Some(Felt::from_str(value).unwrap())) + } + Primitive::ContractAddress(Some(value)) => { + Self::ContractAddress(Some(Felt::from_str(value).unwrap())) + } + _ => unimplemented!(), + } + } +} diff --git a/src/wasm/utils.rs b/src/wasm/utils.rs index 636a06c..b6695de 100644 --- a/src/wasm/utils.rs +++ b/src/wasm/utils.rs @@ -1,110 +1,113 @@ +use std::collections::HashMap; + use dojo_types::primitive::Primitive; -use dojo_types::schema::Ty; -use serde_json::Value; +use serde_json::{json, Value}; use torii_grpc::types::schema::Entity; +use wasm_bindgen::JsValue; -pub fn parse_entities_as_json_str(entities: Vec) -> Value { - entities - .into_iter() - .map(|entity| { - let entity_key = format!("{:#x}", entity.hashed_keys); - let models_map = entity - .models - .into_iter() - .map(|model| { - let model_map = model - .children - .iter() - .map(|member| { - (member.name.to_owned(), parse_ty_as_json_str(&member.ty, member.key)) - }) - .collect::>(); - - (model.name, model_map.into()) - }) - .collect::>(); - - (entity_key, models_map.into()) - }) - .collect::>() - .into() -} +use super::types::{EnumValue, Ty}; -pub fn parse_ty_as_json_str(ty: &Ty, key: bool) -> Value { +pub fn parse_ty_as_json_str(ty: &dojo_types::schema::Ty, key: bool) -> Ty { match ty { - Ty::Primitive(primitive) => serde_json::json!({ - "type": "primitive", - "type_name": ty.name(), - "value": primitive_value_json(*primitive), - "key": key, - }), - - Ty::Struct(struct_ty) => serde_json::json!({ - "type": "struct", - "type_name": ty.name(), - "value": struct_ty + dojo_types::schema::Ty::Primitive(primitive) => Ty { + r#type: "primitive".to_string(), + type_name: ty.name(), + value: primitive_value_json(*primitive), + key, + }, + dojo_types::schema::Ty::Struct(struct_ty) => Ty { + r#type: "struct".to_string(), + type_name: ty.name(), + value: json!(&struct_ty .children .iter() .map(|child| (child.name.to_owned(), parse_ty_as_json_str(&child.ty, child.key))) - .collect::>(), - "key": key, - }), + .collect::>()), + key: key, + }, - Ty::Enum(enum_ty) => serde_json::json!({ - "type": "enum", - "type_name": ty.name(), - "value": if let Some(option) = enum_ty.option { + dojo_types::schema::Ty::Enum(enum_ty) => Ty { + r#type: "enum".to_string(), + type_name: ty.name(), + value: if let Some(option) = enum_ty.option { let option = &enum_ty.options[option as usize]; - serde_json::json!({ - "option": option.name, + json!(&EnumValue { + option: option.name.clone(), // should we hardcode key to always be false for inners of enum? - "value": parse_ty_as_json_str(&option.ty, false), + value: parse_ty_as_json_str(&option.ty, false), }) } else { Value::Null }, - "key": key, - }), + key: key, + }, - Ty::Tuple(tuple) => serde_json::json!({ - "type": "tuple", - "type_name": ty.name(), - "value": tuple - .iter() - // should we hardcode key to always be false for inners of tuple? - .map(|child| parse_ty_as_json_str(child, false)) - .collect::>(), - "key": key, - }), - Ty::Array(array) => serde_json::json!({ - "type": "array", - "type_name": ty.name(), - // should we hardcode key to always be false for inners of array? - "value": array.iter().map(|child| parse_ty_as_json_str(child, false)).collect::>(), - "key": key, - }), - Ty::ByteArray(bytearray) => serde_json::json!({ - "type": "bytearray", - "type_name": ty.name(), - "value": bytearray.to_string(), - "key": key, - }), + dojo_types::schema::Ty::Tuple(tuple) => Ty { + r#type: "tuple".to_string(), + type_name: ty.name(), + value: json!(&tuple + .iter() + // should we hardcode key to always be false for inners of tuple? + .map(|child| parse_ty_as_json_str(child, false)) + .collect::>()), + key: key, + }, + dojo_types::schema::Ty::Array(array) => Ty { + r#type: "array".to_string(), + type_name: ty.name(), + // shoud we hardcode key to always be false for inners of array? + value: json!(&array.iter().map(|child| parse_ty_as_json_str(child, false)).collect::>()), + key: key, + }, + dojo_types::schema::Ty::ByteArray(bytearray) => Ty { + r#type: "bytearray".to_string(), + type_name: ty.name(), + value: json!(bytearray.as_str()), + key: key, + }, } } +// fn primitive_value_json(primitive: Primitive) -> JsValue { +// match primitive { +// Primitive::Bool(Some(value)) => JsValue::from_bool(value), +// Primitive::I8(Some(value)) => JsValue::from_f64(value.into()), +// Primitive::I16(Some(value)) => JsValue::from_f64(value.into()), +// Primitive::I32(Some(value)) => JsValue::from_f64(value.into()), +// Primitive::U8(Some(value)) => JsValue::from_f64(value.into()), +// Primitive::U16(Some(value)) => JsValue::from_f64(value.into()), +// Primitive::U32(Some(value)) => JsValue::from_f64(value.into()), +// Primitive::USize(Some(value)) => JsValue::from_f64(value.into()), +// Primitive::I64(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// Primitive::U64(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// Primitive::I128(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// Primitive::U128(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// Primitive::U256(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// Primitive::Felt252(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// Primitive::ClassHash(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// Primitive::ContractAddress(Some(value)) => JsValue::from_str(&format!("{value:#x}")), +// _ => JsValue::NULL +// } +// } + fn primitive_value_json(primitive: Primitive) -> Value { match primitive { - Primitive::Bool(Some(value)) => Value::Bool(value), - Primitive::U8(Some(value)) => Value::Number(value.into()), - Primitive::U16(Some(value)) => Value::Number(value.into()), - Primitive::U32(Some(value)) => Value::Number(value.into()), - Primitive::U64(Some(value)) => Value::Number(value.into()), - Primitive::USize(Some(value)) => Value::Number(value.into()), - Primitive::U128(Some(value)) => Value::String(format!("{value:#x}")), - Primitive::U256(Some(value)) => Value::String(format!("{value:#x}")), - Primitive::Felt252(Some(value)) => Value::String(format!("{value:#x}")), - Primitive::ClassHash(Some(value)) => Value::String(format!("{value:#x}")), - Primitive::ContractAddress(Some(value)) => Value::String(format!("{value:#x}")), - _ => Value::Null, + Primitive::Bool(Some(value)) => json!(value), + Primitive::I8(Some(value)) => json!(value), + Primitive::I16(Some(value)) => json!(value), + Primitive::I32(Some(value)) => json!(value), + Primitive::U8(Some(value)) => json!(value), + Primitive::U16(Some(value)) => json!(value), + Primitive::U32(Some(value)) => json!(value), + Primitive::USize(Some(value)) => json!(value), + Primitive::I64(Some(value)) => json!(&format!("{value:#x}")), + Primitive::U64(Some(value)) => json!(&format!("{value:#x}")), + Primitive::I128(Some(value)) => json!(&format!("{value:#x}")), + Primitive::U128(Some(value)) => json!(&format!("{value:#x}")), + Primitive::U256(Some(value)) => json!(&format!("{value:#x}")), + Primitive::Felt252(Some(value)) => json!(&format!("{value:#x}")), + Primitive::ClassHash(Some(value)) => json!(&format!("{value:#x}")), + Primitive::ContractAddress(Some(value)) => json!(&format!("{value:#x}")), + _ => Value::Null } -} +} \ No newline at end of file From 5147ddf8d0b31e6abdf10f099825babe635138e2 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 11:36:20 -0400 Subject: [PATCH 2/8] feat; use json for wasm and add morehelpful types --- Cargo.lock | 19 ++++--- Cargo.toml | 2 +- src/wasm/types.rs | 7 ++- src/wasm/utils.rs | 124 +++++++++++++++++++++++++--------------------- 4 files changed, 83 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 556eb1d..94601b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1461,7 +1461,7 @@ checksum = "8bd5c8c127b9362a12ffb9dede38e792c81b4ded5a98b448baec157b745f47d1" dependencies = [ "env_logger", "hashbrown 0.14.5", - "indexmap 2.2.6", + "indexmap 2.3.0", "itertools 0.12.1", "log", "num-bigint", @@ -3960,7 +3960,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.2.6", + "indexmap 2.3.0", "slab", "tokio", "tokio-util", @@ -4573,9 +4573,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -6365,7 +6365,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.2.6", + "indexmap 2.3.0", ] [[package]] @@ -8297,7 +8297,7 @@ dependencies = [ "futures-util", "hashlink", "hex", - "indexmap 2.2.6", + "indexmap 2.3.0", "log", "memchr", "once_cell", @@ -9147,7 +9147,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.3.0", "toml_datetime", "winnow 0.5.40", ] @@ -9158,7 +9158,7 @@ version = "0.22.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.3.0", "serde", "serde_spanned", "toml_datetime", @@ -9423,7 +9423,7 @@ dependencies = [ "dojo-types", "dojo-world", "futures", - "indexmap 2.2.6", + "indexmap 2.3.0", "libp2p", "libp2p-webrtc", "libp2p-webrtc-websys", @@ -9595,7 +9595,6 @@ checksum = "2f4a645dca4ee0800f5ab60ce166deba2db6a0315de795a2691e138a3d55d756" dependencies = [ "gloo-utils", "serde", - "serde-wasm-bindgen", "serde_json", "tsify-next-macros", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index c4f8499..6a9c5e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ web-sys = { version = "0.3.4", features = [ 'console', ] } crypto-bigint = "0.5.5" -tsify-next = { version = "0.5.4", features = ["js"] } +tsify-next = "0.5.4" [build-dependencies] cbindgen = "0.26.0" diff --git a/src/wasm/types.rs b/src/wasm/types.rs index 7f5601e..fe0c886 100644 --- a/src/wasm/types.rs +++ b/src/wasm/types.rs @@ -4,6 +4,7 @@ use std::str::FromStr; use crypto_bigint::U256; use dojo_types::schema::Struct; use serde::{Deserialize, Serialize}; +use serde_wasm_bindgen::to_value; use starknet::core::{types::FunctionCall, utils::get_selector_from_name}; use starknet_crypto::Felt; @@ -38,10 +39,12 @@ extern "C" { #[derive(Tsify, Serialize, Deserialize, Debug)] #[tsify(into_wasm_abi, from_wasm_abi)] pub struct Ty { + #[tsify(type = r#""primitive" | "struct" | "enum" | "array" | "tuple" | "bytearray""#)] pub r#type: String, pub type_name: String, - #[tsify(type = "any")] - pub value: serde_json::Value, + #[serde(with = "serde_wasm_bindgen::preserve")] + #[tsify(type = "boolean | number | string | Ty | null")] + pub value: JsValue, pub key: bool, } diff --git a/src/wasm/utils.rs b/src/wasm/utils.rs index b6695de..7654c40 100644 --- a/src/wasm/utils.rs +++ b/src/wasm/utils.rs @@ -18,12 +18,17 @@ pub fn parse_ty_as_json_str(ty: &dojo_types::schema::Ty, key: bool) -> Ty { dojo_types::schema::Ty::Struct(struct_ty) => Ty { r#type: "struct".to_string(), type_name: ty.name(), - value: json!(&struct_ty - .children - .iter() - .map(|child| (child.name.to_owned(), parse_ty_as_json_str(&child.ty, child.key))) - .collect::>()), - key: key, + value: serde_wasm_bindgen::to_value( + &struct_ty + .children + .iter() + .map(|child| { + (child.name.to_owned(), parse_ty_as_json_str(&child.ty, child.key)) + }) + .collect::>(), + ) + .unwrap(), + key, }, dojo_types::schema::Ty::Enum(enum_ty) => Ty { @@ -31,83 +36,90 @@ pub fn parse_ty_as_json_str(ty: &dojo_types::schema::Ty, key: bool) -> Ty { type_name: ty.name(), value: if let Some(option) = enum_ty.option { let option = &enum_ty.options[option as usize]; - json!(&EnumValue { + serde_wasm_bindgen::to_value(&EnumValue { option: option.name.clone(), // should we hardcode key to always be false for inners of enum? value: parse_ty_as_json_str(&option.ty, false), }) + .unwrap() } else { - Value::Null + JsValue::NULL }, - key: key, + key, }, dojo_types::schema::Ty::Tuple(tuple) => Ty { r#type: "tuple".to_string(), type_name: ty.name(), - value: json!(&tuple + value: serde_wasm_bindgen::to_value( + &tuple .iter() // should we hardcode key to always be false for inners of tuple? .map(|child| parse_ty_as_json_str(child, false)) - .collect::>()), - key: key, + .collect::>(), + ) + .unwrap(), + key, }, dojo_types::schema::Ty::Array(array) => Ty { r#type: "array".to_string(), type_name: ty.name(), // shoud we hardcode key to always be false for inners of array? - value: json!(&array.iter().map(|child| parse_ty_as_json_str(child, false)).collect::>()), - key: key, + value: serde_wasm_bindgen::to_value( + &array.iter().map(|child| parse_ty_as_json_str(child, false)).collect::>(), + ) + .unwrap(), + key, }, dojo_types::schema::Ty::ByteArray(bytearray) => Ty { r#type: "bytearray".to_string(), type_name: ty.name(), - value: json!(bytearray.as_str()), - key: key, + value: serde_wasm_bindgen::to_value(bytearray.as_str()).unwrap(), + key, }, } } -// fn primitive_value_json(primitive: Primitive) -> JsValue { +fn primitive_value_json(primitive: Primitive) -> JsValue { + match primitive { + Primitive::Bool(Some(value)) => JsValue::from_bool(value), + Primitive::I8(Some(value)) => JsValue::from_f64(value.into()), + Primitive::I16(Some(value)) => JsValue::from_f64(value.into()), + Primitive::I32(Some(value)) => JsValue::from_f64(value.into()), + Primitive::U8(Some(value)) => JsValue::from_f64(value.into()), + Primitive::U16(Some(value)) => JsValue::from_f64(value.into()), + Primitive::U32(Some(value)) => JsValue::from_f64(value.into()), + Primitive::USize(Some(value)) => JsValue::from_f64(value.into()), + Primitive::I64(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + Primitive::U64(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + Primitive::I128(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + Primitive::U128(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + Primitive::U256(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + Primitive::Felt252(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + Primitive::ClassHash(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + Primitive::ContractAddress(Some(value)) => JsValue::from_str(&format!("{value:#x}")), + _ => JsValue::NULL, + } +} + +// fn primitive_value_json(primitive: Primitive) -> Value { // match primitive { -// Primitive::Bool(Some(value)) => JsValue::from_bool(value), -// Primitive::I8(Some(value)) => JsValue::from_f64(value.into()), -// Primitive::I16(Some(value)) => JsValue::from_f64(value.into()), -// Primitive::I32(Some(value)) => JsValue::from_f64(value.into()), -// Primitive::U8(Some(value)) => JsValue::from_f64(value.into()), -// Primitive::U16(Some(value)) => JsValue::from_f64(value.into()), -// Primitive::U32(Some(value)) => JsValue::from_f64(value.into()), -// Primitive::USize(Some(value)) => JsValue::from_f64(value.into()), -// Primitive::I64(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// Primitive::U64(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// Primitive::I128(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// Primitive::U128(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// Primitive::U256(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// Primitive::Felt252(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// Primitive::ClassHash(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// Primitive::ContractAddress(Some(value)) => JsValue::from_str(&format!("{value:#x}")), -// _ => JsValue::NULL +// Primitive::Bool(Some(value)) => json!(value), +// Primitive::I8(Some(value)) => json!(value), +// Primitive::I16(Some(value)) => json!(value), +// Primitive::I32(Some(value)) => json!(value), +// Primitive::U8(Some(value)) => json!(value), +// Primitive::U16(Some(value)) => json!(value), +// Primitive::U32(Some(value)) => json!(value), +// Primitive::USize(Some(value)) => json!(value), +// Primitive::I64(Some(value)) => json!(&format!("{value:#x}")), +// Primitive::U64(Some(value)) => json!(&format!("{value:#x}")), +// Primitive::I128(Some(value)) => json!(&format!("{value:#x}")), +// Primitive::U128(Some(value)) => json!(&format!("{value:#x}")), +// Primitive::U256(Some(value)) => json!(&format!("{value:#x}")), +// Primitive::Felt252(Some(value)) => json!(&format!("{value:#x}")), +// Primitive::ClassHash(Some(value)) => json!(&format!("{value:#x}")), +// Primitive::ContractAddress(Some(value)) => json!(&format!("{value:#x}")), +// _ => Value::Null // } // } - -fn primitive_value_json(primitive: Primitive) -> Value { - match primitive { - Primitive::Bool(Some(value)) => json!(value), - Primitive::I8(Some(value)) => json!(value), - Primitive::I16(Some(value)) => json!(value), - Primitive::I32(Some(value)) => json!(value), - Primitive::U8(Some(value)) => json!(value), - Primitive::U16(Some(value)) => json!(value), - Primitive::U32(Some(value)) => json!(value), - Primitive::USize(Some(value)) => json!(value), - Primitive::I64(Some(value)) => json!(&format!("{value:#x}")), - Primitive::U64(Some(value)) => json!(&format!("{value:#x}")), - Primitive::I128(Some(value)) => json!(&format!("{value:#x}")), - Primitive::U128(Some(value)) => json!(&format!("{value:#x}")), - Primitive::U256(Some(value)) => json!(&format!("{value:#x}")), - Primitive::Felt252(Some(value)) => json!(&format!("{value:#x}")), - Primitive::ClassHash(Some(value)) => json!(&format!("{value:#x}")), - Primitive::ContractAddress(Some(value)) => json!(&format!("{value:#x}")), - _ => Value::Null - } -} \ No newline at end of file From f640e47a8c3a908eb28d324804f3afd01cd53908 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 14:28:22 -0400 Subject: [PATCH 3/8] use js types --- Cargo.lock | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 94601b2..9906be1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9595,6 +9595,7 @@ checksum = "2f4a645dca4ee0800f5ab60ce166deba2db6a0315de795a2691e138a3d55d756" dependencies = [ "gloo-utils", "serde", + "serde-wasm-bindgen", "serde_json", "tsify-next-macros", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 6a9c5e2..c4f8499 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ web-sys = { version = "0.3.4", features = [ 'console', ] } crypto-bigint = "0.5.5" -tsify-next = "0.5.4" +tsify-next = { version = "0.5.4", features = ["js"] } [build-dependencies] cbindgen = "0.26.0" From 00c674023d6fd1422fc5fef8a7f102dcef2ce50e Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 15:00:01 -0400 Subject: [PATCH 4/8] refactor: use objects instead of maps for hashmaps --- Cargo.lock | 612 ++++++++++++++++++++++++---------------------- src/wasm/types.rs | 6 +- 2 files changed, 319 insertions(+), 299 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9906be1..3765db0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -127,33 +127,33 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -173,9 +173,9 @@ checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" [[package]] name = "arrayref" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" +checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" [[package]] name = "arrayvec" @@ -210,11 +210,11 @@ dependencies = [ [[package]] name = "asn1-rs" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ad1373757efa0f70ec53939aabc7152e1591cb485208052993070ac8d2429d" +checksum = "5493c3bedbacf7fd7382c6346bbd66687d12bbaad3a89a2d2c303ee6cf20b048" dependencies = [ - "asn1-rs-derive 0.5.0", + "asn1-rs-derive 0.5.1", "asn1-rs-impl 0.2.0", "displaydoc", "nom", @@ -238,13 +238,13 @@ dependencies = [ [[package]] name = "asn1-rs-derive" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1" +checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "synstructure 0.13.1", ] @@ -267,7 +267,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -301,9 +301,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd066d0b4ef8ecb03a55319dc13aa6910616d0f44008a045bb1835af830abff5" +checksum = "fec134f64e2bc57411226dfc4e52dec859ddfc7e711fc5e07b612584f000e4aa" dependencies = [ "brotli", "flate2", @@ -445,7 +445,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -462,7 +462,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -523,7 +523,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -764,9 +764,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.9.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" dependencies = [ "memchr", "regex-automata 0.4.7", @@ -793,9 +793,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.1" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "bytesize" @@ -814,7 +814,7 @@ dependencies = [ "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.3.0)", "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.3.0)", "camino", - "clap 4.5.9", + "clap 4.5.14", "clap_complete", "convert_case", "serde", @@ -839,7 +839,7 @@ dependencies = [ "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.3.2)", "cainome-rs-macro", "camino", - "clap 4.5.9", + "clap 4.5.14", "clap_complete", "convert_case", "serde", @@ -881,7 +881,7 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.71", + "syn 2.0.72", "thiserror", ] @@ -894,7 +894,7 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.71", + "syn 2.0.72", "thiserror", ] @@ -912,7 +912,7 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.71", + "syn 2.0.72", "thiserror", ] @@ -930,7 +930,7 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.71", + "syn 2.0.72", "thiserror", ] @@ -947,7 +947,7 @@ dependencies = [ "quote", "serde_json", "starknet", - "syn 2.0.71", + "syn 2.0.72", "thiserror", ] @@ -1115,7 +1115,7 @@ checksum = "e32e958decd95ae122ee64daa26721da2f76e83231047f947fd9cdc5d3c90cc6" dependencies = [ "quote", "scarb-stable-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -1171,7 +1171,7 @@ checksum = "3d55dcf98a6e1a03e0b36129fad4253f9e6666a1746ab9c075d212ba68a4e9c1" dependencies = [ "cairo-lang-debug", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -1185,7 +1185,7 @@ dependencies = [ "serde", "smol_str", "thiserror", - "toml 0.8.15", + "toml 0.8.19", ] [[package]] @@ -1212,7 +1212,7 @@ dependencies = [ "once_cell", "salsa", "smol_str", - "toml 0.8.15", + "toml 0.8.19", ] [[package]] @@ -1533,9 +1533,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.5" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" +checksum = "504bdec147f2cc13c8b57ed9401fd8a147cc66b67ad5cb241394244f2c947549" dependencies = [ "jobserver", "libc", @@ -1626,9 +1626,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.9" +version = "4.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" +checksum = "c937d4061031a6d0c8da4b9a4f98a172fc2976dfb1c19213a9cf7d0d3c837e36" dependencies = [ "clap_builder", "clap_derive", @@ -1636,35 +1636,35 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.9" +version = "4.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" +checksum = "85379ba512b21a328adf887e85f7742d12e96eb31f3ef077df4ffc26b506ffed" dependencies = [ "anstream", "anstyle", - "clap_lex 0.7.1", + "clap_lex 0.7.2", "strsim 0.11.1", ] [[package]] name = "clap_complete" -version = "4.5.8" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b4be9c4c4b1f30b78d8a750e0822b6a6102d97e62061c583a6c1dea2dfb33ae" +checksum = "aa3c596da3cf0983427b0df0dba359df9182c13bd5b519b585a482b0c351f4e8" dependencies = [ - "clap 4.5.9", + "clap 4.5.14", ] [[package]] name = "clap_derive" -version = "4.5.8" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -1678,9 +1678,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "clru" @@ -1690,9 +1690,9 @@ checksum = "cbd0f76e066e64fdc5631e3bb46381254deab9ef1158292f27c8c57e3bf3fe59" [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "colored" @@ -1993,7 +1993,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2017,7 +2017,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2028,7 +2028,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2118,7 +2118,7 @@ version = "9.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cd0a5c643689626bec213c4d8bd4d96acc8ffdb4ad4bb6bc16abf27d5f4b553" dependencies = [ - "asn1-rs 0.6.1", + "asn1-rs 0.6.2", "displaydoc", "nom", "num-bigint", @@ -2165,7 +2165,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2175,7 +2175,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" dependencies = [ "derive_builder_core", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2288,7 +2288,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2368,7 +2368,7 @@ dependencies = [ "starknet", "starknet-crypto 0.7.1", "thiserror", - "toml 0.8.15", + "toml 0.8.19", "tracing", "url", ] @@ -2420,7 +2420,7 @@ dependencies = [ "starknet-crypto 0.7.1", "thiserror", "tokio", - "toml 0.8.15", + "toml 0.8.19", "topological-sort", "tracing", "url", @@ -2441,9 +2441,9 @@ checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" [[package]] name = "dunce" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "dyn-clone" @@ -2553,14 +2553,14 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] name = "env_filter" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" dependencies = [ "log", "regex", @@ -2568,9 +2568,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" dependencies = [ "anstream", "anstyle", @@ -2761,9 +2761,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920" dependencies = [ "crc32fast", "miniz_oxide", @@ -2940,7 +2940,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -3023,7 +3023,7 @@ checksum = "553630feadf7b76442b0849fd25fdf89b860d933623aec9693fed19af0400c78" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -3068,9 +3068,9 @@ checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "gix" -version = "0.63.0" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984c5018adfa7a4536ade67990b3ebc6e11ab57b3d6cd9968de0947ca99b4b06" +checksum = "d78414d29fcc82329080166077e0f7689f4016551fdb334d787c3d040fe2634f" dependencies = [ "gix-actor", "gix-archive", @@ -3127,23 +3127,23 @@ dependencies = [ [[package]] name = "gix-actor" -version = "0.31.4" +version = "0.31.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b8ee65074b2bbb91d9d97c15d172ea75043aefebf9869b5b329149dc76501c" +checksum = "a0e454357e34b833cc3a00b6efbbd3dd4d18b24b9fb0c023876ec2645e8aa3f2" dependencies = [ "bstr", "gix-date", "gix-utils", "itoa", "thiserror", - "winnow 0.6.13", + "winnow 0.6.18", ] [[package]] name = "gix-archive" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04f103e42cb054d33de74d5e9de471772b94e2bcd0759264f599ae273586ff72" +checksum = "63b6bbebdf0223d1d4a69d6027e8b2482daad8eb1a8d3ec97176c7ec58e796d4" dependencies = [ "bstr", "gix-date", @@ -3154,9 +3154,9 @@ dependencies = [ [[package]] name = "gix-attributes" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eefb48f42eac136a4a0023f49a54ec31be1c7a9589ed762c45dcb9b953f7ecc8" +checksum = "e37ce99c7e81288c28b703641b6d5d119aacc45c1a6b247156e6249afa486257" dependencies = [ "bstr", "gix-glob", @@ -3189,9 +3189,9 @@ dependencies = [ [[package]] name = "gix-command" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c22e086314095c43ffe5cdc5c0922d5439da4fd726f3b0438c56147c34dc225" +checksum = "0d76867867da891cbe32021ad454e8cae90242f6afb06762e4dd0d357afd1d7b" dependencies = [ "bstr", "gix-path", @@ -3201,9 +3201,9 @@ dependencies = [ [[package]] name = "gix-commitgraph" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7b102311085da4af18823413b5176d7c500fb2272eaf391cfa8635d8bcb12c4" +checksum = "133b06f67f565836ec0c473e2116a60fb74f80b6435e21d88013ac0e3c60fc78" dependencies = [ "bstr", "gix-chunk", @@ -3215,9 +3215,9 @@ dependencies = [ [[package]] name = "gix-config" -version = "0.37.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fafe42957e11d98e354a66b6bd70aeea00faf2f62dd11164188224a507c840" +checksum = "28f53fd03d1bf09ebcc2c8654f08969439c4556e644ca925f27cf033bc43e658" dependencies = [ "bstr", "gix-config-value", @@ -3231,14 +3231,14 @@ dependencies = [ "smallvec", "thiserror", "unicode-bom", - "winnow 0.6.13", + "winnow 0.6.18", ] [[package]] name = "gix-config-value" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbd06203b1a9b33a78c88252a625031b094d9e1b647260070c25b09910c0a804" +checksum = "b328997d74dd15dc71b2773b162cb4af9a25c424105e4876e6d0686ab41c383e" dependencies = [ "bitflags 2.6.0", "bstr", @@ -3249,9 +3249,9 @@ dependencies = [ [[package]] name = "gix-credentials" -version = "0.24.2" +version = "0.24.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c70146183bd3c7119329a3c7392d1aa0e0adbe48d727f4df31828fe6d8fdaa1" +checksum = "198588f532e4d1202e04e6c3f50e4d7c060dffc66801c6f53cc246f1d234739e" dependencies = [ "bstr", "gix-command", @@ -3278,9 +3278,9 @@ dependencies = [ [[package]] name = "gix-diff" -version = "0.44.0" +version = "0.44.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b9bd8b2d07b6675a840b56a6c177d322d45fa082672b0dad8f063b25baf0a4" +checksum = "1996d5c8a305b59709467d80617c9fde48d9d75fd1f4179ea970912630886c9d" dependencies = [ "bstr", "gix-command", @@ -3298,9 +3298,9 @@ dependencies = [ [[package]] name = "gix-dir" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60c99f8c545abd63abe541d20ab6cda347de406c0a3f1c80aadc12d9b0e94974" +checksum = "0c975679aa00dd2d757bfd3ddb232e8a188c0094c3306400575a0813858b1365" dependencies = [ "bstr", "gix-discover", @@ -3318,9 +3318,9 @@ dependencies = [ [[package]] name = "gix-discover" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc27c699b63da66b50d50c00668bc0b7e90c3a382ef302865e891559935f3dbf" +checksum = "67662731cec3cb31ba3ed2463809493f76d8e5d6c6d245de8b0560438c13450e" dependencies = [ "bstr", "dunce", @@ -3358,9 +3358,9 @@ dependencies = [ [[package]] name = "gix-filter" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00ce6ea5ac8fca7adbc63c48a1b9e0492c222c386aa15f513405f1003f2f4ab2" +checksum = "e6547738da28275f4dff4e9f3a0f28509f53f94dd6bd822733c91cb306bca61a" dependencies = [ "bstr", "encoding_rs", @@ -3379,9 +3379,9 @@ dependencies = [ [[package]] name = "gix-fs" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3338ff92a2164f5209f185ec0cd316f571a72676bb01d27e22f2867ba69f77a" +checksum = "6adf99c27cdf17b1c4d77680c917e0d94d8783d4e1c73d3be0d1d63107163d7a" dependencies = [ "fastrand 2.1.0", "gix-features", @@ -3390,9 +3390,9 @@ dependencies = [ [[package]] name = "gix-glob" -version = "0.16.3" +version = "0.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a29ad0990cf02c48a7aac76ed0dbddeb5a0d070034b83675cc3bbf937eace4" +checksum = "fa7df15afa265cc8abe92813cd354d522f1ac06b29ec6dfa163ad320575cb447" dependencies = [ "bitflags 2.6.0", "bstr", @@ -3423,9 +3423,9 @@ dependencies = [ [[package]] name = "gix-ignore" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "640dbeb4f5829f9fc14d31f654a34a0350e43a24e32d551ad130d99bf01f63f1" +checksum = "5e6afb8f98e314d4e1adc822449389ada863c174b5707cedd327d67b84dba527" dependencies = [ "bstr", "gix-glob", @@ -3436,9 +3436,9 @@ dependencies = [ [[package]] name = "gix-index" -version = "0.33.0" +version = "0.33.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d8c5a5f1c58edcbc5692b174cda2703aba82ed17d7176ff4c1752eb48b1b167" +checksum = "9a9a44eb55bd84bb48f8a44980e951968ced21e171b22d115d1cdcef82a7d73f" dependencies = [ "bitflags 2.6.0", "bstr", @@ -3481,14 +3481,14 @@ checksum = "999ce923619f88194171a67fb3e6d613653b8d4d6078b529b15a765da0edcc17" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] name = "gix-mailmap" -version = "0.23.4" +version = "0.23.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cb2da346958252cbc8656529f5479830a3bc6046f3d86405c9e77f71dfdf7b2" +checksum = "ef6daca6edb6a590c7c0533f3f8e75c54663eb56ce08f46f0891db9fc6f09208" dependencies = [ "bstr", "gix-actor", @@ -3498,9 +3498,9 @@ dependencies = [ [[package]] name = "gix-negotiate" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d57dec54544d155a495e01de947da024471e1825d7d3f2724301c07a310d6184" +checksum = "9ec879fb6307bb63519ba89be0024c6f61b4b9d61f1a91fd2ce572d89fe9c224" dependencies = [ "bitflags 2.6.0", "gix-commitgraph", @@ -3528,14 +3528,14 @@ dependencies = [ "itoa", "smallvec", "thiserror", - "winnow 0.6.13", + "winnow 0.6.18", ] [[package]] name = "gix-odb" -version = "0.61.0" +version = "0.61.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e92b9790e2c919166865d0825b26cc440a387c175bed1b43a2fa99c0e9d45e98" +checksum = "20d384fe541d93d8a3bb7d5d5ef210780d6df4f50c4e684ccba32665a5e3bc9b" dependencies = [ "arc-swap", "gix-date", @@ -3553,9 +3553,9 @@ dependencies = [ [[package]] name = "gix-pack" -version = "0.51.0" +version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8da51212dbff944713edb2141ed7e002eea326b8992070374ce13a6cb610b3" +checksum = "3e0594491fffe55df94ba1c111a6566b7f56b3f8d2e1efc750e77d572f5f5229" dependencies = [ "clru", "gix-chunk", @@ -3564,9 +3564,7 @@ dependencies = [ "gix-hashtable", "gix-object", "gix-path", - "gix-tempfile", "memmap2", - "parking_lot 0.12.3", "smallvec", "thiserror", "uluru", @@ -3599,9 +3597,9 @@ dependencies = [ [[package]] name = "gix-pathspec" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76cab098dc10ba2d89f634f66bf196dea4d7db4bf10b75c7a9c201c55a2ee19" +checksum = "d307d1b8f84dc8386c4aa20ce0cf09242033840e15469a3ecba92f10cfb5c046" dependencies = [ "bitflags 2.6.0", "bstr", @@ -3614,9 +3612,9 @@ dependencies = [ [[package]] name = "gix-prompt" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fddabbc7c51c241600ab3c4623b19fa53bde7c1a2f637f61043ed5fcadf000cc" +checksum = "7e0595d2be4b6d6a71a099e989bdd610882b882da35fb8503d91d6f81aa0936f" dependencies = [ "gix-command", "gix-config-value", @@ -3638,12 +3636,11 @@ dependencies = [ [[package]] name = "gix-ref" -version = "0.44.1" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3394a2997e5bc6b22ebc1e1a87b41eeefbcfcff3dbfa7c4bd73cb0ac8f1f3e2e" +checksum = "636e96a0a5562715153fee098c217110c33a6f8218f08f4687ff99afde159bb5" dependencies = [ "gix-actor", - "gix-date", "gix-features", "gix-fs", "gix-hash", @@ -3655,14 +3652,14 @@ dependencies = [ "gix-validate", "memmap2", "thiserror", - "winnow 0.6.13", + "winnow 0.6.18", ] [[package]] name = "gix-refspec" -version = "0.23.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dde848865834a54fe4d9b4573f15d0e9a68eaf3d061b42d3ed52b4b8acf880b2" +checksum = "6868f8cd2e62555d1f7c78b784bece43ace40dd2a462daf3b588d5416e603f37" dependencies = [ "bstr", "gix-hash", @@ -3674,9 +3671,9 @@ dependencies = [ [[package]] name = "gix-revision" -version = "0.27.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63e08f8107ed1f93a83bcfbb4c38084c7cb3f6cd849793f1d5eec235f9b13b2b" +checksum = "01b13e43c2118c4b0537ddac7d0821ae0dfa90b7b8dbf20c711e153fb749adce" dependencies = [ "bstr", "gix-date", @@ -3690,9 +3687,9 @@ dependencies = [ [[package]] name = "gix-revwalk" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4181db9cfcd6d1d0fd258e91569dbb61f94cb788b441b5294dd7f1167a3e788f" +checksum = "1b030ccaab71af141f537e0225f19b9e74f25fefdba0372246b844491cab43e0" dependencies = [ "gix-commitgraph", "gix-date", @@ -3705,9 +3702,9 @@ dependencies = [ [[package]] name = "gix-sec" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fddc27984a643b20dd03e97790555804f98cf07404e0e552c0ad8133266a79a1" +checksum = "1547d26fa5693a7f34f05b4a3b59a90890972922172653bcb891ab3f09f436df" dependencies = [ "bitflags 2.6.0", "gix-path", @@ -3717,9 +3714,9 @@ dependencies = [ [[package]] name = "gix-status" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f4373d989713809554d136f51bc7da565adf45c91aa4d86ef6a79801621bfc8" +checksum = "83f7b084cb65c3d007ce6bb479755ca13d602ca3cd91c4f08d7e59904de33736" dependencies = [ "bstr", "filetime", @@ -3734,14 +3731,15 @@ dependencies = [ "gix-path", "gix-pathspec", "gix-worktree", + "portable-atomic", "thiserror", ] [[package]] name = "gix-submodule" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "921cd49924ac14b6611b22e5fb7bbba74d8780dc7ad26153304b64d1272460ac" +checksum = "0f2e0f69aa00805e39d39ec80472a7e9da20ed5d73318b27925a2cc198e854fd" dependencies = [ "bstr", "gix-config", @@ -3754,9 +3752,9 @@ dependencies = [ [[package]] name = "gix-tempfile" -version = "14.0.0" +version = "14.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b0e276cd08eb2a22e9f286a4f13a222a01be2defafa8621367515375644b99" +checksum = "006acf5a613e0b5cf095d8e4b3f48c12a60d9062aa2b2dd105afaf8344a5600c" dependencies = [ "dashmap", "gix-fs", @@ -3776,9 +3774,9 @@ checksum = "f924267408915fddcd558e3f37295cc7d6a3e50f8bd8b606cee0808c3915157e" [[package]] name = "gix-traverse" -version = "0.39.1" +version = "0.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f20cb69b63eb3e4827939f42c05b7756e3488ef49c25c412a876691d568ee2a0" +checksum = "e499a18c511e71cf4a20413b743b9f5bcf64b3d9e81e9c3c6cd399eae55a8840" dependencies = [ "bitflags 2.6.0", "gix-commitgraph", @@ -3793,9 +3791,9 @@ dependencies = [ [[package]] name = "gix-url" -version = "0.27.3" +version = "0.27.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0db829ebdca6180fbe32be7aed393591df6db4a72dbbc0b8369162390954d1cf" +checksum = "e2eb9b35bba92ea8f0b5ab406fad3cf6b87f7929aa677ff10aa042c6da621156" dependencies = [ "bstr", "gix-features", @@ -3828,9 +3826,9 @@ dependencies = [ [[package]] name = "gix-worktree" -version = "0.34.0" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53f6b7de83839274022aff92157d7505f23debf739d257984a300a35972ca94e" +checksum = "26f7326ebe0b9172220694ea69d344c536009a9b98fb0f9de092c440f3efe7a6" dependencies = [ "bstr", "gix-attributes", @@ -3847,9 +3845,9 @@ dependencies = [ [[package]] name = "gix-worktree-state" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b2835892ce553b15aef7f6f7bb1e39e146fdf71eb99609b86710a7786cf34" +checksum = "39ed6205b5f51067a485b11843babcf3304c0799e265a06eb0dde7f69cd85cd8" dependencies = [ "bstr", "gix-features", @@ -3867,9 +3865,9 @@ dependencies = [ [[package]] name = "gix-worktree-stream" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c5a4d58fa1375cd40a24c9d1a501520fcba17eea109c58c7e208b309635b46a" +checksum = "e35d4896249a41856f44571d94d7583b9f3b9cd1a75eaef4f34a4aa2981bed21" dependencies = [ "gix-attributes", "gix-features", @@ -4315,7 +4313,7 @@ dependencies = [ "http 1.1.0", "hyper 1.4.1", "hyper-util", - "rustls 0.23.11", + "rustls 0.23.12", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -4350,9 +4348,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" dependencies = [ "bytes", "futures-channel", @@ -4489,9 +4487,9 @@ dependencies = [ [[package]] name = "imara-diff" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af13c8ceb376860ff0c6a66d83a8cdd4ecd9e464da24621bbffcd02b49619434" +checksum = "fc9da1a252bd44cd341657203722352efc9bc0c847d06ea6d2dc1cd1135e0a01" dependencies = [ "ahash", "hashbrown 0.14.5", @@ -4741,9 +4739,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" @@ -4780,9 +4778,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" dependencies = [ "libc", ] @@ -4817,9 +4815,9 @@ dependencies = [ [[package]] name = "kstring" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747" +checksum = "558bf9508a558512042d3095138b1f7b8fe90c5467d94f9f1da28b3731c5dbd1" dependencies = [ "static_assertions", ] @@ -5326,7 +5324,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -5507,7 +5505,7 @@ checksum = "f8dccda732e04fa3baf2e17cf835bfe2601c7c2edafd64417c627dabae3a8cda" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -5543,9 +5541,9 @@ dependencies = [ [[package]] name = "lru" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" +checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" dependencies = [ "hashbrown 0.14.5", ] @@ -5666,13 +5664,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" dependencies = [ + "hermit-abi 0.3.9", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -6066,9 +6065,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "object" -version = "0.36.1" +version = "0.36.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" +checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" dependencies = [ "memchr", ] @@ -6088,7 +6087,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c958dd45046245b9c3c2547369bb634eb461670b2e7e0de552905801a648d1d" dependencies = [ - "asn1-rs 0.6.1", + "asn1-rs 0.6.2", ] [[package]] @@ -6111,9 +6110,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.64" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -6132,7 +6131,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -6143,9 +6142,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.102" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", @@ -6170,12 +6169,12 @@ dependencies = [ [[package]] name = "os_pipe" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d73ba8daf8fac13b0501d1abeddcfe21ba7401ada61a819144b6c2a4f32209" +checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6400,7 +6399,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -6509,9 +6508,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" [[package]] name = "powerfmt" @@ -6521,9 +6520,12 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "precomputed-hash" @@ -6558,7 +6560,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -6665,7 +6667,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -6727,7 +6729,7 @@ dependencies = [ "prost 0.12.6", "prost-types 0.12.6", "regex", - "syn 2.0.71", + "syn 2.0.72", "tempfile", ] @@ -6754,7 +6756,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -6826,7 +6828,7 @@ dependencies = [ "pin-project-lite", "quinn-proto 0.10.6", "quinn-udp 0.4.1", - "rustc-hash", + "rustc-hash 1.1.0", "rustls 0.21.12", "thiserror", "tokio", @@ -6835,16 +6837,17 @@ dependencies = [ [[package]] name = "quinn" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ceeeeabace7857413798eb1ffa1e9c905a9946a57d81fb69b4b71c4d8eb3ad" +checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" dependencies = [ "bytes", "pin-project-lite", - "quinn-proto 0.11.3", - "quinn-udp 0.5.2", - "rustc-hash", - "rustls 0.23.11", + "quinn-proto 0.11.6", + "quinn-udp 0.5.4", + "rustc-hash 2.0.0", + "rustls 0.23.12", + "socket2 0.5.7", "thiserror", "tokio", "tracing", @@ -6859,7 +6862,7 @@ dependencies = [ "bytes", "rand", "ring 0.16.20", - "rustc-hash", + "rustc-hash 1.1.0", "rustls 0.21.12", "slab", "thiserror", @@ -6869,15 +6872,15 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.3" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddf517c03a109db8100448a4be38d498df8a210a99fe0e1b9eaf39e78c640efe" +checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" dependencies = [ "bytes", "rand", "ring 0.17.8", - "rustc-hash", - "rustls 0.23.11", + "rustc-hash 2.0.0", + "rustls 0.23.12", "slab", "thiserror", "tinyvec", @@ -6899,9 +6902,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.2" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9096629c45860fc7fb143e125eb826b5e721e10be3263160c7d60ca832cf8c46" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" dependencies = [ "libc", "once_cell", @@ -7053,9 +7056,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -7173,9 +7176,9 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "quinn 0.11.2", - "rustls 0.23.11", - "rustls-pemfile 2.1.2", + "quinn 0.11.3", + "rustls 0.23.12", + "rustls-pemfile 2.1.3", "rustls-pki-types", "serde", "serde_json", @@ -7357,6 +7360,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -7434,14 +7443,14 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.11" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4828ea528154ae444e5a642dbb7d5623354030dc9822b83fd9bb79683c7399d0" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", "ring 0.17.8", "rustls-pki-types", - "rustls-webpki 0.102.5", + "rustls-webpki 0.102.6", "subtle", "zeroize", ] @@ -7469,9 +7478,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.2" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ "base64 0.22.1", "rustls-pki-types", @@ -7479,9 +7488,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" [[package]] name = "rustls-webpki" @@ -7495,9 +7504,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.102.5" +version = "0.102.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78" +checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" dependencies = [ "ring 0.17.8", "rustls-pki-types", @@ -7549,7 +7558,7 @@ dependencies = [ "log", "oorandom", "parking_lot 0.11.2", - "rustc-hash", + "rustc-hash 1.1.0", "salsa-macros", "smallvec", ] @@ -7609,7 +7618,7 @@ dependencies = [ "cairo-lang-test-plugin", "cairo-lang-utils", "camino", - "clap 4.5.9", + "clap 4.5.14", "convert_case", "create-output-dir", "data-encoding", @@ -7651,8 +7660,8 @@ dependencies = [ "tar", "thiserror", "tokio", - "toml 0.8.15", - "toml_edit 0.22.16", + "toml 0.8.19", + "toml_edit 0.22.20", "tracing", "tracing-subscriber", "typed-builder", @@ -7711,7 +7720,7 @@ source = "git+https://github.com/software-mansion/scarb?tag=v2.7.0#e9a2b8716daf7 dependencies = [ "anyhow", "camino", - "clap 4.5.9", + "clap 4.5.14", "console", "indicatif", "scarb-metadata", @@ -7751,7 +7760,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -7863,9 +7872,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.204" +version = "1.0.205" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "e33aedb1a7135da52b7c21791455563facbbcc43d0f0f66165b42c21b3dfb150" dependencies = [ "serde_derive", ] @@ -7904,13 +7913,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.205" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "692d6f5ac90220161d6774db30c662202721e64aed9058d2c394f451261420c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -7921,16 +7930,17 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -7954,14 +7964,14 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] name = "serde_spanned" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ "serde", ] @@ -8003,7 +8013,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -8029,9 +8039,9 @@ dependencies = [ [[package]] name = "sha1_smol" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" [[package]] name = "sha2" @@ -8186,7 +8196,7 @@ dependencies = [ "cairo-lang-test-plugin", "cairo-lang-utils", "camino", - "clap 4.5.9", + "clap 4.5.14", "colored", "colored_json", "console", @@ -8209,7 +8219,7 @@ dependencies = [ "starknet-crypto 0.7.1", "thiserror", "tokio", - "toml 0.8.15", + "toml 0.8.19", "tracing", "url", ] @@ -8576,7 +8586,7 @@ checksum = "2e179dedc3fa6da064e56811d3e05d446aa2f7459e4eb0e3e49378a337235437" dependencies = [ "starknet-curve 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "starknet-types-core", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -8586,7 +8596,7 @@ source = "git+https://github.com/kariy/starknet-rs?branch=dojo-patch#a8ed9226902 dependencies = [ "starknet-curve 0.5.0 (git+https://github.com/kariy/starknet-rs?branch=dojo-patch)", "starknet-types-core", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -8613,7 +8623,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4fe4f8d615329410578cbedcdbaa4a36c7f28f68c3f3ac56006cfbdaeaa2b41" dependencies = [ "starknet-core", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -8737,7 +8747,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -8787,9 +8797,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.71" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -8828,7 +8838,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -8871,14 +8881,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand 2.1.0", + "once_cell", "rustix 0.38.34", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -8924,7 +8935,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -9006,21 +9017,20 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.1" +version = "1.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df" +checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot 0.12.3", "pin-project-lite", "signal-hook-registry", "socket2 0.5.7", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -9035,13 +9045,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -9081,7 +9091,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.11", + "rustls 0.23.12", "rustls-pki-types", "tokio", ] @@ -9122,21 +9132,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.16", + "toml_edit 0.22.20", ] [[package]] name = "toml_datetime" -version = "0.6.6" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] @@ -9154,15 +9164,15 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.16" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap 2.3.0", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.13", + "winnow 0.6.18", ] [[package]] @@ -9238,7 +9248,7 @@ dependencies = [ "proc-macro2", "prost-build 0.12.6", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -9515,7 +9525,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -9610,7 +9620,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -9650,7 +9660,7 @@ checksum = "f9534daa9fd3ed0bd911d462a37f172228077e7abf18c18a5f67199d959205f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -9858,9 +9868,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "void" @@ -9935,7 +9945,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "wasm-bindgen-shared", ] @@ -9969,7 +9979,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -10002,7 +10012,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -10355,11 +10365,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -10414,6 +10424,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -10546,9 +10565,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.13" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] @@ -10618,7 +10637,7 @@ version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcbc162f30700d6f3f82a24bf7cc62ffe7caea42c0b2cba8bf7f3ae50cf51f69" dependencies = [ - "asn1-rs 0.6.1", + "asn1-rs 0.6.2", "data-encoding", "der-parser 9.0.0", "lazy_static", @@ -10642,9 +10661,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" +checksum = "539a77ee7c0de333dcc6da69b177380a0b81e0dacfa4f7344c465a36871ee601" [[package]] name = "xmltree" @@ -10672,9 +10691,9 @@ checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" [[package]] name = "xxhash-rust" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63658493314859b4dfdf3fb8c1defd61587839def09582db50b8a4e93afca6bb" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" [[package]] name = "yamux" @@ -10728,6 +10747,7 @@ version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] @@ -10739,7 +10759,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -10759,7 +10779,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -10785,18 +10805,18 @@ dependencies = [ [[package]] name = "zstd-safe" -version = "7.2.0" +version = "7.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa556e971e7b568dc775c136fc9de8c779b1c2fc3a63defaafadffdbd3181afa" +checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" dependencies = [ "zstd-sys", ] [[package]] name = "zstd-sys" -version = "2.0.12+zstd.1.5.6" +version = "2.0.13+zstd.1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e40c320c3cb459d9a9ff6de98cff88f4751ee9275d140e2be94a2b74e4c13" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" dependencies = [ "cc", "pkg-config", diff --git a/src/wasm/types.rs b/src/wasm/types.rs index fe0c886..52fe344 100644 --- a/src/wasm/types.rs +++ b/src/wasm/types.rs @@ -81,7 +81,7 @@ impl From<&Signature> for starknet::core::crypto::Signature { pub type Calls = Vec; #[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] +#[tsify(into_wasm_abi, from_wasm_abi, hashmap_as_object)] pub struct Model(pub HashMap); impl From<&Struct> for Model { @@ -97,7 +97,7 @@ impl From<&Struct> for Model { } #[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] +#[tsify(into_wasm_abi, from_wasm_abi, hashmap_as_object)] pub struct Entity(pub HashMap); impl From<&torii_grpc::types::schema::Entity> for Entity { @@ -107,7 +107,7 @@ impl From<&torii_grpc::types::schema::Entity> for Entity { } #[derive(Tsify, Serialize, Deserialize, Debug)] -#[tsify(into_wasm_abi, from_wasm_abi)] +#[tsify(into_wasm_abi, from_wasm_abi, hashmap_as_object)] pub struct Entities(pub HashMap); impl From<&Vec> for Entities { From 1df3f65c1eb667f6284ad41760163ece9061f8e0 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 15:18:32 -0400 Subject: [PATCH 5/8] feat: json compat serializer for callbacks --- src/wasm/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 6121a21..a31e9ac 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -9,6 +9,7 @@ use crypto_bigint::U256; use futures::StreamExt; use js_sys::Array; use serde::{Deserialize, Serialize}; +use serde_json::json; use starknet::accounts::{ Account as _, ConnectedAccount as _, ExecutionEncoding, SingleOwnerAccount, }; @@ -32,6 +33,9 @@ mod types; use types::{BlockId, Call, Calls, ClientConfig, Entities, KeysClauses, Model, Query, Signature}; +const JSON_COMPAT_SERIALIZER: serde_wasm_bindgen::Serializer = + serde_wasm_bindgen::Serializer::json_compatible(); + #[wasm_bindgen(js_name = typedDataEncode)] pub fn typed_data_encode(typed_data: &str, address: &str) -> Result { let typed_data = serde_json::from_str::(&typed_data) @@ -421,7 +425,7 @@ impl ToriiClient { let _ = callback.call2( &JsValue::null(), &JsValue::from_str(&format!("{:#x}", entity.hashed_keys)), - &serde_wasm_bindgen::to_value(&models).unwrap(), + &models.serialize(&JSON_COMPAT_SERIALIZER).unwrap(), ); } }); @@ -469,7 +473,7 @@ impl ToriiClient { let _ = callback.call2( &JsValue::null(), &JsValue::from_str(&format!("{:#x}", entity.hashed_keys)), - &serde_wasm_bindgen::to_value(&models).unwrap(), + &models.serialize(&JSON_COMPAT_SERIALIZER).unwrap(), ); } }); From c3bd6b37009a59cc5623731d032c693064ca1154 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 15:24:49 -0400 Subject: [PATCH 6/8] entity cast correctly --- src/wasm/mod.rs | 8 +++++--- src/wasm/types.rs | 7 +++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index a31e9ac..88e27ff 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -31,7 +31,9 @@ use crate::utils::watch_tx; mod types; -use types::{BlockId, Call, Calls, ClientConfig, Entities, KeysClauses, Model, Query, Signature}; +use types::{ + BlockId, Call, Calls, ClientConfig, Entities, Entity, KeysClauses, Model, Query, Signature, +}; const JSON_COMPAT_SERIALIZER: serde_wasm_bindgen::Serializer = serde_wasm_bindgen::Serializer::json_compatible(); @@ -420,7 +422,7 @@ impl ToriiClient { let mut stream = stream.take_until_if(tripwire); while let Some(Ok((_, entity))) = stream.next().await { - let models = entity.models.iter().map(|m| m.into()).collect::>(); + let models: Entity = (&entity).into(); let _ = callback.call2( &JsValue::null(), @@ -468,7 +470,7 @@ impl ToriiClient { let mut stream = stream.take_until_if(tripwire); while let Some(Ok((_, entity))) = stream.next().await { - let models = entity.models.iter().map(|m| m.into()).collect::>(); + let models: Entity = (&entity).into(); let _ = callback.call2( &JsValue::null(), diff --git a/src/wasm/types.rs b/src/wasm/types.rs index 52fe344..af18f81 100644 --- a/src/wasm/types.rs +++ b/src/wasm/types.rs @@ -5,11 +5,10 @@ use crypto_bigint::U256; use dojo_types::schema::Struct; use serde::{Deserialize, Serialize}; use serde_wasm_bindgen::to_value; -use starknet::core::{types::FunctionCall, utils::get_selector_from_name}; +use starknet::core::types::FunctionCall; +use starknet::core::utils::get_selector_from_name; use starknet_crypto::Felt; - -use tsify_next::declare; -use tsify_next::Tsify; +use tsify_next::{declare, Tsify}; use wasm_bindgen::prelude::*; use super::utils::parse_ty_as_json_str; From d4b7f5a2590f8e03060a7968c04b9f0eff4a3f02 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 15:28:55 -0400 Subject: [PATCH 7/8] fix: bindgen headees --- build.rs | 2 +- dojo.hpp | 1345 ++++++++++++++++++++++++++++++++++++++---------------- dojo.pyx | 488 ++++++++++++++++++++ 3 files changed, 1432 insertions(+), 403 deletions(-) create mode 100644 dojo.pyx diff --git a/build.rs b/build.rs index 72676ec..e40024f 100644 --- a/build.rs +++ b/build.rs @@ -106,7 +106,7 @@ fn main() { .with_crate(crate_dir.clone()) .generate() .expect("Unable to generate bindings") - .write_to_file("dojo.hpp"); + .write_to_file("dojo.pyx"); // NOTE: disable for now. use c2cs to generate csharp bindings // generics not supported diff --git a/dojo.hpp b/dojo.hpp index 0c33d6e..f056ac6 100644 --- a/dojo.hpp +++ b/dojo.hpp @@ -1,78 +1,110 @@ -from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t -from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t -cdef extern from *: - ctypedef bint bool - ctypedef struct va_list - -cdef extern from *: - - cdef enum BlockTag: - Latest, - Pending, - - cdef enum ComparisonOperator: - Eq, - Neq, - Gt, - Gte, - Lt, - Lte, - - cdef enum LogicalOperator: - And, - Or, - - cdef enum PatternMatching: - FixedLen # = 0, - VariableLen # = 1, - - cdef struct Account: - pass - - cdef struct Provider: - pass - - cdef struct Subscription: - pass - - cdef struct ToriiClient: - pass - - cdef struct Error: - char *message; - - cdef enum ResultToriiClient_Tag: - OkToriiClient, - ErrToriiClient, - - cdef struct ResultToriiClient: - ResultToriiClient_Tag tag; - ToriiClient *ok; - Error err; - - cdef struct FieldElement: - uint8_t data[32]; - - cdef struct CArrayu8: - uint8_t *data; - uintptr_t data_len; - - cdef enum ResultCArrayu8_Tag: - OkCArrayu8, - ErrCArrayu8, - - cdef struct ResultCArrayu8: - ResultCArrayu8_Tag tag; - CArrayu8 ok; - Error err; - - cdef struct Signature: - # The `r` value of a signature - FieldElement r; - # The `s` value of a signature - FieldElement s; - - cdef enum Primitive_Tag: +#include +#include +#include +#include +#include + +namespace dojo_bindings { + +enum class BlockTag { + Latest, + Pending, +}; + +enum class ComparisonOperator { + Eq, + Neq, + Gt, + Gte, + Lt, + Lte, +}; + +enum class LogicalOperator { + And, + Or, +}; + +enum class PatternMatching { + FixedLen = 0, + VariableLen = 1, +}; + +struct Account; + +struct Provider; + +struct Subscription; + +struct ToriiClient; + +struct Error { + char *message; +}; + +template +struct Result { + enum class Tag { + Ok, + Err, + }; + + struct Ok_Body { + T _0; + }; + + struct Err_Body { + Error _0; + }; + + Tag tag; + union { + Ok_Body ok; + Err_Body err; + }; + + static Result Ok(const T &_0) { + Result result; + ::new (&result.ok._0) (T)(_0); + result.tag = Tag::Ok; + return result; + } + + bool IsOk() const { + return tag == Tag::Ok; + } + + static Result Err(const Error &_0) { + Result result; + ::new (&result.err._0) (Error)(_0); + result.tag = Tag::Err; + return result; + } + + bool IsErr() const { + return tag == Tag::Err; + } +}; + +struct FieldElement { + uint8_t data[32]; +}; + +template +struct CArray { + T *data; + uintptr_t data_len; +}; + +struct Signature { + /// The `r` value of a signature + FieldElement r; + /// The `s` value of a signature + FieldElement s; +}; + +struct Primitive { + enum class Tag { I8, I16, I32, @@ -83,406 +115,915 @@ cdef extern from *: U32, U64, U128, +#if !defined(TARGET_POINTER_WIDTH_32) U256, +#endif +#if defined(TARGET_POINTER_WIDTH_32) U256, +#endif USize, Bool, Felt252, ClassHash, ContractAddress, - - cdef struct Primitive: - Primitive_Tag tag; - int8_t i8; - int16_t i16; - int32_t i32; - int64_t i64; - uint8_t i128[16]; - uint8_t u8; - uint16_t u16; - uint32_t u32; - uint64_t u64; - uint8_t u128[16]; - uint64_t u256[4]; - uint32_t u256[8]; - uint32_t u_size; - bool bool_; - FieldElement felt252; - FieldElement class_hash; - FieldElement contract_address; - - cdef struct EnumOption: - const char *name; - Ty *ty; - - cdef struct CArrayEnumOption: - EnumOption *data; - uintptr_t data_len; - - cdef struct Enum: - const char *name; - uint8_t option; - CArrayEnumOption options; - - cdef struct CArrayTy: - Ty *data; - uintptr_t data_len; - - cdef enum Ty_Tag: + }; + + struct I8_Body { + int8_t _0; + }; + + struct I16_Body { + int16_t _0; + }; + + struct I32_Body { + int32_t _0; + }; + + struct I64_Body { + int64_t _0; + }; + + struct I128_Body { + uint8_t _0[16]; + }; + + struct U8_Body { + uint8_t _0; + }; + + struct U16_Body { + uint16_t _0; + }; + + struct U32_Body { + uint32_t _0; + }; + + struct U64_Body { + uint64_t _0; + }; + + struct U128_Body { + uint8_t _0[16]; + }; + +#if !defined(TARGET_POINTER_WIDTH_32) + struct U256_Body { + uint64_t _0[4]; + }; +#endif + +#if defined(TARGET_POINTER_WIDTH_32) + struct U256_Body { + uint32_t _0[8]; + }; +#endif + + struct USize_Body { + uint32_t _0; + }; + + struct Bool_Body { + bool _0; + }; + + struct Felt252_Body { + FieldElement _0; + }; + + struct ClassHash_Body { + FieldElement _0; + }; + + struct ContractAddress_Body { + FieldElement _0; + }; + + Tag tag; + union { + I8_Body i8; + I16_Body i16; + I32_Body i32; + I64_Body i64; + I128_Body i128; + U8_Body u8; + U16_Body u16; + U32_Body u32; + U64_Body u64; + U128_Body u128; +#if !defined(TARGET_POINTER_WIDTH_32) + U256_Body u256; +#endif +#if defined(TARGET_POINTER_WIDTH_32) + U256_Body u256; +#endif + USize_Body u_size; + Bool_Body bool_; + Felt252_Body felt252; + ClassHash_Body class_hash; + ContractAddress_Body contract_address; + }; + + static Primitive I8(const int8_t &_0) { + Primitive result; + ::new (&result.i8._0) (int8_t)(_0); + result.tag = Tag::I8; + return result; + } + + bool IsI8() const { + return tag == Tag::I8; + } + + static Primitive I16(const int16_t &_0) { + Primitive result; + ::new (&result.i16._0) (int16_t)(_0); + result.tag = Tag::I16; + return result; + } + + bool IsI16() const { + return tag == Tag::I16; + } + + static Primitive I32(const int32_t &_0) { + Primitive result; + ::new (&result.i32._0) (int32_t)(_0); + result.tag = Tag::I32; + return result; + } + + bool IsI32() const { + return tag == Tag::I32; + } + + static Primitive I64(const int64_t &_0) { + Primitive result; + ::new (&result.i64._0) (int64_t)(_0); + result.tag = Tag::I64; + return result; + } + + bool IsI64() const { + return tag == Tag::I64; + } + + static Primitive I128(const uint8_t (&_0)[16]) { + Primitive result; + for (int i = 0; i < 16; i++) { + ::new (&result.i128._0[i]) (uint8_t)(_0[i]); + } + result.tag = Tag::I128; + return result; + } + + bool IsI128() const { + return tag == Tag::I128; + } + + static Primitive U8(const uint8_t &_0) { + Primitive result; + ::new (&result.u8._0) (uint8_t)(_0); + result.tag = Tag::U8; + return result; + } + + bool IsU8() const { + return tag == Tag::U8; + } + + static Primitive U16(const uint16_t &_0) { + Primitive result; + ::new (&result.u16._0) (uint16_t)(_0); + result.tag = Tag::U16; + return result; + } + + bool IsU16() const { + return tag == Tag::U16; + } + + static Primitive U32(const uint32_t &_0) { + Primitive result; + ::new (&result.u32._0) (uint32_t)(_0); + result.tag = Tag::U32; + return result; + } + + bool IsU32() const { + return tag == Tag::U32; + } + + static Primitive U64(const uint64_t &_0) { + Primitive result; + ::new (&result.u64._0) (uint64_t)(_0); + result.tag = Tag::U64; + return result; + } + + bool IsU64() const { + return tag == Tag::U64; + } + + static Primitive U128(const uint8_t (&_0)[16]) { + Primitive result; + for (int i = 0; i < 16; i++) { + ::new (&result.u128._0[i]) (uint8_t)(_0[i]); + } + result.tag = Tag::U128; + return result; + } + + bool IsU128() const { + return tag == Tag::U128; + } + +#if !defined(TARGET_POINTER_WIDTH_32) + static Primitive U256(const uint64_t (&_0)[4]) { + Primitive result; + for (int i = 0; i < 4; i++) { + ::new (&result.u256._0[i]) (uint64_t)(_0[i]); + } + result.tag = Tag::U256; + return result; + } + + bool IsU256() const { + return tag == Tag::U256; + } +#endif + +#if defined(TARGET_POINTER_WIDTH_32) + static Primitive U256(const uint32_t (&_0)[8]) { + Primitive result; + for (int i = 0; i < 8; i++) { + ::new (&result.u256._0[i]) (uint32_t)(_0[i]); + } + result.tag = Tag::U256; + return result; + } + + bool IsU256() const { + return tag == Tag::U256; + } +#endif + + static Primitive USize(const uint32_t &_0) { + Primitive result; + ::new (&result.u_size._0) (uint32_t)(_0); + result.tag = Tag::USize; + return result; + } + + bool IsUSize() const { + return tag == Tag::USize; + } + + static Primitive Bool(const bool &_0) { + Primitive result; + ::new (&result.bool_._0) (bool)(_0); + result.tag = Tag::Bool; + return result; + } + + bool IsBool() const { + return tag == Tag::Bool; + } + + static Primitive Felt252(const FieldElement &_0) { + Primitive result; + ::new (&result.felt252._0) (FieldElement)(_0); + result.tag = Tag::Felt252; + return result; + } + + bool IsFelt252() const { + return tag == Tag::Felt252; + } + + static Primitive ClassHash(const FieldElement &_0) { + Primitive result; + ::new (&result.class_hash._0) (FieldElement)(_0); + result.tag = Tag::ClassHash; + return result; + } + + bool IsClassHash() const { + return tag == Tag::ClassHash; + } + + static Primitive ContractAddress(const FieldElement &_0) { + Primitive result; + ::new (&result.contract_address._0) (FieldElement)(_0); + result.tag = Tag::ContractAddress; + return result; + } + + bool IsContractAddress() const { + return tag == Tag::ContractAddress; + } +}; + +struct EnumOption { + const char *name; + Ty *ty; +}; + +struct Enum { + const char *name; + uint8_t option; + CArray options; +}; + +struct Ty { + enum class Tag { Primitive_, Struct_, Enum_, Tuple_, Array_, ByteArray, - - cdef struct Ty: - Ty_Tag tag; - Primitive primitive; - Struct struct_; - Enum enum_; - CArrayTy tuple; - CArrayTy array; - const char *byte_array; - - cdef struct Member: - const char *name; - Ty *ty; - bool key; - - cdef struct CArrayMember: - Member *data; - uintptr_t data_len; - - cdef struct Struct: - const char *name; - CArrayMember children; - - cdef struct CArrayStruct: - Struct *data; - uintptr_t data_len; - - cdef struct Entity: - FieldElement hashed_keys; - CArrayStruct models; - - cdef struct CArrayEntity: - Entity *data; - uintptr_t data_len; - - cdef enum ResultCArrayEntity_Tag: - OkCArrayEntity, - ErrCArrayEntity, - - cdef struct ResultCArrayEntity: - ResultCArrayEntity_Tag tag; - CArrayEntity ok; - Error err; - - cdef enum COptionFieldElement_Tag: - SomeFieldElement, - NoneFieldElement, - - cdef struct COptionFieldElement: - COptionFieldElement_Tag tag; - FieldElement some; - - cdef struct CArrayCOptionFieldElement: - COptionFieldElement *data; - uintptr_t data_len; - - cdef struct CArrayc_char: - const char **data; - uintptr_t data_len; - - cdef struct KeysClause: - CArrayCOptionFieldElement keys; - PatternMatching pattern_matching; - CArrayc_char models; - - cdef enum ValueType_Tag: + }; + + struct Primitive__Body { + Primitive _0; + }; + + struct Struct__Body { + Struct _0; + }; + + struct Enum__Body { + Enum _0; + }; + + struct Tuple__Body { + CArray _0; + }; + + struct Array__Body { + CArray _0; + }; + + struct ByteArray_Body { + const char *_0; + }; + + Tag tag; + union { + Primitive__Body primitive; + Struct__Body struct_; + Enum__Body enum_; + Tuple__Body tuple; + Array__Body array; + ByteArray_Body byte_array; + }; + + static Ty Primitive_(const Primitive &_0) { + Ty result; + ::new (&result.primitive._0) (Primitive)(_0); + result.tag = Tag::Primitive_; + return result; + } + + bool IsPrimitive_() const { + return tag == Tag::Primitive_; + } + + static Ty Struct_(const Struct &_0) { + Ty result; + ::new (&result.struct_._0) (Struct)(_0); + result.tag = Tag::Struct_; + return result; + } + + bool IsStruct_() const { + return tag == Tag::Struct_; + } + + static Ty Enum_(const Enum &_0) { + Ty result; + ::new (&result.enum_._0) (Enum)(_0); + result.tag = Tag::Enum_; + return result; + } + + bool IsEnum_() const { + return tag == Tag::Enum_; + } + + static Ty Tuple_(const CArray &_0) { + Ty result; + ::new (&result.tuple._0) (CArray)(_0); + result.tag = Tag::Tuple_; + return result; + } + + bool IsTuple_() const { + return tag == Tag::Tuple_; + } + + static Ty Array_(const CArray &_0) { + Ty result; + ::new (&result.array._0) (CArray)(_0); + result.tag = Tag::Array_; + return result; + } + + bool IsArray_() const { + return tag == Tag::Array_; + } + + static Ty ByteArray(const char *const &_0) { + Ty result; + ::new (&result.byte_array._0) (const char*)(_0); + result.tag = Tag::ByteArray; + return result; + } + + bool IsByteArray() const { + return tag == Tag::ByteArray; + } +}; + +struct Member { + const char *name; + Ty *ty; + bool key; +}; + +struct Struct { + const char *name; + CArray children; +}; + +struct Entity { + FieldElement hashed_keys; + CArray models; +}; + +template +struct COption { + enum class Tag { + Some, + None, + }; + + struct Some_Body { + T _0; + }; + + Tag tag; + union { + Some_Body some; + }; + + static COption Some(const T &_0) { + COption result; + ::new (&result.some._0) (T)(_0); + result.tag = Tag::Some; + return result; + } + + bool IsSome() const { + return tag == Tag::Some; + } + + static COption None() { + COption result; + result.tag = Tag::None; + return result; + } + + bool IsNone() const { + return tag == Tag::None; + } +}; + +struct KeysClause { + CArray> keys; + PatternMatching pattern_matching; + CArray models; +}; + +struct ValueType { + enum class Tag { String, Int, UInt, VBool, Bytes, - - cdef struct ValueType: - ValueType_Tag tag; - const char *string; - int64_t int_; - uint64_t u_int; - bool v_bool; - CArrayu8 bytes; - - cdef struct Value: - Primitive primitive_type; - ValueType value_type; - - cdef struct MemberClause: - const char *model; - const char *member; - ComparisonOperator operator_; - Value value; - - cdef struct CArrayClause: - Clause *data; - uintptr_t data_len; - - cdef struct CompositeClause: - LogicalOperator operator_; - CArrayClause clauses; - - cdef enum Clause_Tag: + }; + + struct String_Body { + const char *_0; + }; + + struct Int_Body { + int64_t _0; + }; + + struct UInt_Body { + uint64_t _0; + }; + + struct VBool_Body { + bool _0; + }; + + struct Bytes_Body { + CArray _0; + }; + + Tag tag; + union { + String_Body string; + Int_Body int_; + UInt_Body u_int; + VBool_Body v_bool; + Bytes_Body bytes; + }; + + static ValueType String(const char *const &_0) { + ValueType result; + ::new (&result.string._0) (const char*)(_0); + result.tag = Tag::String; + return result; + } + + bool IsString() const { + return tag == Tag::String; + } + + static ValueType Int(const int64_t &_0) { + ValueType result; + ::new (&result.int_._0) (int64_t)(_0); + result.tag = Tag::Int; + return result; + } + + bool IsInt() const { + return tag == Tag::Int; + } + + static ValueType UInt(const uint64_t &_0) { + ValueType result; + ::new (&result.u_int._0) (uint64_t)(_0); + result.tag = Tag::UInt; + return result; + } + + bool IsUInt() const { + return tag == Tag::UInt; + } + + static ValueType VBool(const bool &_0) { + ValueType result; + ::new (&result.v_bool._0) (bool)(_0); + result.tag = Tag::VBool; + return result; + } + + bool IsVBool() const { + return tag == Tag::VBool; + } + + static ValueType Bytes(const CArray &_0) { + ValueType result; + ::new (&result.bytes._0) (CArray)(_0); + result.tag = Tag::Bytes; + return result; + } + + bool IsBytes() const { + return tag == Tag::Bytes; + } +}; + +struct Value { + Primitive primitive_type; + ValueType value_type; +}; + +struct MemberClause { + const char *model; + const char *member; + ComparisonOperator operator_; + Value value; +}; + +struct CompositeClause { + LogicalOperator operator_; + CArray clauses; +}; + +struct Clause { + enum class Tag { Keys, CMember, Composite, - - cdef struct Clause: - Clause_Tag tag; - KeysClause keys; - MemberClause c_member; - CompositeClause composite; - - cdef enum COptionClause_Tag: - SomeClause, - NoneClause, - - cdef struct COptionClause: - COptionClause_Tag tag; - Clause some; - - cdef struct Query: - uint32_t limit; - uint32_t offset; - COptionClause clause; - - cdef struct CArrayFieldElement: - FieldElement *data; - uintptr_t data_len; - - cdef struct ModelMetadata: - Ty schema; - const char *namespace_; - const char *name; - uint32_t packed_size; - uint32_t unpacked_size; - FieldElement class_hash; - FieldElement contract_address; - CArrayFieldElement layout; - - cdef struct CHashItemFieldElementModelMetadata: - FieldElement key; - ModelMetadata value; - - cdef struct CArrayCHashItemFieldElementModelMetadata: - CHashItemFieldElementModelMetadata *data; - uintptr_t data_len; - - cdef struct WorldMetadata: - FieldElement world_address; - FieldElement world_class_hash; - CArrayCHashItemFieldElementModelMetadata models; - - cdef enum ResultSubscription_Tag: - OkSubscription, - ErrSubscription, - - cdef struct ResultSubscription: - ResultSubscription_Tag tag; - Subscription *ok; - Error err; - - cdef enum EntityKeysClause_Tag: + }; + + struct Keys_Body { + KeysClause _0; + }; + + struct CMember_Body { + MemberClause _0; + }; + + struct Composite_Body { + CompositeClause _0; + }; + + Tag tag; + union { + Keys_Body keys; + CMember_Body c_member; + Composite_Body composite; + }; + + static Clause Keys(const KeysClause &_0) { + Clause result; + ::new (&result.keys._0) (KeysClause)(_0); + result.tag = Tag::Keys; + return result; + } + + bool IsKeys() const { + return tag == Tag::Keys; + } + + static Clause CMember(const MemberClause &_0) { + Clause result; + ::new (&result.c_member._0) (MemberClause)(_0); + result.tag = Tag::CMember; + return result; + } + + bool IsCMember() const { + return tag == Tag::CMember; + } + + static Clause Composite(const CompositeClause &_0) { + Clause result; + ::new (&result.composite._0) (CompositeClause)(_0); + result.tag = Tag::Composite; + return result; + } + + bool IsComposite() const { + return tag == Tag::Composite; + } +}; + +struct Query { + uint32_t limit; + uint32_t offset; + COption clause; +}; + +struct ModelMetadata { + Ty schema; + const char *namespace_; + const char *name; + uint32_t packed_size; + uint32_t unpacked_size; + FieldElement class_hash; + FieldElement contract_address; + CArray layout; +}; + +template +struct CHashItem { + K key; + V value; +}; + +struct WorldMetadata { + FieldElement world_address; + FieldElement world_class_hash; + CArray> models; +}; + +struct EntityKeysClause { + enum class Tag { HashedKeys, EntityKeys, - - cdef struct EntityKeysClause: - EntityKeysClause_Tag tag; - CArrayFieldElement hashed_keys; - KeysClause entity_keys; - - cdef enum Resultbool_Tag: - Okbool, - Errbool, - - cdef struct Resultbool: - Resultbool_Tag tag; - bool ok; - Error err; - - cdef enum ResultCArrayFieldElement_Tag: - OkCArrayFieldElement, - ErrCArrayFieldElement, - - cdef struct ResultCArrayFieldElement: - ResultCArrayFieldElement_Tag tag; - CArrayFieldElement ok; - Error err; - - cdef enum Resultc_char_Tag: - Okc_char, - Errc_char, - - cdef struct Resultc_char: - Resultc_char_Tag tag; - const char *ok; - Error err; - - cdef enum ResultFieldElement_Tag: - OkFieldElement, - ErrFieldElement, - - cdef struct ResultFieldElement: - ResultFieldElement_Tag tag; - FieldElement ok; - Error err; - - cdef enum ResultSignature_Tag: - OkSignature, - ErrSignature, - - cdef struct ResultSignature: - ResultSignature_Tag tag; - Signature ok; - Error err; - - cdef enum ResultProvider_Tag: - OkProvider, - ErrProvider, - - cdef struct ResultProvider: - ResultProvider_Tag tag; - Provider *ok; - Error err; - - cdef enum ResultAccount_Tag: - OkAccount, - ErrAccount, - - cdef struct ResultAccount: - ResultAccount_Tag tag; - Account *ok; - Error err; - - cdef struct Call: - FieldElement to; - const char *selector; - CArrayFieldElement calldata; - - # Block hash, number or tag - cdef enum BlockId_Tag: + }; + + struct HashedKeys_Body { + CArray _0; + }; + + struct EntityKeys_Body { + KeysClause _0; + }; + + Tag tag; + union { + HashedKeys_Body hashed_keys; + EntityKeys_Body entity_keys; + }; + + static EntityKeysClause HashedKeys(const CArray &_0) { + EntityKeysClause result; + ::new (&result.hashed_keys._0) (CArray)(_0); + result.tag = Tag::HashedKeys; + return result; + } + + bool IsHashedKeys() const { + return tag == Tag::HashedKeys; + } + + static EntityKeysClause EntityKeys(const KeysClause &_0) { + EntityKeysClause result; + ::new (&result.entity_keys._0) (KeysClause)(_0); + result.tag = Tag::EntityKeys; + return result; + } + + bool IsEntityKeys() const { + return tag == Tag::EntityKeys; + } +}; + +struct Call { + FieldElement to; + const char *selector; + CArray calldata; +}; + +/// Block hash, number or tag +struct BlockId { + enum class Tag { Hash, Number, BlockTag_, + }; + + struct Hash_Body { + FieldElement _0; + }; + + struct Number_Body { + uint64_t _0; + }; + + struct BlockTag__Body { + BlockTag _0; + }; + + Tag tag; + union { + Hash_Body hash; + Number_Body number; + BlockTag__Body block_tag; + }; + + static BlockId Hash(const FieldElement &_0) { + BlockId result; + ::new (&result.hash._0) (FieldElement)(_0); + result.tag = Tag::Hash; + return result; + } + + bool IsHash() const { + return tag == Tag::Hash; + } + + static BlockId Number(const uint64_t &_0) { + BlockId result; + ::new (&result.number._0) (uint64_t)(_0); + result.tag = Tag::Number; + return result; + } - cdef struct BlockId: - BlockId_Tag tag; - FieldElement hash; - uint64_t number; - BlockTag block_tag; + bool IsNumber() const { + return tag == Tag::Number; + } - ResultToriiClient client_new(const char *torii_url, - const char *rpc_url, - const char *libp2p_relay_url, - FieldElement world); + static BlockId BlockTag_(const BlockTag &_0) { + BlockId result; + ::new (&result.block_tag._0) (BlockTag)(_0); + result.tag = Tag::BlockTag_; + return result; + } - void client_set_logger(ToriiClient *client, void (*logger)(const char*)); + bool IsBlockTag_() const { + return tag == Tag::BlockTag_; + } +}; - ResultCArrayu8 client_publish_message(ToriiClient *client, - const char *message, - Signature signature); +extern "C" { - ResultCArrayEntity client_entities(ToriiClient *client, const Query *query); +Result client_new(const char *torii_url, + const char *rpc_url, + const char *libp2p_relay_url, + FieldElement world); - ResultCArrayEntity client_event_messages(ToriiClient *client, const Query *query); +void client_set_logger(ToriiClient *client, void (*logger)(const char*)); - WorldMetadata client_metadata(ToriiClient *client); +Result> client_publish_message(ToriiClient *client, + const char *message, + Signature signature); - ResultSubscription client_on_entity_state_update(ToriiClient *client, - const EntityKeysClause *clauses, - uintptr_t clauses_len, - void (*callback)(FieldElement, CArrayStruct)); +Result> client_entities(ToriiClient *client, const Query *query); - Resultbool client_update_entity_subscription(ToriiClient *client, +Result> client_event_messages(ToriiClient *client, const Query *query); + +WorldMetadata client_metadata(ToriiClient *client); + +Result client_on_entity_state_update(ToriiClient *client, + const EntityKeysClause *clauses, + uintptr_t clauses_len, + void (*callback)(FieldElement, CArray)); + +Result client_update_entity_subscription(ToriiClient *client, Subscription *subscription, const EntityKeysClause *clauses, uintptr_t clauses_len); - ResultSubscription client_on_event_message_update(ToriiClient *client, - const EntityKeysClause *clauses, - uintptr_t clauses_len, - void (*callback)(FieldElement, CArrayStruct)); +Result client_on_event_message_update(ToriiClient *client, + const EntityKeysClause *clauses, + uintptr_t clauses_len, + void (*callback)(FieldElement, CArray)); - Resultbool client_update_event_message_subscription(ToriiClient *client, +Result client_update_event_message_subscription(ToriiClient *client, Subscription *subscription, const EntityKeysClause *clauses, uintptr_t clauses_len); - ResultCArrayFieldElement bytearray_serialize(const char *str); +Result> bytearray_serialize(const char *str); - Resultc_char bytearray_deserialize(const FieldElement *felts, uintptr_t felts_len); +Result bytearray_deserialize(const FieldElement *felts, uintptr_t felts_len); - FieldElement poseidon_hash(const FieldElement *felts, uintptr_t felts_len); +FieldElement poseidon_hash(const FieldElement *felts, uintptr_t felts_len); - ResultFieldElement typed_data_encode(const char *typed_data, FieldElement address); +Result typed_data_encode(const char *typed_data, FieldElement address); - FieldElement signing_key_new(); +FieldElement signing_key_new(); - ResultSignature signing_key_sign(FieldElement private_key, FieldElement hash); +Result signing_key_sign(FieldElement private_key, FieldElement hash); - FieldElement verifying_key_new(FieldElement signing_key); +FieldElement verifying_key_new(FieldElement signing_key); - Resultbool verifying_key_verify(FieldElement verifying_key, +Result verifying_key_verify(FieldElement verifying_key, FieldElement hash, Signature signature); - ResultProvider provider_new(const char *rpc_url); +Result provider_new(const char *rpc_url); - ResultAccount account_new(Provider *rpc, FieldElement private_key, const char *address); +Result account_new(Provider *rpc, FieldElement private_key, const char *address); - ResultCArrayFieldElement starknet_call(Provider *provider, Call call, BlockId block_id); +Result> starknet_call(Provider *provider, Call call, BlockId block_id); - ResultAccount account_deploy_burner(Provider *provider, - Account *master_account, - FieldElement signing_key); +Result account_deploy_burner(Provider *provider, + Account *master_account, + FieldElement signing_key); - FieldElement account_address(Account *account); +FieldElement account_address(Account *account); - FieldElement account_chain_id(Account *account); +FieldElement account_chain_id(Account *account); - void account_set_block_id(Account *account, BlockId block_id); +void account_set_block_id(Account *account, BlockId block_id); - ResultFieldElement account_execute_raw(Account *account, +Result account_execute_raw(Account *account, const Call *calldata, uintptr_t calldata_len); - Resultbool wait_for_transaction(Provider *rpc, FieldElement txn_hash); +Result wait_for_transaction(Provider *rpc, FieldElement txn_hash); + +FieldElement hash_get_contract_address(FieldElement class_hash, + FieldElement salt, + const FieldElement *constructor_calldata, + uintptr_t constructor_calldata_len, + FieldElement deployer_address); + +void subscription_cancel(Subscription *subscription); - FieldElement hash_get_contract_address(FieldElement class_hash, - FieldElement salt, - const FieldElement *constructor_calldata, - uintptr_t constructor_calldata_len, - FieldElement deployer_address); +void client_free(ToriiClient *t); - void subscription_cancel(Subscription *subscription); +void provider_free(Provider *rpc); - void client_free(ToriiClient *t); +void model_free(Struct *model); - void provider_free(Provider *rpc); +void account_free(Account *account); - void model_free(Struct *model); +void ty_free(Ty *ty); - void account_free(Account *account); +void entity_free(Entity *entity); - void ty_free(Ty *ty); +void error_free(Error *error); - void entity_free(Entity *entity); +void world_metadata_free(WorldMetadata *metadata); - void error_free(Error *error); +void carray_free(void *data, uintptr_t data_len); - void world_metadata_free(WorldMetadata *metadata); +void string_free(char *string); - void carray_free(void *data, uintptr_t data_len); +} // extern "C" - void string_free(char *string); +} // namespace dojo_bindings diff --git a/dojo.pyx b/dojo.pyx new file mode 100644 index 0000000..0c33d6e --- /dev/null +++ b/dojo.pyx @@ -0,0 +1,488 @@ +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t +cdef extern from *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef enum BlockTag: + Latest, + Pending, + + cdef enum ComparisonOperator: + Eq, + Neq, + Gt, + Gte, + Lt, + Lte, + + cdef enum LogicalOperator: + And, + Or, + + cdef enum PatternMatching: + FixedLen # = 0, + VariableLen # = 1, + + cdef struct Account: + pass + + cdef struct Provider: + pass + + cdef struct Subscription: + pass + + cdef struct ToriiClient: + pass + + cdef struct Error: + char *message; + + cdef enum ResultToriiClient_Tag: + OkToriiClient, + ErrToriiClient, + + cdef struct ResultToriiClient: + ResultToriiClient_Tag tag; + ToriiClient *ok; + Error err; + + cdef struct FieldElement: + uint8_t data[32]; + + cdef struct CArrayu8: + uint8_t *data; + uintptr_t data_len; + + cdef enum ResultCArrayu8_Tag: + OkCArrayu8, + ErrCArrayu8, + + cdef struct ResultCArrayu8: + ResultCArrayu8_Tag tag; + CArrayu8 ok; + Error err; + + cdef struct Signature: + # The `r` value of a signature + FieldElement r; + # The `s` value of a signature + FieldElement s; + + cdef enum Primitive_Tag: + I8, + I16, + I32, + I64, + I128, + U8, + U16, + U32, + U64, + U128, + U256, + U256, + USize, + Bool, + Felt252, + ClassHash, + ContractAddress, + + cdef struct Primitive: + Primitive_Tag tag; + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + uint8_t i128[16]; + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + uint8_t u128[16]; + uint64_t u256[4]; + uint32_t u256[8]; + uint32_t u_size; + bool bool_; + FieldElement felt252; + FieldElement class_hash; + FieldElement contract_address; + + cdef struct EnumOption: + const char *name; + Ty *ty; + + cdef struct CArrayEnumOption: + EnumOption *data; + uintptr_t data_len; + + cdef struct Enum: + const char *name; + uint8_t option; + CArrayEnumOption options; + + cdef struct CArrayTy: + Ty *data; + uintptr_t data_len; + + cdef enum Ty_Tag: + Primitive_, + Struct_, + Enum_, + Tuple_, + Array_, + ByteArray, + + cdef struct Ty: + Ty_Tag tag; + Primitive primitive; + Struct struct_; + Enum enum_; + CArrayTy tuple; + CArrayTy array; + const char *byte_array; + + cdef struct Member: + const char *name; + Ty *ty; + bool key; + + cdef struct CArrayMember: + Member *data; + uintptr_t data_len; + + cdef struct Struct: + const char *name; + CArrayMember children; + + cdef struct CArrayStruct: + Struct *data; + uintptr_t data_len; + + cdef struct Entity: + FieldElement hashed_keys; + CArrayStruct models; + + cdef struct CArrayEntity: + Entity *data; + uintptr_t data_len; + + cdef enum ResultCArrayEntity_Tag: + OkCArrayEntity, + ErrCArrayEntity, + + cdef struct ResultCArrayEntity: + ResultCArrayEntity_Tag tag; + CArrayEntity ok; + Error err; + + cdef enum COptionFieldElement_Tag: + SomeFieldElement, + NoneFieldElement, + + cdef struct COptionFieldElement: + COptionFieldElement_Tag tag; + FieldElement some; + + cdef struct CArrayCOptionFieldElement: + COptionFieldElement *data; + uintptr_t data_len; + + cdef struct CArrayc_char: + const char **data; + uintptr_t data_len; + + cdef struct KeysClause: + CArrayCOptionFieldElement keys; + PatternMatching pattern_matching; + CArrayc_char models; + + cdef enum ValueType_Tag: + String, + Int, + UInt, + VBool, + Bytes, + + cdef struct ValueType: + ValueType_Tag tag; + const char *string; + int64_t int_; + uint64_t u_int; + bool v_bool; + CArrayu8 bytes; + + cdef struct Value: + Primitive primitive_type; + ValueType value_type; + + cdef struct MemberClause: + const char *model; + const char *member; + ComparisonOperator operator_; + Value value; + + cdef struct CArrayClause: + Clause *data; + uintptr_t data_len; + + cdef struct CompositeClause: + LogicalOperator operator_; + CArrayClause clauses; + + cdef enum Clause_Tag: + Keys, + CMember, + Composite, + + cdef struct Clause: + Clause_Tag tag; + KeysClause keys; + MemberClause c_member; + CompositeClause composite; + + cdef enum COptionClause_Tag: + SomeClause, + NoneClause, + + cdef struct COptionClause: + COptionClause_Tag tag; + Clause some; + + cdef struct Query: + uint32_t limit; + uint32_t offset; + COptionClause clause; + + cdef struct CArrayFieldElement: + FieldElement *data; + uintptr_t data_len; + + cdef struct ModelMetadata: + Ty schema; + const char *namespace_; + const char *name; + uint32_t packed_size; + uint32_t unpacked_size; + FieldElement class_hash; + FieldElement contract_address; + CArrayFieldElement layout; + + cdef struct CHashItemFieldElementModelMetadata: + FieldElement key; + ModelMetadata value; + + cdef struct CArrayCHashItemFieldElementModelMetadata: + CHashItemFieldElementModelMetadata *data; + uintptr_t data_len; + + cdef struct WorldMetadata: + FieldElement world_address; + FieldElement world_class_hash; + CArrayCHashItemFieldElementModelMetadata models; + + cdef enum ResultSubscription_Tag: + OkSubscription, + ErrSubscription, + + cdef struct ResultSubscription: + ResultSubscription_Tag tag; + Subscription *ok; + Error err; + + cdef enum EntityKeysClause_Tag: + HashedKeys, + EntityKeys, + + cdef struct EntityKeysClause: + EntityKeysClause_Tag tag; + CArrayFieldElement hashed_keys; + KeysClause entity_keys; + + cdef enum Resultbool_Tag: + Okbool, + Errbool, + + cdef struct Resultbool: + Resultbool_Tag tag; + bool ok; + Error err; + + cdef enum ResultCArrayFieldElement_Tag: + OkCArrayFieldElement, + ErrCArrayFieldElement, + + cdef struct ResultCArrayFieldElement: + ResultCArrayFieldElement_Tag tag; + CArrayFieldElement ok; + Error err; + + cdef enum Resultc_char_Tag: + Okc_char, + Errc_char, + + cdef struct Resultc_char: + Resultc_char_Tag tag; + const char *ok; + Error err; + + cdef enum ResultFieldElement_Tag: + OkFieldElement, + ErrFieldElement, + + cdef struct ResultFieldElement: + ResultFieldElement_Tag tag; + FieldElement ok; + Error err; + + cdef enum ResultSignature_Tag: + OkSignature, + ErrSignature, + + cdef struct ResultSignature: + ResultSignature_Tag tag; + Signature ok; + Error err; + + cdef enum ResultProvider_Tag: + OkProvider, + ErrProvider, + + cdef struct ResultProvider: + ResultProvider_Tag tag; + Provider *ok; + Error err; + + cdef enum ResultAccount_Tag: + OkAccount, + ErrAccount, + + cdef struct ResultAccount: + ResultAccount_Tag tag; + Account *ok; + Error err; + + cdef struct Call: + FieldElement to; + const char *selector; + CArrayFieldElement calldata; + + # Block hash, number or tag + cdef enum BlockId_Tag: + Hash, + Number, + BlockTag_, + + cdef struct BlockId: + BlockId_Tag tag; + FieldElement hash; + uint64_t number; + BlockTag block_tag; + + ResultToriiClient client_new(const char *torii_url, + const char *rpc_url, + const char *libp2p_relay_url, + FieldElement world); + + void client_set_logger(ToriiClient *client, void (*logger)(const char*)); + + ResultCArrayu8 client_publish_message(ToriiClient *client, + const char *message, + Signature signature); + + ResultCArrayEntity client_entities(ToriiClient *client, const Query *query); + + ResultCArrayEntity client_event_messages(ToriiClient *client, const Query *query); + + WorldMetadata client_metadata(ToriiClient *client); + + ResultSubscription client_on_entity_state_update(ToriiClient *client, + const EntityKeysClause *clauses, + uintptr_t clauses_len, + void (*callback)(FieldElement, CArrayStruct)); + + Resultbool client_update_entity_subscription(ToriiClient *client, + Subscription *subscription, + const EntityKeysClause *clauses, + uintptr_t clauses_len); + + ResultSubscription client_on_event_message_update(ToriiClient *client, + const EntityKeysClause *clauses, + uintptr_t clauses_len, + void (*callback)(FieldElement, CArrayStruct)); + + Resultbool client_update_event_message_subscription(ToriiClient *client, + Subscription *subscription, + const EntityKeysClause *clauses, + uintptr_t clauses_len); + + ResultCArrayFieldElement bytearray_serialize(const char *str); + + Resultc_char bytearray_deserialize(const FieldElement *felts, uintptr_t felts_len); + + FieldElement poseidon_hash(const FieldElement *felts, uintptr_t felts_len); + + ResultFieldElement typed_data_encode(const char *typed_data, FieldElement address); + + FieldElement signing_key_new(); + + ResultSignature signing_key_sign(FieldElement private_key, FieldElement hash); + + FieldElement verifying_key_new(FieldElement signing_key); + + Resultbool verifying_key_verify(FieldElement verifying_key, + FieldElement hash, + Signature signature); + + ResultProvider provider_new(const char *rpc_url); + + ResultAccount account_new(Provider *rpc, FieldElement private_key, const char *address); + + ResultCArrayFieldElement starknet_call(Provider *provider, Call call, BlockId block_id); + + ResultAccount account_deploy_burner(Provider *provider, + Account *master_account, + FieldElement signing_key); + + FieldElement account_address(Account *account); + + FieldElement account_chain_id(Account *account); + + void account_set_block_id(Account *account, BlockId block_id); + + ResultFieldElement account_execute_raw(Account *account, + const Call *calldata, + uintptr_t calldata_len); + + Resultbool wait_for_transaction(Provider *rpc, FieldElement txn_hash); + + FieldElement hash_get_contract_address(FieldElement class_hash, + FieldElement salt, + const FieldElement *constructor_calldata, + uintptr_t constructor_calldata_len, + FieldElement deployer_address); + + void subscription_cancel(Subscription *subscription); + + void client_free(ToriiClient *t); + + void provider_free(Provider *rpc); + + void model_free(Struct *model); + + void account_free(Account *account); + + void ty_free(Ty *ty); + + void entity_free(Entity *entity); + + void error_free(Error *error); + + void world_metadata_free(WorldMetadata *metadata); + + void carray_free(void *data, uintptr_t data_len); + + void string_free(char *string); From 5567807049b0107baf836c06666990dc596a1158 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 15:29:32 -0400 Subject: [PATCH 8/8] chore; wasm target --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c4f8499..b1789e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.3.0" } # WASM -# [target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(target_arch = "wasm32")'.dependencies] serde-wasm-bindgen = "0.6.3" wasm-bindgen-futures = "0.4.39" js-sys = "0.3.66" diff --git a/src/lib.rs b/src/lib.rs index 61ff93e..fd7abea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,6 @@ mod utils; #[cfg(not(target_arch = "wasm32"))] mod c; -// #[cfg(target_arch = "wasm32")] +#[cfg(target_arch = "wasm32")] /// cbindgen:ignore mod wasm;