From 97989e4170fb5b91166cdf2661ad447b0083a8ff Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 8 Aug 2024 16:42:28 -0400 Subject: [PATCH] feat: add get nonce to wasm --- dojo.pyx | 10 ++++++++++ src/wasm/mod.rs | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/dojo.pyx b/dojo.pyx index 0c33d6e..55472ee 100644 --- a/dojo.pyx +++ b/dojo.pyx @@ -425,6 +425,14 @@ cdef extern from *: FieldElement poseidon_hash(const FieldElement *felts, uintptr_t felts_len); + ResultFieldElement get_selector_from_name(const char *name); + + FieldElement starknet_keccak(const uint8_t *bytes, uintptr_t bytes_len); + + ResultFieldElement cairo_short_string_to_felt(const char *str); + + Resultc_char parse_cairo_short_string(FieldElement felt); + ResultFieldElement typed_data_encode(const char *typed_data, FieldElement address); FieldElement signing_key_new(); @@ -453,6 +461,8 @@ cdef extern from *: void account_set_block_id(Account *account, BlockId block_id); + ResultFieldElement account_nonce(Account *account); + ResultFieldElement account_execute_raw(Account *account, const Call *calldata, uintptr_t calldata_len); diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 75427a6..bc6abe1 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -287,6 +287,12 @@ impl Account { Result::Ok(Account(account)) } + + #[wasm_bindgen(js_name = nonce)] + pub async unsafe fn nonce(&self) -> Result { + let nonce = self.0.get_nonce().await.map_err(|e| JsValue::from(e.to_string()))?; + Ok(format!("{:#x}", nonce)) + } } #[wasm_bindgen(js_name = hashGetContractAddress)]