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()));
}
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);
}
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);
}
}
}
}
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());
}
}
}
}
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()));
}
}
Aggregations