|
53 | 53 | import org.tron.common.args.Witness; |
54 | 54 | import org.tron.common.config.DbBackupConfig; |
55 | 55 | import org.tron.common.cron.CronExpression; |
56 | | -import org.tron.common.crypto.SignInterface; |
57 | 56 | import org.tron.common.logsfilter.EventPluginConfig; |
58 | 57 | import org.tron.common.logsfilter.FilterQuery; |
59 | 58 | import org.tron.common.logsfilter.TriggerConfig; |
|
62 | 61 | import org.tron.common.parameter.CommonParameter; |
63 | 62 | import org.tron.common.parameter.RateLimiterInitialization; |
64 | 63 | import org.tron.common.setting.RocksDbSettings; |
65 | | -import org.tron.common.utils.ByteArray; |
66 | 64 | import org.tron.common.utils.Commons; |
67 | 65 | import org.tron.common.utils.LocalWitnesses; |
68 | 66 | import org.tron.core.Constant; |
69 | 67 | import org.tron.core.Wallet; |
70 | 68 | import org.tron.core.config.Configuration; |
71 | 69 | import org.tron.core.config.Parameter.NetConstants; |
72 | 70 | import org.tron.core.config.Parameter.NodeConstant; |
73 | | -import org.tron.core.exception.CipherException; |
74 | 71 | import org.tron.core.exception.TronError; |
75 | 72 | import org.tron.core.store.AccountStore; |
76 | | -import org.tron.keystore.Credentials; |
77 | | -import org.tron.keystore.WalletUtils; |
78 | 73 | import org.tron.p2p.P2pConfig; |
79 | 74 | import org.tron.p2p.dns.update.DnsType; |
80 | 75 | import org.tron.p2p.dns.update.PublishConfig; |
@@ -378,6 +373,7 @@ private static Map<String, String[]> getOptionGroup() { |
378 | 373 | */ |
379 | 374 | public static void setParam(final String[] args, final String confFileName) { |
380 | 375 | Arch.throwUnsupportedJavaException(); |
| 376 | + clearParam(); // reset all parameters to avoid the influence in test |
381 | 377 | JCommander.newBuilder().addObject(PARAMETER).build().parse(args); |
382 | 378 | if (PARAMETER.version) { |
383 | 379 | printVersion(); |
@@ -412,61 +408,7 @@ public static void setParam(final Config config) { |
412 | 408 | PARAMETER.cryptoEngine = config.hasPath(Constant.CRYPTO_ENGINE) ? config |
413 | 409 | .getString(Constant.CRYPTO_ENGINE) : Constant.ECKey_ENGINE; |
414 | 410 |
|
415 | | - if (StringUtils.isNoneBlank(PARAMETER.privateKey)) { |
416 | | - localWitnesses = (new LocalWitnesses(PARAMETER.privateKey)); |
417 | | - if (StringUtils.isNoneBlank(PARAMETER.witnessAddress)) { |
418 | | - byte[] bytes = Commons.decodeFromBase58Check(PARAMETER.witnessAddress); |
419 | | - if (bytes != null) { |
420 | | - localWitnesses.setWitnessAccountAddress(bytes); |
421 | | - logger.debug("Got localWitnessAccountAddress from cmd"); |
422 | | - } else { |
423 | | - PARAMETER.witnessAddress = ""; |
424 | | - logger.warn(IGNORE_WRONG_WITNESS_ADDRESS_FORMAT); |
425 | | - } |
426 | | - } |
427 | | - localWitnesses.initWitnessAccountAddress(PARAMETER.isECKeyCryptoEngine()); |
428 | | - logger.debug("Got privateKey from cmd"); |
429 | | - } else if (config.hasPath(Constant.LOCAL_WITNESS)) { |
430 | | - localWitnesses = new LocalWitnesses(); |
431 | | - List<String> localwitness = config.getStringList(Constant.LOCAL_WITNESS); |
432 | | - localWitnesses.setPrivateKeys(localwitness); |
433 | | - witnessAddressCheck(config); |
434 | | - localWitnesses.initWitnessAccountAddress(PARAMETER.isECKeyCryptoEngine()); |
435 | | - logger.debug("Got privateKey from config.conf"); |
436 | | - } else if (config.hasPath(Constant.LOCAL_WITNESS_KEYSTORE)) { |
437 | | - localWitnesses = new LocalWitnesses(); |
438 | | - List<String> privateKeys = new ArrayList<String>(); |
439 | | - if (PARAMETER.isWitness()) { |
440 | | - List<String> localwitness = config.getStringList(Constant.LOCAL_WITNESS_KEYSTORE); |
441 | | - if (localwitness.size() > 0) { |
442 | | - String fileName = System.getProperty("user.dir") + "/" + localwitness.get(0); |
443 | | - String password; |
444 | | - if (StringUtils.isEmpty(PARAMETER.password)) { |
445 | | - System.out.println("Please input your password."); |
446 | | - password = WalletUtils.inputPassword(); |
447 | | - } else { |
448 | | - password = PARAMETER.password; |
449 | | - PARAMETER.password = null; |
450 | | - } |
451 | | - |
452 | | - try { |
453 | | - Credentials credentials = WalletUtils |
454 | | - .loadCredentials(password, new File(fileName)); |
455 | | - SignInterface sign = credentials.getSignInterface(); |
456 | | - String prikey = ByteArray.toHexString(sign.getPrivateKey()); |
457 | | - privateKeys.add(prikey); |
458 | | - } catch (IOException | CipherException e) { |
459 | | - logger.error("Witness node start failed!"); |
460 | | - throw new TronError(e, TronError.ErrCode.WITNESS_KEYSTORE_LOAD); |
461 | | - } |
462 | | - } |
463 | | - } |
464 | | - localWitnesses.setPrivateKeys(privateKeys); |
465 | | - witnessAddressCheck(config); |
466 | | - localWitnesses.initWitnessAccountAddress(PARAMETER.isECKeyCryptoEngine()); |
467 | | - logger.debug("Got privateKey from keystore"); |
468 | | - } |
469 | | - |
| 411 | + localWitnesses = new WitnessInitializer(config).initLocalWitnesses(); |
470 | 412 | if (PARAMETER.isWitness() |
471 | 413 | && CollectionUtils.isEmpty(localWitnesses.getPrivateKeys())) { |
472 | 414 | throw new TronError("This is a witness node, but localWitnesses is null", |
@@ -1817,19 +1759,6 @@ public static void logConfig() { |
1817 | 1759 | logger.info("\n"); |
1818 | 1760 | } |
1819 | 1761 |
|
1820 | | - private static void witnessAddressCheck(Config config) { |
1821 | | - if (config.hasPath(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS)) { |
1822 | | - byte[] bytes = Commons |
1823 | | - .decodeFromBase58Check(config.getString(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS)); |
1824 | | - if (bytes != null) { |
1825 | | - localWitnesses.setWitnessAccountAddress(bytes); |
1826 | | - logger.debug("Got localWitnessAccountAddress from config.conf"); |
1827 | | - } else { |
1828 | | - logger.warn(IGNORE_WRONG_WITNESS_ADDRESS_FORMAT); |
1829 | | - } |
1830 | | - } |
1831 | | - } |
1832 | | - |
1833 | 1762 | /** |
1834 | 1763 | * get output directory. |
1835 | 1764 | */ |
|
0 commit comments