Search in sources :

Example 16 with TokenTransferList

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

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

the class TokenUpdateTransactionHandlerTest method updateTreasury.

@Test
void updateTreasury() {
    AbstractEntity entity = getExpectedUpdatedEntity();
    AccountID previousAccountId = AccountID.newBuilder().setAccountNum(1L).build();
    AccountID newAccountId = AccountID.newBuilder().setAccountNum(2L).build();
    TokenID tokenID = TokenID.newBuilder().setTokenNum(3L).build();
    long consensusTimestamp = DomainUtils.timestampInNanosMax(MODIFIED_TIMESTAMP);
    TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(tokenID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(newAccountId).setSenderAccountID(previousAccountId).setSerialNumber(NftTransferId.WILDCARD_SERIAL_NUMBER).build()).build();
    TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
    RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
    when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
    Transaction transaction = new Transaction();
    transaction.setEntityId(entity.toEntityId());
    transactionHandler.updateTransaction(transaction, recordItem);
    TransactionBody body = recordItem.getTransactionBody();
    var payerAccount = EntityId.of(body.getTransactionID().getAccountID()).toEntity().getId();
    verify(nftRepository).updateTreasury(tokenID.getTokenNum(), previousAccountId.getAccountNum(), newAccountId.getAccountNum(), consensusTimestamp, payerAccount, false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) TokenID(com.hederahashgraph.api.proto.java.TokenID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with TokenTransferList

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

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

the class TokenAssociationSpecs method dissociationFromExpiredTokensAsExpected.

public HapiApiSpec dissociationFromExpiredTokensAsExpected() {
    final String treasury = "accountA";
    final String frozenAccount = "frozen";
    final String unfrozenAccount = "unfrozen";
    final String expiringToken = "expiringToken";
    long lifetimeSecs = 10;
    AtomicLong now = new AtomicLong();
    return defaultHapiSpec("DissociationFromExpiredTokensAsExpected").given(newKeyNamed("freezeKey"), cryptoCreate(treasury), cryptoCreate(frozenAccount).via("creation"), cryptoCreate(unfrozenAccount).via("creation"), withOpContext((spec, opLog) -> {
        var subOp = getTxnRecord("creation");
        allRunFor(spec, subOp);
        var record = subOp.getResponseRecord();
        now.set(record.getConsensusTimestamp().getSeconds());
    }), sourcing(() -> tokenCreate(expiringToken).freezeKey("freezeKey").freezeDefault(true).treasury(treasury).initialSupply(1000L).expiry(now.get() + lifetimeSecs))).when(tokenAssociate(unfrozenAccount, expiringToken), tokenAssociate(frozenAccount, expiringToken), tokenUnfreeze(expiringToken, unfrozenAccount), cryptoTransfer(moving(100L, expiringToken).between(treasury, unfrozenAccount))).then(getAccountBalance(treasury).hasTokenBalance(expiringToken, 900L), sleepFor(lifetimeSecs * 1_000L), tokenDissociate(treasury, expiringToken).hasKnownStatus(ACCOUNT_IS_TREASURY), tokenDissociate(unfrozenAccount, expiringToken).via("dissociateTxn"), getTxnRecord("dissociateTxn").hasPriority(recordWith().tokenTransfers(new BaseErroringAssertsProvider<>() {

        @Override
        public ErroringAsserts<List<TokenTransferList>> assertsFor(HapiApiSpec spec) {
            return tokenXfers -> {
                try {
                    assertEquals(1, tokenXfers.size(), "Wrong number of tokens transferred!");
                    TokenTransferList xfers = tokenXfers.get(0);
                    assertEquals(spec.registry().getTokenID(expiringToken), xfers.getToken(), "Wrong token transferred!");
                    AccountAmount toTreasury = xfers.getTransfers(0);
                    assertEquals(spec.registry().getAccountID(treasury), toTreasury.getAccountID(), "Treasury should come first!");
                    assertEquals(100L, toTreasury.getAmount(), "Treasury should get 100 tokens back!");
                    AccountAmount fromAccount = xfers.getTransfers(1);
                    assertEquals(spec.registry().getAccountID(unfrozenAccount), fromAccount.getAccountID(), "Account should come second!");
                    assertEquals(-100L, fromAccount.getAmount(), "Account should send 100 tokens back!");
                } catch (Throwable error) {
                    return List.of(error);
                }
                return Collections.emptyList();
            };
        }
    })), getAccountBalance(treasury).hasTokenBalance(expiringToken, 1000L), getAccountInfo(frozenAccount).hasToken(relationshipWith(expiringToken).freeze(Frozen)), tokenDissociate(frozenAccount, expiringToken).hasKnownStatus(ACCOUNT_FROZEN_FOR_TOKEN));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ACCOUNT_IS_TREASURY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_IS_TREASURY) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) Frozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Frozen) SomeFungibleTransfers.changingFungibleBalances(com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) TOKEN_NOT_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT) TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) StandardCharsets(java.nio.charset.StandardCharsets) NoTokenTransfers.emptyTokenTransfers(com.hedera.services.bdd.spec.assertions.NoTokenTransfers.emptyTokenTransfers) ByteString(com.google.protobuf.ByteString) BaseErroringAssertsProvider(com.hedera.services.bdd.spec.assertions.BaseErroringAssertsProvider) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) TxnVerbs.tokenDissociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDissociate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) KycNotApplicable(com.hederahashgraph.api.proto.java.TokenKycStatus.KycNotApplicable) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) Granted(com.hederahashgraph.api.proto.java.TokenKycStatus.Granted) ErroringAsserts(com.hedera.services.bdd.spec.assertions.ErroringAsserts) Unfrozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Unfrozen) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FreezeNotApplicable(com.hederahashgraph.api.proto.java.TokenFreezeStatus.FreezeNotApplicable) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ACCOUNT_FROZEN_FOR_TOKEN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_FROZEN_FOR_TOKEN) TxnVerbs.tokenFreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenFreeze) INVALID_TOKEN_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AtomicLong(java.util.concurrent.atomic.AtomicLong) ErroringAsserts(com.hedera.services.bdd.spec.assertions.ErroringAsserts) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ByteString(com.google.protobuf.ByteString) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 20 with TokenTransferList

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

the class EntityRecordItemListenerTokenTest method tokenWipeNft.

@Test
void tokenWipeNft() {
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    long mintTimestamp = 10L;
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, SERIAL_NUMBER_LIST);
    Transaction mintTransaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, SERIAL_NUMBER_LIST);
    insertAndParseTransaction(mintTimestamp, mintTransaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(2L).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        builder.addTokenTransferLists(mintTransfer);
    });
    // approve allowance for nft 1
    long approveAllowanceTimestamp = 12L;
    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(mintTimestamp).deleted(false).metadata(METADATA.getBytes()).modifiedTimestamp(approveAllowanceTimestamp).spender(EntityId.of(SPENDER)).build();
    assertThat(nftRepository.findById(expectedNft1.getId())).get().isEqualTo(expectedNft1);
    long wipeTimestamp = 15L;
    TokenTransferList wipeTransfer = nftTransfer(TOKEN_ID, DEFAULT_ACCOUNT_ID, PAYER, List.of(SERIAL_NUMBER_1));
    Transaction transaction = tokenWipeTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, 0, List.of(SERIAL_NUMBER_1));
    insertAndParseTransaction(wipeTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(1L);
        builder.addTokenTransferLists(wipeTransfer);
    });
    expectedNft1.setAccountId(null);
    expectedNft1.setDeleted(true);
    expectedNft1.setModifiedTimestamp(wipeTimestamp);
    expectedNft1.setSpender(null);
    var expectedNft2 = Nft.builder().id(new NftId(SERIAL_NUMBER_2, EntityId.of(TOKEN_ID))).accountId(EntityId.of(PAYER)).createdTimestamp(mintTimestamp).deleted(false).metadata(METADATA.getBytes()).modifiedTimestamp(mintTimestamp).build();
    // Verify
    assertThat(nftTransferRepository.count()).isEqualTo(3L);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_1, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(mintTimestamp, SERIAL_NUMBER_2, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(wipeTimestamp, SERIAL_NUMBER_1, TOKEN_ID, null, PAYER);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, wipeTimestamp, SYMBOL, 1);
    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