Skip to content

Commit

Permalink
[rooch-networkgh-2022] eliminate account_index param.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Jul 9, 2024
1 parent 4332fc2 commit 14780b2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
3 changes: 2 additions & 1 deletion crates/rooch-key/src/keystore/account_keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use super::types::LocalAccount;
use crate::key_derive::{generate_derivation_path, generate_new_key_pair};
use ethers::etherscan::account;
use rooch_types::framework::session_key::SessionKey;
use rooch_types::key_struct::{MnemonicData, MnemonicResult};
use rooch_types::{
Expand Down Expand Up @@ -48,11 +49,11 @@ pub trait AccountKeystore {

fn generate_and_add_new_key(
&mut self,
account_index: u32,
password: Option<String>,
) -> Result<GeneratedKeyPair, anyhow::Error> {
// load mnemonic phrase from keystore
let mnemonic = self.get_mnemonic(password.clone())?;
let account_index = mnemonic.mnemonic_data.addresses.len() as u32;
let derivation_path = generate_derivation_path(account_index)?;
let result = generate_new_key_pair(
Some(mnemonic.mnemonic_phrase),
Expand Down
5 changes: 1 addition & 4 deletions crates/rooch-key/src/keystore/memory_keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@ impl InMemKeystore {
pub fn new_insecure_for_tests(initial_key_number: usize) -> Self {
let mut keystore = BaseKeyStore::new();
keystore.init_keystore(None, None, None).unwrap();
let account_index = keystore.addresses().len() as u32;
for _ in 0..initial_key_number {
keystore
.generate_and_add_new_key(account_index, None)
.unwrap();
keystore.generate_and_add_new_key(None).unwrap();
}

Self { keystore }
Expand Down
5 changes: 1 addition & 4 deletions crates/rooch/src/commands/account/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ impl CommandAction<Option<RoochAddressView>> for CreateCommand {
async fn execute(self) -> RoochResult<Option<RoochAddressView>> {
let mut context = self.context_options.build_require_password()?;
let password = context.get_password();
let account_index = context.keystore.addresses().len() as u32;
let result = context
.keystore
.generate_and_add_new_key(account_index, password)?;
let result = context.keystore.generate_and_add_new_key(password)?;

if self.json {
Ok(Some(result.address.into()))
Expand Down

0 comments on commit 14780b2

Please sign in to comment.