Search in sources :

Example 41 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class ContractCreateTransactionHandler method updateStakingInfo.

private void updateStakingInfo(RecordItem recordItem, Contract contract) {
    var transactionBody = recordItem.getTransactionBody().getContractCreateInstance();
    contract.setDeclineReward(transactionBody.getDeclineReward());
    switch(transactionBody.getStakedIdCase()) {
        case STAKEDID_NOT_SET:
            return;
        case STAKED_NODE_ID:
            contract.setStakedNodeId(transactionBody.getStakedNodeId());
            contract.setStakedAccountId(-1L);
            break;
        case STAKED_ACCOUNT_ID:
            EntityId accountId = EntityId.of(transactionBody.getStakedAccountId());
            contract.setStakedAccountId(AccountIdConverter.INSTANCE.convertToDatabaseColumn(accountId));
            contract.setStakedNodeId(-1L);
            break;
    }
    contract.setStakePeriodStart(Utility.getEpochDay(recordItem.getConsensusTimestamp()));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Example 42 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class ContractDeleteTransactionHandler method doUpdateEntity.

@Override
protected void doUpdateEntity(Contract contract, RecordItem recordItem) {
    var transactionBody = recordItem.getTransactionBody().getContractDeleteInstance();
    EntityId obtainerId = null;
    if (transactionBody.hasTransferAccountID()) {
        obtainerId = EntityId.of(transactionBody.getTransferAccountID());
    } else if (transactionBody.hasTransferContractID()) {
        obtainerId = entityIdService.lookup(transactionBody.getTransferContractID());
    }
    contract.setObtainerId(obtainerId);
    contract.setPermanentRemoval(transactionBody.getPermanentRemoval());
    entityListener.onContract(contract);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Example 43 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class CryptoApproveAllowanceTransactionHandler method parseNftAllowances.

private void parseNftAllowances(List<com.hederahashgraph.api.proto.java.NftAllowance> nftAllowances, RecordItem recordItem) {
    var consensusTimestamp = recordItem.getConsensusTimestamp();
    var payerAccountId = recordItem.getPayerAccountId();
    var nftAllowanceState = new HashMap<NftAllowance.Id, NftAllowance>();
    var nftSerialAllowanceState = new HashMap<NftId, Nft>();
    // iterate the nft allowance list in reverse order and honor the last allowance for either
    // the same owner, spender, and token for approved for all allowances, or the last serial allowance for
    // the same owner, spender, token, and serial
    var iterator = nftAllowances.listIterator(nftAllowances.size());
    while (iterator.hasPrevious()) {
        var nftApproval = iterator.previous();
        EntityId ownerAccountId = getOwnerAccountId(nftApproval.getOwner(), payerAccountId);
        if (ownerAccountId == EntityId.EMPTY) {
            // and the partialDataAction is SKIP
            continue;
        }
        EntityId spender = EntityId.of(nftApproval.getSpender());
        EntityId tokenId = EntityId.of(nftApproval.getTokenId());
        if (nftApproval.hasApprovedForAll()) {
            var approvedForAll = nftApproval.getApprovedForAll().getValue();
            NftAllowance nftAllowance = new NftAllowance();
            nftAllowance.setApprovedForAll(approvedForAll);
            nftAllowance.setOwner(ownerAccountId.getId());
            nftAllowance.setPayerAccountId(payerAccountId);
            nftAllowance.setSpender(spender.getId());
            nftAllowance.setTokenId(tokenId.getId());
            nftAllowance.setTimestampLower(consensusTimestamp);
            if (nftAllowanceState.putIfAbsent(nftAllowance.getId(), nftAllowance) == null) {
                entityListener.onNftAllowance(nftAllowance);
            }
        }
        EntityId delegatingSpender = EntityId.of(nftApproval.getDelegatingSpender());
        for (var serialNumber : nftApproval.getSerialNumbersList()) {
            // services allows the same serial number of a nft token appears in multiple nft allowances to
            // different spenders. The last spender will be granted such allowance.
            Nft nft = new Nft(serialNumber, tokenId);
            nft.setAccountId(ownerAccountId);
            nft.setDelegatingSpender(delegatingSpender);
            nft.setModifiedTimestamp(consensusTimestamp);
            nft.setSpender(spender);
            if (nftSerialAllowanceState.putIfAbsent(nft.getId(), nft) == null) {
                entityListener.onNft(nft);
            }
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) HashMap(java.util.HashMap) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) Nft(com.hedera.mirror.common.domain.token.Nft)

Example 44 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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 45 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class CryptoUpdateTransactionHandler method updateStakingInfo.

private void updateStakingInfo(RecordItem recordItem, Entity entity) {
    var transactionBody = recordItem.getTransactionBody().getCryptoUpdateAccount();
    if (transactionBody.hasDeclineReward()) {
        entity.setDeclineReward(transactionBody.getDeclineReward().getValue());
    }
    switch(transactionBody.getStakedIdCase()) {
        case STAKEDID_NOT_SET:
            break;
        case STAKED_NODE_ID:
            entity.setStakedNodeId(transactionBody.getStakedNodeId());
            entity.setStakedAccountId(-1L);
            break;
        case STAKED_ACCOUNT_ID:
            EntityId accountId = EntityId.of(transactionBody.getStakedAccountId());
            entity.setStakedAccountId(AccountIdConverter.INSTANCE.convertToDatabaseColumn(accountId));
            entity.setStakedNodeId(-1L);
            break;
    }
    // If the stake node id or the decline reward value has changed, we start a new stake period.
    if (transactionBody.getStakedIdCase() != STAKEDID_NOT_SET || transactionBody.hasDeclineReward()) {
        entity.setStakePeriodStart(Utility.getEpochDay(recordItem.getConsensusTimestamp()));
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)134 Test (org.junit.jupiter.api.Test)64 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)33 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 EntityType (com.hedera.mirror.common.domain.entity.EntityType)21 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)21 Token (com.hedera.mirror.common.domain.token.Token)20 Entity (com.hedera.mirror.common.domain.entity.Entity)17 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)17 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)16 Assertions (org.junit.jupiter.api.Assertions)16 Contract (com.hedera.mirror.common.domain.contract.Contract)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)15 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 ByteString (com.google.protobuf.ByteString)14 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)14 ContractID (com.hederahashgraph.api.proto.java.ContractID)14 Consumer (java.util.function.Consumer)13