From 4d1b13dbef5eeb0b8ae86bcf04032aea78a32c14 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Wed, 3 Jan 2024 18:49:33 +0800 Subject: [PATCH] (console): fix load account failed not exit bug. (#813) --- src/main/java/console/ConsoleInitializer.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/console/ConsoleInitializer.java b/src/main/java/console/ConsoleInitializer.java index 3155df63..a853f687 100644 --- a/src/main/java/console/ConsoleInitializer.java +++ b/src/main/java/console/ConsoleInitializer.java @@ -171,25 +171,31 @@ private void loadAccountInfo(AccountInfo accountInfo, String groupID) { .getConfig() .getAccountConfig() .isAccountConfigured()) { - accountInfo = loadAccountRandomly(bcosSDK, client); - if (accountInfo != null) { + // load key from account dir + AccountInfo newAccountInfo = loadAccountRandomly(bcosSDK, client); + if (newAccountInfo != null) { this.client .getCryptoSuite() .loadAccount( - accountInfo.accountFileFormat, - accountInfo.accountFile, - accountInfo.password); + newAccountInfo.accountFileFormat, + newAccountInfo.accountFile, + newAccountInfo.password); } - if (accountInfo == null) { + if (newAccountInfo == null) { + // still not found key, use client crypto key pair // save the keyPair client.getCryptoSuite().getCryptoKeyPair().storeKeyPairWithPemFormat(); } } } catch (LoadKeyStoreException e) { - logger.warn( + logger.error( "loadAccountRandomly failed, try to generate and load the random account, error info: {}", e.getMessage(), e); + System.out.println( + "Failed to load the account from the keyStoreDir, error info: " + + e.getMessage()); + System.exit(0); } catch (Exception e) { System.out.println( "Failed to create BcosSDK failed! Please check the node status and the console configuration, error info: "