Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cargo fmt
Browse files Browse the repository at this point in the history
ybensacq committed Aug 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d521e68 commit 5608d0c
Showing 31 changed files with 235 additions and 236 deletions.
3 changes: 2 additions & 1 deletion bin/solis/src/args.rs
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 2 additions & 11 deletions bin/solis/src/contracts/account.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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<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 {
@@ -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!(
@@ -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()),
@@ -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()),
@@ -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) => {
@@ -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
@@ -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) => {
@@ -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,
22 changes: 12 additions & 10 deletions bin/solis/src/main.rs
Original file line number Diff line number Diff line change
@@ -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([
@@ -118,17 +118,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?;

12 changes: 10 additions & 2 deletions crates/dojo-lang/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
}

@@ -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
}
}
}

25 changes: 12 additions & 13 deletions crates/dojo-world/src/metadata_test.rs
Original file line number Diff line number Diff line change
@@ -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());
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
@@ -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
);
}
}
}
Original file line number Diff line number Diff line change
@@ -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(
6 changes: 5 additions & 1 deletion crates/katana/executor/tests/executor.rs
Original file line number Diff line number Diff line change
@@ -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 {
10 changes: 4 additions & 6 deletions crates/katana/primitives/src/genesis/json.rs
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion crates/katana/rpc/rpc-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -13,5 +13,5 @@ pub enum ApiKind {
Torii,
Dev,
Saya,
Solis
Solis,
}
2 changes: 1 addition & 1 deletion crates/katana/rpc/rpc-api/src/torii.rs
Original file line number Diff line number Diff line change
@@ -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<TransactionsPage>;
-> RpcResult<TransactionsPage>;
}
2 changes: 1 addition & 1 deletion crates/katana/rpc/rpc-types/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod katana;
pub mod saya;
pub mod solis;
pub mod starknet;
pub mod torii;
pub mod solis;
Loading

0 comments on commit 5608d0c

Please sign in to comment.