Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Jun 14, 2024
1 parent 3a84165 commit 9293c71
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
14 changes: 10 additions & 4 deletions bin/sozo/src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl AuthArgs {
env_metadata,
kind,
transaction,
config,
))
}
AuthCommand::Revoke { kind, world, starknet, account, transaction } => {
Expand All @@ -84,6 +85,7 @@ impl AuthArgs {
env_metadata,
kind,
transaction,
config,
))
}
}
Expand Down Expand Up @@ -123,10 +125,12 @@ pub async fn grant(
env_metadata: Option<Environment>,
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 } => {
Expand Down Expand Up @@ -154,10 +158,12 @@ pub async fn revoke(
env_metadata: Option<Environment>,
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!(
Expand Down
1 change: 1 addition & 0 deletions bin/sozo/src/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl ExecuteArgs {
self.account,
self.starknet,
&env_metadata,
config,
)
.await
.unwrap();
Expand Down
14 changes: 7 additions & 7 deletions bin/sozo/src/commands/options/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ impl AccountOptions {
&self,
provider: P,
env_metadata: Option<&Environment>,
) -> SingleOwnerAccount<P, LocalWallet>
) -> Result<SingleOwnerAccount<P, LocalWallet>>
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 };
Expand All @@ -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<FieldElement> {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion bin/sozo/src/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 10 additions & 3 deletions bin/sozo/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -54,11 +55,17 @@ pub async fn world_from_env_metadata(
account: AccountOptions,
starknet: StarknetOptions,
env_metadata: &Option<Environment>,
) -> Result<WorldContract<SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>>, Error> {
config: &Config,
) -> Result<
WorldContract<SessionAccount<JsonRpcClient<HttpTransport>, SigningKey, SigningKey>>,
Error,
> {
// ) -> Result<WorldContract<SingleOwnerAccount<JsonRpcClient<HttpTransport>, 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))
}

Expand Down

0 comments on commit 9293c71

Please sign in to comment.