Skip to content

Commit

Permalink
fix account generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Nov 19, 2024
1 parent f5b6c07 commit 7230293
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
30 changes: 20 additions & 10 deletions cli/src/command/deployments/accounts.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
};
}
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 7230293

Please sign in to comment.