Skip to content

Commit

Permalink
Dropped basic wallet account from genesis file (#510)
Browse files Browse the repository at this point in the history
* feat: remove wallet from genesis config

* fix: print message

* feat: remove support of basic wallet in genesis file

* docs: update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: igamigo <[email protected]>

---------

Co-authored-by: igamigo <[email protected]>
  • Loading branch information
polydez and igamigo authored Oct 3, 2024
1 parent 8a9aa8b commit a0150ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [BREAKING] Changed `GetAccountDetailsResponse` field to `details` (#481).
- Improve `--version` by adding build metadata (#495).
- [BREAKING] Introduced additional limits for note/account number (#503).
- [BREAKING] Removed support for basic wallets in genesis creation (#510).

## 0.5.1 (2024-09-12)

Expand Down
41 changes: 11 additions & 30 deletions bin/node/src/commands/genesis/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,9 @@ pub struct GenesisInput {
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum AccountInput {
BasicWallet(BasicWalletInputs),
BasicFungibleFaucet(BasicFungibleFaucetInputs),
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct BasicWalletInputs {
pub init_seed: String,
pub auth_scheme: AuthSchemeInput,
pub auth_seed: String,
pub storage_mode: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct BasicFungibleFaucetInputs {
pub init_seed: String,
Expand All @@ -54,27 +45,17 @@ impl Default for GenesisInput {
.duration_since(UNIX_EPOCH)
.expect("Current timestamp should be greater than unix epoch")
.as_secs() as u32,
accounts: Some(vec![
AccountInput::BasicWallet(BasicWalletInputs {
init_seed: "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
.to_string(),
auth_scheme: AuthSchemeInput::RpoFalcon512,
auth_seed: "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
.to_string(),
storage_mode: "private".to_string(),
}),
AccountInput::BasicFungibleFaucet(BasicFungibleFaucetInputs {
init_seed: "0xc123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
.to_string(),
auth_scheme: AuthSchemeInput::RpoFalcon512,
auth_seed: "0xd123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
.to_string(),
token_symbol: "POL".to_string(),
decimals: 12,
max_supply: 1000000,
storage_mode: "public".to_string(),
}),
]),
accounts: Some(vec![AccountInput::BasicFungibleFaucet(BasicFungibleFaucetInputs {
init_seed: "0xc123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
.to_string(),
auth_scheme: AuthSchemeInput::RpoFalcon512,
auth_seed: "0xd123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
.to_string(),
token_symbol: "POL".to_string(),
decimals: 12,
max_supply: 1000000,
storage_mode: "public".to_string(),
})]),
}
}
}
47 changes: 7 additions & 40 deletions bin/node/src/commands/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ use std::{

use anyhow::{anyhow, bail, Context, Result};
pub use inputs::{AccountInput, AuthSchemeInput, GenesisInput};
use miden_lib::{
accounts::{faucets::create_basic_fungible_faucet, wallets::create_basic_wallet},
AuthScheme,
};
use miden_lib::{accounts::faucets::create_basic_fungible_faucet, AuthScheme};
use miden_node_store::genesis::GenesisState;
use miden_node_utils::config::load_config;
use miden_objects::{
accounts::{Account, AccountData, AccountStorageMode, AccountType, AuthSecretKey},
accounts::{Account, AccountData, AccountStorageMode, AuthSecretKey},
assets::TokenSymbol,
crypto::{
dsa::rpo_falcon512::SecretKey,
Expand Down Expand Up @@ -81,7 +78,7 @@ pub fn make_genesis(inputs_path: &PathBuf, output_path: &PathBuf, force: &bool)
let genesis_input: GenesisInput = load_config(inputs_path).map_err(|err| {
anyhow!("Failed to load {} genesis input file: {err}", inputs_path.display())
})?;
info!("Genesis input file: {} has successfully been loaded.", output_path.display());
info!("Genesis input file: {} has successfully been loaded.", inputs_path.display());

let accounts =
create_accounts(&genesis_input.accounts.unwrap_or_default(), parent_path, force)?;
Expand Down Expand Up @@ -128,24 +125,6 @@ fn create_accounts(
for account in accounts {
// build offchain account data from account inputs
let mut account_data = match account {
AccountInput::BasicWallet(inputs) => {
info!("Creating basic wallet account...");
let init_seed = hex_to_bytes(&inputs.init_seed)?;

let (auth_scheme, auth_secret_key) =
parse_auth_inputs(inputs.auth_scheme, &inputs.auth_seed)?;

let storage_mode: AccountStorageMode = inputs.storage_mode.as_str().try_into()?;

let (account, account_seed) = create_basic_wallet(
init_seed,
auth_scheme,
AccountType::RegularAccountImmutableCode,
storage_mode,
)?;

AccountData::new(account, Some(account_seed), auth_secret_key)
},
AccountInput::BasicFungibleFaucet(inputs) => {
info!("Creating fungible faucet account...");
let init_seed = hex_to_bytes(&inputs.init_seed)?;
Expand Down Expand Up @@ -234,13 +213,6 @@ mod tests {
version = 1
timestamp = 1672531200
[[accounts]]
type = "BasicWallet"
init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
storage_mode = "private"
[[accounts]]
type = "BasicFungibleFaucet"
init_seed = "0xc123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
Expand All @@ -259,27 +231,22 @@ mod tests {
make_genesis(&genesis_inputs_file_path, &genesis_dat_file_path, &true).unwrap();

let a0_file_path = PathBuf::from("accounts/account0.mac");
let a1_file_path = PathBuf::from("accounts/account1.mac");

// assert that the genesis.dat and account files exist
assert!(genesis_dat_file_path.exists());
assert!(a0_file_path.exists());
assert!(a1_file_path.exists());

// deserialize accounts and genesis_state
// deserialize account and genesis_state
let a0 = AccountData::read(a0_file_path).unwrap();
let a1 = AccountData::read(a1_file_path).unwrap();

// assert that the accounts have the corresponding storage mode
assert!(!a0.account.is_public());
assert!(a1.account.is_public());
// assert that the account has the corresponding storage mode
assert!(a0.account.is_public());

let genesis_file_contents = fs::read(genesis_dat_file_path).unwrap();
let genesis_state = GenesisState::read_from_bytes(&genesis_file_contents).unwrap();

// build supposed genesis_state
let supposed_genesis_state =
GenesisState::new(vec![a0.account, a1.account], 1, 1672531200);
let supposed_genesis_state = GenesisState::new(vec![a0.account], 1, 1672531200);

// assert that both genesis_state(s) are eq
assert_eq!(genesis_state, supposed_genesis_state);
Expand Down
7 changes: 0 additions & 7 deletions config/genesis.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
version = 1
timestamp = 1672531200

[[accounts]]
type = "BasicWallet"
storage_mode = "private"
init_seed = "0xa123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
auth_scheme = "RpoFalcon512"
auth_seed = "0xb123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"

[[accounts]]
type = "BasicFungibleFaucet"
storage_mode = "public"
Expand Down

0 comments on commit a0150ee

Please sign in to comment.