Skip to content

Commit

Permalink
fix(fmt): apply cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ybensacq committed Aug 9, 2024
1 parent 1be79f6 commit d83fe52
Show file tree
Hide file tree
Showing 33 changed files with 244 additions and 237 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/solis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions bin/solis/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
13 changes: 2 additions & 11 deletions bin/solis/src/contracts/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
59 changes: 18 additions & 41 deletions bin/solis/src/hooker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,10 +90,7 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
);

// 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 {
Expand Down Expand Up @@ -145,10 +140,8 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
}

// 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!(
Expand Down Expand Up @@ -179,10 +172,7 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
// 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()),
Expand Down Expand Up @@ -220,7 +210,8 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
SolisHooker<P, EF>
{
fn get_addresses_from_file() -> Result<(FieldElement, FieldElement), Box<dyn std::error::Error>> {
fn get_addresses_from_file() -> Result<(FieldElement, FieldElement), Box<dyn std::error::Error>>
{
let mut file = match File::open(FILE_PATH_ADDRESSES) {
Ok(file) => file,
Err(_) => return Err("File not found".into()),
Expand Down Expand Up @@ -264,7 +255,9 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
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) => {
Expand All @@ -276,22 +269,15 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
(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.
#[allow(dead_code)]
pub fn sequencer_ref(&self) -> &Arc<KatanaSequencer<EF>> {
// 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
Expand Down Expand Up @@ -369,10 +355,7 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
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) => {
Expand Down Expand Up @@ -418,19 +401,13 @@ impl<P: Provider + Sync + Send + 'static + std::fmt::Debug, EF: ExecutorFactory>
&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::<TxCall>::cairo_deserialize(&calldata, 0) {
Ok(calls) => calls,
Expand Down
22 changes: 12 additions & 10 deletions bin/solis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -116,17 +116,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let executor_address = FieldElement::ZERO;
let orderbook_address = FieldElement::ZERO;

let hooker:Arc<AsyncRwLock<dyn KatanaHooker<BlockifierFactory> + Send + Sync>> =
Arc::new(AsyncRwLock::new(SolisHooker::new(
sn_utils_reader,
orderbook_address,
executor_address,
)));
let hooker: Arc<AsyncRwLock<dyn KatanaHooker<BlockifierFactory> + 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?;

Expand Down
12 changes: 10 additions & 2 deletions crates/dojo-lang/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() { self == other } else { false }
if let Some(other) = other.as_any().downcast_ref::<Self>() {
self == other
} else {
false
}
}
}

Expand All @@ -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>() { self == other } else { false }
if let Some(other) = other.as_any().downcast_ref::<Self>() {
self == other
} else {
false
}
}
}

Expand Down
25 changes: 12 additions & 13 deletions crates/dojo-world/src/metadata_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
26 changes: 13 additions & 13 deletions crates/katana/core/src/service/messaging/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,25 @@ impl<EF: katana_executor::ExecutorFactory + Send + Sync> StarknetMessaging<EF> {

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
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ impl<S: StateDb> StateProvider for CachedState<S> {
};

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(
Expand Down
6 changes: 5 additions & 1 deletion crates/katana/executor/tests/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ fn test_executor_with_valid_blocks_impl<EF: ExecutorFactory>(

// 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 {
Expand Down
Loading

0 comments on commit d83fe52

Please sign in to comment.