Search in sources :

Example 26 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class TokenUpdateTransactionHandlerTest method updateTransactionSuccessful.

@Test
void updateTransactionSuccessful() {
    RecordItem recordItem = recordItemBuilder.tokenUpdate().build();
    var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
    when(entityIdService.lookup(any(AccountID.class))).thenReturn(EntityIdEndec.decode(10, EntityType.ACCOUNT));
    transactionHandler.updateTransaction(transaction, recordItem);
    assertTokenUpdate(timestamp, tokenId, id -> assertEquals(10L, id));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) DomainUtils(com.hedera.mirror.common.util.DomainUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.when(org.mockito.Mockito.when) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) 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) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AccountID(com.hederahashgraph.api.proto.java.AccountID) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class TransactionRepositoryTest method transaction.

private Transaction transaction() {
    Transaction transaction = new Transaction();
    transaction.setChargedTxFee(100L);
    transaction.setConsensusTimestamp(++count);
    transaction.setEntityId(EntityId.of(0, 0, 1, EntityType.ACCOUNT));
    transaction.setInitialBalance(1000L);
    transaction.setMemo("transaction memo".getBytes());
    transaction.setNodeAccountId(EntityId.of(0, 0, 2, EntityType.ACCOUNT));
    transaction.setNonce(0);
    transaction.setPayerAccountId(EntityId.of(0, 0, 3, EntityType.ACCOUNT));
    transaction.setResult(ResponseCodeEnum.SUCCESS.getNumber());
    transaction.setType(TransactionType.CRYPTOCREATEACCOUNT.getProtoId());
    transaction.setValidStartNs(20L);
    transaction.setValidDurationSeconds(11L);
    transaction.setMaxFee(33L);
    return transaction;
}
Also used : Transaction(com.hedera.mirror.common.domain.transaction.Transaction)

Example 28 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class TransactionRepositoryTest method save.

@Test
void save() {
    Transaction transaction = transactionRepository.save(transaction());
    assertThat(transactionRepository.findById(transaction.getConsensusTimestamp())).get().isEqualTo(transaction);
}
Also used : Transaction(com.hedera.mirror.common.domain.transaction.Transaction) Test(org.junit.jupiter.api.Test)

Example 29 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method onItem.

@Override
public void onItem(RecordItem recordItem) throws ImporterException {
    TransactionRecord txRecord = recordItem.getRecord();
    TransactionBody body = recordItem.getTransactionBody();
    int transactionTypeValue = recordItem.getTransactionType();
    TransactionType transactionType = TransactionType.of(transactionTypeValue);
    TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
    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;
    }
    log.debug("Processing {} transaction {} for entity {}", transactionType, consensusTimestamp, entityId);
    // to:do - exclude Freeze from Filter transaction type
    TransactionFilterFields transactionFilterFields = new TransactionFilterFields(entityId, transactionType);
    if (!transactionFilter.test(transactionFilterFields)) {
        log.debug("Ignoring transaction. consensusTimestamp={}, transactionType={}, entityId={}", consensusTimestamp, transactionType, entityId);
        return;
    }
    Transaction transaction = buildTransaction(consensusTimestamp, recordItem);
    transaction.setEntityId(entityId);
    transactionHandler.updateTransaction(transaction, recordItem);
    if (txRecord.hasTransferList() && entityProperties.getPersist().isCryptoTransferAmounts()) {
        insertTransferList(recordItem);
    }
    // insert staking reward transfers even on failure
    insertStakingRewardTransfers(recordItem);
    // handle scheduled transaction, even on failure
    if (transaction.isScheduled()) {
        onScheduledTransaction(recordItem);
    }
    if (recordItem.isSuccessful()) {
        if (entityProperties.getPersist().getTransactionSignatures().contains(transactionType)) {
            insertTransactionSignatures(transaction.getEntityId(), recordItem.getConsensusTimestamp(), recordItem.getSignatureMap().getSigPairList());
        }
        // Only add non-fee transfers on success as the data is assured to be valid
        processNonFeeTransfers(consensusTimestamp, recordItem);
        if (body.hasConsensusSubmitMessage()) {
            insertConsensusTopicMessage(recordItem);
        } else if (body.hasCryptoAddLiveHash()) {
            insertCryptoAddLiveHash(consensusTimestamp, body.getCryptoAddLiveHash());
        } else if (body.hasFileAppend()) {
            insertFileAppend(consensusTimestamp, body.getFileAppend(), transactionTypeValue);
        } else if (body.hasFileCreate()) {
            insertFileData(consensusTimestamp, DomainUtils.toBytes(body.getFileCreate().getContents()), txRecord.getReceipt().getFileID(), transactionTypeValue);
        } else if (body.hasFileUpdate()) {
            insertFileUpdate(consensusTimestamp, body.getFileUpdate(), transactionTypeValue);
        } else if (body.hasTokenAssociate()) {
            insertTokenAssociate(recordItem);
        } else if (body.hasTokenBurn()) {
            insertTokenBurn(recordItem);
        } else if (body.hasTokenCreation()) {
            insertTokenCreate(recordItem);
        } else if (body.hasTokenDissociate()) {
            insertTokenDissociate(recordItem);
        } else if (body.hasTokenFeeScheduleUpdate()) {
            insertTokenFeeScheduleUpdate(recordItem);
        } else if (body.hasTokenFreeze()) {
            insertTokenAccountFreezeBody(recordItem);
        } else if (body.hasTokenGrantKyc()) {
            insertTokenAccountGrantKyc(recordItem);
        } else if (body.hasTokenMint()) {
            insertTokenMint(recordItem);
        } else if (body.hasTokenPause()) {
            insertTokenPause(recordItem);
        } else if (body.hasTokenRevokeKyc()) {
            insertTokenAccountRevokeKyc(recordItem);
        } else if (body.hasTokenUnfreeze()) {
            insertTokenAccountUnfreeze(recordItem);
        } else if (body.hasTokenUnpause()) {
            insertTokenUnpause(recordItem);
        } else if (body.hasTokenUpdate()) {
            insertTokenUpdate(recordItem);
        } else if (body.hasTokenWipe()) {
            insertTokenAccountWipe(recordItem);
        }
        // Record token transfers can be populated for multiple transaction types
        insertTokenTransfers(recordItem);
        insertAssessedCustomFees(recordItem);
        insertAutomaticTokenAssociations(recordItem);
    }
    contractResultService.process(recordItem, transaction);
    entityListener.onTransaction(transaction);
    log.debug("Storing transaction: {}", transaction);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) 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) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TransactionHandler(com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler) TransactionFilterFields(com.hedera.mirror.importer.domain.TransactionFilterFields) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException)

Example 30 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class NodeStakeUpdateTransactionHandler method updateTransaction.

@Override
public void updateTransaction(Transaction transaction, RecordItem recordItem) {
    long consensusTimestamp = recordItem.getConsensusTimestamp();
    if (!recordItem.isSuccessful()) {
        var record = recordItem.getRecord();
        log.warn("NodeStakeUpdateTransaction at consensus timestamp {} failed with status {}", consensusTimestamp, record.getReceipt().getStatus());
        return;
    }
    // We subtract one since we get stake update in current day, but it applies to previous day
    long epochDay = Utility.getEpochDay(consensusTimestamp) - 1L;
    var transactionBody = recordItem.getTransactionBody().getNodeStakeUpdate();
    long stakingPeriod = DomainUtils.timestampInNanosMax(transactionBody.getEndOfStakingPeriod());
    long stakeTotal = transactionBody.getNodeStakeList().stream().map(n -> n.getStake()).reduce(0L, Long::sum);
    for (var nodeStakeProto : transactionBody.getNodeStakeList()) {
        NodeStake nodeStake = new NodeStake();
        nodeStake.setConsensusTimestamp(consensusTimestamp);
        nodeStake.setEpochDay(epochDay);
        nodeStake.setNodeId(nodeStakeProto.getNodeId());
        nodeStake.setRewardRate(nodeStakeProto.getRewardRate());
        nodeStake.setStake(nodeStakeProto.getStake());
        nodeStake.setStakeRewarded(nodeStakeProto.getStakeRewarded());
        nodeStake.setStakeTotal(stakeTotal);
        nodeStake.setStakingPeriod(stakingPeriod);
        entityListener.onNodeStake(nodeStake);
    }
}
Also used : DomainUtils(com.hedera.mirror.common.util.DomainUtils) EntityId(com.hedera.mirror.common.domain.entity.EntityId) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Log4j2(lombok.extern.log4j.Log4j2) Named(javax.inject.Named) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) NodeStake(com.hedera.mirror.common.domain.addressbook.NodeStake) EntityListener(com.hedera.mirror.importer.parser.record.entity.EntityListener) Utility(com.hedera.mirror.importer.util.Utility) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) NodeStake(com.hedera.mirror.common.domain.addressbook.NodeStake)

Aggregations

Transaction (com.hedera.mirror.common.domain.transaction.Transaction)37 Test (org.junit.jupiter.api.Test)24 EntityId (com.hedera.mirror.common.domain.entity.EntityId)23 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)19 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)18 DomainUtils (com.hedera.mirror.common.util.DomainUtils)17 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 EntityType (com.hedera.mirror.common.domain.entity.EntityType)16 AccountID (com.hederahashgraph.api.proto.java.AccountID)16 Mockito.verify (org.mockito.Mockito.verify)16 RecordParserProperties (com.hedera.mirror.importer.parser.record.RecordParserProperties)15 Mockito.verifyNoInteractions (org.mockito.Mockito.verifyNoInteractions)15 Range (com.google.common.collect.Range)14 AliasNotFoundException (com.hedera.mirror.importer.exception.AliasNotFoundException)14 PartialDataAction (com.hedera.mirror.importer.parser.PartialDataAction)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 Assertions (org.junit.jupiter.api.Assertions)14 EnumSource (org.junit.jupiter.params.provider.EnumSource)14 Mockito.when (org.mockito.Mockito.when)14