Skip to content

Commit

Permalink
Update execute to work with contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Sep 27, 2023
1 parent 28eebb8 commit d97e756
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 441 deletions.
3 changes: 0 additions & 3 deletions crates/sozo/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::commands::execute::ExecuteArgs;
use crate::commands::init::InitArgs;
use crate::commands::migrate::MigrateArgs;
use crate::commands::register::RegisterArgs;
use crate::commands::system::SystemArgs;
use crate::commands::test::TestArgs;

#[derive(Parser)]
Expand Down Expand Up @@ -66,8 +65,6 @@ pub enum Commands {
Execute(ExecuteArgs),
#[command(about = "Interact with a worlds components")]
Component(ComponentArgs),
#[command(about = "Interact with a worlds systems")]
System(SystemArgs),
#[command(about = "Register new systems and components")]
Register(RegisterArgs),
#[command(about = "Queries world events")]
Expand Down
11 changes: 5 additions & 6 deletions crates/sozo/src/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@ use starknet::core::types::FieldElement;

use super::options::account::AccountOptions;
use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;
use crate::ops::execute;

#[derive(Debug, Args)]
#[command(about = "Execute a system with the given calldata.")]
pub struct ExecuteArgs {
#[arg(help = "The name of the system to be executed.")]
pub system: String,
#[arg(help = "The address of the contract to be executed.")]
pub contract: FieldElement,

#[arg(help = "The name of the entrypoint to be executed.")]
pub entrypoint: String,

#[arg(short, long)]
#[arg(value_delimiter = ',')]
#[arg(help = "The calldata to be passed to the system. Comma seperated values e.g., \
0x12345,0x69420.")]
pub calldata: Vec<FieldElement>,

#[command(flatten)]
pub world: WorldOptions,

#[command(flatten)]
pub starknet: StarknetOptions,

Expand Down
2 changes: 0 additions & 2 deletions crates/sozo/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub(crate) mod init;
pub(crate) mod migrate;
pub(crate) mod options;
pub(crate) mod register;
pub(crate) mod system;
pub(crate) mod test;

// copy of non pub functions from scarb
Expand All @@ -30,7 +29,6 @@ pub fn run(command: Commands, config: &Config) -> Result<()> {
Commands::Auth(args) => args.run(config),
Commands::Execute(args) => args.run(config),
Commands::Component(args) => args.run(config),
Commands::System(args) => args.run(config),
Commands::Register(args) => args.run(config),
Commands::Events(args) => args.run(config),
Commands::Completions(args) => args.run(),
Expand Down
61 changes: 0 additions & 61 deletions crates/sozo/src/commands/system.rs

This file was deleted.

18 changes: 12 additions & 6 deletions crates/sozo/src/ops/execute.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
use anyhow::{Context, Result};
use dojo_world::metadata::Environment;
use torii_client::contract::world::WorldContract;
use starknet::accounts::{Account, Call};
use starknet::core::utils::get_selector_from_name;

use crate::commands::execute::ExecuteArgs;

pub async fn execute(args: ExecuteArgs, env_metadata: Option<Environment>) -> Result<()> {
let ExecuteArgs { system, calldata, world, starknet, account } = args;
let ExecuteArgs { contract, entrypoint, calldata, starknet, account } = args;

let world_address = world.address(env_metadata.as_ref())?;
let provider = starknet.provider(env_metadata.as_ref())?;

let account = account.account(provider, env_metadata.as_ref()).await?;
let world = WorldContract::new(world_address, &account);

let res =
world.execute(&system, calldata).await.with_context(|| "Failed to send transaction")?;
let res = account
.execute(vec![Call {
calldata,
to: contract,
selector: get_selector_from_name(&entrypoint).unwrap(),
}])
.send()
.await
.with_context(|| "Failed to send transaction")?;

println!("Transaction: {:#x}", res.transaction_hash);

Expand Down
1 change: 0 additions & 1 deletion crates/sozo/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ pub mod events;
pub mod execute;
pub mod migration;
pub mod register;
pub mod system;
66 changes: 0 additions & 66 deletions crates/sozo/src/ops/system.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/torii/client/src/contract/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod component;
pub mod system;
pub mod world;
Loading

0 comments on commit d97e756

Please sign in to comment.