Search in sources :

Example 91 with TransactionBody

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

the class OpUsageCtxHelperTest method getMetaForTokenBurnWorks.

@Test
void getMetaForTokenBurnWorks() {
    TokenBurnTransactionBody burnTxnBody = getFungibleCommonTokenBurnOp();
    TransactionBody txn = getTxnBody(burnTxnBody);
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getSubType()).willReturn(TOKEN_FUNGIBLE_COMMON);
    final var tokenBurnMeta = subject.metaForTokenBurn(accessor);
    // then:
    assertEquals(32, tokenBurnMeta.getBpt());
    assertEquals(SubType.TOKEN_FUNGIBLE_COMMON, tokenBurnMeta.getSubType());
    assertEquals(0, tokenBurnMeta.getSerialNumsCount());
    assertEquals(56, tokenBurnMeta.getTransferRecordDb());
}
Also used : TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TokenFeeScheduleUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenFeeScheduleUpdateTransactionBody) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TokenWipeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenWipeAccountTransactionBody) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody) Test(org.junit.jupiter.api.Test)

Example 92 with TransactionBody

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

the class TransactionThrottlingTest method delegatesExpectedFunction.

@Test
void delegatesExpectedFunction() {
    // setup:
    TransactionBody createTxn = TransactionBody.newBuilder().setConsensusCreateTopic(ConsensusCreateTopicTransactionBody.newBuilder().setMemo("Hi!")).build();
    final var accessor = SignedTxnAccessor.uncheckedFrom(Transaction.newBuilder().setSignedTransactionBytes(SignedTransaction.newBuilder().setBodyBytes(createTxn.toByteString()).build().toByteString()).build());
    given(functionalThrottling.shouldThrottleTxn(accessor)).willReturn(true);
    // when:
    boolean should = subject.shouldThrottle(accessor);
    // then:
    assertTrue(should);
    verify(functionalThrottling).shouldThrottleTxn(accessor);
}
Also used : ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Test(org.junit.jupiter.api.Test)

Example 93 with TransactionBody

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

the class CryptoApproveAllowanceTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    /* --- Extract gRPC --- */
    final TransactionBody cryptoApproveAllowanceTxn = txnCtx.accessor().getTxn();
    final AccountID payer = cryptoApproveAllowanceTxn.getTransactionID().getAccountID();
    final var op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    entitiesChanged.clear();
    /* --- Use models --- */
    final Id payerId = Id.fromGrpcAccount(payer);
    final var payerAccount = accountStore.loadAccount(payerId);
    /* --- Do the business logic --- */
    applyCryptoAllowances(op.getCryptoAllowancesList(), payerAccount);
    applyFungibleTokenAllowances(op.getTokenAllowancesList(), payerAccount);
    applyNftAllowances(op.getNftAllowancesList(), payerAccount);
    /* --- Persist the payer account --- */
    for (final var entry : entitiesChanged.entrySet()) {
        accountStore.commitAccount(entry.getValue());
    }
    txnCtx.setStatus(SUCCESS);
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) FcTokenAllowanceId(com.hedera.services.state.submerkle.FcTokenAllowanceId) Id(com.hedera.services.store.models.Id)

Example 94 with TransactionBody

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

the class HapiTopicCreate method updateStateOf.

@Override
protected void updateStateOf(HapiApiSpec spec) {
    if (actualStatus != SUCCESS) {
        return;
    }
    spec.registry().saveKey(topic, adminKey);
    submitKey.ifPresent(key -> spec.registry().saveKey(topic + "Submit", key));
    spec.registry().saveTopicId(topic, lastReceipt.getTopicID());
    spec.registry().saveBytes(topic, ByteString.copyFrom(new byte[48]));
    try {
        TransactionBody txn = CommonUtils.extractTransactionBody(txnSubmitted);
        long approxConsensusTime = txn.getTransactionID().getTransactionValidStart().getSeconds() + 1;
        spec.registry().saveTopicMeta(topic, txn.getConsensusCreateTopic(), approxConsensusTime);
    } catch (Exception impossible) {
        throw new IllegalStateException(impossible);
    }
    if (advertiseCreation) {
        String banner = "\n\n" + bannerWith(String.format("Created topic '%s' with id '0.0.%d'.", topic, lastReceipt.getTopicID().getTopicNum()));
        log.info(banner);
    }
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) ByteString(com.google.protobuf.ByteString)

Example 95 with TransactionBody

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

the class HapiTopicUpdate method updateStateOf.

@Override
protected void updateStateOf(HapiApiSpec spec) {
    if (actualStatus != ResponseCodeEnum.SUCCESS) {
        return;
    }
    newAdminKey.ifPresent(k -> {
        if (newAdminKey.get() == EMPTY_KEY) {
            spec.registry().removeKey(topic);
        } else {
            spec.registry().saveKey(topic, k);
        }
    });
    newSubmitKey.ifPresent(k -> {
        if (newSubmitKey.get() == EMPTY_KEY) {
            spec.registry().removeKey(submitKeyName());
        } else {
            spec.registry().saveKey(submitKeyName(), k);
        }
    });
    try {
        TransactionBody txn = CommonUtils.extractTransactionBody(txnSubmitted);
        spec.registry().saveTopicMeta(topic, txn.getConsensusUpdateTopic());
    } catch (Exception impossible) {
        throw new IllegalStateException(impossible);
    }
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody)

Aggregations

TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)145 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)106 Test (org.junit.jupiter.api.Test)100 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)96 Transaction (com.hederahashgraph.api.proto.java.Transaction)91 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)91 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)34 AccountID (com.hederahashgraph.api.proto.java.AccountID)32 EnumSource (org.junit.jupiter.params.provider.EnumSource)32 EntityId (com.hedera.mirror.common.domain.entity.EntityId)31 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)31 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)31 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)31 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)31 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)31 Entity (com.hedera.mirror.common.domain.entity.Entity)29 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)29 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 Contract (com.hedera.mirror.common.domain.contract.Contract)27