Search in sources :

Example 1 with CryptoCreateTransactionBody

use of com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody in project hedera-services by hashgraph.

the class CryptoCreateTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    try {
        TransactionBody cryptoCreateTxn = txnCtx.accessor().getTxn();
        AccountID sponsor = cryptoCreateTxn.getTransactionID().getAccountID();
        CryptoCreateTransactionBody op = cryptoCreateTxn.getCryptoCreateAccount();
        long balance = op.getInitialBalance();
        final var created = ledger.create(sponsor, balance, asCustomizer(op));
        sigImpactHistorian.markEntityChanged(created.getAccountNum());
        txnCtx.setCreated(created);
        txnCtx.setStatus(SUCCESS);
    } catch (InsufficientFundsException ife) {
        txnCtx.setStatus(INSUFFICIENT_PAYER_BALANCE);
    } catch (Exception e) {
        log.warn("Avoidable exception!", e);
        txnCtx.setStatus(FAIL_INVALID);
    }
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) InsufficientFundsException(com.hedera.services.exceptions.InsufficientFundsException) InsufficientFundsException(com.hedera.services.exceptions.InsufficientFundsException)

Example 2 with CryptoCreateTransactionBody

use of com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody in project hedera-services by hashgraph.

the class CryptoCreateTransitionLogic method validate.

public ResponseCodeEnum validate(TransactionBody cryptoCreateTxn) {
    CryptoCreateTransactionBody op = cryptoCreateTxn.getCryptoCreateAccount();
    var memoValidity = validator.memoCheck(op.getMemo());
    if (memoValidity != OK) {
        return memoValidity;
    }
    if (!op.hasKey()) {
        return KEY_REQUIRED;
    }
    if (!validator.hasGoodEncoding(op.getKey())) {
        return BAD_ENCODING;
    }
    var fcKey = asFcKeyUnchecked(op.getKey());
    if (fcKey.isEmpty()) {
        return KEY_REQUIRED;
    }
    if (!fcKey.isValid()) {
        return BAD_ENCODING;
    }
    if (op.getInitialBalance() < 0L) {
        return INVALID_INITIAL_BALANCE;
    }
    if (!op.hasAutoRenewPeriod()) {
        return INVALID_RENEWAL_PERIOD;
    }
    if (!validator.isValidAutoRenewPeriod(op.getAutoRenewPeriod())) {
        return AUTORENEW_DURATION_NOT_IN_RANGE;
    }
    if (op.getSendRecordThreshold() < 0L) {
        return INVALID_SEND_RECORD_THRESHOLD;
    }
    if (op.getReceiveRecordThreshold() < 0L) {
        return INVALID_RECEIVE_RECORD_THRESHOLD;
    }
    if (op.getMaxAutomaticTokenAssociations() > dynamicProperties.maxTokensPerAccount()) {
        return REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT;
    }
    return OK;
}
Also used : CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)

Example 3 with CryptoCreateTransactionBody

use of com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody in project hedera-services by hashgraph.

the class HapiCryptoCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    key = key != null ? key : netOf(spec, keyName, keyShape, keyType, Optional.of(this::effectiveKeyGen));
    long amount = balanceFn.map(fn -> fn.apply(spec)).orElse(initialBalance.orElse(-1L));
    initialBalance = (amount >= 0) ? Optional.of(amount) : Optional.empty();
    CryptoCreateTransactionBody opBody = spec.txns().<CryptoCreateTransactionBody, CryptoCreateTransactionBody.Builder>body(CryptoCreateTransactionBody.class, b -> {
        b.setKey(key);
        proxy.ifPresent(b::setProxyAccountID);
        entityMemo.ifPresent(b::setMemo);
        sendThresh.ifPresent(b::setSendRecordThreshold);
        receiveThresh.ifPresent(b::setReceiveRecordThreshold);
        initialBalance.ifPresent(b::setInitialBalance);
        receiverSigRequired.ifPresent(b::setReceiverSigRequired);
        autoRenewDurationSecs.ifPresent(s -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(s).build()));
        maxAutomaticTokenAssociations.ifPresent(b::setMaxAutomaticTokenAssociations);
    });
    return b -> b.setCryptoCreateAccount(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) Arrays(java.util.Arrays) SigControl(com.hedera.services.bdd.spec.keys.SigControl) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) CryptoCreateMeta(com.hedera.services.usage.crypto.CryptoCreateMeta) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TxnUtils.netOf(com.hedera.services.bdd.spec.transactions.TxnUtils.netOf) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) KeyType(com.hedera.services.bdd.spec.keys.KeyFactory.KeyType) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)

Example 4 with CryptoCreateTransactionBody

use of com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerCryptoTest method cryptoCreateWithZeroInitialBalance.

@Test
void cryptoCreateWithZeroInitialBalance() {
    final long initialBalance = 0;
    CryptoCreateTransactionBody.Builder cryptoCreateBuilder = cryptoCreateAccountBuilderWithDefaults().setInitialBalance(initialBalance);
    Transaction transaction = cryptoCreateTransaction(cryptoCreateBuilder);
    TransactionBody transactionBody = getTransactionBody(transaction);
    CryptoCreateTransactionBody cryptoCreateTransactionBody = transactionBody.getCryptoCreateAccount();
    TransactionRecord record = transactionRecordSuccess(transactionBody);
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    var accountEntityId = EntityId.of(accountId1);
    var consensusTimestamp = DomainUtils.timeStampInNanos(record.getConsensusTimestamp());
    var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
    Optional<CryptoTransfer> initialBalanceTransfer = cryptoTransferRepository.findById(new CryptoTransfer.Id(initialBalance, consensusTimestamp, accountEntityId.getId()));
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(accountEntityId), () -> assertCryptoTransfers(3), () -> assertCryptoTransaction(transactionBody, record), () -> assertCryptoEntity(cryptoCreateTransactionBody, record.getConsensusTimestamp()), () -> assertEquals(cryptoCreateTransactionBody.getInitialBalance(), dbTransaction.getInitialBalance()), () -> assertThat(initialBalanceTransfer).isEmpty());
}
Also used : CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with CryptoCreateTransactionBody

use of com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody in project hedera-services by hashgraph.

the class RequestBuilder method getCreateAccountBuilder.

public static Transaction getCreateAccountBuilder(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp startTime, Duration transactionDuration, boolean generateRecord, String memo, Key key, long initBal, long sendRecordThreshold, long receiveRecordThreshold, boolean receiverSign, Duration autoRenew) {
    CryptoCreateTransactionBody createAccount = CryptoCreateTransactionBody.newBuilder().setKey(key).setInitialBalance(initBal).setProxyAccountID(getAccountIdBuild(0L, 0L, 0L)).setReceiveRecordThreshold(receiveRecordThreshold).setSendRecordThreshold(sendRecordThreshold).setReceiverSigRequired(receiverSign).setAutoRenewPeriod(autoRenew).build();
    TransactionBody.Builder body = getTransactionBody(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, startTime, transactionDuration, generateRecord, memo);
    body.setCryptoCreateAccount(createAccount);
    byte[] bodyBytesArr = body.build().toByteArray();
    ByteString bodyBytes = ByteString.copyFrom(bodyBytesArr);
    return Transaction.newBuilder().setBodyBytes(bodyBytes).build();
}
Also used : FileDeleteTransactionBody(com.hederahashgraph.api.proto.java.FileDeleteTransactionBody) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) ByteString(com.google.protobuf.ByteString)

Aggregations

CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)9 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)8 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)6 Transaction (com.hederahashgraph.api.proto.java.Transaction)6 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)5 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)5 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)5 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)5 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)5 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)5 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)3 ByteString (com.google.protobuf.ByteString)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 MoreObjects (com.google.common.base.MoreObjects)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiPropertySource (com.hedera.services.bdd.spec.HapiPropertySource)1 AdapterUtils (com.hedera.services.bdd.spec.fees.AdapterUtils)1 KeyType (com.hedera.services.bdd.spec.keys.KeyFactory.KeyType)1