diff --git a/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CallContractTxValidator.java b/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CallContractTxValidator.java index e9c1c0ea6..46ca469f3 100644 --- a/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CallContractTxValidator.java +++ b/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CallContractTxValidator.java @@ -30,6 +30,7 @@ import io.nuls.contract.entity.txdata.CallContractData; import io.nuls.contract.ledger.util.ContractLedgerUtil; import io.nuls.core.tools.array.ArraysTool; +import io.nuls.core.tools.calc.LongUtils; import io.nuls.core.tools.log.Log; import io.nuls.kernel.constant.TransactionErrorCode; import io.nuls.kernel.exception.NulsException; @@ -38,6 +39,7 @@ import io.nuls.kernel.model.Na; import io.nuls.kernel.script.SignatureUtil; import io.nuls.kernel.utils.AddressTool; +import io.nuls.kernel.utils.TransactionFeeCalculator; import io.nuls.kernel.validate.NulsDataValidator; import io.nuls.kernel.validate.ValidateResult; import io.nuls.protocol.constant.ProtocolConstant; @@ -60,12 +62,12 @@ public ValidateResult validate(CallContractTransaction tx) throws NulsException Set addressSet = SignatureUtil.getAddressFromTX(tx); if(!ContractLedgerUtil.isExistContractAddress(contractAddress)) { - Log.error("contract data error: The contract does not exist."); + Log.error("contract call error: The contract does not exist."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), ContractErrorCode.CONTRACT_ADDRESS_NOT_EXIST); } if (!addressSet.contains(AddressTool.getStringAddressByBytes(sender))) { - Log.error("contract data error: The contract caller is not the transaction creator."); + Log.error("contract call error: The contract caller is not the transaction creator."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.TX_DATA_VALIDATION_ERROR); } @@ -82,26 +84,34 @@ public ValidateResult validate(CallContractTransaction tx) throws NulsException } if (coin.getLockTime() != 0) { - Log.error("contract data error: The amount of the transfer cannot be locked(UTXO status error)."); + Log.error("contract call error: The amount of the transfer cannot be locked(UTXO status error)."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.UTXO_STATUS_CHANGE); } if (!ArraysTool.arrayEquals(owner, contractAddress)) { - Log.error("contract data error: The receiver is not the contract address."); + Log.error("contract call error: The receiver is not the contract address."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.TX_DATA_VALIDATION_ERROR); } else { contractReceivedNa = contractReceivedNa.add(coin.getNa()); } if (coin.getNa().isLessThan(ProtocolConstant.MININUM_TRANSFER_AMOUNT)) { - Log.error("contract data error: The amount of the transfer is too small."); + Log.error("contract call error: The amount of the transfer is too small."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.TOO_SMALL_AMOUNT); } } if (contractReceivedNa.isLessThan(transferNa)) { - Log.error("contract data error: Insufficient amount to transfer to the contract address."); + Log.error("contract call error: Insufficient amount to transfer to the contract address."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.INVALID_AMOUNT); } - return ValidateResult.getSuccessResult(); + + Na realFee = tx.getCoinData().getFee(); + Na fee = TransactionFeeCalculator.getTransferFee(tx.size()).add(Na.valueOf(LongUtils.mul(txData.getGasLimit(), txData.getPrice()))); + if (realFee.isGreaterOrEquals(fee)) { + return ValidateResult.getSuccessResult(); + } else { + Log.error("contract call error: The contract transaction fee is not right."); + return ValidateResult.getFailedResult(this.getClass().getName(), TransactionErrorCode.FEE_NOT_RIGHT); + } } } diff --git a/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CreateContractTxValidator.java b/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CreateContractTxValidator.java index ff5a2b33a..42b3db1cf 100644 --- a/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CreateContractTxValidator.java +++ b/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/CreateContractTxValidator.java @@ -29,12 +29,15 @@ import io.nuls.contract.entity.tx.CreateContractTransaction; import io.nuls.contract.entity.txdata.CreateContractData; import io.nuls.contract.util.ContractUtil; +import io.nuls.core.tools.calc.LongUtils; import io.nuls.core.tools.log.Log; import io.nuls.kernel.constant.TransactionErrorCode; import io.nuls.kernel.exception.NulsException; import io.nuls.kernel.lite.annotation.Component; +import io.nuls.kernel.model.Na; import io.nuls.kernel.script.SignatureUtil; import io.nuls.kernel.utils.AddressTool; +import io.nuls.kernel.utils.TransactionFeeCalculator; import io.nuls.kernel.validate.NulsDataValidator; import io.nuls.kernel.validate.ValidateResult; @@ -53,16 +56,23 @@ public ValidateResult validate(CreateContractTransaction tx) throws NulsExceptio byte[] sender = txData.getSender(); byte[] contractAddress = txData.getContractAddress(); if(!ContractUtil.isLegalContractAddress(contractAddress)) { - Log.error("contract data error: Illegal contract address."); + Log.error("contract create error: Illegal contract address."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), ContractErrorCode.ILLEGAL_CONTRACT_ADDRESS); } Set addressSet = SignatureUtil.getAddressFromTX(tx); if (!addressSet.contains(AddressTool.getStringAddressByBytes(sender))) { - Log.error("contract data error: The contract creater is not the transaction creator."); + Log.error("contract create error: The contract creater is not the transaction creator."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.TX_DATA_VALIDATION_ERROR); } - return ValidateResult.getSuccessResult(); + Na realFee = tx.getCoinData().getFee(); + Na fee = TransactionFeeCalculator.getTransferFee(tx.size()).add(Na.valueOf(LongUtils.mul(txData.getGasLimit(), txData.getPrice()))); + if (realFee.isGreaterOrEquals(fee)) { + return ValidateResult.getSuccessResult(); + } else { + Log.error("contract create error: The contract transaction fee is not right."); + return ValidateResult.getFailedResult(this.getClass().getName(), TransactionErrorCode.FEE_NOT_RIGHT); + } } } diff --git a/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/DeleteContractTxValidator.java b/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/DeleteContractTxValidator.java index b940c12f3..cbeebc952 100644 --- a/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/DeleteContractTxValidator.java +++ b/contract-module/base/contract-tx/src/main/java/io/nuls/contract/entity/tx/validator/DeleteContractTxValidator.java @@ -69,7 +69,7 @@ public ValidateResult validate(DeleteContractTransaction tx) throws NulsExceptio Set addressSet = SignatureUtil.getAddressFromTX(tx); if (!addressSet.contains(AddressTool.getStringAddressByBytes(sender))) { - Log.error("contract data error: The contract deleter is not the transaction creator."); + Log.error("contract delete error: The contract deleter is not the transaction creator."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.TX_DATA_VALIDATION_ERROR); } @@ -79,24 +79,24 @@ public ValidateResult validate(DeleteContractTransaction tx) throws NulsExceptio } ContractAddressInfoPo contractAddressInfoPo = contractAddressInfoPoResult.getData(); if(contractAddressInfoPo == null) { - Log.error("contract data error: The contract does not exist."); + Log.error("contract delete error: The contract does not exist."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), ContractErrorCode.CONTRACT_ADDRESS_NOT_EXIST); } if(!ArraysTool.arrayEquals(sender, contractAddressInfoPo.getSender())) { - Log.error("contract data error: The contract deleter is not the contract creator."); + Log.error("contract delete error: The contract deleter is not the contract creator."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.TX_DATA_VALIDATION_ERROR); } Result result = contractUtxoService.getBalance(contractAddressBytes); ContractBalance balance = (ContractBalance) result.getData(); if(balance == null) { - Log.error("contract data error: That balance of the contract is abnormal."); + Log.error("contract delete error: That balance of the contract is abnormal."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), TransactionErrorCode.TX_DATA_VALIDATION_ERROR); } Na totalBalance = balance.getBalance(); if(totalBalance.compareTo(Na.ZERO) != 0) { - Log.error("contract data error: The balance of the contract is not 0."); + Log.error("contract delete error: The balance of the contract is not 0."); return ValidateResult.getFailedResult(this.getClass().getSimpleName(), ContractErrorCode.CONTRACT_DELETE_BALANCE); }