use of org.tron.protos.Contract.AccountCreateContract 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;
}
use of org.tron.protos.Contract.AccountCreateContract in project java-tron by tronprotocol.
the class CreateAccountActuator method execute.
@Override
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
long fee = calcFee();
try {
AccountCreateContract accountCreateContract = contract.unpack(AccountCreateContract.class);
AccountCapsule accountCapsule = new AccountCapsule(accountCreateContract);
dbManager.getAccountStore().put(accountCreateContract.getOwnerAddress().toByteArray(), accountCapsule);
ret.setStatus(fee, code.SUCESS);
return true;
} catch (InvalidProtocolBufferException e) {
ret.setStatus(fee, code.FAILED);
logger.debug(e.getMessage(), e);
throw new ContractExeException(e.getMessage());
}
}
Aggregations