Search in sources :

Example 21 with TokenID

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

the class HapiCryptoTransfer method aggregateOnTokenIds.

private Map<TokenID, Pair<Integer, List<AccountAmount>>> aggregateOnTokenIds(final HapiApiSpec spec) {
    Map<TokenID, Pair<Integer, List<AccountAmount>>> map = new HashMap<>();
    for (TokenMovement tm : tokenAwareProviders) {
        if (tm.isFungibleToken()) {
            var list = tm.specializedFor(spec);
            if (map.containsKey(list.getToken())) {
                var existingVal = map.get(list.getToken());
                List<AccountAmount> newList = Stream.of(existingVal.getRight(), list.getTransfersList()).flatMap(Collection::stream).collect(Collectors.toList());
                map.put(list.getToken(), Pair.of(existingVal.getLeft(), newList));
            } else {
                map.put(list.getToken(), Pair.of(list.getExpectedDecimals().getValue(), list.getTransfersList()));
            }
        }
    }
    return map;
}
Also used : TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TokenID(com.hederahashgraph.api.proto.java.TokenID) Pair(org.apache.commons.lang3.tuple.Pair) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 22 with TokenID

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

the class TypedTokenStore method commitToken.

/**
 * Persists the given token to the Swirlds state, inviting the injected {@link TransactionRecordService}
 * to update the {@link com.hedera.services.state.submerkle.ExpirableTxnRecord} of the active transaction
 * with these changes.
 *
 * @param token
 * 		the token to save
 */
public void commitToken(Token token) {
    final var mutableToken = tokens.getRef(token.getId().asGrpcToken());
    mapModelChanges(token, mutableToken);
    tokens.put(token.getId().asGrpcToken(), mutableToken);
    if (token.hasMintedUniqueTokens()) {
        persistMinted(token.mintedUniqueTokens());
    }
    if (token.hasRemovedUniqueTokens()) {
        destroyRemoved(token.removedUniqueTokens());
    }
    /* Only needed during HTS refactor. Will be removed once all operations that
		 * refer to the knownTreasuries in-memory structure are refactored */
    if (token.isDeleted()) {
        final AccountID affectedTreasury = token.getTreasury().getId().asGrpcAccount();
        final TokenID mutatedToken = token.getId().asGrpcToken();
        delegate.removeKnownTreasuryForToken(affectedTreasury, mutatedToken);
    }
    sideEffectsTracker.trackTokenChanges(token);
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 23 with TokenID

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

the class EntityRecordItemListenerTokenTest method tokenTransfer.

void tokenTransfer(List<AssessedCustomFee> assessedCustomFees, List<com.hederahashgraph.api.proto.java.AssessedCustomFee> protoAssessedCustomFees, boolean hasAutoTokenAssociations, boolean isPrecompile) {
    // given
    createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
    TokenID tokenId2 = TokenID.newBuilder().setTokenNum(7).build();
    String symbol2 = "MIRROR";
    createTokenEntity(tokenId2, FUNGIBLE_COMMON, symbol2, 10L, false, false, false);
    AccountID accountId = AccountID.newBuilder().setAccountNum(1).build();
    // token transfer
    Transaction transaction = tokenTransferTransaction();
    TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(-1000).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(1000).build()).build();
    TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(tokenId2).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(333).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(-333).build()).build();
    List<TokenTransferList> transferLists = List.of(transferList1, transferList2);
    // token treasury associations <TOKEN_ID, PAYER> and <tokenId2, PAYER> are created in the token create
    // transaction and they are not auto associations; the two token transfers' <token, recipient> pairs are
    // <TOKEN_ID, accountId> and <tokenId2, PAYER>, since <tokenId2, PAYER> already exists, only
    // <TOKEN_ID accountId> will be auto associated
    var autoTokenAssociation = TokenAssociation.newBuilder().setAccountId(accountId).setTokenId(TOKEN_ID).build();
    var autoTokenAccount = new TokenAccount(EntityId.of(TOKEN_ID), EntityId.of(accountId), TRANSFER_TIMESTAMP);
    autoTokenAccount.setAssociated(true);
    autoTokenAccount.setAutomaticAssociation(true);
    autoTokenAccount.setCreatedTimestamp(TRANSFER_TIMESTAMP);
    autoTokenAccount.setFreezeStatus(TokenFreezeStatusEnum.NOT_APPLICABLE);
    autoTokenAccount.setKycStatus(TokenKycStatusEnum.NOT_APPLICABLE);
    List<TokenAccount> expectedAutoAssociatedTokenAccounts = hasAutoTokenAssociations ? List.of(autoTokenAccount) : Collections.emptyList();
    // when
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(TRANSFER_TIMESTAMP, transaction, builder -> {
        builder.addAllTokenTransferLists(transferLists).addAllAssessedCustomFees(protoAssessedCustomFees);
        if (hasAutoTokenAssociations) {
            builder.addAutomaticTokenAssociations(autoTokenAssociation);
        }
        if (isPrecompile) {
            buildContractFunctionResult(builder.getContractCallResultBuilder());
            contractFunctionResultAtomic.set(builder.getContractCallResult());
        }
    });
    // then
    assertTokenTransferInRepository(TOKEN_ID, PAYER, TRANSFER_TIMESTAMP, -1000);
    assertTokenTransferInRepository(TOKEN_ID, accountId, TRANSFER_TIMESTAMP, 1000);
    assertTokenTransferInRepository(tokenId2, PAYER, TRANSFER_TIMESTAMP, 333);
    assertTokenTransferInRepository(tokenId2, accountId, TRANSFER_TIMESTAMP, -333);
    assertAssessedCustomFeesInDb(assessedCustomFees);
    assertThat(tokenAccountRepository.findAll()).filteredOn(TokenAccount::getAutomaticAssociation).containsExactlyInAnyOrderElementsOf(expectedAutoAssociatedTokenAccounts);
    if (isPrecompile) {
        assertContractResult(TRANSFER_TIMESTAMP, contractFunctionResultAtomic.get());
    }
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 24 with TokenID

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

the class EntityRecordItemListenerTokenTest method nftTransferMissingNft.

@Test
void nftTransferMissingNft() {
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    TokenID tokenID2 = TokenID.newBuilder().setTokenNum(7).build();
    String symbol2 = "MIRROR";
    createTokenEntity(tokenID2, FUNGIBLE_COMMON, symbol2, 15L, false, false, false);
    // token transfer
    Transaction transaction = tokenTransferTransaction();
    TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(tokenID2).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_1).build()).build();
    TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(tokenID2).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(RECEIVER).setSenderAccountID(PAYER).setSerialNumber(SERIAL_NUMBER_2).build()).build();
    long transferTimestamp = 25L;
    insertAndParseTransaction(transferTimestamp, transaction, builder -> {
        builder.addAllTokenTransferLists(List.of(transferList1, transferList2));
    });
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(transferTimestamp, 1L, tokenID2, RECEIVER, PAYER);
    assertNftTransferInRepository(transferTimestamp, 2L, tokenID2, RECEIVER, PAYER);
    assertNftInRepository(tokenID2, SERIAL_NUMBER_1, false, transferTimestamp, transferTimestamp, METADATA.getBytes(), EntityId.of(RECEIVER), false);
    assertNftInRepository(tokenID2, SERIAL_NUMBER_2, false, transferTimestamp, transferTimestamp, METADATA.getBytes(), EntityId.of(RECEIVER), false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TokenID (com.hederahashgraph.api.proto.java.TokenID)24 AccountID (com.hederahashgraph.api.proto.java.AccountID)11 Test (org.junit.jupiter.api.Test)9 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)5 TokenUpdateTransactionBody (com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)5 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)5 ByteString (com.google.protobuf.ByteString)4 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 Range (com.google.common.collect.Range)3 Entity (com.hedera.mirror.common.domain.entity.Entity)3 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)3 EntityType (com.hedera.mirror.common.domain.entity.EntityType)3 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)3 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)3