Skip to content

Commit

Permalink
refactor code and remove unused file
Browse files Browse the repository at this point in the history
  • Loading branch information
niuniublockchain committed Jul 28, 2020
1 parent 3b259d0 commit 43c2da6
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public boolean validate() throws ContractValidateException {

if (!Arrays.equals(ownerAddress, deployedContractOwnerAddress)) {
throw new ContractValidateException(
"Account[" + readableOwnerAddress + "] is not the owner of the contract");
ActuatorConstant.ACCOUNT_EXCEPTION_STR
+ readableOwnerAddress + "] is not the owner of the contract");
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.tron.core.actuator;

import static org.tron.core.capsule.utils.TransactionUtil.isNumber;
import static org.tron.core.config.Parameter.ChainSymbol.TRX_SYMBOL_BYTES;

import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -175,12 +176,12 @@ public boolean validate() throws ContractValidateException {
long secondTokenBalance = contract.getSecondTokenBalance();

if (dynamicStore.getAllowSameTokenName() == 1) {
if (!Arrays.equals(firstTokenID, TRX_SYMBOL_BYTES) && !TransactionUtil
.isNumber(firstTokenID)) {
if (!Arrays.equals(firstTokenID, TRX_SYMBOL_BYTES)
&& !isNumber(firstTokenID)) {
throw new ContractValidateException("first token id is not a valid number");
}
if (!Arrays.equals(secondTokenID, TRX_SYMBOL_BYTES) && !TransactionUtil
.isNumber(secondTokenID)) {
if (!Arrays.equals(secondTokenID, TRX_SYMBOL_BYTES)
&& !isNumber(secondTokenID)) {
throw new ContractValidateException("second token id is not a valid number");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.tron.core.actuator;

import static org.tron.core.capsule.utils.TransactionUtil.isNumber;
import static org.tron.core.config.Parameter.ChainSymbol.TRX_SYMBOL_BYTES;

import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -180,7 +181,7 @@ public boolean validate() throws ContractValidateException {

if (dynamicStore.getAllowSameTokenName() == 1 &&
!Arrays.equals(tokenID, TRX_SYMBOL_BYTES) &&
!TransactionUtil.isNumber(tokenID)) {
!isNumber(tokenID)) {
throw new ContractValidateException("token id is not a valid number");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.tron.core.actuator;

import static org.tron.core.capsule.utils.TransactionUtil.isNumber;
import static org.tron.core.config.Parameter.ChainSymbol.TRX_SYMBOL_BYTES;

import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -165,7 +166,7 @@ public boolean validate() throws ContractValidateException {

if (dynamicStore.getAllowSameTokenName() == 1 &&
!Arrays.equals(tokenID, TRX_SYMBOL_BYTES) &&
!TransactionUtil.isNumber(tokenID)) {
!isNumber(tokenID)) {
throw new ContractValidateException("token id is not a valid number");
}
if (!Arrays.equals(tokenID, firstTokenID) && !Arrays.equals(tokenID, secondTokenID)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.tron.core.actuator;

import static org.tron.core.capsule.utils.TransactionUtil.isNumber;
import static org.tron.core.config.Parameter.ChainSymbol.TRX_SYMBOL_BYTES;

import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -188,7 +189,7 @@ public boolean validate() throws ContractValidateException {

if (dynamicStore.getAllowSameTokenName() == 1 &&
!Arrays.equals(tokenID, TRX_SYMBOL_BYTES) &&
!TransactionUtil.isNumber(tokenID)) {
!isNumber(tokenID)) {
throw new ContractValidateException("token id is not a valid number");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public boolean validate() throws ContractValidateException {
if (receiverCapsule == null) {
String readableOwnerAddress = StringUtil.createReadableString(receiverAddress);
throw new ContractValidateException(
"Account[" + readableOwnerAddress + "] not exists");
ActuatorConstant.ACCOUNT_EXCEPTION_STR
+ readableOwnerAddress + "] not exists");
}

if (dynamicStore.getAllowTvmConstantinople() == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package org.tron.core.actuator;

import static org.tron.core.capsule.utils.TransactionUtil.isNumber;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.Arrays;
Expand Down Expand Up @@ -203,11 +205,10 @@ public boolean validate() throws ContractValidateException {
throw new ContractValidateException("Account does not exist!");
}

if (!Arrays.equals(sellTokenID, "_".getBytes()) && !TransactionUtil.isNumber(sellTokenID)) {
if (!Arrays.equals(sellTokenID, "_".getBytes()) && !isNumber(sellTokenID)) {
throw new ContractValidateException("sellTokenId is not a valid number");
}
if (!Arrays.equals(buyTokenID, "_".getBytes()) && !TransactionUtil
.isNumber(buyTokenID)) {
if (!Arrays.equals(buyTokenID, "_".getBytes()) && !isNumber(buyTokenID)) {
throw new ContractValidateException("buyTokenId is not a valid number");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public boolean validate() throws ContractValidateException {

if (!Arrays.equals(ownerAddress, deployedContractOwnerAddress)) {
throw new ContractValidateException(
"Account[" + readableOwnerAddress + "] is not the owner of the contract");
ActuatorConstant.ACCOUNT_EXCEPTION_STR
+ readableOwnerAddress + "] is not the owner of the contract");
}

return true;
Expand Down
13 changes: 0 additions & 13 deletions actuator/src/main/java/org/tron/core/utils/TransactionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,6 @@ private static boolean validReadableBytes(byte[] bytes, int maxLength) {
return true;
}

public static boolean isNumber(byte[] id) {
if (ArrayUtils.isEmpty(id)) {
return false;
}
for (byte b : id) {
if (b < '0' || b > '9') {
return false;
}
}

return !(id.length > 1 && id[0] == '0');
}

public static Sha256Hash getTransactionId(Transaction transaction) {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
transaction.getRawData().toByteArray());
Expand Down
10 changes: 0 additions & 10 deletions chainbase/src/main/java/org/tron/common/utils/LocalWitnesses.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,4 @@ public String getPrivateKey() {
return privateKeys.get(0);
}

public byte[] getPublicKey() {
if (CollectionUtils.isEmpty(privateKeys)) {
logger.warn("privateKey is null");
return null;
}
byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
final ECKey ecKey = ECKey.fromPrivate(privateKey);
return ecKey.getAddress();
}

}
6 changes: 6 additions & 0 deletions chainbase/src/main/java/org/tron/core/ChainBaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.tron.core.store.StorageRowStore;
import org.tron.core.store.TransactionHistoryStore;
import org.tron.core.store.TransactionRetStore;
import org.tron.core.store.TreeBlockIndexStore;
import org.tron.core.store.VotesStore;
import org.tron.core.store.WitnessScheduleStore;
import org.tron.core.store.WitnessStore;
Expand Down Expand Up @@ -191,6 +192,11 @@ public class ChainBaseManager {
@Getter
private ForkController forkController = ForkController.instance();

@Autowired
@Getter
@Setter
private TreeBlockIndexStore merkleTreeIndexStore;

public void closeOneStore(ITronChainBase database) {
logger.info("******** begin to close " + database.getName() + " ********");
try {
Expand Down
7 changes: 0 additions & 7 deletions crypto/src/main/java/org/tron/common/crypto/SignUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@

public class SignUtils {

public static SignInterface getGeneratedRandomSign(boolean isECKeyCryptoEngine) {
if (isECKeyCryptoEngine) {
return new ECKey();
}
return new SM2();
}

public static SignInterface getGeneratedRandomSign(
SecureRandom secureRandom, boolean isECKeyCryptoEngine) {
if (isECKeyCryptoEngine) {
Expand Down
6 changes: 3 additions & 3 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Lo
ByteString txId = outPoint.getHash();

//Get the tree in blockNum-1 position
byte[] treeRoot = dbManager.getMerkleTreeIndexStore().get(blockNumber - 1);
byte[] treeRoot = chainBaseManager.getMerkleTreeIndexStore().get(blockNumber - 1);
if (treeRoot == null) {
throw new RuntimeException("treeRoot is null, blockNumber:" + (blockNumber - 1));
}
Expand Down Expand Up @@ -1623,9 +1623,9 @@ public IncrementalMerkleTree getMerkleTreeOfBlock(long blockNum) throws ZksnarkE
}

try {
if (dbManager.getMerkleTreeIndexStore().has(ByteArray.fromLong(blockNum))) {
if (chainBaseManager.getMerkleTreeIndexStore().has(ByteArray.fromLong(blockNum))) {
return IncrementalMerkleTree
.parseFrom(dbManager.getMerkleTreeIndexStore().get(blockNum));
.parseFrom(chainBaseManager.getMerkleTreeIndexStore().get(blockNum));
}
} catch (Exception ex) {
logger.error(ex.getMessage());
Expand Down
12 changes: 3 additions & 9 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ public class Manager {
@Getter
@Setter
private MerkleContainer merkleContainer;
@Autowired
@Getter
@Setter
private TreeBlockIndexStore merkleTreeIndexStore;
private ExecutorService validateSignService;
private boolean isRunRePushThread = true;
private boolean isRunTriggerCapsuleProcessThread = true;
Expand Down Expand Up @@ -350,7 +346,7 @@ public void init() {
this.setProposalController(ProposalController.createInstance(this));
this.setMerkleContainer(
merkleContainer.createInstance(chainBaseManager.getMerkleTreeStore(),
this.merkleTreeIndexStore));
chainBaseManager.getMerkleTreeIndexStore()));
this.pendingTransactions = Collections.synchronizedList(Lists.newArrayList());
this.rePushTransactions = new LinkedBlockingQueue<>();
this.triggerCapsuleQueue = new LinkedBlockingQueue<>();
Expand Down Expand Up @@ -1574,8 +1570,7 @@ private void postBlockTrigger(final BlockCapsule newBlock) {
BlockLogTriggerCapsule blockLogTriggerCapsule = new BlockLogTriggerCapsule(newBlock);
blockLogTriggerCapsule.setLatestSolidifiedBlockNumber(getDynamicPropertiesStore()
.getLatestSolidifiedBlockNum());
boolean result = triggerCapsuleQueue.offer(blockLogTriggerCapsule);
if (!result) {
if (!triggerCapsuleQueue.offer(blockLogTriggerCapsule)) {
logger.info("too many triggers, block trigger lost: {}", newBlock.getBlockId());
}
}
Expand All @@ -1591,8 +1586,7 @@ private void postTransactionTrigger(final TransactionCapsule trxCap,
TransactionLogTriggerCapsule trx = new TransactionLogTriggerCapsule(trxCap, blockCap);
trx.setLatestSolidifiedBlockNumber(getDynamicPropertiesStore()
.getLatestSolidifiedBlockNum());
boolean result = triggerCapsuleQueue.offer(trx);
if (!result) {
if (!triggerCapsuleQueue.offer(trx)) {
logger.info("too many triggers, transaction trigger lost: {}", trxCap.getTransactionId());
}
}
Expand Down

This file was deleted.

0 comments on commit 43c2da6

Please sign in to comment.