diff --git a/Cargo.toml b/Cargo.toml index 3aaf546..baa5122 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,5 +21,4 @@ serde = "1" serde_json = "1" thiserror = "1.0.32" url = "2.2.2" -rand = "0.8.4" starknet = "0.12.0" diff --git a/cli/src/command/deployments/accounts.rs b/cli/src/command/deployments/accounts.rs index 47e3a92..15358d9 100644 --- a/cli/src/command/deployments/accounts.rs +++ b/cli/src/command/deployments/accounts.rs @@ -1,15 +1,13 @@ #![allow(clippy::enum_variant_names)] +use std::collections::BTreeMap; use std::str::FromStr; use anyhow::Result; use clap::Args; use katana_primitives::contract::ContractAddress; -use katana_primitives::genesis::allocation::GenesisAccountAlloc; -use katana_primitives::genesis::allocation::{ - DevAllocationsGenerator, DevGenesisAccount, GenesisAccount, -}; -use katana_primitives::genesis::Genesis; +use katana_primitives::genesis::allocation::{DevAllocationsGenerator, GenesisAccountAlloc}; +use katana_primitives::genesis::allocation::{DevGenesisAccount, GenesisAccount}; use slot::graphql::deployments::katana_accounts::KatanaAccountsDeploymentConfig::KatanaConfig; use slot::graphql::deployments::{katana_accounts::*, KatanaAccounts}; use slot::graphql::GraphQLQuery; @@ -69,14 +67,24 @@ impl AccountsArgs { print_genesis_accounts(accounts_vec.iter().map(|(a, b)| (a, b)), None); } None => { + // NOTICE: This is implementation assume that the Katana instance is configured with the default seed and total number of accounts. If not, the + // generated addresses will be different from the ones in the Katana instance. This is rather a hack until `slot` can return the addresses directly (or + // at least the exact configurations of the instance). + + let seed = "0"; + + // TODO: change the output of `.generate()` into a BTreeMap instead of HashMap let accounts = DevAllocationsGenerator::new(10) - .with_seed(parse_seed(&config.seed)) + .with_seed(parse_seed(seed)) .generate(); - let mut genesis = Genesis::default(); - genesis - .extend_allocations(accounts.into_iter().map(|(k, v)| (k, v.into()))); - print_genesis_accounts(genesis.accounts().peekable(), Some(&config.seed)); + // Convert to BTreeMap to order the accounts by address + let accounts = accounts + .into_iter() + .map(|(a, acc)| (a, GenesisAccountAlloc::DevAccount(acc))); + let accounts = BTreeMap::from_iter(accounts); + + print_genesis_accounts(accounts.iter(), Some(seed)); } }; } @@ -127,6 +135,8 @@ ACCOUNTS SEED } } +// Mimic how Katana parse the seed to generate the predeployed accounts +// https://github.com/dojoengine/dojo/blob/85c0b025f108bd1ed64a5b35cfb574f61545a0ff/crates/katana/cli/src/utils.rs#L24-L34 fn parse_seed(seed: &str) -> [u8; 32] { let seed = seed.as_bytes();