Search in sources :

Example 1 with AccountCreateContract

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

Example 2 with AccountCreateContract

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());
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AccountCreateContract(org.tron.protos.Contract.AccountCreateContract) ContractExeException(org.tron.core.exception.ContractExeException)

Aggregations

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