Skip to content

Commit b72a9c7

Browse files
authored
Merge branch 'develop' into longvalue_exact
2 parents 5ce7d1b + f7d24a5 commit b72a9c7

File tree

2 files changed

+48
-63
lines changed

2 files changed

+48
-63
lines changed

src/main/java/org/tron/common/runtime/Runtime.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ private double getThisTxCPULimitInUsRatio() {
293293
/*
294294
**/
295295
private void create()
296-
throws ContractExeException, ContractValidateException {
296+
throws ContractValidateException {
297297
if (!deposit.getDbManager().getDynamicPropertiesStore().supportVM()) {
298-
throw new ContractExeException("vm work is off, need to be opened by the committee");
298+
throw new ContractValidateException("vm work is off, need to be opened by the committee");
299299
}
300300

301301
CreateSmartContract contract = ContractCapsule.getSmartContractFromTransaction(trx);
@@ -307,12 +307,12 @@ private void create()
307307

308308
long percent = contract.getNewContract().getConsumeUserResourcePercent();
309309
if (percent < 0 || percent > 100) {
310-
throw new ContractExeException("percent must be >= 0 and <= 100");
310+
throw new ContractValidateException("percent must be >= 0 and <= 100");
311311
}
312312

313313
// insure the new contract address haven't exist
314314
if (deposit.getAccount(contractAddress) != null) {
315-
throw new ContractExeException(
315+
throw new ContractValidateException(
316316
"Trying to create a contract with existing contract address: " + Wallet
317317
.encode58Check(contractAddress));
318318
}
@@ -356,7 +356,7 @@ private void create()
356356
Program.setRootCallConstant(isCallConstant());
357357
} catch (Exception e) {
358358
logger.error(e.getMessage());
359-
throw new ContractExeException(e.getMessage());
359+
throw new ContractValidateException(e.getMessage());
360360
}
361361

362362
program.getResult().setContractAddress(contractAddress);
@@ -381,10 +381,10 @@ private void create()
381381
*/
382382

383383
private void call()
384-
throws ContractExeException, ContractValidateException {
384+
throws ContractValidateException {
385385

386386
if (!deposit.getDbManager().getDynamicPropertiesStore().supportVM()) {
387-
throw new ContractExeException("VM work is off, need to be opened by the committee");
387+
throw new ContractValidateException("VM work is off, need to be opened by the committee");
388388
}
389389

390390
Contract.TriggerSmartContract contract = ContractCapsule.getTriggerContractFromTransaction(trx);
@@ -414,15 +414,10 @@ private void call()
414414

415415
long feeLimit = trx.getRawData().getFeeLimit();
416416
long energyLimit;
417-
try {
418-
if (isCallConstant(contractAddress)) {
419-
energyLimit = Constant.MAX_ENERGY_IN_TX;
420-
} else {
421-
energyLimit = getEnergyLimit(creator, caller, contract, feeLimit, callValue);
422-
}
423-
} catch (Exception e) {
424-
logger.error(e.getMessage());
425-
throw new ContractExeException(e.getMessage());
417+
if (isCallConstant(contractAddress)) {
418+
energyLimit = Constant.MAX_ENERGY_IN_TX;
419+
} else {
420+
energyLimit = getEnergyLimit(creator, caller, contract, feeLimit, callValue);
426421
}
427422

428423
ProgramInvoke programInvoke = programInvokeFactory

src/main/java/org/tron/core/Wallet.java

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,8 @@ public Transaction deployContract(CreateSmartContract createSmartContract,
860860

861861
public Transaction triggerContract(TriggerSmartContract triggerSmartContract,
862862
TransactionCapsule trxCap, Builder builder,
863-
Return.Builder retBuilder) throws ContractValidateException {
863+
Return.Builder retBuilder)
864+
throws ContractValidateException, ContractExeException, HeaderNotFound {
864865

865866
ContractStore contractStore = dbManager.getContractStore();
866867
byte[] contractAddress = triggerSmartContract.getContractAddress().toByteArray();
@@ -869,54 +870,46 @@ public Transaction triggerContract(TriggerSmartContract triggerSmartContract,
869870
throw new ContractValidateException("No contract or not a smart contract");
870871
}
871872

872-
try {
873-
byte[] selector = getSelector(triggerSmartContract.getData().toByteArray());
873+
byte[] selector = getSelector(triggerSmartContract.getData().toByteArray());
874874

875-
boolean constant = isConstant(abi, selector);
876-
if (!constant) {
877-
return trxCap.getInstance();
878-
} else {
879-
if (!Args.getInstance().isSupportConstant()) {
880-
throw new ContractValidateException("this node don't support constant");
881-
}
882-
DepositImpl deposit = DepositImpl.createRoot(dbManager);
875+
if (!isConstant(abi, selector)) {
876+
return trxCap.getInstance();
877+
} else {
878+
if (!Args.getInstance().isSupportConstant()) {
879+
throw new ContractValidateException("this node don't support constant");
880+
}
881+
DepositImpl deposit = DepositImpl.createRoot(dbManager);
883882

884-
Block headBlock;
885-
List<BlockCapsule> blockCapsuleList = dbManager.getBlockStore().getBlockByLatestNum(1);
886-
if (CollectionUtils.isEmpty(blockCapsuleList)) {
887-
throw new HeaderNotFound("latest block not found");
888-
} else {
889-
headBlock = blockCapsuleList.get(0).getInstance();
890-
}
883+
Block headBlock;
884+
List<BlockCapsule> blockCapsuleList = dbManager.getBlockStore().getBlockByLatestNum(1);
885+
if (CollectionUtils.isEmpty(blockCapsuleList)) {
886+
throw new HeaderNotFound("latest block not found");
887+
} else {
888+
headBlock = blockCapsuleList.get(0).getInstance();
889+
}
891890

892-
Runtime runtime = new Runtime(trxCap.getInstance(), new BlockCapsule(headBlock), deposit,
893-
new ProgramInvokeFactoryImpl());
894-
runtime.execute();
895-
runtime.go();
896-
runtime.finalization();
897-
// TODO exception
898-
if (runtime.getResult().getException() != null) {
891+
Runtime runtime = new Runtime(trxCap.getInstance(), new BlockCapsule(headBlock), deposit,
892+
new ProgramInvokeFactoryImpl());
893+
runtime.execute();
894+
runtime.go();
895+
runtime.finalization();
896+
// TODO exception
897+
if (runtime.getResult().getException() != null) {
899898
// runtime.getResult().getException().printStackTrace();
900-
throw new RuntimeException("Runtime exe failed!");
901-
}
899+
throw new RuntimeException("Runtime exe failed!");
900+
}
902901

903-
ProgramResult result = runtime.getResult();
904-
TransactionResultCapsule ret = new TransactionResultCapsule();
902+
ProgramResult result = runtime.getResult();
903+
TransactionResultCapsule ret = new TransactionResultCapsule();
905904

906-
builder.addConstantResult(ByteString.copyFrom(result.getHReturn()));
907-
ret.setStatus(0, code.SUCESS);
908-
if (StringUtils.isNoneEmpty(runtime.getRuntimeError())) {
909-
ret.setStatus(0, code.FAILED);
910-
retBuilder.setMessage(ByteString.copyFromUtf8(runtime.getRuntimeError())).build();
911-
}
912-
trxCap.setResult(ret);
913-
return trxCap.getInstance();
905+
builder.addConstantResult(ByteString.copyFrom(result.getHReturn()));
906+
ret.setStatus(0, code.SUCESS);
907+
if (StringUtils.isNoneEmpty(runtime.getRuntimeError())) {
908+
ret.setStatus(0, code.FAILED);
909+
retBuilder.setMessage(ByteString.copyFromUtf8(runtime.getRuntimeError())).build();
914910
}
915-
} catch (ContractValidateException e) {
916-
throw e;
917-
} catch (Exception e) {
918-
logger.error(e.getMessage());
919-
return null;
911+
trxCap.setResult(ret);
912+
return trxCap.getInstance();
920913
}
921914
}
922915

@@ -948,14 +941,11 @@ private static byte[] getSelector(byte[] data) {
948941
return ret;
949942
}
950943

951-
private static boolean isConstant(SmartContract.ABI abi, byte[] selector) throws Exception {
944+
private static boolean isConstant(SmartContract.ABI abi, byte[] selector) {
952945

953-
if (selector == null || abi.getEntrysList().size() == 0) {
946+
if (selector == null || selector.length != 4 || abi.getEntrysList().size() == 0) {
954947
return false;
955948
}
956-
if (selector.length != 4) {
957-
throw new Exception("Selector's length or selector itself is invalid");
958-
}
959949

960950
for (int i = 0; i < abi.getEntrysCount(); i++) {
961951
ABI.Entry entry = abi.getEntrys(i);

0 commit comments

Comments
 (0)