Search in sources :

Example 86 with TransactionBody

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

the class TokenUpdateTransactionHandlerTest method updateTreasury.

@Test
void updateTreasury() {
    AbstractEntity entity = getExpectedUpdatedEntity();
    AccountID previousAccountId = AccountID.newBuilder().setAccountNum(1L).build();
    AccountID newAccountId = AccountID.newBuilder().setAccountNum(2L).build();
    TokenID tokenID = TokenID.newBuilder().setTokenNum(3L).build();
    long consensusTimestamp = DomainUtils.timestampInNanosMax(MODIFIED_TIMESTAMP);
    TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(tokenID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(newAccountId).setSenderAccountID(previousAccountId).setSerialNumber(NftTransferId.WILDCARD_SERIAL_NUMBER).build()).build();
    TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
    RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
    when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
    Transaction transaction = new Transaction();
    transaction.setEntityId(entity.toEntityId());
    transactionHandler.updateTransaction(transaction, recordItem);
    TransactionBody body = recordItem.getTransactionBody();
    var payerAccount = EntityId.of(body.getTransactionID().getAccountID()).toEntity().getId();
    verify(nftRepository).updateTreasury(tokenID.getTokenNum(), previousAccountId.getAccountNum(), newAccountId.getAccountNum(), consensusTimestamp, payerAccount, false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) TokenID(com.hederahashgraph.api.proto.java.TokenID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 87 with TransactionBody

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

the class EntityRecordItemListener method insertTokenTransfers.

private void insertTokenTransfers(RecordItem recordItem) {
    if (!entityProperties.getPersist().isTokens()) {
        return;
    }
    long consensusTimestamp = recordItem.getConsensusTimestamp();
    TransactionBody body = recordItem.getTransactionBody();
    boolean isTokenDissociate = body.hasTokenDissociate();
    recordItem.getRecord().getTokenTransferListsList().forEach(tokenTransferList -> {
        TokenID tokenId = tokenTransferList.getToken();
        EntityId entityTokenId = EntityId.of(tokenId);
        EntityId payerAccountId = recordItem.getPayerAccountId();
        insertFungibleTokenTransfers(consensusTimestamp, body, isTokenDissociate, tokenId, entityTokenId, payerAccountId, tokenTransferList.getTransfersList());
        insertNonFungibleTokenTransfers(consensusTimestamp, body, tokenId, entityTokenId, payerAccountId, tokenTransferList.getNftTransfersList());
    });
}
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) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 88 with TransactionBody

use of com.hederahashgraph.api.proto.java.TransactionBody 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 89 with TransactionBody

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

the class OpUsageCtxHelperTest method getMetaForTokenMintWorks.

@Test
void getMetaForTokenMintWorks() {
    TokenMintTransactionBody mintTxnBody = getUniqueTokenMintOp();
    TransactionBody txn = getTxnBody(mintTxnBody);
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getSubType()).willReturn(TOKEN_NON_FUNGIBLE_UNIQUE);
    Optional<TokenType> tokenType = Optional.of(TokenType.NON_FUNGIBLE_UNIQUE);
    given(workingView.tokenWith(target)).willReturn(Optional.of(extant));
    final var tokenMintMeta = subject.metaForTokenMint(accessor);
    // then:
    assertEquals(34, tokenMintMeta.getBpt());
    assertEquals(TOKEN_NON_FUNGIBLE_UNIQUE, tokenMintMeta.getSubType());
    assertEquals(12345670, tokenMintMeta.getRbs());
    assertEquals(80, tokenMintMeta.getTransferRecordDb());
}
Also used : 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) TokenType(com.hederahashgraph.api.proto.java.TokenType) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) Test(org.junit.jupiter.api.Test)

Example 90 with TransactionBody

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

the class OpUsageCtxHelperTest method getMetaForTokenWipeWorks.

@Test
void getMetaForTokenWipeWorks() {
    TokenWipeAccountTransactionBody wipeTxnBody = getUniqueTokenWipeOp();
    TransactionBody txn = getTxnBody(wipeTxnBody);
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getSubType()).willReturn(TOKEN_NON_FUNGIBLE_UNIQUE);
    final var tokenWipeMeta = subject.metaForTokenWipe(accessor);
    // then:
    assertEquals(32, tokenWipeMeta.getBpt());
    assertEquals(TOKEN_NON_FUNGIBLE_UNIQUE, tokenWipeMeta.getSubType());
    assertEquals(1, tokenWipeMeta.getSerialNumsCount());
    assertEquals(80, tokenWipeMeta.getTransferRecordDb());
}
Also used : TokenWipeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenWipeAccountTransactionBody) 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)

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