Search in sources :

Example 1 with AssessedCustomFee

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

the class EntityRecordItemListenerTokenTest method provideAssessedCustomFees.

private static Stream<Arguments> provideAssessedCustomFees() {
    // without effective payer account ids, this is prior to services 0.17.1
    // paid in HBAR
    AssessedCustomFee assessedCustomFee1 = new AssessedCustomFee();
    assessedCustomFee1.setAmount(12505L);
    assessedCustomFee1.setEffectivePayerAccountIds(Collections.emptyList());
    assessedCustomFee1.setId(new AssessedCustomFee.Id(FEE_COLLECTOR_ACCOUNT_ID_1, TRANSFER_TIMESTAMP));
    assessedCustomFee1.setPayerAccountId(EntityId.of(PAYER));
    // paid in FEE_DOMAIN_TOKEN_ID
    AssessedCustomFee assessedCustomFee2 = new AssessedCustomFee();
    assessedCustomFee2.setAmount(8750L);
    assessedCustomFee2.setEffectivePayerAccountIds(Collections.emptyList());
    assessedCustomFee2.setId(new AssessedCustomFee.Id(FEE_COLLECTOR_ACCOUNT_ID_2, TRANSFER_TIMESTAMP));
    assessedCustomFee2.setTokenId(FEE_DOMAIN_TOKEN_ID);
    assessedCustomFee2.setPayerAccountId(EntityId.of(PAYER));
    List<AssessedCustomFee> assessedCustomFees = List.of(assessedCustomFee1, assessedCustomFee2);
    // build the corresponding protobuf assessed custom fee list
    var protoAssessedCustomFee1 = com.hederahashgraph.api.proto.java.AssessedCustomFee.newBuilder().setAmount(12505L).setFeeCollectorAccountId(convertAccountId(FEE_COLLECTOR_ACCOUNT_ID_1)).build();
    var protoAssessedCustomFee2 = com.hederahashgraph.api.proto.java.AssessedCustomFee.newBuilder().setAmount(8750L).setFeeCollectorAccountId(convertAccountId(FEE_COLLECTOR_ACCOUNT_ID_2)).setTokenId(convertTokenId(FEE_DOMAIN_TOKEN_ID)).build();
    var protoAssessedCustomFees = List.of(protoAssessedCustomFee1, protoAssessedCustomFee2);
    // with effective payer account ids
    // paid in HBAR, one effective payer
    AssessedCustomFee assessedCustomFee3 = new AssessedCustomFee();
    assessedCustomFee3.setAmount(12300L);
    assessedCustomFee3.setEffectivePayerEntityIds(List.of(FEE_PAYER_1));
    assessedCustomFee3.setId(new AssessedCustomFee.Id(FEE_COLLECTOR_ACCOUNT_ID_1, TRANSFER_TIMESTAMP));
    assessedCustomFee3.setPayerAccountId(EntityId.of(PAYER));
    // paid in FEE_DOMAIN_TOKEN_ID, two effective payers
    AssessedCustomFee assessedCustomFee4 = new AssessedCustomFee();
    assessedCustomFee4.setAmount(8790L);
    assessedCustomFee4.setId(new AssessedCustomFee.Id(FEE_COLLECTOR_ACCOUNT_ID_2, TRANSFER_TIMESTAMP));
    assessedCustomFee4.setEffectivePayerEntityIds(List.of(FEE_PAYER_1, FEE_PAYER_2));
    assessedCustomFee4.setTokenId(FEE_DOMAIN_TOKEN_ID);
    assessedCustomFee4.setPayerAccountId(EntityId.of(PAYER));
    List<AssessedCustomFee> assessedCustomFeesWithPayers = List.of(assessedCustomFee3, assessedCustomFee4);
    // build the corresponding protobuf assessed custom fee list, with effective payer account ids
    var protoAssessedCustomFee3 = com.hederahashgraph.api.proto.java.AssessedCustomFee.newBuilder().addAllEffectivePayerAccountId(List.of(convertAccountId(FEE_PAYER_1))).setAmount(12300L).setFeeCollectorAccountId(convertAccountId(FEE_COLLECTOR_ACCOUNT_ID_1)).build();
    var protoAssessedCustomFee4 = com.hederahashgraph.api.proto.java.AssessedCustomFee.newBuilder().addAllEffectivePayerAccountId(List.of(convertAccountId(FEE_PAYER_1), convertAccountId(FEE_PAYER_2))).setAmount(8790L).setFeeCollectorAccountId(convertAccountId(FEE_COLLECTOR_ACCOUNT_ID_2)).setTokenId(convertTokenId(FEE_DOMAIN_TOKEN_ID)).build();
    var protoAssessedCustomFeesWithPayers = List.of(protoAssessedCustomFee3, protoAssessedCustomFee4);
    return Stream.of(Arguments.of("no assessed custom fees", Collections.emptyList(), Collections.emptyList()), Arguments.of("has assessed custom fees without effective payer account ids", assessedCustomFees, protoAssessedCustomFees), Arguments.of("has assessed custom fees with effective payer account ids", assessedCustomFeesWithPayers, protoAssessedCustomFeesWithPayers));
}
Also used : AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee)

Example 2 with AssessedCustomFee

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

the class TransferTransactionPayerMigrationTest method verifyEntityTimestampMigration.

@Test
void verifyEntityTimestampMigration() throws Exception {
    Entity node = domainBuilder.entity().customize(e -> e.createdTimestamp(10L).timestampRange(Range.atLeast(10L))).get();
    Entity treasury = domainBuilder.entity().customize(e -> e.createdTimestamp(20L).timestampRange(Range.atLeast(20L))).get();
    Entity sender = domainBuilder.entity().customize(e -> e.createdTimestamp(30L).timestampRange(Range.atLeast(30L))).get();
    Entity receiver = domainBuilder.entity().customize(e -> e.createdTimestamp(40L).timestampRange(Range.atLeast(40L))).get();
    Entity contract = domainBuilder.entity().customize(e -> e.createdTimestamp(50L).timestampRange(Range.atLeast(50L)).type(EntityType.CONTRACT)).get();
    Entity file = domainBuilder.entity().customize(e -> e.createdTimestamp(60L).timestampRange(Range.atLeast(60L)).type(EntityType.FILE)).get();
    Entity topic = domainBuilder.entity().customize(e -> e.createdTimestamp(70L).timestampRange(Range.atLeast(70L)).type(EntityType.TOPIC)).get();
    Entity token = domainBuilder.entity().customize(e -> e.createdTimestamp(80L).timestampRange(Range.atLeast(80L)).type(TOKEN)).get();
    Entity schedule = domainBuilder.entity().customize(e -> e.createdTimestamp(90L).timestampRange(Range.atLeast(90L)).type(EntityType.SCHEDULE)).get();
    // given
    persistEntities(List.of(node, treasury, sender, receiver, contract, file, topic, token, schedule));
    MigrationTransaction transfer1 = transaction(schedule.getCreatedTimestamp() + 200L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer2 = transaction(schedule.getCreatedTimestamp() + 300L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer3 = transaction(schedule.getCreatedTimestamp() + 400L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer4 = transaction(schedule.getCreatedTimestamp() + 500L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    MigrationTransaction transfer5 = transaction(schedule.getCreatedTimestamp() + 600L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
    persistTransactions(List.of(transaction(contract.getCreatedTimestamp(), contract.getId(), SUCCESS, TransactionType.CONTRACTCREATEINSTANCE), transaction(contract.getCreatedTimestamp() + 1, contract.getId(), INSUFFICIENT_TX_FEE, TransactionType.CONTRACTUPDATEINSTANCE), transaction(file.getCreatedTimestamp(), file.getId(), SUCCESS, TransactionType.FILECREATE), transaction(file.getCreatedTimestamp() + 1, file.getId(), SUCCESS, TransactionType.FILEDELETE), transaction(topic.getCreatedTimestamp(), topic.getId(), SUCCESS, TransactionType.CONSENSUSCREATETOPIC), transaction(topic.getCreatedTimestamp() + 1, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(topic.getCreatedTimestamp() + 2, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(topic.getCreatedTimestamp() + 3, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(token.getCreatedTimestamp(), token.getId(), SUCCESS, TransactionType.TOKENCREATION), transaction(schedule.getCreatedTimestamp(), schedule.getId(), SUCCESS, TransactionType.SCHEDULECREATE), transfer1, transfer2, transfer3, transfer4, transfer5));
    EntityId nodeId = node.toEntityId();
    EntityId treasuryId = treasury.toEntityId();
    EntityId senderId = sender.toEntityId();
    EntityId receiverId = receiver.toEntityId();
    EntityId tokenId = token.toEntityId();
    long senderPaymentAmount = -45L;
    long receivedAmount = 30L;
    long nodePaymentAmount = 10L;
    long treasuryPaymentAmount = 5L;
    AssessedCustomFee assessedCustomFee1 = new AssessedCustomFee();
    assessedCustomFee1.setAmount(receivedAmount);
    assessedCustomFee1.setEffectivePayerAccountIds(List.of(senderId.getId()));
    assessedCustomFee1.setId(new AssessedCustomFee.Id(receiverId, transfer1.getConsensusTimestamp()));
    assessedCustomFee1.setPayerAccountId(tokenId);
    assessedCustomFee1.setTokenId(tokenId);
    AssessedCustomFee assessedCustomFee2 = new AssessedCustomFee();
    assessedCustomFee2.setAmount(receivedAmount);
    assessedCustomFee2.setEffectivePayerAccountIds(List.of(senderId.getId()));
    assessedCustomFee2.setId(new AssessedCustomFee.Id(receiverId, transfer5.getConsensusTimestamp()));
    assessedCustomFee2.setPayerAccountId(tokenId);
    assessedCustomFee2.setTokenId(tokenId);
    persistAssessedCustomFees(List.of(// assessed custom fee transfer
    assessedCustomFee1, // all transfers
    assessedCustomFee2));
    persistCryptoTransfers(List.of(// assessed custom fee transfer
    new CryptoTransfer(transfer1.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer1.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer1.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer1.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // crypto only transfer
    new CryptoTransfer(transfer2.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer2.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer2.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer2.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // nft transfer
    new CryptoTransfer(transfer3.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer3.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer3.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer3.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // token transfer
    new CryptoTransfer(transfer4.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer4.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer4.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer4.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // all transfers
    new CryptoTransfer(transfer5.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer5.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer5.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer5.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId)));
    persistNonFeeTransfers(List.of(// assessed custom fee only transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.consensusTimestamp(transfer1.getConsensusTimestamp()).amount(senderPaymentAmount).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer1.getConsensusTimestamp()).entityId(receiverId)).get(), // crypto only transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer2.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer2.getConsensusTimestamp()).entityId(receiverId)).get(), // nft transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer3.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer3.getConsensusTimestamp()).entityId(receiverId)).get(), // token transfer
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer4.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer4.getConsensusTimestamp()).entityId(receiverId)).get(), // all transfers
    domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer5.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer5.getConsensusTimestamp()).entityId(receiverId)).get()));
    persistNftTransfers(List.of(// nft transfer
    domainBuilder.nftTransfer().customize(n -> n.id(new NftTransferId(transfer3.getConsensusTimestamp(), 1L, tokenId)).payerAccountId(null).receiverAccountId(receiverId).senderAccountId(senderId)).get(), // all transfers
    domainBuilder.nftTransfer().customize(n -> n.id(new NftTransferId(transfer5.getConsensusTimestamp(), 2L, tokenId)).payerAccountId(null).receiverAccountId(receiverId).senderAccountId(senderId)).get()));
    persistTokenTransfers(List.of(// token transfer
    new TokenTransfer(transfer4.getConsensusTimestamp(), -receivedAmount, tokenId, senderId), new TokenTransfer(transfer4.getConsensusTimestamp(), receivedAmount, tokenId, receiverId), // all transfers
    new TokenTransfer(transfer5.getConsensusTimestamp(), -receivedAmount, tokenId, senderId), new TokenTransfer(transfer5.getConsensusTimestamp(), receivedAmount, tokenId, receiverId)));
    // when
    migrate();
    List<SharedTransfer> expectedAssessedCustomFeeTransfers = List.of(// assessed custom fee transfer
    new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, senderId));
    List<SharedTransfer> expectedCryptoTransfers = List.of(// assessed custom fee transfer
    new SharedTransfer(senderPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // crypto only transfer
    new SharedTransfer(senderPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer2.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // nft transfer
    new SharedTransfer(senderPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // token transfer
    new SharedTransfer(senderPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // all transfers
    new SharedTransfer(senderPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, treasuryId, null));
    List<SharedTransfer> expectedNftTransfers = List.of(// nft transfer
    new SharedTransfer(1L, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, senderId), new SharedTransfer(2L, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, senderId));
    List<SharedTransfer> expectedNonFeeTransfers = List.of(// assessed custom fee only transfer
    new SharedTransfer(senderPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, null), // crypto only transfer
    new SharedTransfer(senderPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer2.getConsensusTimestamp(), PAYER_ID, receiverId, null), // nft transfer
    new SharedTransfer(senderPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, null), // token transfer
    new SharedTransfer(senderPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), // token transfer
    new SharedTransfer(senderPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null));
    List<SharedTransfer> expectedTokenTransfers = List.of(// token transfer
    new SharedTransfer(-receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), // all transfer
    new SharedTransfer(-receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null));
    // then
    assertThat(findAssessedCustomFees()).containsExactlyInAnyOrderElementsOf(expectedAssessedCustomFeeTransfers);
    assertThat(findCryptoTransfers()).containsExactlyInAnyOrderElementsOf(expectedCryptoTransfers);
    assertThat(findNftTransfers()).containsExactlyInAnyOrderElementsOf(expectedNftTransfers);
    assertThat(findNonFeeTransfersAsSharedTransfers()).containsExactlyInAnyOrderElementsOf(expectedNonFeeTransfers);
    assertThat(findTokenTransfers()).containsExactlyInAnyOrderElementsOf(expectedTokenTransfers);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TransactionRepository(com.hedera.mirror.importer.repository.TransactionRepository) StringUtils(org.apache.commons.lang3.StringUtils) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) Value(org.springframework.beans.factory.annotation.Value) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) ObjectUtils(org.apache.commons.lang3.ObjectUtils) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) NftTransferRepository(com.hedera.mirror.importer.repository.NftTransferRepository) Tag(org.junit.jupiter.api.Tag) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) EnabledIfV1(com.hedera.mirror.importer.EnabledIfV1) NonFeeTransferRepository(com.hedera.mirror.importer.repository.NonFeeTransferRepository) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) TestPropertySource(org.springframework.test.context.TestPropertySource) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) PostgreSQLGuavaRangeType(com.vladmihalcea.hibernate.type.range.guava.PostgreSQLGuavaRangeType) PreparedStatement(java.sql.PreparedStatement) File(java.io.File) TokenTransferRepository(com.hedera.mirror.importer.repository.TokenTransferRepository) Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) List(java.util.List) EntityRepository(com.hedera.mirror.importer.repository.EntityRepository) CryptoTransferRepository(com.hedera.mirror.importer.repository.CryptoTransferRepository) Data(lombok.Data) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) AllArgsConstructor(lombok.AllArgsConstructor) NoArgsConstructor(lombok.NoArgsConstructor) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 3 with AssessedCustomFee

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

the class TransferTransactionPayerMigrationTest method persistAssessedCustomFees.

private void persistAssessedCustomFees(List<AssessedCustomFee> assessedCustomFees) throws IOException {
    for (AssessedCustomFee assessedCustomFee : assessedCustomFees) {
        var id = assessedCustomFee.getId();
        jdbcOperations.update("insert into assessed_custom_fee (amount, collector_account_id, consensus_timestamp, token_id," + "effective_payer_account_ids)" + " values (?,?,?,?,?::bigint[])", assessedCustomFee.getAmount(), id.getCollectorAccountId().getId(), id.getConsensusTimestamp(), assessedCustomFee.getTokenId().getId(), longListSerializer(assessedCustomFee.getEffectivePayerAccountIds()));
    }
}
Also used : AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee)

Example 4 with AssessedCustomFee

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

the class EntityRecordItemListener method insertAssessedCustomFees.

private void insertAssessedCustomFees(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        for (var protoAssessedCustomFee : recordItem.getRecord().getAssessedCustomFeesList()) {
            EntityId collectorAccountId = EntityId.of(protoAssessedCustomFee.getFeeCollectorAccountId());
            // the effective payers must also appear in the *transfer lists of this transaction and the
            // corresponding EntityIds should have been added to EntityListener, so skip it here.
            List<EntityId> payerEntityIds = protoAssessedCustomFee.getEffectivePayerAccountIdList().stream().map(EntityId::of).collect(Collectors.toList());
            AssessedCustomFee assessedCustomFee = new AssessedCustomFee();
            assessedCustomFee.setAmount(protoAssessedCustomFee.getAmount());
            assessedCustomFee.setEffectivePayerEntityIds(payerEntityIds);
            assessedCustomFee.setId(new AssessedCustomFee.Id(collectorAccountId, consensusTimestamp));
            assessedCustomFee.setTokenId(EntityId.of(protoAssessedCustomFee.getTokenId()));
            assessedCustomFee.setPayerAccountId(recordItem.getPayerAccountId());
            entityListener.onAssessedCustomFee(assessedCustomFee);
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee)

Example 5 with AssessedCustomFee

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

the class BatchInserterTest method assessedCustomFees.

@Test
void assessedCustomFees() {
    long consensusTimestamp = 10L;
    EntityId collectorId1 = EntityId.of("0.0.2000", EntityType.ACCOUNT);
    EntityId collectorId2 = EntityId.of("0.0.2001", EntityType.ACCOUNT);
    EntityId payerId1 = EntityId.of("0.0.3000", EntityType.ACCOUNT);
    EntityId payerId2 = EntityId.of("0.0.3001", EntityType.ACCOUNT);
    EntityId tokenId1 = EntityId.of("0.0.5000", EntityType.TOKEN);
    EntityId tokenId2 = EntityId.of("0.0.5001", EntityType.TOKEN);
    // fee paid in HBAR with empty effective payer list
    AssessedCustomFee assessedCustomFee1 = new AssessedCustomFee();
    assessedCustomFee1.setAmount(10L);
    assessedCustomFee1.setId(new AssessedCustomFee.Id(collectorId1, consensusTimestamp));
    assessedCustomFee1.setPayerAccountId(payerId1);
    AssessedCustomFee assessedCustomFee2 = new AssessedCustomFee();
    assessedCustomFee2.setAmount(20L);
    assessedCustomFee2.setEffectivePayerAccountIds(List.of(payerId1.getId()));
    assessedCustomFee2.setTokenId(tokenId1);
    assessedCustomFee2.setId(new AssessedCustomFee.Id(collectorId2, consensusTimestamp));
    assessedCustomFee2.setPayerAccountId(payerId1);
    AssessedCustomFee assessedCustomFee3 = new AssessedCustomFee();
    assessedCustomFee3.setAmount(30L);
    assessedCustomFee3.setEffectivePayerAccountIds(List.of(payerId1.getId(), payerId2.getId()));
    assessedCustomFee3.setTokenId(tokenId2);
    assessedCustomFee3.setId(new AssessedCustomFee.Id(collectorId2, consensusTimestamp));
    assessedCustomFee3.setPayerAccountId(payerId2);
    List<AssessedCustomFee> assessedCustomFees = List.of(assessedCustomFee1, assessedCustomFee2, assessedCustomFee3);
    // when
    batchInserter.persist(assessedCustomFees);
    // then
    List<AssessedCustomFeeWrapper> actual = jdbcTemplate.query(AssessedCustomFeeWrapper.SELECT_QUERY, AssessedCustomFeeWrapper.ROW_MAPPER);
    assertThat(actual).map(AssessedCustomFeeWrapper::getAssessedCustomFee).containsExactlyInAnyOrderElementsOf(assessedCustomFees);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AssessedCustomFeeWrapper(com.hedera.mirror.importer.domain.AssessedCustomFeeWrapper) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

AssessedCustomFee (com.hedera.mirror.common.domain.transaction.AssessedCustomFee)5 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)2 Range (com.google.common.collect.Range)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 TOKEN (com.hedera.mirror.common.domain.entity.EntityType.TOKEN)1 NftTransfer (com.hedera.mirror.common.domain.token.NftTransfer)1 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)1 TokenTransfer (com.hedera.mirror.common.domain.token.TokenTransfer)1 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)1 NonFeeTransfer (com.hedera.mirror.common.domain.transaction.NonFeeTransfer)1 TransactionType (com.hedera.mirror.common.domain.transaction.TransactionType)1 EnabledIfV1 (com.hedera.mirror.importer.EnabledIfV1)1 AssessedCustomFeeWrapper (com.hedera.mirror.importer.domain.AssessedCustomFeeWrapper)1 CryptoTransferRepository (com.hedera.mirror.importer.repository.CryptoTransferRepository)1 EntityRepository (com.hedera.mirror.importer.repository.EntityRepository)1 NftTransferRepository (com.hedera.mirror.importer.repository.NftTransferRepository)1 NonFeeTransferRepository (com.hedera.mirror.importer.repository.NonFeeTransferRepository)1