Skip to content

Commit

Permalink
sozo keystore, sozo account
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyFate committed Mar 21, 2024
1 parent f4c8111 commit 44b6bb0
Show file tree
Hide file tree
Showing 14 changed files with 1,215 additions and 221 deletions.
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: 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-bigint = "0.4.3"
num-integer = "0.1.45"
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
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
124 changes: 124 additions & 0 deletions bin/sozo/src/commands/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// MIT License

// Copyright (c) 2022 Jonathan LEI

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

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,

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

#[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,

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

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

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

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()).unwrap();
account::new(signer, force, output).await
}
AccountCommand::Deploy {
starknet,
signer,
fee,
simulate,
nonce,
poll_interval,
file,
} => {
let provider = starknet.provider(env_metadata.as_ref()).unwrap();
let signer = signer.signer(env_metadata.as_ref()).unwrap();
let fee_setting = fee.into_setting()?;
account::deploy(
provider,
signer,
fee_setting,
simulate,
nonce,
poll_interval,
file,
)
.await
}
}
})
}
}
Loading

0 comments on commit 44b6bb0

Please sign in to comment.