Skip to content

Commit

Permalink
put all under feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Sep 10, 2024
1 parent 6112180 commit 75e6f93
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 15 deletions.
6 changes: 4 additions & 2 deletions bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ serde.workspace = true
serde_json.workspace = true
smol_str.workspace = true
sozo-ops.workspace = true
sozo-walnut.workspace = true
sozo-walnut = { workspace = true, optional = true }
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
Expand All @@ -71,5 +71,7 @@ katana-runner.workspace = true
snapbox = "0.4.6"

[features]
default = [ "controller", "walnut" ]

controller = [ "dep:account_sdk", "dep:reqwest", "dep:slot" ]
default = [ "controller" ]
walnut = [ "dep:sozo-walnut" ]
7 changes: 7 additions & 0 deletions bin/sozo/src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use dojo_world::metadata::get_default_namespace_from_ws;
use scarb::core::Config;
use scarb_ui::Ui;
use sozo_ops::auth;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use tracing::trace;

Expand Down Expand Up @@ -152,6 +153,7 @@ pub async fn grant(
let world =
utils::world_from_env_metadata(world, account, &starknet, &env_metadata, config).await?;

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

Expand All @@ -167,6 +169,7 @@ pub async fn grant(
&models_contracts,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand All @@ -182,6 +185,7 @@ pub async fn grant(
&owners_resources,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand All @@ -205,6 +209,7 @@ pub async fn revoke(
let world =
utils::world_from_env_metadata(world, account, &starknet, &env_metadata, config).await?;

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

Expand All @@ -220,6 +225,7 @@ pub async fn revoke(
&models_contracts,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand All @@ -235,6 +241,7 @@ pub async fn revoke(
&owners_resources,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand Down
3 changes: 3 additions & 0 deletions bin/sozo/src/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use dojo_world::contracts::naming::ensure_namespace;
use dojo_world::metadata::get_default_namespace_from_ws;
use scarb::core::Config;
use sozo_ops::execute;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use tracing::trace;

Expand Down Expand Up @@ -62,6 +63,7 @@ impl ExecuteArgs {
ensure_namespace(&self.tag_or_address, &default_namespace)
};

#[cfg(feature = "walnut")]
let walnut_debugger = WalnutDebugger::new_from_flag(
self.transaction.walnut,
self.starknet.url(env_metadata.as_ref())?,
Expand Down Expand Up @@ -99,6 +101,7 @@ impl ExecuteArgs {
calldata,
&world,
&tx_config,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand Down
3 changes: 3 additions & 0 deletions bin/sozo/src/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::{Args, Subcommand};
use dojo_world::contracts::WorldContractReader;
use scarb::core::Config;
use sozo_ops::register;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::ConnectedAccount;
use starknet::core::types::{BlockId, BlockTag, Felt};
Expand Down Expand Up @@ -59,6 +60,7 @@ impl RegisterArgs {
let world_address = world.world_address.unwrap_or_default();
trace!(?world_address, "Using world address.");

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

Expand All @@ -77,6 +79,7 @@ impl RegisterArgs {
world_reader,
world_address,
config,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand Down
3 changes: 2 additions & 1 deletion crates/sozo/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
smol_str.workspace = true
sozo-walnut = { workspace = true, optional = true }
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
tracing.workspace = true
url.workspace = true
sozo-walnut.workspace = true

dojo-test-utils = { workspace = true, features = [ "build-examples" ], optional = true }
katana-runner = { workspace = true, optional = true }
Expand All @@ -64,3 +64,4 @@ tee = "0.1.0"

[features]
test-utils = [ "dep:dojo-test-utils", "dep:katana-runner" ]
walnut = [ "dep:sozo-walnut" ]
13 changes: 9 additions & 4 deletions crates/sozo/ops/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use dojo_world::contracts::naming::{
use dojo_world::contracts::world::WorldContract;
use dojo_world::contracts::WorldContractReader;
use scarb_ui::Ui;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::{Account, ConnectedAccount};
use starknet::core::types::{BlockId, BlockTag, Felt};
Expand Down Expand Up @@ -111,7 +112,7 @@ pub async fn grant_writer<'a, A>(
new_writers: &[ResourceWriter],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send,
Expand Down Expand Up @@ -143,6 +144,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand All @@ -157,7 +159,7 @@ pub async fn grant_owner<A>(
new_owners: &[ResourceOwner],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand Down Expand Up @@ -185,6 +187,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand All @@ -198,7 +201,7 @@ pub async fn revoke_writer<A>(
new_writers: &[ResourceWriter],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand Down Expand Up @@ -229,6 +232,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand All @@ -243,7 +247,7 @@ pub async fn revoke_owner<A>(
new_owners: &[ResourceOwner],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand All @@ -269,6 +273,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand Down
4 changes: 3 additions & 1 deletion crates/sozo/ops/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{Context, Result};
use dojo_utils::{TransactionExt, TxnConfig};
use dojo_world::contracts::world::WorldContract;
use scarb_ui::Ui;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::{Call, ConnectedAccount};
use starknet::core::types::Felt;
Expand All @@ -16,7 +17,7 @@ pub async fn execute<A>(
calldata: Vec<Felt>,
world: &WorldContract<A>,
txn_config: &TxnConfig,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand All @@ -39,6 +40,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await
Expand Down
25 changes: 22 additions & 3 deletions crates/sozo/ops/src/migration/auto_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use dojo_utils::TxnConfig;
use dojo_world::contracts::WorldContract;
use scarb::core::Workspace;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::ConnectedAccount;

Expand All @@ -14,16 +15,34 @@ pub async fn auto_authorize<A>(
default_namespace: &str,
grant: &[ResourceWriter],
revoke: &[ResourceWriter],
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
A::SignError: 'static,
{
let ui = ws.config().ui();

grant_writer(&ui, world, grant, txn_config, default_namespace, walnut_debugger).await?;
revoke_writer(&ui, world, revoke, txn_config, default_namespace, walnut_debugger).await?;
grant_writer(
&ui,
world,
grant,
txn_config,
default_namespace,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
revoke_writer(
&ui,
world,
revoke,
txn_config,
default_namespace,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;

Ok(())
}
6 changes: 6 additions & 0 deletions crates/sozo/ops/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use dojo_world::metadata::get_default_namespace_from_ws;
use dojo_world::migration::world::WorldDiff;
use dojo_world::migration::{DeployOutput, UpgradeOutput};
use scarb::core::Workspace;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::{Call, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount};
use starknet::core::types::{BlockId, BlockTag, Felt, InvokeTransactionResult};
Expand Down Expand Up @@ -135,6 +136,8 @@ where
A::SignError: 'static,
{
let ui = ws.config().ui();

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(txn_config.walnut, Url::parse(&rpc_url).unwrap());

Expand Down Expand Up @@ -219,6 +222,7 @@ where

Ok(None)
} else {
#[cfg(feature = "walnut")]
if txn_config.walnut {
WalnutDebugger::check_api_key()?;
}
Expand Down Expand Up @@ -283,6 +287,7 @@ where
&default_namespace,
&grant,
&revoke,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand Down Expand Up @@ -373,6 +378,7 @@ where
}
}

#[cfg(feature = "walnut")]
if let Some(walnut_debugger) = &walnut_debugger {
walnut_debugger.verify_migration_strategy(ws, &strategy).await?;
}
Expand Down
4 changes: 3 additions & 1 deletion crates/sozo/ops/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use dojo_world::contracts::model::ModelReader;
use dojo_world::contracts::{WorldContract, WorldContractReader};
use dojo_world::manifest::DeploymentManifest;
use scarb::core::Config;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::ConnectedAccount;
use starknet::core::types::Felt;
Expand All @@ -20,7 +21,7 @@ pub async fn model_register<A, P>(
world_reader: WorldContractReader<P>,
world_address: Felt,
config: &Config,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand Down Expand Up @@ -78,6 +79,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand Down
1 change: 1 addition & 0 deletions crates/sozo/ops/src/test_utils/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub async fn setup(
&default_namespace,
&grant,
&revoke,
#[cfg(feature = "walnut")]
&None,
)
.await?;
Expand Down
Loading

0 comments on commit 75e6f93

Please sign in to comment.