Search in sources :

Example 1 with WitnessUpdateContract

use of org.tron.protos.Contract.WitnessUpdateContract in project java-tron by tronprotocol.

the class WitnessUpdateActuator method execute.

@Override
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
    long fee = calcFee();
    try {
        final WitnessUpdateContract witnessUpdateContract = this.contract.unpack(WitnessUpdateContract.class);
        this.updateWitness(witnessUpdateContract);
        ret.setStatus(fee, code.SUCESS);
    } catch (final InvalidProtocolBufferException e) {
        logger.debug(e.getMessage(), e);
        ret.setStatus(fee, code.FAILED);
        throw new ContractExeException(e.getMessage());
    }
    return true;
}
Also used : WitnessUpdateContract(org.tron.protos.Contract.WitnessUpdateContract) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ContractExeException(org.tron.core.exception.ContractExeException)

Example 2 with WitnessUpdateContract

use of org.tron.protos.Contract.WitnessUpdateContract 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)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ContractExeException (org.tron.core.exception.ContractExeException)2 WitnessUpdateContract (org.tron.protos.Contract.WitnessUpdateContract)2 ContractValidateException (org.tron.core.exception.ContractValidateException)1