Search in sources :

Example 1 with TokenTransferList

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

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

the class BasicTransactionContextTest method buildExpectedRecord.

private ExpirableTxnRecord.Builder buildExpectedRecord(long otherNonThresholdFees, byte[] hash, TxnAccessor accessor, Instant consensusTime, TxnReceipt receipt) {
    long amount = narratedCharging.totalFeesChargedToPayer() + otherNonThresholdFees;
    TransferList transfersList = transfers;
    List<TokenTransferList> tokenTransferList = List.of(tokenTransfers);
    var builder = ExpirableTxnRecord.newBuilder().setReceipt(receipt).setTxnHash(hash).setTxnId(TxnId.fromGrpc(accessor.getTxnId())).setConsensusTime(RichInstant.fromJava(consensusTime)).setMemo(accessor.getTxn().getMemo()).setFee(amount).setTransferList(!transfersList.getAccountAmountsList().isEmpty() ? CurrencyAdjustments.fromGrpc(transfersList) : null).setScheduleRef(accessor.isTriggeredTxn() ? fromGrpcScheduleId(accessor.getScheduleRef()) : null).setNewTokenAssociations(newTokenAssociations);
    List<EntityId> tokens = new ArrayList<>();
    List<CurrencyAdjustments> tokenAdjustments = new ArrayList<>();
    for (TokenTransferList tokenTransfers : tokenTransferList) {
        tokens.add(EntityId.fromGrpcTokenId(tokenTransfers.getToken()));
        tokenAdjustments.add(CurrencyAdjustments.fromGrpc(tokenTransfers.getTransfersList()));
    }
    builder.setTokens(tokens).setTokenAdjustments(tokenAdjustments);
    return builder;
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) ArrayList(java.util.ArrayList) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransferList(com.hederahashgraph.api.proto.java.TransferList)

Example 3 with TokenTransferList

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

the class ExpirableTxnRecordTestHelper method fromGprc.

public static ExpirableTxnRecord fromGprc(TransactionRecord record) {
    List<EntityId> tokens = NO_TOKENS;
    List<CurrencyAdjustments> tokenAdjustments = null;
    List<NftAdjustments> nftTokenAdjustments = null;
    int n = record.getTokenTransferListsCount();
    if (n > 0) {
        tokens = new ArrayList<>();
        tokenAdjustments = new ArrayList<>();
        nftTokenAdjustments = new ArrayList<>();
        for (TokenTransferList tokenTransfers : record.getTokenTransferListsList()) {
            tokens.add(EntityId.fromGrpcTokenId(tokenTransfers.getToken()));
            tokenAdjustments.add(CurrencyAdjustments.fromGrpc(tokenTransfers.getTransfersList()));
            nftTokenAdjustments.add(NftAdjustments.fromGrpc(tokenTransfers.getNftTransfersList()));
        }
    }
    return createExpiryTxnRecordFrom(record, tokens, tokenAdjustments, nftTokenAdjustments);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList)

Example 4 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenSupplyNftsPrecompile.

private void tokenSupplyNftsPrecompile(boolean isMint) {
    entityProperties.getPersist().setContractResults(true);
    // given
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    long timestamp = 10L;
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, SERIAL_NUMBER_LIST);
    Transaction transaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, isMint, 0, SERIAL_NUMBER_LIST);
    // when
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(timestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(SERIAL_NUMBER_LIST.size()).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        builder.addTokenTransferLists(mintTransfer);
        buildContractFunctionResult(builder.getContractCallResultBuilder());
        contractFunctionResultAtomic.set(builder.getContractCallResult());
    });
    // then
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(timestamp, SERIAL_NUMBER_2, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(timestamp, SERIAL_NUMBER_1, TOKEN_ID, PAYER, null);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, timestamp, SYMBOL, 2);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, true, timestamp, timestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_2, true, timestamp, timestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    assertContractResult(timestamp, contractFunctionResultAtomic.get());
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 5 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method nftTransfer.

@Test
void nftTransfer() {
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    long mintTimestamp1 = 20L;
    TokenTransferList mintTransfer1 = nftTransfer(TOKEN_ID, RECEIVER, DEFAULT_ACCOUNT_ID, List.of(SERIAL_NUMBER_1));
    Transaction mintTransaction1 = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, List.of(SERIAL_NUMBER_1));
    insertAndParseTransaction(mintTimestamp1, mintTransaction1, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(1L).addSerialNumbers(SERIAL_NUMBER_1);
        builder.addTokenTransferLists(mintTransfer1);
    });
    // approve allowance for nft 1
    long approveAllowanceTimestamp = 25L;
    var cryptoApproveAllowanceTransaction = buildTransaction(b -> b.getCryptoApproveAllowanceBuilder().addNftAllowances(NftAllowance.newBuilder().setOwner(PAYER).setTokenId(TOKEN_ID).addSerialNumbers(SERIAL_NUMBER_1).setSpender(SPENDER)));
    insertAndParseTransaction(approveAllowanceTimestamp, cryptoApproveAllowanceTransaction);
    var expectedNft1 = Nft.builder().id(new NftId(SERIAL_NUMBER_1, EntityId.of(TOKEN_ID))).accountId(EntityId.of(PAYER)).createdTimestamp(mintTimestamp1).deleted(false).metadata(METADATA.getBytes()).modifiedTimestamp(approveAllowanceTimestamp).spender(EntityId.of(SPENDER)).build();
    assertThat(nftRepository.findById(expectedNft1.getId())).get().isEqualTo(expectedNft1);
    long mintTimestamp2 = 30L;
    TokenTransferList mintTransfer2 = nftTransfer(TOKEN_ID, RECEIVER, DEFAULT_ACCOUNT_ID, List.of(SERIAL_NUMBER_2));
    Transaction mintTransaction2 = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, List.of(SERIAL_NUMBER_2));
    // Verify
    insertAndParseTransaction(mintTimestamp2, mintTransaction2, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(2L).addSerialNumbers(SERIAL_NUMBER_2);
        builder.addTokenTransferLists(mintTransfer2);
    });
    // token transfer
    Transaction transaction = tokenTransferTransaction();
    TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_1).build()).build();
    TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_2).build()).build();
    long transferTimestamp = 40L;
    insertAndParseTransaction(transferTimestamp, transaction, builder -> {
        builder.addAllTokenTransferLists(List.of(transferList1, transferList2));
    });
    expectedNft1.setAccountId(EntityId.of(RECEIVER));
    expectedNft1.setModifiedTimestamp(transferTimestamp);
    expectedNft1.setSpender(null);
    var expectedNft2 = Nft.builder().id(new NftId(SERIAL_NUMBER_2, EntityId.of(TOKEN_ID))).accountId(EntityId.of(RECEIVER)).createdTimestamp(mintTimestamp2).deleted(false).metadata(METADATA.getBytes()).modifiedTimestamp(transferTimestamp).build();
    assertThat(nftTransferRepository.count()).isEqualTo(4L);
    assertNftTransferInRepository(mintTimestamp1, SERIAL_NUMBER_1, TOKEN_ID, RECEIVER, null);
    assertNftTransferInRepository(mintTimestamp2, SERIAL_NUMBER_2, TOKEN_ID, RECEIVER, null);
    assertNftTransferInRepository(transferTimestamp, 1L, TOKEN_ID, RECEIVER, PAYER);
    assertNftTransferInRepository(transferTimestamp, 2L, TOKEN_ID, RECEIVER, PAYER);
    assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(expectedNft1, expectedNft2);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) NftId(com.hedera.mirror.common.domain.token.NftId) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)29 Transaction (com.hederahashgraph.api.proto.java.Transaction)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Test (org.junit.jupiter.api.Test)18 ContractFunctionResult (com.hederahashgraph.api.proto.java.ContractFunctionResult)6 TokenID (com.hederahashgraph.api.proto.java.TokenID)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ByteString (com.google.protobuf.ByteString)5 NftId (com.hedera.mirror.common.domain.token.NftId)5 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)5 AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)5 AccountID (com.hederahashgraph.api.proto.java.AccountID)5 NftTransfer (com.hederahashgraph.api.proto.java.NftTransfer)5 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 ArrayList (java.util.ArrayList)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)3 StringValue (com.google.protobuf.StringValue)2 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)2 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)2