Search in sources :

Example 81 with TransactionBody

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

the class CryptoUpdateTransactionHandlerTest method updateTransactionDeclineReward.

@Test
void updateTransactionDeclineReward() {
    RecordItem withDeclineValueSet = recordItemBuilder.cryptoUpdate().transactionBody(body -> body.clear().setDeclineReward(BoolValue.of(true))).build();
    setupForCrytoUpdateTransactionTest(withDeclineValueSet, t -> assertThat(t).returns(true, Entity::isDeclineReward).returns(null, Entity::getStakedNodeId).returns(null, Entity::getStakedAccountId).extracting(Entity::getStakePeriodStart).isNotNull());
}
Also used : CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Assertions(org.junit.jupiter.api.Assertions) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) Entity(com.hedera.mirror.common.domain.entity.Entity) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

Example 82 with TransactionBody

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

the class CryptoUpdateTransactionHandlerTest method updateTransactionStakedAccountId.

@Test
void updateTransactionStakedAccountId() {
    AccountID accountId = AccountID.newBuilder().setAccountNum(1L).build();
    RecordItem withStakedNodeIdSet = recordItemBuilder.cryptoUpdate().transactionBody(body -> body.clear().setStakedAccountId(accountId)).build();
    setupForCrytoUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Entity::getStakedAccountId).returns(false, Entity::isDeclineReward).returns(-1L, Entity::getStakedNodeId).returns(Utility.getEpochDay(withStakedNodeIdSet.getConsensusTimestamp()), Entity::getStakePeriodStart));
}
Also used : CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Assertions(org.junit.jupiter.api.Assertions) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) Entity(com.hedera.mirror.common.domain.entity.Entity) AccountID(com.hederahashgraph.api.proto.java.AccountID) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

Example 83 with TransactionBody

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

the class SystemUndeleteTransactionHandlerTest method testSystemUndeleteForContract.

// SystemUndelete for file is tested by common test case in AbstractTransactionHandlerTest.
// Test SystemUndelete for contract here.
@Test
void testSystemUndeleteForContract() {
    TransactionBody transactionBody = TransactionBody.newBuilder().setSystemUndelete(SystemUndeleteTransactionBody.newBuilder().setContractID(ContractID.newBuilder().setContractNum(DEFAULT_ENTITY_NUM).build())).build();
    testGetEntityIdHelper(transactionBody, getDefaultTransactionRecord().build(), EntityId.of(0L, 0L, DEFAULT_ENTITY_NUM, EntityType.CONTRACT));
}
Also used : SystemUndeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Test(org.junit.jupiter.api.Test)

Example 84 with TransactionBody

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

the class EntityRecordItemListener method buildTransaction.

private Transaction buildTransaction(long consensusTimestamp, RecordItem recordItem) {
    TransactionBody body = recordItem.getTransactionBody();
    TransactionRecord txRecord = recordItem.getRecord();
    Long validDurationSeconds = body.hasTransactionValidDuration() ? body.getTransactionValidDuration().getSeconds() : null;
    // transactions in stream always have valid node account id.
    var nodeAccount = EntityId.of(body.getNodeAccountID());
    var transactionId = body.getTransactionID();
    // build transaction
    Transaction transaction = new Transaction();
    transaction.setChargedTxFee(txRecord.getTransactionFee());
    transaction.setConsensusTimestamp(consensusTimestamp);
    transaction.setIndex(recordItem.getTransactionIndex());
    transaction.setInitialBalance(0L);
    transaction.setMaxFee(body.getTransactionFee());
    transaction.setMemo(DomainUtils.toBytes(body.getMemoBytes()));
    transaction.setNodeAccountId(nodeAccount);
    transaction.setNonce(transactionId.getNonce());
    transaction.setPayerAccountId(recordItem.getPayerAccountId());
    transaction.setResult(txRecord.getReceipt().getStatusValue());
    transaction.setScheduled(txRecord.hasScheduleRef());
    transaction.setTransactionBytes(entityProperties.getPersist().isTransactionBytes() ? recordItem.getTransactionBytes() : null);
    transaction.setTransactionHash(DomainUtils.toBytes(txRecord.getTransactionHash()));
    transaction.setType(recordItem.getTransactionType());
    transaction.setValidDurationSeconds(validDurationSeconds);
    transaction.setValidStartNs(DomainUtils.timeStampInNanos(transactionId.getTransactionValidStart()));
    if (txRecord.hasParentConsensusTimestamp()) {
        transaction.setParentConsensusTimestamp(DomainUtils.timestampInNanosMax(txRecord.getParentConsensusTimestamp()));
    }
    return transaction;
}
Also used : TokenUnpauseTransactionBody(com.hederahashgraph.api.proto.java.TokenUnpauseTransactionBody) TokenRevokeKycTransactionBody(com.hederahashgraph.api.proto.java.TokenRevokeKycTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TokenPauseTransactionBody(com.hederahashgraph.api.proto.java.TokenPauseTransactionBody) TokenFeeScheduleUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenFeeScheduleUpdateTransactionBody) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) TokenAssociateTransactionBody(com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) TokenGrantKycTransactionBody(com.hederahashgraph.api.proto.java.TokenGrantKycTransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody) TokenUnfreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenUnfreezeAccountTransactionBody) TokenWipeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenWipeAccountTransactionBody) TokenDissociateTransactionBody(com.hederahashgraph.api.proto.java.TokenDissociateTransactionBody) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody) TokenFreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenFreezeAccountTransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Example 85 with TransactionBody

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

the class PubSubRecordItemListener method onItem.

@Override
public void onItem(RecordItem recordItem) throws ImporterException {
    TransactionBody body = recordItem.getTransactionBody();
    TransactionRecord txRecord = recordItem.getRecord();
    TransactionType transactionType = TransactionType.of(recordItem.getTransactionType());
    TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
    log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body));
    long consensusTimestamp = DomainUtils.timeStampInNanos(txRecord.getConsensusTimestamp());
    EntityId entityId;
    try {
        entityId = transactionHandler.getEntity(recordItem);
    } catch (InvalidEntityException e) {
        // transaction can have invalid topic/contract/file id
        log.warn("Invalid entity encountered for consensusTimestamp {} : {}", consensusTimestamp, e.getMessage());
        entityId = null;
    }
    PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entityId, recordItem);
    try {
        sendPubSubMessage(pubSubMessage);
    } catch (Exception e) {
        // greater than that of last correctly sent txn.
        throw new ParserException("Error sending transaction to pubsub", e);
    }
    log.debug("Published transaction : {}", consensusTimestamp);
    if (addressBookService.isAddressBook(entityId)) {
        FileID fileID = null;
        byte[] fileBytes = null;
        if (body.hasFileAppend()) {
            fileID = body.getFileAppend().getFileID();
            fileBytes = body.getFileAppend().getContents().toByteArray();
        } else if (body.hasFileCreate()) {
            fileID = txRecord.getReceipt().getFileID();
            fileBytes = body.getFileCreate().getContents().toByteArray();
        } else if (body.hasFileUpdate()) {
            fileID = body.getFileUpdate().getFileID();
            fileBytes = body.getFileUpdate().getContents().toByteArray();
        }
        FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem.getTransactionType());
        fileDataRepository.save(fileData);
        addressBookService.update(fileData);
    }
}
Also used : ParserException(com.hedera.mirror.importer.exception.ParserException) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) MessageTimeoutException(org.springframework.integration.MessageTimeoutException) ParserException(com.hedera.mirror.importer.exception.ParserException) ImporterException(com.hedera.mirror.importer.exception.ImporterException) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionHandler(com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler) PubSubMessage(com.hedera.mirror.importer.parser.domain.PubSubMessage) FileID(com.hederahashgraph.api.proto.java.FileID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) FileData(com.hedera.mirror.common.domain.file.FileData)

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