Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sozo] Deploy Account #1601

Merged
merged 21 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ torii-server = { path = "crates/torii/server" }
saya-core = { path = "crates/saya/core" }

# sozo
sozo-signers = { path = "crates/sozo/signers" }
sozo-ops = { path = "crates/sozo/ops" }
sozo-signers = { path = "crates/sozo/signers" }

anyhow = "1.0.75"
assert_matches = "1.5.0"
Expand Down Expand Up @@ -142,6 +142,8 @@ once_cell = "1.0"
parking_lot = "0.12.1"
pretty_assertions = "1.2.1"
rayon = "1.8.0"
regex = "1.10.3"
rpassword = "7.2.0"
salsa = "0.16.1"
scarb = { git = "https://github.com/software-mansion/scarb", tag = "v2.5.4" }
scarb-ui = { git = "https://github.com/software-mansion/scarb", tag = "v2.5.4" }
Expand All @@ -163,7 +165,6 @@ tokio = { version = "1.32.0", features = [ "full" ] }
toml = "0.7.4"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.16", features = [ "env-filter", "json" ] }
regex = "1.10.3"
url = { version = "2.4.0", features = [ "serde" ] }

# server
Expand Down
5 changes: 4 additions & 1 deletion bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version.workspace = true
[dependencies]
anyhow.workspace = true
async-trait.workspace = true
bigdecimal = "0.4.1"
cairo-lang-compiler.workspace = true
cairo-lang-defs.workspace = true
cairo-lang-filesystem.workspace = true
Expand All @@ -31,20 +32,22 @@ dojo-world = { workspace = true, features = [ "contracts", "metadata", "migratio
futures.workspace = true
notify = "6.0.1"
notify-debouncer-mini = "0.3.0"
num-integer = "0.1.45"
rpassword.workspace = true
scarb-ui.workspace = true
scarb.workspace = true
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
smol_str.workspace = true
sozo-ops.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing-log = "0.1.3"
tracing.workspace = true
url.workspace = true
sozo-ops.workspace = true

cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.2.2" }

Expand Down
3 changes: 3 additions & 0 deletions bin/sozo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ curl -L https://install.dojoengine.org | bash
```

[Documentation](https://book.dojoengine.org/toolchain/sozo/overview)

Some parts of sozo were inspired by [starkli](https://github.com/xJonathanLEI/starkli) created by Jonathan LEI.
It is licensed under Apache 2.0 / MIT License.
6 changes: 6 additions & 0 deletions bin/sozo/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use smol_str::SmolStr;
use tracing::level_filters::LevelFilter;
use tracing_log::AsTrace;

use crate::commands::account::AccountArgs;
use crate::commands::auth::AuthArgs;
use crate::commands::build::BuildArgs;
use crate::commands::clean::CleanArgs;
Expand All @@ -15,6 +16,7 @@ use crate::commands::dev::DevArgs;
use crate::commands::events::EventsArgs;
use crate::commands::execute::ExecuteArgs;
use crate::commands::init::InitArgs;
use crate::commands::keystore::KeystoreArgs;
use crate::commands::migrate::MigrateArgs;
use crate::commands::model::ModelArgs;
use crate::commands::register::RegisterArgs;
Expand Down Expand Up @@ -51,6 +53,8 @@ pub struct SozoArgs {

#[derive(Subcommand)]
pub enum Commands {
#[command(about = "Manage accounts")]
Account(AccountArgs),
#[command(about = "Build the world, generating the necessary artifacts for deployment")]
Build(BuildArgs),
#[command(about = "Initialize a new project")]
Expand All @@ -74,6 +78,8 @@ pub enum Commands {
Events(EventsArgs),
#[command(about = "Manage world authorization")]
Auth(AuthArgs),
#[clap(about = "Manage keystore files")]
Keystore(KeystoreArgs),
#[command(about = "Generate shell completion file for specified shell")]
Completions(CompletionsArgs),
}
Expand Down
121 changes: 121 additions & 0 deletions bin/sozo/src/commands/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use std::path::PathBuf;

use anyhow::Result;
use clap::{Args, Subcommand};
use scarb::core::Config;
use sozo_ops::account;
use starknet::signers::LocalWallet;
use starknet_crypto::FieldElement;

use super::options::fee::FeeOptions;
use super::options::signer::SignerOptions;
use super::options::starknet::StarknetOptions;
use crate::utils;

#[derive(Debug, Args)]
pub struct AccountArgs {
#[clap(subcommand)]
command: AccountCommand,
}

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Subcommand)]
pub enum AccountCommand {
#[clap(about = "Create a new account configuration without actually deploying.")]
New {
#[clap(flatten)]
signer: SignerOptions,

#[clap(long, short, help = "Overwrite the account config file if it already exists")]
force: bool,

Check warning on line 30 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L30

Added line #L30 was not covered by tests

#[clap(help = "Path to save the account config file")]
output: PathBuf,

Check warning on line 33 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L33

Added line #L33 was not covered by tests
JimmyFate marked this conversation as resolved.
Show resolved Hide resolved
},

#[clap(about = "Deploy account contract with a DeployAccount transaction.")]
Deploy {
#[clap(flatten)]
starknet: StarknetOptions,

#[clap(flatten)]
signer: SignerOptions,

#[clap(flatten)]
fee: FeeOptions,

#[clap(long, help = "Simulate the transaction only")]
simulate: bool,

Check warning on line 48 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L48

Added line #L48 was not covered by tests

#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<FieldElement>,

#[clap(
long,
env = "STARKNET_POLL_INTERVAL",
default_value = "1000",
help = "Transaction result poll interval in milliseconds"
)]
poll_interval: u64,

Check warning on line 59 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L59

Added line #L59 was not covered by tests

#[clap(help = "Path to the account config file")]
file: PathBuf,

Check warning on line 62 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L62

Added line #L62 was not covered by tests
},

#[clap(about = "Fetch account config from an already deployed account contract.")]
Fetch {
#[clap(flatten)]
starknet: StarknetOptions,

#[clap(long, help = "Overwrite the file if it already exists")]
force: bool,

Check warning on line 71 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L71

Added line #L71 was not covered by tests

#[clap(long, help = "Path to save the account config file")]
output: PathBuf,

Check warning on line 74 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L74

Added line #L74 was not covered by tests

#[clap(help = "Contract address")]
address: FieldElement,

Check warning on line 77 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L77

Added line #L77 was not covered by tests
},
}

impl AccountArgs {
pub fn run(self, config: &Config) -> Result<()> {
let env_metadata = utils::load_metadata_from_config(config)?;

config.tokio_handle().block_on(async {
match self.command {
AccountCommand::New { signer, force, output } => {
let signer: LocalWallet = signer.signer(env_metadata.as_ref())?;
account::new(signer, force, output).await
}
AccountCommand::Deploy {
starknet,
signer,
fee,
simulate,
nonce,
poll_interval,
file,

Check warning on line 98 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L92-L98

Added lines #L92 - L98 were not covered by tests
} => {
let provider = starknet.provider(env_metadata.as_ref())?;
let signer = signer.signer(env_metadata.as_ref())?;
let fee_setting = fee.into_setting()?;
account::deploy(
provider,
signer,
fee_setting,
simulate,
nonce,
poll_interval,
file,
)
.await

Check warning on line 112 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L100-L112

Added lines #L100 - L112 were not covered by tests
}
AccountCommand::Fetch { starknet, force, output, address } => {
let provider = starknet.provider(env_metadata.as_ref())?;
account::fetch(provider, force, output, address).await

Check warning on line 116 in bin/sozo/src/commands/account.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/account.rs#L114-L116

Added lines #L114 - L116 were not covered by tests
}
}
})
}
}
Loading
Loading