Search in sources :

Example 26 with ContractValidateException

use of org.tron.core.exception.ContractValidateException in project java-tron by tronprotocol.

the class WitnessUpdateActuator method validate.

@Override
public boolean validate() throws ContractValidateException {
    try {
        if (!this.contract.is(WitnessUpdateContract.class)) {
            throw new ContractValidateException("contract type error,expected type [WitnessUpdateContract],real type[" + this.contract.getClass() + "]");
        }
        final WitnessUpdateContract contract = this.contract.unpack(WitnessUpdateContract.class);
        Preconditions.checkNotNull(contract.getOwnerAddress(), "OwnerAddress is null");
        if (this.dbManager.getWitnessStore().get(contract.getOwnerAddress().toByteArray()) == null) {
            throw new ContractValidateException("Witness not existed");
        }
    } catch (final Exception ex) {
        ex.printStackTrace();
        throw new ContractValidateException(ex.getMessage());
    }
    return true;
}
Also used : WitnessUpdateContract(org.tron.protos.Contract.WitnessUpdateContract) ContractValidateException(org.tron.core.exception.ContractValidateException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ContractValidateException(org.tron.core.exception.ContractValidateException) ContractExeException(org.tron.core.exception.ContractExeException)

Example 27 with ContractValidateException

use of org.tron.core.exception.ContractValidateException in project java-tron by tronprotocol.

the class AssetIssueActuator method validate.

@Override
public boolean validate() throws ContractValidateException {
    if (!this.contract.is(AssetIssueContract.class)) {
        throw new ContractValidateException();
    }
    try {
        final AssetIssueContract assetIssueContract = this.contract.unpack(AssetIssueContract.class);
        Preconditions.checkNotNull(assetIssueContract.getOwnerAddress(), "OwnerAddress is null");
        Preconditions.checkNotNull(assetIssueContract.getName(), "name is null");
        if (this.dbManager.getAssetIssueStore().get(assetIssueContract.getName().toByteArray()) != null) {
            throw new ContractValidateException();
        }
    } catch (InvalidProtocolBufferException e) {
        throw new ContractValidateException();
    }
    return false;
}
Also used : ContractValidateException(org.tron.core.exception.ContractValidateException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AssetIssueContract(org.tron.protos.Contract.AssetIssueContract)

Example 28 with ContractValidateException

use of org.tron.core.exception.ContractValidateException in project java-tron by tronprotocol.

the class CreateAccountActuator method validate.

@Override
public boolean validate() throws ContractValidateException {
    try {
        if (!contract.is(AccountCreateContract.class)) {
            throw new ContractValidateException("contract type error,expected type [AccountCreateContract],real type[" + contract.getClass() + "]");
        }
        AccountCreateContract contract = this.contract.unpack(AccountCreateContract.class);
        Preconditions.checkNotNull(contract.getAccountName(), "AccountName is null");
        Preconditions.checkNotNull(contract.getOwnerAddress(), "OwnerAddress is null");
        Preconditions.checkNotNull(contract.getType(), "Type is null");
        if (dbManager.getAccountStore().has(contract.getOwnerAddress().toByteArray())) {
            throw new ContractValidateException("Account has existed");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new ContractValidateException(ex.getMessage());
    }
    return true;
}
Also used : ContractValidateException(org.tron.core.exception.ContractValidateException) AccountCreateContract(org.tron.protos.Contract.AccountCreateContract) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ContractValidateException(org.tron.core.exception.ContractValidateException) ContractExeException(org.tron.core.exception.ContractExeException)

Aggregations

ContractValidateException (org.tron.core.exception.ContractValidateException)28 ContractExeException (org.tron.core.exception.ContractExeException)25 AccountCapsule (org.tron.core.capsule.AccountCapsule)20 Test (org.junit.Test)16 TransactionResultCapsule (org.tron.core.capsule.TransactionResultCapsule)16 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 DateTime (org.joda.time.DateTime)6 ByteString (com.google.protobuf.ByteString)5 BlockCapsule (org.tron.core.capsule.BlockCapsule)4 ValidateSignatureException (org.tron.core.exception.ValidateSignatureException)4 AssetIssueCapsule (org.tron.core.capsule.AssetIssueCapsule)3 Dialog (org.tron.core.db.AbstractRevokingStore.Dialog)3 RevokingStoreIllegalStateException (org.tron.core.exception.RevokingStoreIllegalStateException)3 Iterator (java.util.Iterator)2 TransactionCapsule (org.tron.core.capsule.TransactionCapsule)2 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)2 UnLinkedBlockException (org.tron.core.exception.UnLinkedBlockException)2 Contract (org.tron.protos.Contract)2 Preconditions (com.google.common.base.Preconditions)1 Any (com.google.protobuf.Any)1