Search in sources :

Example 1 with WitnessCreateContract

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

the class WitnessCreateActuator method execute.

@Override
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
    long fee = calcFee();
    try {
        final WitnessCreateContract witnessCreateContract = this.contract.unpack(WitnessCreateContract.class);
        this.createWitness(witnessCreateContract);
        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 : WitnessCreateContract(org.tron.protos.Contract.WitnessCreateContract) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ContractExeException(org.tron.core.exception.ContractExeException)

Example 2 with WitnessCreateContract

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

the class WitnessCreateActuator method validate.

@Override
public boolean validate() throws ContractValidateException {
    try {
        if (!this.contract.is(WitnessCreateContract.class)) {
            throw new ContractValidateException("contract type error,expected type [AccountCreateContract],real type[" + this.contract.getClass() + "]");
        }
        final WitnessCreateContract contract = this.contract.unpack(WitnessCreateContract.class);
        Preconditions.checkNotNull(contract.getOwnerAddress(), "OwnerAddress is null");
        Preconditions.checkArgument(this.dbManager.getAccountStore().has(contract.getOwnerAddress().toByteArray()), "account not exists");
        AccountCapsule accountCapsule = this.dbManager.getAccountStore().get(contract.getOwnerAddress().toByteArray());
        Preconditions.checkArgument(accountCapsule.getShare() >= WitnessCapsule.MIN_BALANCE, "witnessAccount  has balance[" + accountCapsule.getShare() + "] < MIN_BALANCE[" + WitnessCapsule.MIN_BALANCE + "]");
        Preconditions.checkArgument(!this.dbManager.getWitnessStore().has(contract.getOwnerAddress().toByteArray()), "Witness has existed");
    } catch (final Exception ex) {
        ex.printStackTrace();
        throw new ContractValidateException(ex.getMessage());
    }
    return true;
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) WitnessCreateContract(org.tron.protos.Contract.WitnessCreateContract) 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 WitnessCreateContract (org.tron.protos.Contract.WitnessCreateContract)2 AccountCapsule (org.tron.core.capsule.AccountCapsule)1 ContractValidateException (org.tron.core.exception.ContractValidateException)1