Skip to content

Commit 3c6da9d

Browse files
committed
refine code
1 parent e925fbd commit 3c6da9d

2 files changed

Lines changed: 4 additions & 20 deletions

File tree

‎src/main/java/org/tron/common/runtime/utils/MUtil.java‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package org.tron.common.runtime.utils;
22

3-
import com.google.protobuf.ByteString;
43
import java.util.Arrays;
54
import org.spongycastle.util.encoders.Hex;
65
import org.tron.common.crypto.Hash;
76
import org.tron.common.storage.Deposit;
87
import org.tron.core.Wallet;
9-
import org.tron.core.actuator.Actuator;
10-
import org.tron.core.actuator.ActuatorFactory;
118
import org.tron.core.actuator.TransferActuator;
12-
import org.tron.core.capsule.TransactionCapsule;
13-
import org.tron.core.exception.ContractExeException;
149
import org.tron.core.exception.ContractValidateException;
15-
import org.tron.protos.Contract;
16-
import org.tron.protos.Contract.TransferContract;
17-
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
10+
1811

1912
/**
2013
* @author Guo Yonggang
@@ -24,10 +17,7 @@ public class MUtil {
2417

2518
public static void transfer(Deposit deposit, byte[] fromAddress, byte[] toAddress, long amount)
2619
throws ContractValidateException {
27-
if (!TransferActuator.validate(deposit, fromAddress, toAddress, amount)){
28-
throw new RuntimeException(
29-
Hex.toHexString(fromAddress).toUpperCase() + " transfer to" +Hex.toHexString(toAddress).toUpperCase() +" validation fail!");
30-
}
20+
TransferActuator.validate(deposit, fromAddress, toAddress, amount);
3121
if (deposit.getBalance(fromAddress) < amount) {
3222
throw new RuntimeException(
3323
Hex.toHexString(fromAddress).toUpperCase() + " not enough balance!");

‎src/main/java/org/tron/common/runtime/vm/program/Program.java‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,7 @@ public void createContract(DataWord value, DataWord memStart, DataWord memSize)
462462
// [4] TRANSFER THE BALANCE
463463
long newBalance = 0L;
464464
if (!byTestingSuite()) {
465-
if (!TransferActuator.validate(deposit, senderAddress, newAddress, endowment)){
466-
throw new RuntimeException(
467-
Hex.toHexString(senderAddress).toUpperCase() + " transfer to" +Hex.toHexString(newAddress).toUpperCase() +" validation fail!");
468-
}
465+
TransferActuator.validate(deposit, senderAddress, newAddress, endowment);
469466
deposit.addBalance(senderAddress, -endowment);
470467
newBalance = deposit.addBalance(newAddress, endowment);
471468
}
@@ -620,10 +617,7 @@ public void callToAddress(MessageCall msg)
620617
msg.getGas().getNoLeadZeroesData(),
621618
msg.getEndowment().getNoLeadZeroesData());
622619
} else if(!ArrayUtils.isEmpty(senderAddress) && !ArrayUtils.isEmpty(contextAddress) && senderAddress != contextAddress && endowment > 0) {
623-
if (!TransferActuator.validate(deposit, senderAddress, contextAddress, endowment)){
624-
throw new RuntimeException(
625-
Hex.toHexString(senderAddress).toUpperCase() + " transfer to" +Hex.toHexString(contextAddress).toUpperCase() +" validation fail!");
626-
}
620+
TransferActuator.validate(deposit, senderAddress, contextAddress, endowment);
627621
deposit.addBalance(senderAddress, -endowment);
628622
contextBalance = deposit.addBalance(contextAddress, endowment);
629623
}

0 commit comments

Comments
 (0)