Search in sources :

Example 1 with NftTransfer

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

the class RequestBuilder method getTokenTransferRequestToAlias.

public static Transaction getTokenTransferRequestToAlias(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 tokenNum, 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();
    NftTransfer a3 = NftTransfer.newBuilder().setReceiverAccountID(AccountID.newBuilder().setAlias(receivingAlias).build()).setSenderAccountID(getAccountIdBuild(senderActNum, 0l, 0l)).setSerialNumber(1).build();
    TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(TokenID.newBuilder().setTokenNum(tokenNum).build()).addTransfers(a1).addTransfers(a2).addNftTransfers(a3).build();
    return getTokenTransferRequest(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, timestamp, transactionDuration, generateRecord, memo, tokenTransferList);
}
Also used : NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 2 with NftTransfer

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

the class EntityRecordItemListener method insertNonFungibleTokenTransfers.

private void insertNonFungibleTokenTransfers(long consensusTimestamp, TransactionBody body, TokenID tokenId, EntityId entityTokenId, EntityId payerAccountId, List<com.hederahashgraph.api.proto.java.NftTransfer> nftTransfersList) {
    for (NftTransfer nftTransfer : nftTransfersList) {
        long serialNumber = nftTransfer.getSerialNumber();
        if (serialNumber == NftTransferId.WILDCARD_SERIAL_NUMBER) {
            // treasury change
            return;
        }
        EntityId receiverId = EntityId.of(nftTransfer.getReceiverAccountID());
        EntityId senderId = EntityId.of(nftTransfer.getSenderAccountID());
        var nftTransferDomain = new com.hedera.mirror.common.domain.token.NftTransfer();
        nftTransferDomain.setId(new NftTransferId(consensusTimestamp, serialNumber, entityTokenId));
        nftTransferDomain.setIsApproval(false);
        nftTransferDomain.setReceiverAccountId(receiverId);
        nftTransferDomain.setSenderAccountId(senderId);
        nftTransferDomain.setPayerAccountId(payerAccountId);
        var nftTransferInsideBody = findNftTransferInsideBody(nftTransfer, tokenId, body);
        if (nftTransferInsideBody != null) {
            nftTransferDomain.setIsApproval(nftTransferInsideBody.getIsApproval());
        }
        entityListener.onNftTransfer(nftTransferDomain);
        if (!EntityId.isEmpty(receiverId)) {
            transferNftOwnership(consensusTimestamp, serialNumber, entityTokenId, receiverId);
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId)

Example 3 with NftTransfer

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

the class TokenUpdateTransactionHandler method updateTreasury.

private void updateTreasury(RecordItem recordItem) {
    var payerAccountId = EntityId.of(recordItem.getTransactionBody().getTransactionID().getAccountID()).getId();
    for (TokenTransferList tokenTransferList : recordItem.getRecord().getTokenTransferListsList()) {
        for (NftTransfer nftTransfer : tokenTransferList.getNftTransfersList()) {
            if (nftTransfer.getSerialNumber() == NftTransferId.WILDCARD_SERIAL_NUMBER) {
                EntityId newTreasury = EntityId.of(nftTransfer.getReceiverAccountID());
                EntityId previousTreasury = EntityId.of(nftTransfer.getSenderAccountID());
                EntityId tokenId = EntityId.of(tokenTransferList.getToken());
                nftRepository.updateTreasury(tokenId.getId(), previousTreasury.getId(), newTreasury.getId(), recordItem.getConsensusTimestamp(), payerAccountId, nftTransfer.getIsApproval());
            }
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer)

Example 4 with NftTransfer

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

the class SigRequirements method cryptoTransfer.

private <T> SigningOrderResult<T> cryptoTransfer(final AccountID payer, final CryptoTransferTransactionBody op, final SigningOrderResultFactory<T> factory, @Nullable final LinkedRefs linkedRefs) {
    List<JKey> required = new ArrayList<>();
    KeyOrderingFailure failure;
    for (TokenTransferList xfers : op.getTokenTransfersList()) {
        for (AccountAmount adjust : xfers.getTransfersList()) {
            if ((failure = includeIfNecessary(payer, adjust, required, false, linkedRefs)) != NONE) {
                return accountFailure(failure, factory);
            }
        }
        final var token = xfers.getToken();
        for (NftTransfer adjust : xfers.getNftTransfersList()) {
            final var sender = adjust.getSenderAccountID();
            if ((failure = nftIncludeIfNecessary(payer, sender, null, adjust.getIsApproval(), required, token, op, linkedRefs)) != NONE) {
                return accountFailure(failure, factory);
            }
            final var receiver = adjust.getReceiverAccountID();
            if ((failure = nftIncludeIfNecessary(payer, receiver, sender, false, required, token, op, linkedRefs)) != NONE) {
                return (failure == MISSING_TOKEN) ? factory.forMissingToken() : accountFailure(failure, factory);
            }
        }
    }
    for (AccountAmount adjust : op.getTransfers().getAccountAmountsList()) {
        if ((failure = includeIfNecessary(payer, adjust, required, true, linkedRefs)) != NONE) {
            return accountFailure(failure, factory);
        }
    }
    return factory.forValidOrder(required);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) JKey(com.hedera.services.legacy.core.jproto.JKey) ArrayList(java.util.ArrayList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 5 with NftTransfer

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

the class EntityRecordItemListenerTokenTest method nftUpdateTreasury.

@Test
void nftUpdateTreasury() {
    // given
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    long mintTimestamp = 10L;
    List<Long> serialNumbers = List.of(1L);
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, serialNumbers);
    Transaction mintTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, serialNumbers);
    insertAndParseTransaction(mintTimestamp, mintTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(serialNumbers.size()).addAllSerialNumbers(serialNumbers);
        builder.addTokenTransferLists(mintTransfer);
    });
    // when
    long updateTimestamp = 15L;
    TokenTransferList treasuryUpdateTransfer = nftTransfer(TOKEN_ID, PAYER2, PAYER, List.of(NftTransferId.WILDCARD_SERIAL_NUMBER));
    insertAndParseTransaction(updateTimestamp, buildTransaction(builder -> builder.getTokenUpdateBuilder().setToken(TOKEN_ID).setTreasury(PAYER2)), builder -> builder.addTokenTransferLists(treasuryUpdateTransfer));
    // then
    assertThat(nftTransferRepository.findAll()).containsExactlyInAnyOrder(domainNftTransfer(mintTimestamp, PAYER, DEFAULT_ACCOUNT_ID, 1L, TOKEN_ID, PAYER), domainNftTransfer(updateTimestamp, PAYER2, PAYER, 1L, TOKEN_ID, PAYER));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) EntityId(com.hedera.mirror.common.domain.entity.EntityId) FixedFee(com.hederahashgraph.api.proto.java.FixedFee) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) StringUtils(org.apache.commons.lang3.StringUtils) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) TestUtils(com.hedera.mirror.importer.TestUtils) MethodSource(org.junit.jupiter.params.provider.MethodSource) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) TokenRepository(com.hedera.mirror.importer.repository.TokenRepository) TokenFreezeStatusEnum(com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum) Assertions.from(org.assertj.core.api.Assertions.from) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Resource(javax.annotation.Resource) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) CustomFee(com.hedera.mirror.common.domain.transaction.CustomFee) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) Stream(java.util.stream.Stream) Builder(lombok.Builder) AssessedCustomFeeWrapper(com.hedera.mirror.importer.domain.AssessedCustomFeeWrapper) Lists(org.assertj.core.util.Lists) TokenAccountRepository(com.hedera.mirror.importer.repository.TokenAccountRepository) ObjectAssert(org.assertj.core.api.ObjectAssert) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) Optional(java.util.Optional) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenAssociation(com.hederahashgraph.api.proto.java.TokenAssociation) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) NftId(com.hedera.mirror.common.domain.token.NftId) RoyaltyFee(com.hederahashgraph.api.proto.java.RoyaltyFee) EnumSource(org.junit.jupiter.params.provider.EnumSource) CustomFeeWrapper(com.hedera.mirror.importer.domain.CustomFeeWrapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) FractionalFee(com.hederahashgraph.api.proto.java.FractionalFee) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) NftTransferRepository(com.hedera.mirror.importer.repository.NftTransferRepository) AccountID(com.hederahashgraph.api.proto.java.AccountID) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenAccountId(com.hedera.mirror.common.domain.token.TokenAccountId) TokenTransferRepository(com.hedera.mirror.importer.repository.TokenTransferRepository) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) TokenType(com.hederahashgraph.api.proto.java.TokenType) Fraction(com.hederahashgraph.api.proto.java.Fraction) Key(com.hederahashgraph.api.proto.java.Key) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) TokenKycStatusEnum(com.hedera.mirror.common.domain.token.TokenKycStatusEnum) Assertions(org.junit.jupiter.api.Assertions) NON_FUNGIBLE_UNIQUE(com.hederahashgraph.api.proto.java.TokenType.NON_FUNGIBLE_UNIQUE) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) Comparator(java.util.Comparator) Collections(java.util.Collections) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NftTransfer (com.hederahashgraph.api.proto.java.NftTransfer)6 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)3 AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)3 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 StringValue (com.google.protobuf.StringValue)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)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 Nft (com.hedera.mirror.common.domain.token.Nft)1 NftId (com.hedera.mirror.common.domain.token.NftId)1 Token (com.hedera.mirror.common.domain.token.Token)1 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)1 TokenAccountId (com.hedera.mirror.common.domain.token.TokenAccountId)1 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)1 TokenId (com.hedera.mirror.common.domain.token.TokenId)1 TokenKycStatusEnum (com.hedera.mirror.common.domain.token.TokenKycStatusEnum)1