Search in sources :

Example 6 with AccountAmount

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

the class AbstractEntityRecordItemListenerTest method assertRecordTransfers.

protected void assertRecordTransfers(TransactionRecord record) {
    long consensusTimestamp = DomainUtils.timeStampInNanos(record.getConsensusTimestamp());
    if (entityProperties.getPersist().isCryptoTransferAmounts()) {
        TransferList transferList = record.getTransferList();
        for (AccountAmount accountAmount : transferList.getAccountAmountsList()) {
            EntityId account = EntityId.of(accountAmount.getAccountID());
            assertThat(cryptoTransferRepository.findById(new CryptoTransfer.Id(accountAmount.getAmount(), consensusTimestamp, account.getId()))).isPresent();
        }
    } else {
        assertThat(cryptoTransferRepository.count()).isEqualTo(0L);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) TransferList(com.hederahashgraph.api.proto.java.TransferList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 7 with AccountAmount

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

the class PubSubRecordItemListenerTest method testPubSubMessageWithNonFeeTransferAndNullEntityId.

@Test
void testPubSubMessageWithNonFeeTransferAndNullEntityId() throws Exception {
    // given
    List<AccountAmount> nonFeeTransfers = new ArrayList<>();
    nonFeeTransfers.add(buildAccountAmount(10L, 100L));
    nonFeeTransfers.add(buildAccountAmount(11L, 111L));
    CryptoTransferTransactionBody cryptoTransfer = CryptoTransferTransactionBody.newBuilder().setTransfers(TransferList.newBuilder().addAccountAmounts(nonFeeTransfers.get(0)).addAccountAmounts(nonFeeTransfers.get(1)).build()).build();
    Transaction transaction = buildTransaction(builder -> builder.setCryptoTransfer(cryptoTransfer));
    var recordItem = new RecordItem(transaction, DEFAULT_RECORD);
    when(nonFeeTransferExtractionStrategy.extractNonFeeTransfers(recordItem.getTransactionBody(), recordItem.getRecord())).thenReturn(cryptoTransfer.getTransfers().getAccountAmountsList());
    // when
    pubSubRecordItemListener.onItem(recordItem);
    // then
    var pubSubMessage = assertPubSubMessage(buildPubSubTransaction(transaction), 1);
    assertThat(pubSubMessage.getEntity()).isNull();
    assertThat(pubSubMessage.getNonFeeTransfers()).isEqualTo(nonFeeTransfers);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) ArrayList(java.util.ArrayList) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) Test(org.junit.jupiter.api.Test)

Example 8 with AccountAmount

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

the class EntityRecordItemListener method insertFungibleTokenTransfers.

private void insertFungibleTokenTransfers(long consensusTimestamp, TransactionBody body, boolean isTokenDissociate, TokenID tokenId, EntityId entityTokenId, EntityId payerAccountId, List<AccountAmount> tokenTransfers) {
    for (AccountAmount accountAmount : tokenTransfers) {
        EntityId accountId = EntityId.of(accountAmount.getAccountID());
        long amount = accountAmount.getAmount();
        TokenTransfer tokenTransfer = new TokenTransfer();
        tokenTransfer.setAmount(amount);
        tokenTransfer.setId(new TokenTransfer.Id(consensusTimestamp, entityTokenId, accountId));
        tokenTransfer.setIsApproval(false);
        tokenTransfer.setPayerAccountId(payerAccountId);
        tokenTransfer.setTokenDissociate(isTokenDissociate);
        // then again set is_approval=true
        if (amount < 0) {
            // Is the accountAmount from the record also inside a body's transfer list for the given tokenId?
            AccountAmount accountAmountInsideTransferList = findAccountAmount(accountAmount::equals, tokenId, body);
            if (accountAmountInsideTransferList == null) {
                // Is there any account amount inside the body's transfer list for the given tokenId
                // with the same accountId as the accountAmount from the record?
                AccountAmount accountAmountWithSameIdInsideBody = findAccountAmount(aa -> aa.getAccountID().equals(accountAmount.getAccountID()) && aa.getIsApproval(), tokenId, body);
                if (accountAmountWithSameIdInsideBody != null) {
                    tokenTransfer.setIsApproval(true);
                }
            } else {
                tokenTransfer.setIsApproval(accountAmountInsideTransferList.getIsApproval());
            }
        }
        entityListener.onTokenTransfer(tokenTransfer);
        if (isTokenDissociate) {
            // token transfers in token dissociate are for deleted tokens and the amount is negative to
            // bring the account's balance of the token to 0. Set the totalSupply of the token object to the
            // negative amount, later in the pipeline the token total supply will be reduced accordingly
            Token token = Token.of(entityTokenId);
            token.setModifiedTimestamp(consensusTimestamp);
            token.setTotalSupply(accountAmount.getAmount());
            entityListener.onToken(token);
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Token(com.hedera.mirror.common.domain.token.Token) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 9 with AccountAmount

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

the class EntityRecordItemListener method insertTransferList.

private void insertTransferList(RecordItem recordItem) {
    long consensusTimestamp = recordItem.getConsensusTimestamp();
    var transferList = recordItem.getRecord().getTransferList();
    EntityId payerAccountId = recordItem.getPayerAccountId();
    var body = recordItem.getTransactionBody();
    boolean failedTransfer = !recordItem.isSuccessful() && body.hasCryptoTransfer();
    for (int i = 0; i < transferList.getAccountAmountsCount(); ++i) {
        var aa = transferList.getAccountAmounts(i);
        var account = EntityId.of(aa.getAccountID());
        CryptoTransfer cryptoTransfer = new CryptoTransfer();
        cryptoTransfer.setAmount(aa.getAmount());
        cryptoTransfer.setConsensusTimestamp(consensusTimestamp);
        cryptoTransfer.setEntityId(account.getId());
        cryptoTransfer.setIsApproval(false);
        cryptoTransfer.setPayerAccountId(payerAccountId);
        AccountAmount accountAmountInsideBody = null;
        if (cryptoTransfer.getAmount() < 0 || failedTransfer) {
            accountAmountInsideBody = findAccountAmount(aa, body);
        }
        if (accountAmountInsideBody != null) {
            cryptoTransfer.setIsApproval(accountAmountInsideBody.getIsApproval());
            if (failedTransfer) {
                cryptoTransfer.setErrata(ErrataType.DELETE);
            }
        }
        entityListener.onCryptoTransfer(cryptoTransfer);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 10 with AccountAmount

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

the class RequestBuilder method getHbarCryptoTransferRequestToAlias.

public static Transaction getHbarCryptoTransferRequestToAlias(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp timestamp, Duration transactionDuration, boolean generateRecord, String memo, Long senderActNum, Long amountSend, ByteString receivingAlias, Long amountReceived) {
    AccountAmount a1 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(senderActNum, 0l, 0l)).setAmount(amountSend).build();
    AccountAmount a2 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(receivingAlias, 0l, 0l)).setAmount(amountReceived).build();
    TransferList transferList = TransferList.newBuilder().addAccountAmounts(a1).addAccountAmounts(a2).build();
    return getCryptoTransferRequest(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, timestamp, transactionDuration, generateRecord, memo, transferList);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransferList(com.hederahashgraph.api.proto.java.TransferList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Aggregations

AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)18 TransferList (com.hederahashgraph.api.proto.java.TransferList)5 ByteString (com.google.protobuf.ByteString)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)4 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)3 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)2 TokenMovement (com.hedera.services.bdd.spec.transactions.token.TokenMovement)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)2 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)2 TokenID (com.hederahashgraph.api.proto.java.TokenID)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.jupiter.api.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BoolValue (com.google.protobuf.BoolValue)1 Int32Value (com.google.protobuf.Int32Value)1