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;
}
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;
}
Aggregations