Search in sources :

Example 1 with NonFeeTransfer

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

the class EntityRecordItemListenerCryptoTest method cryptoTransferWithUnknownAlias.

@ParameterizedTest
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "SKIP" })
void cryptoTransferWithUnknownAlias(PartialDataAction partialDataAction) {
    // given
    // both accounts have alias, and only account2's alias is in db
    entityProperties.getPersist().setCryptoTransferAmounts(true);
    entityProperties.getPersist().setNonFeeTransfers(true);
    parserProperties.setPartialDataAction(partialDataAction);
    Entity account1 = domainBuilder.entity().get();
    Entity account2 = domainBuilder.entity().persist();
    // crypto transfer from unknown account1 alias to account2 alias
    Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(accountAliasAmount(DomainUtils.fromBytes(account1.getAlias()), 100)).addAccountAmounts(accountAliasAmount(DomainUtils.fromBytes(account2.getAlias()), -100)));
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord transactionRecord = buildTransactionRecord(r -> r.getTransferListBuilder().addAccountAmounts(accountAmount(account1.getNum(), 100)).addAccountAmounts(accountAmount(account2.getNum(), -100)), transactionBody, ResponseCodeEnum.SUCCESS.getNumber());
    List<EntityId> expectedEntityIds = partialDataAction == PartialDataAction.DEFAULT ? Arrays.asList(account2.toEntityId(), null) : List.of(account2.toEntityId());
    // when
    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
    // then
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(5, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, transactionRecord), () -> assertThat(findNonFeeTransfers()).extracting(NonFeeTransfer::getEntityId).containsExactlyInAnyOrderElementsOf(expectedEntityIds));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) 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) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with NonFeeTransfer

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

the class SqlEntityListenerTest method onNonFeeTransfer.

@Test
void onNonFeeTransfer() {
    // given
    NonFeeTransfer nonFeeTransfer1 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(1L).consensusTimestamp(1L).entityId(EntityId.of(1L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
    NonFeeTransfer nonFeeTransfer2 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(2L).consensusTimestamp(2L).entityId(EntityId.of(2L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
    // when
    sqlEntityListener.onNonFeeTransfer(nonFeeTransfer1);
    sqlEntityListener.onNonFeeTransfer(nonFeeTransfer2);
    completeFileAndCommit();
    // then
    assertThat(findNonFeeTransfers()).containsExactlyInAnyOrder(nonFeeTransfer1, nonFeeTransfer2);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SCHEDULE(com.hedera.mirror.common.domain.entity.EntityType.SCHEDULE) CryptoAllowanceRepository(com.hedera.mirror.importer.repository.CryptoAllowanceRepository) SneakyThrows(lombok.SneakyThrows) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) ContractResultRepository(com.hedera.mirror.importer.repository.ContractResultRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeStakeRepository(com.hedera.mirror.importer.repository.NodeStakeRepository) ScheduleRepository(com.hedera.mirror.importer.repository.ScheduleRepository) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) TokenSupplyTypeEnum(com.hedera.mirror.common.domain.token.TokenSupplyTypeEnum) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) NftAllowanceRepository(com.hedera.mirror.importer.repository.NftAllowanceRepository) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) TestUtils(com.hedera.mirror.importer.TestUtils) TransactionSignatureRepository(com.hedera.mirror.importer.repository.TransactionSignatureRepository) FileDataRepository(com.hedera.mirror.importer.repository.FileDataRepository) MethodSource(org.junit.jupiter.params.provider.MethodSource) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) TokenRepository(com.hedera.mirror.importer.repository.TokenRepository) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) TokenFreezeStatusEnum(com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) CryptoAllowance(com.hedera.mirror.common.domain.entity.CryptoAllowance) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) StakingRewardTransferRepository(com.hedera.mirror.importer.repository.StakingRewardTransferRepository) Arguments(org.junit.jupiter.params.provider.Arguments) StandardCharsets(java.nio.charset.StandardCharsets) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) Stream(java.util.stream.Stream) EntityRepository(com.hedera.mirror.importer.repository.EntityRepository) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) CryptoTransferRepository(com.hedera.mirror.importer.repository.CryptoTransferRepository) TokenAccountRepository(com.hedera.mirror.importer.repository.TokenAccountRepository) EthereumTransactionRepository(com.hedera.mirror.importer.repository.EthereumTransactionRepository) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) Schedule(com.hedera.mirror.common.domain.schedule.Schedule) TokenTypeEnum(com.hedera.mirror.common.domain.token.TokenTypeEnum) NftId(com.hedera.mirror.common.domain.token.NftId) Contract(com.hedera.mirror.common.domain.contract.Contract) TransactionRepository(com.hedera.mirror.importer.repository.TransactionRepository) Hex(org.apache.commons.codec.binary.Hex) ArrayList(java.util.ArrayList) LiveHashRepository(com.hedera.mirror.importer.repository.LiveHashRepository) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) NftTransferRepository(com.hedera.mirror.importer.repository.NftTransferRepository) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) LiveHash(com.hedera.mirror.common.domain.transaction.LiveHash) ValueSource(org.junit.jupiter.params.provider.ValueSource) NftRepository(com.hedera.mirror.importer.repository.NftRepository) TokenAllowanceRepository(com.hedera.mirror.importer.repository.TokenAllowanceRepository) TopicMessageRepository(com.hedera.mirror.importer.repository.TopicMessageRepository) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) TokenTransferRepository(com.hedera.mirror.importer.repository.TokenTransferRepository) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) Key(com.hederahashgraph.api.proto.java.Key) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecordFileRepository(com.hedera.mirror.importer.repository.RecordFileRepository) TokenKycStatusEnum(com.hedera.mirror.common.domain.token.TokenKycStatusEnum) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Assertions(org.junit.jupiter.api.Assertions) TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with NonFeeTransfer

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

the class EntityRecordItemListener method processNonFeeTransfers.

/**
 * Additionally store rows in the non_fee_transactions table if applicable. This will allow the rest-api to create
 * an itemized set of transfers that reflects non-fees (explicit transfers), threshold records, node fee, and
 * network+service fee (paid to treasury).
 */
private void processNonFeeTransfers(long consensusTimestamp, RecordItem recordItem) {
    if (!entityProperties.getPersist().isNonFeeTransfers()) {
        return;
    }
    var body = recordItem.getTransactionBody();
    var partialDataAction = parserProperties.getPartialDataAction();
    var transactionRecord = recordItem.getRecord();
    for (var aa : nonFeeTransfersExtractor.extractNonFeeTransfers(body, transactionRecord)) {
        var entityId = EntityId.EMPTY;
        if (aa.getAmount() != 0) {
            try {
                entityId = entityIdService.lookup(aa.getAccountID());
            } catch (AliasNotFoundException ex) {
                switch(partialDataAction) {
                    case DEFAULT:
                        log.warn("Setting non-fee transfer account to default value due to partial data issue");
                        break;
                    case ERROR:
                        throw ex;
                    case SKIP:
                        log.warn("Skipping non-fee transfer due to partial data issue");
                        continue;
                }
            }
            NonFeeTransfer nonFeeTransfer = new NonFeeTransfer();
            nonFeeTransfer.setAmount(aa.getAmount());
            nonFeeTransfer.setConsensusTimestamp(consensusTimestamp);
            nonFeeTransfer.setEntityId(entityId);
            nonFeeTransfer.setIsApproval(aa.getIsApproval());
            nonFeeTransfer.setPayerAccountId(recordItem.getPayerAccountId());
            entityListener.onNonFeeTransfer(nonFeeTransfer);
        }
    }
}
Also used : NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException)

Example 4 with NonFeeTransfer

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

the class EntityRecordItemListenerCryptoTest method cryptoTransferWithEvmAddressAlias.

@Test
void cryptoTransferWithEvmAddressAlias() {
    Contract contract = domainBuilder.contract().persist();
    assertThat(contractRepository.findByEvmAddress(contract.getEvmAddress())).isPresent();
    entityProperties.getPersist().setNonFeeTransfers(true);
    long transferAmount = 123;
    var transfer1 = accountAliasAmount(DomainUtils.fromBytes(contract.getEvmAddress()), transferAmount).build();
    Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(transfer1));
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord transactionRecord = transactionRecordSuccess(transactionBody);
    RecordItem recordItem = new RecordItem(transaction, transactionRecord);
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, transactionRecord), () -> assertThat(findNonFeeTransfers()).allSatisfy(nonFeeTransfer -> {
        assertThat(nonFeeTransfer.getEntityId()).isEqualTo(contract.toEntityId());
        assertThat(nonFeeTransfer.getAmount()).isEqualTo(transferAmount);
        assertThat(nonFeeTransfer.getPayerAccountId()).isEqualTo(recordItem.getPayerAccountId());
    }));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CryptoAllowanceRepository(com.hedera.mirror.importer.repository.CryptoAllowanceRepository) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) KeyList(com.hederahashgraph.api.proto.java.KeyList) NftAllowanceRepository(com.hedera.mirror.importer.repository.NftAllowanceRepository) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) Collection(java.util.Collection) Resource(javax.annotation.Resource) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) RealmID(com.hederahashgraph.api.proto.java.RealmID) Stream(java.util.stream.Stream) ShardID(com.hederahashgraph.api.proto.java.ShardID) NftRemoveAllowance(com.hederahashgraph.api.proto.java.NftRemoveAllowance) StakingRewardTransfer(com.hedera.mirror.common.domain.transaction.StakingRewardTransfer) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) ErrataType(com.hedera.mirror.common.domain.transaction.ErrataType) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) NftId(com.hedera.mirror.common.domain.token.NftId) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) BoolValue(com.google.protobuf.BoolValue) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) LinkedList(java.util.LinkedList) AccountID(com.hederahashgraph.api.proto.java.AccountID) LiveHash(com.hedera.mirror.common.domain.transaction.LiveHash) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TransferList(com.hederahashgraph.api.proto.java.TransferList) NftRepository(com.hedera.mirror.importer.repository.NftRepository) TokenAllowanceRepository(com.hedera.mirror.importer.repository.TokenAllowanceRepository) Int32Value(com.google.protobuf.Int32Value) IterableAssert(org.assertj.core.api.IterableAssert) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) DisplayName(org.junit.jupiter.api.DisplayName) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) Condition(org.assertj.core.api.Condition) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) 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) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) Contract(com.hedera.mirror.common.domain.contract.Contract) 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 NonFeeTransfer

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

the class TransferTransactionPayerMigrationTest method persistNonFeeTransfers.

private void persistNonFeeTransfers(List<NonFeeTransfer> nonFeeTransfers) {
    for (NonFeeTransfer nonFeeTransfer : nonFeeTransfers) {
        var id = nonFeeTransfer.getId();
        jdbcOperations.update("insert into non_fee_transfer (amount, entity_id, consensus_timestamp)" + " values (?,?,?)", nonFeeTransfer.getAmount(), nonFeeTransfer.getEntityId().getId(), nonFeeTransfer.getConsensusTimestamp());
    }
}
Also used : NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer)

Aggregations

NonFeeTransfer (com.hedera.mirror.common.domain.transaction.NonFeeTransfer)5 Entity (com.hedera.mirror.common.domain.entity.Entity)3 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 ByteString (com.google.protobuf.ByteString)2 Contract (com.hedera.mirror.common.domain.contract.Contract)2 Nft (com.hedera.mirror.common.domain.token.Nft)2 NftId (com.hedera.mirror.common.domain.token.NftId)2 LiveHash (com.hedera.mirror.common.domain.transaction.LiveHash)2 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)2 TestUtils (com.hedera.mirror.importer.TestUtils)2 AliasNotFoundException (com.hedera.mirror.importer.exception.AliasNotFoundException)2 ContractRepository (com.hedera.mirror.importer.repository.ContractRepository)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 BoolValue (com.google.protobuf.BoolValue)1 Int32Value (com.google.protobuf.Int32Value)1 StringValue (com.google.protobuf.StringValue)1 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)1 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)1 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1