|
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; |
@@ -412,63 +407,7 @@ public static void setParam(final Config config) { |
412 | 407 | PARAMETER.cryptoEngine = config.hasPath(Constant.CRYPTO_ENGINE) ? config |
413 | 408 | .getString(Constant.CRYPTO_ENGINE) : Constant.ECKey_ENGINE; |
414 | 409 |
|
415 | | - if (StringUtils.isNoneBlank(PARAMETER.privateKey)) { |
416 | | - localWitnesses = (new LocalWitnesses(PARAMETER.privateKey)); |
417 | | - byte[] witnessAddress = null; |
418 | | - if (StringUtils.isNoneBlank(PARAMETER.witnessAddress)) { |
419 | | - witnessAddress = Commons.decodeFromBase58Check(PARAMETER.witnessAddress); |
420 | | - if (witnessAddress != null) { |
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(witnessAddress, PARAMETER.isECKeyCryptoEngine()); |
428 | | - logger.debug("Got privateKey from cmd"); |
429 | | - } else if (config.hasPath(Constant.LOCAL_WITNESS)) { |
430 | | - localWitnesses = new LocalWitnesses(); |
431 | | - byte[] witnessAddress = getWitnessAddress(config); |
432 | | - List<String> localwitness = config.getStringList(Constant.LOCAL_WITNESS); |
433 | | - if (!localwitness.isEmpty()) { |
434 | | - localWitnesses.setPrivateKeys(localwitness); |
435 | | - logger.debug("Got privateKey from config.conf"); |
436 | | - } |
437 | | - localWitnesses.initWitnessAccountAddress(witnessAddress, PARAMETER.isECKeyCryptoEngine()); |
438 | | - } else if (config.hasPath(Constant.LOCAL_WITNESS_KEYSTORE)) { |
439 | | - localWitnesses = new LocalWitnesses(); |
440 | | - List<String> privateKeys = new ArrayList<String>(); |
441 | | - if (PARAMETER.isWitness()) { |
442 | | - List<String> localwitness = config.getStringList(Constant.LOCAL_WITNESS_KEYSTORE); |
443 | | - if (!localwitness.isEmpty()) { |
444 | | - String fileName = System.getProperty("user.dir") + "/" + localwitness.get(0); |
445 | | - String password; |
446 | | - if (StringUtils.isEmpty(PARAMETER.password)) { |
447 | | - System.out.println("Please input your password."); |
448 | | - password = WalletUtils.inputPassword(); |
449 | | - } else { |
450 | | - password = PARAMETER.password; |
451 | | - PARAMETER.password = null; |
452 | | - } |
453 | | - |
454 | | - try { |
455 | | - Credentials credentials = WalletUtils |
456 | | - .loadCredentials(password, new File(fileName)); |
457 | | - SignInterface sign = credentials.getSignInterface(); |
458 | | - String prikey = ByteArray.toHexString(sign.getPrivateKey()); |
459 | | - privateKeys.add(prikey); |
460 | | - } catch (IOException | CipherException e) { |
461 | | - logger.error("Witness node start failed!"); |
462 | | - throw new TronError(e, TronError.ErrCode.WITNESS_KEYSTORE_LOAD); |
463 | | - } |
464 | | - } |
465 | | - } |
466 | | - localWitnesses.setPrivateKeys(privateKeys); |
467 | | - byte[] witnessAddress = getWitnessAddress(config); |
468 | | - localWitnesses.initWitnessAccountAddress(witnessAddress, PARAMETER.isECKeyCryptoEngine()); |
469 | | - logger.debug("Got privateKey from keystore"); |
470 | | - } |
471 | | - |
| 410 | + localWitnesses = new WitnessInitializer(config).initLocalWitnesses(); |
472 | 411 | if (PARAMETER.isWitness() |
473 | 412 | && CollectionUtils.isEmpty(localWitnesses.getPrivateKeys())) { |
474 | 413 | throw new TronError("This is a witness node, but localWitnesses is null", |
@@ -1819,20 +1758,6 @@ public static void logConfig() { |
1819 | 1758 | logger.info("\n"); |
1820 | 1759 | } |
1821 | 1760 |
|
1822 | | - private static byte[] getWitnessAddress(Config config) { |
1823 | | - byte[] witnessAddress = null; |
1824 | | - if (config.hasPath(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS)) { |
1825 | | - witnessAddress = Commons |
1826 | | - .decodeFromBase58Check(config.getString(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS)); |
1827 | | - if (witnessAddress != null) { |
1828 | | - logger.debug("Got localWitnessAccountAddress from config.conf"); |
1829 | | - } else { |
1830 | | - logger.warn(IGNORE_WRONG_WITNESS_ADDRESS_FORMAT); |
1831 | | - } |
1832 | | - } |
1833 | | - return witnessAddress; |
1834 | | - } |
1835 | | - |
1836 | 1761 | /** |
1837 | 1762 | * get output directory. |
1838 | 1763 | */ |
|
0 commit comments