use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertTokenAccountRevokeKyc.
private void insertTokenAccountRevokeKyc(RecordItem recordItem) {
if (entityProperties.getPersist().isTokens()) {
TokenRevokeKycTransactionBody tokenRevokeKycTransactionBody = recordItem.getTransactionBody().getTokenRevokeKyc();
EntityId tokenId = EntityId.of(tokenRevokeKycTransactionBody.getToken());
EntityId accountId = EntityId.of(tokenRevokeKycTransactionBody.getAccount());
TokenAccount tokenAccount = new TokenAccount(tokenId, accountId, recordItem.getConsensusTimestamp());
tokenAccount.setKycStatus(TokenKycStatusEnum.REVOKED);
entityListener.onTokenAccount(tokenAccount);
}
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertAutomaticTokenAssociations.
private void insertAutomaticTokenAssociations(RecordItem recordItem) {
if (entityProperties.getPersist().isTokens()) {
if (recordItem.getTransactionBody().hasTokenCreation()) {
// automatic token associations for token create transactions are handled in insertTokenCreate
return;
}
long consensusTimestamp = recordItem.getConsensusTimestamp();
recordItem.getRecord().getAutomaticTokenAssociationsList().forEach(tokenAssociation -> {
// the only other transaction which creates auto associations is crypto transfer. The accounts and
// tokens in the associations should have been added to EntityListener when inserting the corresponding
// token transfers, so no need to duplicate the logic here
EntityId accountId = EntityId.of(tokenAssociation.getAccountId());
EntityId tokenId = EntityId.of(tokenAssociation.getTokenId());
TokenAccount tokenAccount = getAssociatedTokenAccount(accountId, true, consensusTimestamp, tokenId);
entityListener.onTokenAccount(tokenAccount);
});
}
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertFileData.
private void insertFileData(long consensusTimestamp, byte[] contents, FileID fileID, int transactionTypeValue) {
EntityId entityId = EntityId.of(fileID);
FileData fileData = new FileData(consensusTimestamp, contents, entityId, transactionTypeValue);
// We always store file data for address books since they're used by the address book service
if (addressBookService.isAddressBook(entityId)) {
fileDataRepository.save(fileData);
addressBookService.update(fileData);
} else if (entityProperties.getPersist().isFiles() || (entityProperties.getPersist().isSystemFiles() && entityId.getEntityNum() < 1000)) {
entityListener.onFileData(fileData);
}
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertCustomFees.
/**
* Inserts custom fees. Returns the list of collectors automatically associated with the newly created token if the
* custom fees are from a token create transaction
*
* @param customFeeList protobuf custom fee list
* @param consensusTimestamp consensus timestamp of the corresponding transaction
* @param isTokenCreate if the transaction with the custom fees is a token create
* @param tokenId the token id the custom fees are attached to
* @return A list of collectors automatically associated with the token if it's a token create transaction
*/
private Set<EntityId> insertCustomFees(List<com.hederahashgraph.api.proto.java.CustomFee> customFeeList, long consensusTimestamp, boolean isTokenCreate, EntityId tokenId) {
Set<EntityId> autoAssociatedAccounts = new HashSet<>();
CustomFee.Id id = new CustomFee.Id(consensusTimestamp, tokenId);
for (var protoCustomFee : customFeeList) {
EntityId collector = EntityId.of(protoCustomFee.getFeeCollectorAccountId());
CustomFee customFee = new CustomFee();
customFee.setId(id);
customFee.setCollectorAccountId(collector);
var feeCase = protoCustomFee.getFeeCase();
boolean chargedInAttachedToken;
switch(feeCase) {
case FIXED_FEE:
chargedInAttachedToken = parseFixedFee(customFee, protoCustomFee.getFixedFee(), tokenId);
break;
case FRACTIONAL_FEE:
// only FT can have fractional fee
parseFractionalFee(customFee, protoCustomFee.getFractionalFee());
chargedInAttachedToken = true;
break;
case ROYALTY_FEE:
// only NFT can have royalty fee, and fee can't be paid in NFT. Thus though royalty fee has a
// fixed fee fallback, the denominating token of the fixed fee can't be the NFT itself
parseRoyaltyFee(customFee, protoCustomFee.getRoyaltyFee(), tokenId);
chargedInAttachedToken = false;
break;
default:
log.error("Invalid CustomFee FeeCase {}", feeCase);
throw new InvalidDatasetException(String.format("Invalid CustomFee FeeCase %s", feeCase));
}
if (isTokenCreate && chargedInAttachedToken) {
// if it's from a token create transaction, and the fee is charged in the attached token, the attached
// token and the collector should have been auto associated
autoAssociatedAccounts.add(collector);
}
entityListener.onCustomFee(customFee);
}
if (customFeeList.isEmpty()) {
// for empty custom fees, add a single row with only the timestamp and tokenId.
CustomFee customFee = new CustomFee();
customFee.setId(id);
entityListener.onCustomFee(customFee);
}
return autoAssociatedAccounts;
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class PubSubRecordItemListener method onItem.
@Override
public void onItem(RecordItem recordItem) throws ImporterException {
TransactionBody body = recordItem.getTransactionBody();
TransactionRecord txRecord = recordItem.getRecord();
TransactionType transactionType = TransactionType.of(recordItem.getTransactionType());
TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body));
long consensusTimestamp = DomainUtils.timeStampInNanos(txRecord.getConsensusTimestamp());
EntityId entityId;
try {
entityId = transactionHandler.getEntity(recordItem);
} catch (InvalidEntityException e) {
// transaction can have invalid topic/contract/file id
log.warn("Invalid entity encountered for consensusTimestamp {} : {}", consensusTimestamp, e.getMessage());
entityId = null;
}
PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entityId, recordItem);
try {
sendPubSubMessage(pubSubMessage);
} catch (Exception e) {
// greater than that of last correctly sent txn.
throw new ParserException("Error sending transaction to pubsub", e);
}
log.debug("Published transaction : {}", consensusTimestamp);
if (addressBookService.isAddressBook(entityId)) {
FileID fileID = null;
byte[] fileBytes = null;
if (body.hasFileAppend()) {
fileID = body.getFileAppend().getFileID();
fileBytes = body.getFileAppend().getContents().toByteArray();
} else if (body.hasFileCreate()) {
fileID = txRecord.getReceipt().getFileID();
fileBytes = body.getFileCreate().getContents().toByteArray();
} else if (body.hasFileUpdate()) {
fileID = body.getFileUpdate().getFileID();
fileBytes = body.getFileUpdate().getContents().toByteArray();
}
FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem.getTransactionType());
fileDataRepository.save(fileData);
addressBookService.update(fileData);
}
}
Aggregations