diff --git a/bin/sozo/src/commands/options/account/controller.rs b/bin/sozo/src/commands/options/account/controller.rs index 408570914d..68ced5c81b 100644 --- a/bin/sozo/src/commands/options/account/controller.rs +++ b/bin/sozo/src/commands/options/account/controller.rs @@ -1,9 +1,7 @@ -use std::str::FromStr; use std::sync::Arc; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; -use dojo_utils::TransactionWaiter; use dojo_world::contracts::naming::get_name_from_tag; use dojo_world::manifest::{BaseManifest, Class, DojoContract, Manifest}; use dojo_world::migration::strategy::generate_salt; @@ -13,16 +11,14 @@ use slot::account_sdk::account::session::merkle::MerkleTree; use slot::account_sdk::account::session::SessionAccount; use slot::session::{FullSessionInfo, PolicyMethod}; use starknet::core::types::contract::{AbiEntry, StateMutability}; -use starknet::core::types::StarknetError::ContractNotFound; -use starknet::core::types::{BlockId, BlockTag, Felt}; +use starknet::core::types::Felt; use starknet::core::utils::{ cairo_short_string_to_felt, get_contract_address, get_selector_from_name, }; use starknet::macros::felt; use starknet::providers::Provider; -use starknet::providers::ProviderError::StarknetError; use starknet_crypto::poseidon_hash_single; -use tracing::{trace, warn}; +use tracing::trace; use url::Url; use super::WorldAddressOrName; @@ -37,6 +33,16 @@ use super::WorldAddressOrName; pub type ControllerSessionAccount
= SessionAccount (
- rpc_url: Url,
- provider: &P,
- chain_id: Felt,
- address: Felt,
- username: &str,
-) -> Result<()>
-where
- P: Provider + Send,
-{
- use reqwest::Client;
- use serde_json::json;
-
- // Check if the account exists on the chain
- match provider.get_class_at(BlockId::Tag(BlockTag::Pending), address).await {
- Ok(_) => Ok(()),
-
- // if account doesn't exist, deploy it by calling `cartridge_deployController` method
- Err(err @ StarknetError(ContractNotFound)) => {
- trace!(
- %username,
- chain = format!("{chain_id:#}"),
- address = format!("{address:#x}"),
- "Controller does not exist on chain. Attempting to deploy..."
- );
-
- // Skip deployment if the rpc_url is not a Slot instance
- if !rpc_url.host_str().map_or(false, |host| host.contains("api.cartridge.gg")) {
- warn!(%rpc_url, "Unable to deploy Controller on non-Slot instance.");
- bail!("Controller with username '{username}' does not exist: {err}");
- }
-
- let body = json!({
- "id": 1,
- "jsonrpc": "2.0",
- "params": { "id": username },
- "method": "cartridge_deployController",
- });
-
- // The response object is in the form:
- //
- // {
- // "id": 1,
- // "jsonrpc": "2.0",
- // "result": {
- // "already_deployed": false,
- // "transaction_hash": "0x12345"
- // }
- // }
- let res = Client::new()
- .post(rpc_url)
- .json(&body)
- .send()
- .await?
- .error_for_status()
- .context("Failed to deploy controller")?;
-
- // TODO: handle this more elegantly
- let response = res.json::