Skip to content

Commit cdfaa9c

Browse files
committed
refactor: modify code
1 parent 6ef88f9 commit cdfaa9c

29 files changed

Lines changed: 101 additions & 106 deletions

‎src/main/java/org/tron/command/SendCommand.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.tron.utils.ByteArray;
1111

1212
public class SendCommand extends Command {
13-
private static final Logger logger = LoggerFactory.getLogger("command");
13+
private static final Logger LOGGER = LoggerFactory.getLogger("Command");
1414

1515
public SendCommand() {
1616
}
@@ -42,12 +42,12 @@ public void usage() {
4242
@Override
4343
public boolean check(String[] parameters) {
4444
if (parameters.length < 2) {
45-
logger.error("missing parameters");
45+
LOGGER.error("missing parameters");
4646
return false;
4747
}
4848

4949
if (parameters[0].length() != 40) {
50-
logger.error("address invalid");
50+
LOGGER.error("address invalid");
5151
return false;
5252
}
5353

@@ -56,12 +56,12 @@ public boolean check(String[] parameters) {
5656
try {
5757
amount = Long.valueOf(parameters[1]);
5858
} catch (NumberFormatException e) {
59-
logger.error("amount invalid");
59+
LOGGER.error("amount invalid");
6060
return false;
6161
}
6262

6363
if (amount <= 0) {
64-
logger.error("amount required a positive number");
64+
LOGGER.error("amount required a positive number");
6565
return false;
6666
}
6767

‎src/main/java/org/tron/config/Configer.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.Properties;
1313

1414
public class Configer {
15-
private static Logger logger = LoggerFactory.getLogger("configer");
15+
private static final Logger LOGGER = LoggerFactory.getLogger("Configer");
1616

1717
private final static String TRON_CONF = "tron.conf";
1818
private final static String DATABASE_DIRECTORY = "database.directory";
@@ -42,9 +42,9 @@ public class Configer {
4242
try (Writer w = new FileWriter(file)) {
4343
props.store(w, "Generated NodeID.");
4444
}
45-
logger.info("New nodeID generated: " + props.getProperty
45+
LOGGER.info("New nodeID generated: " + props.getProperty
4646
("nodeId"));
47-
logger.info("Generated nodeID and its private key stored " +
47+
LOGGER.info("Generated nodeID and its private key stored " +
4848
"in " + file);
4949
}
5050
generatedNodePrivateKey = props.getProperty("nodeIdPrivateKey");

‎src/main/java/org/tron/config/SystemProperties.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public class SystemProperties {
99
private @interface ValidateMe {
1010
}
1111

12-
;
13-
1412
private static SystemProperties CONFIG;
1513
private static boolean useOnlySpringConfig = false;
1614

‎src/main/java/org/tron/core/Blockchain.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import static org.tron.datasource.leveldb.LevelDbDataSource.databaseName;
3030

3131
public class Blockchain {
32-
public static final Logger logger = LoggerFactory.getLogger("BlockChain");
33-
public static final String genesisCoinbaseData = "0x00";
32+
private static final Logger LOGGER = LoggerFactory.getLogger("Blockchain");
33+
public static final String GENESIS_COINBASE_DATA = "0x00";
3434
private LevelDbDataSource blockDB = null;
3535
private PendingState pendingState = new PendingStateImpl();
3636

@@ -44,15 +44,15 @@ public class Blockchain {
4444
*/
4545
public Blockchain(String address) {
4646
if (dbExists()) {
47-
logger.info("blockchain already exists.");
47+
LOGGER.info("blockchain already exists.");
4848
System.exit(0);
4949
}
5050

5151
blockDB = new LevelDbDataSource(BLOCK_DB_NAME);
5252
blockDB.init();
5353

5454
Transaction coinbase = TransactionUtils.newCoinbaseTransaction
55-
(address, genesisCoinbaseData);
55+
(address, GENESIS_COINBASE_DATA);
5656
Block genesisBlock = BlockUtils.newGenesisBlock(coinbase);
5757

5858
this.lastHash = genesisBlock.getBlockHeader().getHash().toByteArray();
@@ -66,15 +66,15 @@ public Blockchain(String address) {
6666

6767
blockDB.put(LAST_HASH, lastHash);
6868

69-
logger.info("new blockchain");
69+
LOGGER.info("new blockchain");
7070
}
7171

7272
/**
7373
* create blockchain by db source
7474
*/
7575
public Blockchain() {
7676
if (!dbExists()) {
77-
logger.info("no existing blockchain found. please create one " +
77+
LOGGER.info("no existing blockchain found. please create one " +
7878
"first");
7979
System.exit(0);
8080
}
@@ -85,7 +85,7 @@ public Blockchain() {
8585
this.lastHash = blockDB.get(LAST_HASH);
8686
this.currentHash = this.lastHash;
8787

88-
logger.info("load blockchain");
88+
LOGGER.info("load blockchain");
8989
}
9090

9191
/**
@@ -277,7 +277,7 @@ public void receiveBlock(Block block, UTXOSet utxoSet) {
277277
}
278278

279279
public static String getGenesisCoinbaseData() {
280-
return genesisCoinbaseData;
280+
return GENESIS_COINBASE_DATA;
281281
}
282282

283283
public LevelDbDataSource getBlockDB() {

‎src/main/java/org/tron/core/PendingStateImpl.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public void addPendingTransaction(Transaction tx) {
4343
public synchronized void addPendingTransaction(Blockchain blockchain, Transaction tx, Net net) {
4444
pendingTransactions.add(tx);
4545
if (pendingTransactions.size() == 1) {
46-
System.out.println("pending...");
4746
blockchain.addBlock(pendingTransactions, net);
4847
pendingTransactions.clear();
4948
System.out.println();

‎src/main/java/org/tron/core/TransactionUtils.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import static org.tron.utils.Utils.getRandom;
2121

2222
public class TransactionUtils {
23-
private static final Logger logger = LoggerFactory.getLogger("transaction");
24-
private final static int subsidy = 10; // Mining reward
23+
private static final Logger LOGGER = LoggerFactory.getLogger("Transaction");
24+
private final static int RESERVE_BALANCE = 10;
2525

2626
public static Transaction newTransaction(Wallet wallet, String to, long amount, UTXOSet utxoSet) {
2727
ArrayList<TXInput> txInputs = new ArrayList<>();
@@ -32,7 +32,7 @@ public static Transaction newTransaction(Wallet wallet, String to, long amount,
3232
SpendableOutputs spendableOutputs = utxoSet.findSpendableOutputs(pubKeyHash, amount);
3333

3434
if (spendableOutputs.getAmount() < amount) {
35-
logger.error("Not enough funds");
35+
LOGGER.error("Not enough funds");
3636
return null;
3737
}
3838

@@ -87,7 +87,7 @@ public static Transaction newCoinbaseTransaction(String to, String data) {
8787

8888
TXInput txi = TXInputUtils.newTXInput(new byte[]{}, -1, new byte[]{},
8989
ByteArray.fromHexString(data));
90-
TXOutput txo = TXOutputUtils.newTXOutput(subsidy, to);
90+
TXOutput txo = TXOutputUtils.newTXOutput(RESERVE_BALANCE, to);
9191

9292
Transaction.Builder coinbaseTransaction = Transaction.newBuilder()
9393
.addVin(txi)
@@ -193,7 +193,7 @@ public static Transaction sign(Transaction transaction, ECKey myKey,
193193
for (TXInput vin : transaction.getVinList()) {
194194
if (prevTXs.get(ByteArray.toHexString(vin.getTxID().toByteArray()
195195
)).getId().toByteArray().length == 0) {
196-
logger.error("ERROR: Previous transaction is not correct");
196+
LOGGER.error("ERROR: Previous transaction is not correct");
197197
return null;
198198
}
199199
}
@@ -237,7 +237,7 @@ public static boolean verify(ECKey myKey, Transaction transaction,
237237
for (TXInput vin : transaction.getVinList()) {
238238
if (prevTXs.get(ByteArray.toHexString(vin.getTxID().toByteArray()
239239
)).getId().toByteArray().length == 0) {
240-
logger.error("ERROR: Previous transaction is not correct");
240+
LOGGER.error("ERROR: Previous transaction is not correct");
241241
}
242242
}
243243

‎src/main/java/org/tron/core/TronBlockChainImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class TronBlockChainImpl implements TronBlockChain, org.tron.facade
2525
.TronBlockChain {
2626

27-
private static final Logger logger = LoggerFactory.getLogger("blockchain");
27+
private static final Logger LOGGER = LoggerFactory.getLogger("Blockchain");
2828

2929
SystemProperties config = SystemProperties.getDefault();
3030

@@ -120,7 +120,7 @@ private void recordBlock(TronBlock.Block block) {
120120
bw.write("\n");
121121

122122
} catch (IOException e) {
123-
logger.error(e.getMessage(), e);
123+
LOGGER.error(e.getMessage(), e);
124124
} finally {
125125
try {
126126
if (bw != null) bw.close();

‎src/main/java/org/tron/core/UTXOSet.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import static org.tron.core.Constant.TRANSACTION_DB_NAME;
1616

1717
public class UTXOSet {
18-
private static final Logger logger = LoggerFactory.getLogger("UTXOSet");
18+
private static final Logger LOGGER = LoggerFactory.getLogger("UTXOSet");
1919

2020
private Blockchain blockchain;
2121
private LevelDbDataSource txDB = null;
@@ -34,7 +34,7 @@ public void setBlockchain(Blockchain blockchain) {
3434
}
3535

3636
public void reindex() {
37-
logger.info("reindex");
37+
LOGGER.info("reindex");
3838

3939
txDB.reset();
4040

‎src/main/java/org/tron/crypto/ECKey.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import static org.tron.utils.ByteUtil.bigIntegerToBytes;
4646

4747
public class ECKey implements Serializable {
48-
private static final Logger logger = LoggerFactory.getLogger(ECKey.class);
48+
private static final Logger LOGGER = LoggerFactory.getLogger(ECKey.class);
4949
private static final BigInteger SECP256K1N = new BigInteger
5050
("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16);
5151

@@ -965,7 +965,7 @@ public static boolean verify(byte[] data, ECDSASignature signature,
965965
// specially crafted signatures.
966966
// Those signatures are inherently invalid/attack sigs so we just
967967
// fail them here rather than crash the thread.
968-
logger.error("Caught NPE inside bouncy castle", npe);
968+
LOGGER.error("Caught NPE inside bouncy castle", npe);
969969
return false;
970970
}
971971
}

‎src/main/java/org/tron/datasource/leveldb/LevelDbDataSource.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
public class LevelDbDataSource implements DbSource<byte[]> {
2525

26-
private static final Logger logger = LoggerFactory.getLogger("db");
26+
private static final Logger LOGGER = LoggerFactory.getLogger("DB");
2727

2828
private final static String LEVEL_DB_DIRECTORY = "database-test.directory";
2929
public final static String databaseName = Configer.getConf().getString
@@ -41,14 +41,14 @@ public LevelDbDataSource() {
4141

4242
public LevelDbDataSource(String name) {
4343
this.name = name;
44-
logger.debug("New LevelDbDataSource: " + name);
44+
LOGGER.debug("New LevelDbDataSource: " + name);
4545
}
4646

4747
@Override
4848
public void init() {
4949
resetDbLock.writeLock().lock();
5050
try {
51-
logger.debug("~> LevelDbDataSource.init(): " + name);
51+
LOGGER.debug("~> LevelDbDataSource.init(): " + name);
5252

5353
if (isAlive()) return;
5454

@@ -104,12 +104,12 @@ public boolean isAlive() {
104104
public void destroyDB(File fileLocation) {
105105
resetDbLock.writeLock().lock();
106106
try {
107-
logger.debug("Destroying existing database: " + fileLocation);
107+
LOGGER.debug("Destroying existing database: " + fileLocation);
108108
Options options = new Options();
109109
try {
110110
factory.destroy(fileLocation, options);
111111
} catch (IOException e) {
112-
logger.error(e.getMessage(), e);
112+
LOGGER.error(e.getMessage(), e);
113113
}
114114
} finally {
115115
resetDbLock.writeLock().unlock();
@@ -229,7 +229,7 @@ public void close() {
229229
db.close();
230230
alive = false;
231231
} catch (IOException e) {
232-
logger.error("Failed to find the db file on the close: {} ", name);
232+
LOGGER.error("Failed to find the db file on the close: {} ", name);
233233
}
234234
} finally {
235235
resetDbLock.writeLock().unlock();

0 commit comments

Comments
 (0)