From d83fe5270a94f029303c8bc7648bab5af970a38c Mon Sep 17 00:00:00 2001 From: bexan Date: Fri, 9 Aug 2024 13:48:14 +0200 Subject: [PATCH] fix(fmt): apply cargo fmt --- Cargo.lock | 7 ++ bin/solis/Cargo.toml | 1 + bin/solis/src/args.rs | 5 +- bin/solis/src/contracts/account.rs | 13 +- bin/solis/src/hooker.rs | 59 +++------ bin/solis/src/main.rs | 22 ++-- crates/dojo-lang/src/plugin.rs | 12 +- crates/dojo-world/src/metadata_test.rs | 25 ++-- crates/katana/core/src/lib.rs | 2 +- .../core/src/service/messaging/starknet.rs | 26 ++-- .../src/implementation/blockifier/state.rs | 6 +- crates/katana/executor/tests/executor.rs | 6 +- crates/katana/primitives/src/genesis/json.rs | 10 +- crates/katana/rpc/rpc-api/src/lib.rs | 2 +- crates/katana/rpc/rpc-api/src/torii.rs | 2 +- crates/katana/rpc/rpc-types/src/error/mod.rs | 2 +- crates/katana/rpc/rpc/src/solis.rs | 2 +- crates/katana/rpc/rpc/src/starknet.rs | 9 +- crates/katana/runner/runner-macro/src/lib.rs | 6 +- crates/katana/runner/src/lib.rs | 6 +- crates/katana/storage/db/src/mdbx/cursor.rs | 6 +- .../provider/src/providers/db/state.rs | 6 +- .../storage/provider/src/traits/contract.rs | 2 +- .../storage/provider/src/traits/state.rs | 2 +- crates/sozo/ops/src/tests/call.rs | 114 +++++++++--------- crates/sozo/ops/src/tests/migration.rs | 18 ++- crates/torii/client/src/client/storage.rs | 8 +- .../torii/client/src/client/subscription.rs | 6 +- crates/torii/graphql/src/object/entity.rs | 12 +- crates/torii/graphql/src/object/event.rs | 12 +- .../torii/graphql/src/object/event_message.rs | 54 ++++----- crates/torii/graphql/src/object/model.rs | 12 +- crates/torii/libp2p/src/typed_data.rs | 6 +- 33 files changed, 244 insertions(+), 237 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f0bcd44a0..ace78f9245 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3863,6 +3863,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dotenvy" version = "0.15.7" @@ -11403,6 +11409,7 @@ dependencies = [ "common", "console", "dojo-metrics", + "dotenv", "katana-core", "katana-executor", "katana-primitives", diff --git a/bin/solis/Cargo.toml b/bin/solis/Cargo.toml index 5b8debb1c2..0a0c5a07d9 100644 --- a/bin/solis/Cargo.toml +++ b/bin/solis/Cargo.toml @@ -19,6 +19,7 @@ clap_complete.workspace = true common.workspace = true console.workspace = true dojo-metrics.workspace = true +dotenv = "0.15.0" katana-core.workspace = true katana-executor.workspace = true katana-primitives.workspace = true diff --git a/bin/solis/src/args.rs b/bin/solis/src/args.rs index f2fb8b6b01..cb31691377 100644 --- a/bin/solis/src/args.rs +++ b/bin/solis/src/args.rs @@ -9,7 +9,7 @@ //! and leak detection functionality. See [jemalloc's opt.prof](https://jemalloc.net/jemalloc.3.html#opt.prof) //! documentation for usage details. This is **not recommended on Windows**. See [here](https://rust-lang.github.io/rfcs/1974-global-allocators.html#jemalloc) //! for more info. - +use std::env; use std::net::SocketAddr; use std::path::PathBuf; @@ -230,7 +230,8 @@ impl KatanaArgs { } pub fn server_config(&self) -> ServerConfig { - let mut apis = vec![ApiKind::Starknet, ApiKind::Katana, ApiKind::Torii, ApiKind::Saya, ApiKind::Solis]; + let mut apis = + vec![ApiKind::Starknet, ApiKind::Katana, ApiKind::Torii, ApiKind::Saya, ApiKind::Solis]; // only enable `katana` API in dev mode if self.dev { apis.push(ApiKind::Dev); diff --git a/bin/solis/src/contracts/account.rs b/bin/solis/src/contracts/account.rs index f19a7d9c6c..ec17fb5d46 100644 --- a/bin/solis/src/contracts/account.rs +++ b/bin/solis/src/contracts/account.rs @@ -25,18 +25,9 @@ pub async fn new_account( AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc_url.clone()))); // TODO: need error instead of expect. - let chain_id = provider - .chain_id() - .await - .expect("couldn't get chain_id from provider"); + let chain_id = provider.chain_id().await.expect("couldn't get chain_id from provider"); let signer = LocalWallet::from(SigningKey::from_secret_scalar(private_key)); - SingleOwnerAccount::new( - provider, - signer, - account_address, - chain_id, - ExecutionEncoding::Legacy, - ) + SingleOwnerAccount::new(provider, signer, account_address, chain_id, ExecutionEncoding::Legacy) } diff --git a/bin/solis/src/hooker.rs b/bin/solis/src/hooker.rs index 4068940884..d64ca57806 100644 --- a/bin/solis/src/hooker.rs +++ b/bin/solis/src/hooker.rs @@ -12,24 +12,22 @@ use katana_primitives::chain::ChainId; use katana_primitives::contract::ContractAddress; use katana_primitives::transaction::{ExecutableTx, ExecutableTxWithHash, L1HandlerTx}; use katana_primitives::utils::transaction::compute_l1_message_hash; +use serde_json::json; +use serde_json::Value; use starknet::accounts::Call; use starknet::core::types::BroadcastedInvokeTransaction; use starknet::core::types::FieldElement; use starknet::macros::selector; use starknet::providers::Provider; -use std::sync::Arc; use std::fs::File; use std::fs::OpenOptions; -use std::io::Write; use std::io::Read; -use serde_json::Value; +use std::io::Write; use std::path::Path; -use serde_json::json; - +use std::sync::Arc; const FILE_PATH_ADDRESSES: &str = "addresses.json"; - use crate::contracts::orderbook::{OrderV1, RouteType}; use crate::contracts::starknet_utils::StarknetUtilsReader; use crate::CHAIN_ID_SOLIS; @@ -92,10 +90,7 @@ impl ); // check the current owner of the token. - let owner = sn_utils_reader_nft_address - .ownerOf(&ownership_verifier.token_id) - .call() - .await; + let owner = sn_utils_reader_nft_address.ownerOf(&ownership_verifier.token_id).call().await; if let Ok(owner_address) = owner { if owner_address != ownership_verifier.current_owner { @@ -145,10 +140,8 @@ impl } // check the balance - let balance = sn_utils_reader_erc20_address - .balanceOf(&balance_verifier.offerer) - .call() - .await; + let balance = + sn_utils_reader_erc20_address.balanceOf(&balance_verifier.offerer).call().await; if let Ok(balance) = balance { if balance < balance_verifier.start_amount { tracing::trace!( @@ -179,10 +172,7 @@ impl // ERC721 to ERC20 if order.route == RouteType::Erc721ToErc20 { let token_id = order.token_id.clone().unwrap(); - let n_token_id = U256 { - low: token_id.low, - high: token_id.high, - }; + let n_token_id = U256 { low: token_id.low, high: token_id.high }; let verifier = OwnershipVerifier { token_address: ContractAddress(order.token_address.into()), @@ -220,7 +210,8 @@ impl impl SolisHooker { - fn get_addresses_from_file() -> Result<(FieldElement, FieldElement), Box> { + fn get_addresses_from_file() -> Result<(FieldElement, FieldElement), Box> + { let mut file = match File::open(FILE_PATH_ADDRESSES) { Ok(file) => file, Err(_) => return Err("File not found".into()), @@ -264,7 +255,9 @@ impl orderbook_address: FieldElement, sn_executor_address: FieldElement, ) -> Self { - let (orderbook_address, sn_executor_address) = if orderbook_address == FieldElement::ZERO && sn_executor_address == FieldElement::ZERO { + let (orderbook_address, sn_executor_address) = if orderbook_address == FieldElement::ZERO + && sn_executor_address == FieldElement::ZERO + { match Self::get_addresses_from_file() { Ok((orderbook, executor)) => (orderbook, executor), Err(e) => { @@ -276,12 +269,7 @@ impl (orderbook_address, sn_executor_address) }; - Self { - orderbook_address, - sn_utils_reader, - sn_executor_address, - sequencer: None, - } + Self { orderbook_address, sn_utils_reader, sn_executor_address, sequencer: None } } /// Retrieves a reference to the sequencer. @@ -289,9 +277,7 @@ impl pub fn sequencer_ref(&self) -> &Arc> { // The expect is used here as it must always be set by Katana core. // If not set, the merge on Katana may be revised. - self.sequencer - .as_ref() - .expect("Sequencer must be set to get a reference to it") + self.sequencer.as_ref().expect("Sequencer must be set to get a reference to it") } /// Adds a `L1HandlerTransaction` to the transaction pool that is directed to the @@ -369,10 +355,7 @@ impl self.sn_executor_address = addresses.executor_starknet; let path = Path::new(FILE_PATH_ADDRESSES); - let file = OpenOptions::new() - .write(true) - .create(true) - .open(&path); + let file = OpenOptions::new().write(true).create(true).open(&path); match file { Ok(mut file) => { @@ -418,19 +401,13 @@ impl &self, transaction: BroadcastedInvokeTransaction, ) -> bool { - info!( - "HOOKER: verify_invoke_tx_before_pool called with transaction: {:?}", - transaction - ); + info!("HOOKER: verify_invoke_tx_before_pool called with transaction: {:?}", transaction); let calldata = match transaction { BroadcastedInvokeTransaction::V1(v1_transaction) => v1_transaction.calldata, BroadcastedInvokeTransaction::V3(v3_transaction) => v3_transaction.calldata, }; - info!( - "HOOKER: cairo_deserialize called with transaction: {:?}", - calldata - ); + info!("HOOKER: cairo_deserialize called with transaction: {:?}", calldata); let calls = match Vec::::cairo_deserialize(&calldata, 0) { Ok(calls) => calls, diff --git a/bin/solis/src/main.rs b/bin/solis/src/main.rs index ce806b1e34..7ae9c8f89b 100644 --- a/bin/solis/src/main.rs +++ b/bin/solis/src/main.rs @@ -24,9 +24,9 @@ use tokio::sync::RwLock as AsyncRwLock; use tracing::info; mod args; -mod utils; -mod hooker; mod contracts; +mod hooker; +mod utils; // Chain ID: 'SOLIS' cairo short string. pub const CHAIN_ID_SOLIS: FieldElement = FieldElement::from_mont([ @@ -116,17 +116,19 @@ async fn main() -> Result<(), Box> { let executor_address = FieldElement::ZERO; let orderbook_address = FieldElement::ZERO; - let hooker:Arc + Send + Sync>> = - Arc::new(AsyncRwLock::new(SolisHooker::new( - sn_utils_reader, - orderbook_address, - executor_address, - ))); + let hooker: Arc + Send + Sync>> = Arc::new( + AsyncRwLock::new(SolisHooker::new(sn_utils_reader, orderbook_address, executor_address)), + ); // ** let sequencer = Arc::new( - KatanaSequencer::new(executor_factory, sequencer_config, starknet_config, Some(hooker.clone())) - .await?, + KatanaSequencer::new( + executor_factory, + sequencer_config, + starknet_config, + Some(hooker.clone()), + ) + .await?, ); let NodeHandle { addr, handle, .. } = spawn(Arc::clone(&sequencer), server_config).await?; diff --git a/crates/dojo-lang/src/plugin.rs b/crates/dojo-lang/src/plugin.rs index 9341807f78..af884f2a37 100644 --- a/crates/dojo-lang/src/plugin.rs +++ b/crates/dojo-lang/src/plugin.rs @@ -70,7 +70,11 @@ impl GeneratedFileAuxData for DojoAuxData { self } fn eq(&self, other: &dyn GeneratedFileAuxData) -> bool { - if let Some(other) = other.as_any().downcast_ref::() { self == other } else { false } + if let Some(other) = other.as_any().downcast_ref::() { + self == other + } else { + false + } } } @@ -88,7 +92,11 @@ impl GeneratedFileAuxData for ComputedValuesAuxData { self } fn eq(&self, other: &dyn GeneratedFileAuxData) -> bool { - if let Some(other) = other.as_any().downcast_ref::() { self == other } else { false } + if let Some(other) = other.as_any().downcast_ref::() { + self == other + } else { + false + } } } diff --git a/crates/dojo-world/src/metadata_test.rs b/crates/dojo-world/src/metadata_test.rs index ec48befb6f..6f34df68b6 100644 --- a/crates/dojo-world/src/metadata_test.rs +++ b/crates/dojo-world/src/metadata_test.rs @@ -132,23 +132,22 @@ async fn get_full_dojo_metadata_from_workspace() { assert!(env.rpc_url.unwrap().eq("http://localhost:5050/")); assert!(env.account_address.is_some()); - assert!( - env.account_address - .unwrap() - .eq("0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03") - ); + assert!(env + .account_address + .unwrap() + .eq("0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03")); assert!(env.private_key.is_some()); - assert!( - env.private_key.unwrap().eq("0x1800000000300000180000000000030000000000003006001800006600") - ); + assert!(env + .private_key + .unwrap() + .eq("0x1800000000300000180000000000030000000000003006001800006600")); assert!(env.world_address.is_some()); - assert!( - env.world_address - .unwrap() - .eq("0x3898144a24151443f0c6501a1de46a6e9e27abd9fb5d08cdeeff5a5127d1d25") - ); + assert!(env + .world_address + .unwrap() + .eq("0x3898144a24151443f0c6501a1de46a6e9e27abd9fb5d08cdeeff5a5127d1d25")); assert!(env.keystore_path.is_none()); assert!(env.keystore_password.is_none()); diff --git a/crates/katana/core/src/lib.rs b/crates/katana/core/src/lib.rs index 099e04b025..f202735ea8 100644 --- a/crates/katana/core/src/lib.rs +++ b/crates/katana/core/src/lib.rs @@ -1,10 +1,10 @@ pub mod backend; pub mod constants; pub mod env; +pub mod hooker; pub mod pool; pub mod sequencer; pub mod service; pub mod utils; -pub mod hooker; pub mod sequencer_error; diff --git a/crates/katana/core/src/service/messaging/starknet.rs b/crates/katana/core/src/service/messaging/starknet.rs index 6375f78227..b0ece4ce22 100644 --- a/crates/katana/core/src/service/messaging/starknet.rs +++ b/crates/katana/core/src/service/messaging/starknet.rs @@ -108,25 +108,25 @@ impl StarknetMessaging { if let Ok(tx) = l1_handler_tx_from_event(&event, chain_id) { if let Ok((from, to, selector)) = info_from_event(&event) { - let hooker = Arc::clone(&self.hooker); - let is_message_accepted = hooker - .read() - .await - .verify_message_to_appchain(from, to, selector) - .await; + let hooker = Arc::clone(&self.hooker); + let is_message_accepted = hooker + .read() + .await + .verify_message_to_appchain(from, to, selector) + .await; if is_message_accepted { debug!(target: LOG_TARGET, "Event ID: {} accepted, adding to transactions", event_id); l1_handler_txs.push(tx); let mut cache = self.event_cache.write().await; cache.insert(event_id); } else { - debug!( - target: LOG_TARGET, - "Event ID: {} not accepted by hooker, check the contract addresses defined in the hooker: executor address: {:?}, orderbook address: {:?}", - event_id, - from, - to - ); + debug!( + target: LOG_TARGET, + "Event ID: {} not accepted by hooker, check the contract addresses defined in the hooker: executor address: {:?}, orderbook address: {:?}", + event_id, + from, + to + ); } } } diff --git a/crates/katana/executor/src/implementation/blockifier/state.rs b/crates/katana/executor/src/implementation/blockifier/state.rs index c6d7f27572..cbe21e1e45 100644 --- a/crates/katana/executor/src/implementation/blockifier/state.rs +++ b/crates/katana/executor/src/implementation/blockifier/state.rs @@ -171,7 +171,11 @@ impl StateProvider for CachedState { }; let hash = hash.0.into(); - if hash == FieldElement::ZERO { Ok(None) } else { Ok(Some(hash)) } + if hash == FieldElement::ZERO { + Ok(None) + } else { + Ok(Some(hash)) + } } fn nonce( diff --git a/crates/katana/executor/tests/executor.rs b/crates/katana/executor/tests/executor.rs index b35c9ae409..00f86b010c 100644 --- a/crates/katana/executor/tests/executor.rs +++ b/crates/katana/executor/tests/executor.rs @@ -55,7 +55,11 @@ fn test_executor_with_valid_blocks_impl( // ensure that all transactions succeeded, if not panic with the error message and tx index let has_failed = transactions.iter().enumerate().find_map(|(i, (_, res))| { - if let ExecutionResult::Failed { error } = res { Some((i, error)) } else { None } + if let ExecutionResult::Failed { error } = res { + Some((i, error)) + } else { + None + } }); if let Some((pos, error)) = has_failed { diff --git a/crates/katana/primitives/src/genesis/json.rs b/crates/katana/primitives/src/genesis/json.rs index 102020e7c9..5a65d9059a 100644 --- a/crates/katana/primitives/src/genesis/json.rs +++ b/crates/katana/primitives/src/genesis/json.rs @@ -1071,12 +1071,10 @@ mod tests { fn genesis_from_json_with_unresolved_paths() { let file = File::open("./src/genesis/test-genesis.json").unwrap(); let json: GenesisJson = serde_json::from_reader(file).unwrap(); - assert!( - Genesis::try_from(json) - .unwrap_err() - .to_string() - .contains("Unresolved class artifact path") - ); + assert!(Genesis::try_from(json) + .unwrap_err() + .to_string() + .contains("Unresolved class artifact path")); } #[test] diff --git a/crates/katana/rpc/rpc-api/src/lib.rs b/crates/katana/rpc/rpc-api/src/lib.rs index c56f5cbd27..f568a9e4ce 100644 --- a/crates/katana/rpc/rpc-api/src/lib.rs +++ b/crates/katana/rpc/rpc-api/src/lib.rs @@ -13,5 +13,5 @@ pub enum ApiKind { Torii, Dev, Saya, - Solis + Solis, } diff --git a/crates/katana/rpc/rpc-api/src/torii.rs b/crates/katana/rpc/rpc-api/src/torii.rs index 272497041a..3308806004 100644 --- a/crates/katana/rpc/rpc-api/src/torii.rs +++ b/crates/katana/rpc/rpc-api/src/torii.rs @@ -7,5 +7,5 @@ use katana_rpc_types::transaction::{TransactionsPage, TransactionsPageCursor}; pub trait ToriiApi { #[method(name = "getTransactions")] async fn get_transactions(&self, cursor: TransactionsPageCursor) - -> RpcResult; + -> RpcResult; } diff --git a/crates/katana/rpc/rpc-types/src/error/mod.rs b/crates/katana/rpc/rpc-types/src/error/mod.rs index c68defcea8..82686bf94f 100644 --- a/crates/katana/rpc/rpc-types/src/error/mod.rs +++ b/crates/katana/rpc/rpc-types/src/error/mod.rs @@ -1,5 +1,5 @@ pub mod katana; pub mod saya; +pub mod solis; pub mod starknet; pub mod torii; -pub mod solis; \ No newline at end of file diff --git a/crates/katana/rpc/rpc/src/solis.rs b/crates/katana/rpc/rpc/src/solis.rs index 16d4690674..35da1dedc4 100644 --- a/crates/katana/rpc/rpc/src/solis.rs +++ b/crates/katana/rpc/rpc/src/solis.rs @@ -3,11 +3,11 @@ use std::sync::Arc; use crate::config::ServerConfig; use jsonrpsee::core::{async_trait, Error as RpcError}; -use katana_rpc_types::error::solis::SolisApiError; use katana_core::hooker::HookerAddresses; use katana_core::sequencer::KatanaSequencer; use katana_executor::ExecutorFactory; use katana_rpc_api::solis::SolisApiServer; +use katana_rpc_types::error::solis::SolisApiError; pub struct SolisApi { sequencer: Arc>, pub rpc_user: String, diff --git a/crates/katana/rpc/rpc/src/starknet.rs b/crates/katana/rpc/rpc/src/starknet.rs index a0fde82e7e..296d9c8db6 100644 --- a/crates/katana/rpc/rpc/src/starknet.rs +++ b/crates/katana/rpc/rpc/src/starknet.rs @@ -36,9 +36,9 @@ use katana_rpc_types::{ use katana_rpc_types_builder::ReceiptBuilder; use katana_tasks::{BlockingTaskPool, TokioTaskSpawner}; use starknet::core::types::{ - BlockTag, BroadcastedInvokeTransaction, DeclareTransactionTrace, DeployAccountTransactionTrace, ExecuteInvocation, - InvokeTransactionTrace, L1HandlerTransactionTrace, RevertedInvocation, SimulatedTransaction, - TransactionExecutionStatus, TransactionStatus, TransactionTrace, + BlockTag, BroadcastedInvokeTransaction, DeclareTransactionTrace, DeployAccountTransactionTrace, + ExecuteInvocation, InvokeTransactionTrace, L1HandlerTransactionTrace, RevertedInvocation, + SimulatedTransaction, TransactionExecutionStatus, TransactionStatus, TransactionTrace, }; pub struct StarknetApi { @@ -675,11 +675,10 @@ impl StarknetApiServer for StarknetApi { &self, invoke_transaction: BroadcastedInvokeTx, ) -> RpcResult { - if let Some(hooker) = &self.inner.sequencer.hooker { let tx = invoke_transaction.0.clone(); if !hooker.read().await.verify_invoke_tx_before_pool(tx).await { - return Err(StarknetApiError::SolisAssetFault.into()); + return Err(StarknetApiError::SolisAssetFault.into()); } } self.on_io_blocking_task(move |this| { diff --git a/crates/katana/runner/runner-macro/src/lib.rs b/crates/katana/runner/runner-macro/src/lib.rs index 77867a284f..8cb426c16e 100644 --- a/crates/katana/runner/runner-macro/src/lib.rs +++ b/crates/katana/runner/runner-macro/src/lib.rs @@ -28,7 +28,11 @@ fn parse_metadata(metadata: String) -> (u16, Option, Option) { // if set to `true`, we use a default block time. let block_time = if args.len() >= 2 { if let Ok(b) = args[1].trim().parse::() { - if !b { None } else { Some(DEFAULT_BLOCK_TIME) } + if !b { + None + } else { + Some(DEFAULT_BLOCK_TIME) + } } else if let Ok(block_time_ms) = args[1].trim().parse::() { Some(block_time_ms) } else { diff --git a/crates/katana/runner/src/lib.rs b/crates/katana/runner/src/lib.rs index 13a19fe771..adf9051ad2 100644 --- a/crates/katana/runner/src/lib.rs +++ b/crates/katana/runner/src/lib.rs @@ -185,7 +185,11 @@ impl Drop for KatanaRunner { /// Determines the default program path for the katana runner based on the KATANA_RUNNER_BIN /// environment variable. If not set, try to to use katana from the PATH. fn determine_default_program_path() -> String { - if let Ok(bin) = std::env::var("KATANA_RUNNER_BIN") { bin } else { "katana".to_string() } + if let Ok(bin) = std::env::var("KATANA_RUNNER_BIN") { + bin + } else { + "katana".to_string() + } } #[cfg(test)] diff --git a/crates/katana/storage/db/src/mdbx/cursor.rs b/crates/katana/storage/db/src/mdbx/cursor.rs index 9cac3876e3..e08ca8499a 100644 --- a/crates/katana/storage/db/src/mdbx/cursor.rs +++ b/crates/katana/storage/db/src/mdbx/cursor.rs @@ -304,7 +304,11 @@ impl Walker<'_, RW, T> { impl std::iter::Iterator for Walker<'_, K, T> { type Item = Result, DatabaseError>; fn next(&mut self) -> Option { - if let value @ Some(_) = self.start.take() { value } else { self.cursor.next().transpose() } + if let value @ Some(_) = self.start.take() { + value + } else { + self.cursor.next().transpose() + } } } diff --git a/crates/katana/storage/provider/src/providers/db/state.rs b/crates/katana/storage/provider/src/providers/db/state.rs index bb8f070646..286b16920d 100644 --- a/crates/katana/storage/provider/src/providers/db/state.rs +++ b/crates/katana/storage/provider/src/providers/db/state.rs @@ -292,7 +292,11 @@ fn recent_change_from_block( // 1. the list is empty // 2. there are no prior changes occured before/at `block_number` let rank = block_list.rank(block_number); - if rank == 0 { None } else { block_list.select(rank - 1) } + if rank == 0 { + None + } else { + block_list.select(rank - 1) + } } #[cfg(test)] diff --git a/crates/katana/storage/provider/src/traits/contract.rs b/crates/katana/storage/provider/src/traits/contract.rs index 7ff77f1999..b0a09d61aa 100644 --- a/crates/katana/storage/provider/src/traits/contract.rs +++ b/crates/katana/storage/provider/src/traits/contract.rs @@ -40,5 +40,5 @@ pub trait ContractClassWriter: Send + Sync { /// Retrieves the Sierra class definition of a contract class given its class hash. fn set_sierra_class(&self, hash: ClassHash, sierra: FlattenedSierraClass) - -> ProviderResult<()>; + -> ProviderResult<()>; } diff --git a/crates/katana/storage/provider/src/traits/state.rs b/crates/katana/storage/provider/src/traits/state.rs index 3ec9aade09..c18d4f72d1 100644 --- a/crates/katana/storage/provider/src/traits/state.rs +++ b/crates/katana/storage/provider/src/traits/state.rs @@ -26,7 +26,7 @@ pub trait StateProvider: ContractClassProvider + Send + Sync { /// Returns the class hash of a contract. fn class_hash_of_contract(&self, address: ContractAddress) - -> ProviderResult>; + -> ProviderResult>; } /// A type which can create [`StateProvider`] for states at a particular block. diff --git a/crates/sozo/ops/src/tests/call.rs b/crates/sozo/ops/src/tests/call.rs index 84d6c4f5bc..f93b498fd3 100644 --- a/crates/sozo/ops/src/tests/call.rs +++ b/crates/sozo/ops/src/tests/call.rs @@ -20,17 +20,15 @@ async fn call_with_bad_address() { let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); - assert!( - call::call( - world_reader, - "0xBadCoffeeBadCode".to_string(), - ENTRYPOINT.to_string(), - vec![FieldElement::ZERO, FieldElement::ZERO], - None - ) - .await - .is_err() - ); + assert!(call::call( + world_reader, + "0xBadCoffeeBadCode".to_string(), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None + ) + .await + .is_err()); } #[tokio::test] @@ -41,17 +39,15 @@ async fn call_with_bad_name() { let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); - assert!( - call::call( - world_reader, - "BadName".to_string(), - ENTRYPOINT.to_string(), - vec![FieldElement::ZERO, FieldElement::ZERO], - None - ) - .await - .is_err() - ); + assert!(call::call( + world_reader, + "BadName".to_string(), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None + ) + .await + .is_err()); } #[tokio::test] @@ -62,17 +58,15 @@ async fn call_with_bad_entrypoint() { let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); - assert!( - call::call( - world_reader, - CONTRACT_NAME.to_string(), - "BadEntryPoint".to_string(), - vec![FieldElement::ZERO, FieldElement::ZERO], - None - ) - .await - .is_err() - ); + assert!(call::call( + world_reader, + CONTRACT_NAME.to_string(), + "BadEntryPoint".to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None + ) + .await + .is_err()); } #[tokio::test] @@ -83,11 +77,15 @@ async fn call_with_bad_calldata() { let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); - assert!( - call::call(world_reader, CONTRACT_NAME.to_string(), ENTRYPOINT.to_string(), vec![], None) - .await - .is_err() - ); + assert!(call::call( + world_reader, + CONTRACT_NAME.to_string(), + ENTRYPOINT.to_string(), + vec![], + None + ) + .await + .is_err()); } #[tokio::test] @@ -98,17 +96,15 @@ async fn call_with_contract_name() { let provider = sequencer.provider(); let world_reader = WorldContractReader::new(world.address, provider); - assert!( - call::call( - world_reader, - CONTRACT_NAME.to_string(), - ENTRYPOINT.to_string(), - vec![FieldElement::ZERO, FieldElement::ZERO], - None, - ) - .await - .is_ok() - ); + assert!(call::call( + world_reader, + CONTRACT_NAME.to_string(), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None, + ) + .await + .is_ok()); } #[tokio::test] @@ -125,15 +121,13 @@ async fn call_with_contract_address() { .await .unwrap(); - assert!( - call::call( - world_reader, - format!("{:#x}", contract_address), - ENTRYPOINT.to_string(), - vec![FieldElement::ZERO, FieldElement::ZERO], - None, - ) - .await - .is_ok() - ); + assert!(call::call( + world_reader, + format!("{:#x}", contract_address), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None, + ) + .await + .is_ok()); } diff --git a/crates/sozo/ops/src/tests/migration.rs b/crates/sozo/ops/src/tests/migration.rs index 06903c5f37..84c45e90ba 100644 --- a/crates/sozo/ops/src/tests/migration.rs +++ b/crates/sozo/ops/src/tests/migration.rs @@ -81,16 +81,14 @@ async fn migrate_with_small_fee_multiplier_will_fail() { let account = sequencer.account(0); - assert!( - execute_strategy( - &ws, - &migration, - &account, - TxnConfig { fee_estimate_multiplier: Some(0.2f64), ..Default::default() }, - ) - .await - .is_err() - ); + assert!(execute_strategy( + &ws, + &migration, + &account, + TxnConfig { fee_estimate_multiplier: Some(0.2f64), ..Default::default() }, + ) + .await + .is_err()); } #[tokio::test] diff --git a/crates/torii/client/src/client/storage.rs b/crates/torii/client/src/client/storage.rs index 48541a2314..caa00dee5c 100644 --- a/crates/torii/client/src/client/storage.rs +++ b/crates/torii/client/src/client/storage.rs @@ -264,10 +264,8 @@ mod tests { ); assert!(actual_values == expected_values); assert!(storage.storage.read().len() == model.packed_size as usize); - assert!( - actual_storage_addresses - .into_iter() - .all(|address| expected_storage_addresses.contains(&address)) - ); + assert!(actual_storage_addresses + .into_iter() + .all(|address| expected_storage_addresses.contains(&address))); } } diff --git a/crates/torii/client/src/client/subscription.rs b/crates/torii/client/src/client/subscription.rs index ac21707104..b167e6a614 100644 --- a/crates/torii/client/src/client/subscription.rs +++ b/crates/torii/client/src/client/subscription.rs @@ -192,7 +192,11 @@ impl SubscriptionService { let storage_entries = diff.storage_diffs.into_iter().find_map(|d| { let expected = self.world_metadata.read().world_address; let current = d.address; - if current == expected { Some(d.storage_entries) } else { None } + if current == expected { + Some(d.storage_entries) + } else { + None + } }); let Some(entries) = storage_entries else { diff --git a/crates/torii/graphql/src/object/entity.rs b/crates/torii/graphql/src/object/entity.rs index dd73c9c6fd..209fd28141 100644 --- a/crates/torii/graphql/src/object/entity.rs +++ b/crates/torii/graphql/src/object/entity.rs @@ -63,8 +63,10 @@ impl ResolvableObject for EntityObject { } fn subscriptions(&self) -> Option> { - Some(vec![ - SubscriptionField::new("entityUpdated", TypeRef::named_nn(self.type_name()), |ctx| { + Some(vec![SubscriptionField::new( + "entityUpdated", + TypeRef::named_nn(self.type_name()), + |ctx| { SubscriptionFieldFuture::new(async move { let id = match ctx.args.get("id") { Some(id) => Some(id.string()?.to_string()), @@ -81,9 +83,9 @@ impl ResolvableObject for EntityObject { } })) }) - }) - .argument(InputValue::new("id", TypeRef::named(TypeRef::ID))), - ]) + }, + ) + .argument(InputValue::new("id", TypeRef::named(TypeRef::ID)))]) } } diff --git a/crates/torii/graphql/src/object/event.rs b/crates/torii/graphql/src/object/event.rs index f0063f76c1..975d98afe9 100644 --- a/crates/torii/graphql/src/object/event.rs +++ b/crates/torii/graphql/src/object/event.rs @@ -44,15 +44,17 @@ impl ResolvableObject for EventObject { } fn subscriptions(&self) -> Option> { - Some(vec![ - SubscriptionField::new("eventEmitted", TypeRef::named_nn(self.type_name()), |ctx| { + Some(vec![SubscriptionField::new( + "eventEmitted", + TypeRef::named_nn(self.type_name()), + |ctx| { SubscriptionFieldFuture::new(async move { let input_keys = parse_keys_argument(&ctx)?; Ok(EventObject::subscription_stream(input_keys)) }) - }) - .argument(InputValue::new("keys", TypeRef::named_list(TypeRef::STRING))), - ]) + }, + ) + .argument(InputValue::new("keys", TypeRef::named_list(TypeRef::STRING)))]) } } diff --git a/crates/torii/graphql/src/object/event_message.rs b/crates/torii/graphql/src/object/event_message.rs index 007573b3ca..11da937cfb 100644 --- a/crates/torii/graphql/src/object/event_message.rs +++ b/crates/torii/graphql/src/object/event_message.rs @@ -63,35 +63,31 @@ impl ResolvableObject for EventMessageObject { } fn subscriptions(&self) -> Option> { - Some(vec![ - SubscriptionField::new( - "eventMessageUpdated", - TypeRef::named_nn(self.type_name()), - |ctx| { - SubscriptionFieldFuture::new(async move { - let id = match ctx.args.get("id") { - Some(id) => Some(id.string()?.to_string()), - None => None, - }; - // if id is None, then subscribe to all entities - // if id is Some, then subscribe to only the entity with that id - Ok(SimpleBroker::::subscribe().filter_map( - move |entity: EventMessage| { - if id.is_none() || id == Some(entity.id.clone()) { - Some(Ok(Value::Object(EventMessageObject::value_mapping( - entity, - )))) - } else { - // id != entity.id , then don't send anything, still listening - None - } - }, - )) - }) - }, - ) - .argument(InputValue::new("id", TypeRef::named(TypeRef::ID))), - ]) + Some(vec![SubscriptionField::new( + "eventMessageUpdated", + TypeRef::named_nn(self.type_name()), + |ctx| { + SubscriptionFieldFuture::new(async move { + let id = match ctx.args.get("id") { + Some(id) => Some(id.string()?.to_string()), + None => None, + }; + // if id is None, then subscribe to all entities + // if id is Some, then subscribe to only the entity with that id + Ok(SimpleBroker::::subscribe().filter_map( + move |entity: EventMessage| { + if id.is_none() || id == Some(entity.id.clone()) { + Some(Ok(Value::Object(EventMessageObject::value_mapping(entity)))) + } else { + // id != entity.id , then don't send anything, still listening + None + } + }, + )) + }) + }, + ) + .argument(InputValue::new("id", TypeRef::named(TypeRef::ID)))]) } } diff --git a/crates/torii/graphql/src/object/model.rs b/crates/torii/graphql/src/object/model.rs index a9ecb13607..4b326b0207 100644 --- a/crates/torii/graphql/src/object/model.rs +++ b/crates/torii/graphql/src/object/model.rs @@ -74,8 +74,10 @@ impl ResolvableObject for ModelObject { } fn subscriptions(&self) -> Option> { - Some(vec![ - SubscriptionField::new("modelRegistered", TypeRef::named_nn(self.type_name()), |ctx| { + Some(vec![SubscriptionField::new( + "modelRegistered", + TypeRef::named_nn(self.type_name()), + |ctx| { { SubscriptionFieldFuture::new(async move { let id = match ctx.args.get("id") { @@ -94,9 +96,9 @@ impl ResolvableObject for ModelObject { })) }) } - }) - .argument(InputValue::new("id", TypeRef::named(TypeRef::ID))), - ]) + }, + ) + .argument(InputValue::new("id", TypeRef::named(TypeRef::ID)))]) } } diff --git a/crates/torii/libp2p/src/typed_data.rs b/crates/torii/libp2p/src/typed_data.rs index dc752f751b..e018184814 100644 --- a/crates/torii/libp2p/src/typed_data.rs +++ b/crates/torii/libp2p/src/typed_data.rs @@ -149,7 +149,11 @@ pub fn encode_type(name: &str, types: &IndexMap>) -> Result>() .join(",");