@@ -168,7 +168,7 @@ private AccountDTO addInternalAccount(int derivation) throws ValidationException
168168 return null ;
169169 }
170170 final ECKey firstDerivation = root .deriveHardened (new int []{44 , 60 , 0 , 0 , derivation }).getEcKey ();
171- AccountDTO account = createAccountWithPrivateKey (TypeConverter .toJsonHex (firstDerivation .computeAddress (firstDerivation .getPubKey ())), firstDerivation .getPrivKeyBytes (), false );
171+ AccountDTO account = createAccountWithPrivateKey (TypeConverter .toJsonHex (firstDerivation .computeAddress (firstDerivation .getPubKey ())), firstDerivation .getPrivKeyBytes (), false , derivation );
172172 EventPublisher .fireTransactionFinished ();
173173 return account ;
174174 }
@@ -186,7 +186,7 @@ private AccountDTO addExternalAccount(final ECKey key, final byte[] fileContent,
186186 if (!Keystore .exist (address )) {
187187 address = Keystore .create (password , key );
188188 if (AddressUtils .isValid (address )) {
189- accountDTO = createAccountWithPrivateKey (address , key .getPrivKeyBytes (), true );
189+ accountDTO = createImportedAccountFromPrivateKey (address , key .getPrivKeyBytes ());
190190 } else {
191191 throw new ValidationException ("Failed to save keystore file" );
192192 }
@@ -195,7 +195,7 @@ private AccountDTO addExternalAccount(final ECKey key, final byte[] fileContent,
195195 }
196196 } else {
197197 if (!addressToAccount .keySet ().contains (address )) {
198- accountDTO = createAccountWithPrivateKey (address , key .getPrivKeyBytes (), true );
198+ accountDTO = createImportedAccountFromPrivateKey (address , key .getPrivKeyBytes ());
199199 } else {
200200 throw new ValidationException ("Account already exists!" );
201201 }
@@ -280,7 +280,11 @@ private void handleSettingsChanged(final SettingsEvent event) {
280280 }
281281 }
282282
283- private AccountDTO createAccountWithPrivateKey (final String address , final byte [] privateKeyBytes , boolean isImported ) {
283+ private AccountDTO createImportedAccountFromPrivateKey (final String address , final byte [] privateKeyBytes ) {
284+ return createAccountWithPrivateKey (address , privateKeyBytes , true , -1 );
285+ }
286+
287+ private AccountDTO createAccountWithPrivateKey (final String address , final byte [] privateKeyBytes , boolean isImported , int derivation ) {
284288 if (address == null ) {
285289 log .error ("Can't create account with null address" );
286290 return null ;
@@ -292,13 +296,9 @@ private AccountDTO createAccountWithPrivateKey(final String address, final byte[
292296 final String name = getStoredAccountName (address );
293297 final String balance = BalanceUtils .formatBalance (balanceProvider .apply (address ));
294298
295- AccountDTO account = new AccountDTO (name , address , balance , currencySupplier .get ());
299+ AccountDTO account = new AccountDTO (name , address , balance , currencySupplier .get (), isImported , derivation );
296300 account .setPrivateKey (privateKeyBytes );
297301 account .setActive (true );
298- account .setImported (isImported );
299- if (!isImported ) {
300- account .setDerivationIndex (walletStorage .getMasterAccountDerivations ());
301- }
302302 addressToAccount .put (account .getPublicAddress (), account );
303303 return account ;
304304 }
@@ -338,7 +338,7 @@ private String getStoredAccountName(final String publicAddress) {
338338 private AccountDTO getNewAccount (final String publicAddress ) {
339339 final String name = getStoredAccountName (publicAddress );
340340 final String balance = BalanceUtils .formatBalance (balanceProvider .apply (publicAddress ));
341- return new AccountDTO (name , publicAddress , balance , currencySupplier .get ());
341+ return new AccountDTO (name , publicAddress , balance , currencySupplier .get (), true , - 1 );
342342 }
343343
344344 private void storeAccountName (final String address , final String name ) {
0 commit comments