From 9293c7140c59031f0c6a95cac76eeaea5544d664 Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Fri, 14 Jun 2024 15:17:04 -0400 Subject: [PATCH] wip --- bin/sozo/src/commands/auth.rs | 14 ++++++++++---- bin/sozo/src/commands/execute.rs | 1 + bin/sozo/src/commands/options/account/mod.rs | 14 +++++++------- bin/sozo/src/commands/register.rs | 3 ++- bin/sozo/src/utils.rs | 13 ++++++++++--- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/bin/sozo/src/commands/auth.rs b/bin/sozo/src/commands/auth.rs index ef6a687406..33b795d11f 100644 --- a/bin/sozo/src/commands/auth.rs +++ b/bin/sozo/src/commands/auth.rs @@ -73,6 +73,7 @@ impl AuthArgs { env_metadata, kind, transaction, + config, )) } AuthCommand::Revoke { kind, world, starknet, account, transaction } => { @@ -84,6 +85,7 @@ impl AuthArgs { env_metadata, kind, transaction, + config, )) } } @@ -123,10 +125,12 @@ pub async fn grant( env_metadata: Option, kind: AuthKind, transaction: TransactionOptions, + config: &Config, ) -> Result<()> { trace!(?kind, ?world, ?starknet, ?account, ?transaction, "Executing Grant command."); - let world = - utils::world_from_env_metadata(world, account, starknet, &env_metadata).await.unwrap(); + let world = utils::world_from_env_metadata(world, account, starknet, &env_metadata, config) + .await + .unwrap(); match kind { AuthKind::Writer { models_contracts } => { @@ -154,10 +158,12 @@ pub async fn revoke( env_metadata: Option, kind: AuthKind, transaction: TransactionOptions, + config: &Config, ) -> Result<()> { trace!(?kind, ?world, ?starknet, ?account, ?transaction, "Executing Revoke command."); - let world = - utils::world_from_env_metadata(world, account, starknet, &env_metadata).await.unwrap(); + let world = utils::world_from_env_metadata(world, account, starknet, &env_metadata, config) + .await + .unwrap(); match kind { AuthKind::Writer { models_contracts } => { trace!( diff --git a/bin/sozo/src/commands/execute.rs b/bin/sozo/src/commands/execute.rs index 40e3305e42..15d3b69a4c 100644 --- a/bin/sozo/src/commands/execute.rs +++ b/bin/sozo/src/commands/execute.rs @@ -55,6 +55,7 @@ impl ExecuteArgs { self.account, self.starknet, &env_metadata, + config, ) .await .unwrap(); diff --git a/bin/sozo/src/commands/options/account/mod.rs b/bin/sozo/src/commands/options/account/mod.rs index 8814625896..05fcddfe27 100644 --- a/bin/sozo/src/commands/options/account/mod.rs +++ b/bin/sozo/src/commands/options/account/mod.rs @@ -165,17 +165,17 @@ impl AccountOptions { &self, provider: P, env_metadata: Option<&Environment>, - ) -> SingleOwnerAccount + ) -> Result> where P: Send + Sync, { - let account_address = self.account_address(env_metadata).unwrap(); + let account_address = self.account_address(env_metadata)?; trace!(?account_address, "Account address determined."); - let signer = self.signer.signer(env_metadata, false).unwrap(); + let signer = self.signer.signer(env_metadata, false)?; trace!(?signer, "Signer obtained."); - let chain_id = provider.chain_id().await.unwrap(); + let chain_id = provider.chain_id().await?; trace!(?chain_id); let encoding = if self.legacy { ExecutionEncoding::Legacy } else { ExecutionEncoding::New }; @@ -186,7 +186,7 @@ impl AccountOptions { // The default is `Latest` in starknet-rs, which does not reflect // the nonce changes in the pending block. account.set_block_id(BlockId::Tag(BlockTag::Pending)); - account + Ok(account) } pub fn account_address(&self, env_metadata: Option<&Environment>) -> Result { @@ -352,7 +352,7 @@ mod tests { // HACK: SingleOwnerAccount doesn't expose a way to check `encoding` type used in struct, so // checking it by encoding a dummy call and checking which method it used to encode the call - let account = cmd.account.account(runner.provider(), None).await; + let account = cmd.account.account(runner.provider(), None).await.unwrap(); let result = account.encode_calls(&dummy_call); // 0x0 is the data offset. assert!(*result.get(3).unwrap() == FieldElement::from_hex_be("0x0").unwrap()); @@ -372,7 +372,7 @@ mod tests { // HACK: SingleOwnerAccount doesn't expose a way to check `encoding` type used in struct, so // checking it by encoding a dummy call and checking which method it used to encode the call - let account = cmd.account.account(runner.provider(), None).await; + let account = cmd.account.account(runner.provider(), None).await.unwrap(); let result = account.encode_calls(&dummy_call); // 0x2 is the Calldata len. assert!(*result.get(3).unwrap() == FieldElement::from_hex_be("0x2").unwrap()); diff --git a/bin/sozo/src/commands/register.rs b/bin/sozo/src/commands/register.rs index 8893cea2d4..f69fac41d2 100644 --- a/bin/sozo/src/commands/register.rs +++ b/bin/sozo/src/commands/register.rs @@ -60,7 +60,8 @@ impl RegisterArgs { config.tokio_handle().block_on(async { let world = - utils::world_from_env_metadata(world, account, starknet, &env_metadata).await?; + utils::world_from_env_metadata(world, account, starknet, &env_metadata, config) + .await?; let provider = world.account.provider(); let mut world_reader = WorldContractReader::new(world_address, &provider); world_reader.set_block(BlockId::Tag(BlockTag::Pending)); diff --git a/bin/sozo/src/utils.rs b/bin/sozo/src/utils.rs index d277c8d910..0701ad9033 100644 --- a/bin/sozo/src/utils.rs +++ b/bin/sozo/src/utils.rs @@ -1,5 +1,6 @@ use std::str::FromStr; +use account_sdk::account::session::SessionAccount; use anyhow::{Error, Result}; use camino::Utf8PathBuf; use dojo_world::contracts::world::WorldContract; @@ -10,7 +11,7 @@ use semver::Version; use starknet::accounts::SingleOwnerAccount; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; -use starknet::signers::LocalWallet; +use starknet::signers::{LocalWallet, SigningKey}; use crate::commands::options::account::AccountOptions; use crate::commands::options::starknet::StarknetOptions; @@ -54,11 +55,17 @@ pub async fn world_from_env_metadata( account: AccountOptions, starknet: StarknetOptions, env_metadata: &Option, -) -> Result, LocalWallet>>, Error> { + config: &Config, +) -> Result< + WorldContract, SigningKey, SigningKey>>, + Error, +> { + // ) -> Result, LocalWallet>>, Error> { 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 account = account.account(provider, env_metadata.as_ref()).await?; + let account = account.controller(provider, config).await?; Ok(WorldContract::new(world_address, account)) }