use of com.hederahashgraph.api.proto.java.TransactionRecord 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);
}
}
use of com.hederahashgraph.api.proto.java.TransactionRecord 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);
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertConsensusTopicMessage.
private void insertConsensusTopicMessage(RecordItem recordItem) {
if (!entityProperties.getPersist().isTopics()) {
return;
}
ConsensusSubmitMessageTransactionBody transactionBody = recordItem.getTransactionBody().getConsensusSubmitMessage();
TransactionRecord transactionRecord = recordItem.getRecord();
var receipt = transactionRecord.getReceipt();
var topicId = transactionBody.getTopicID();
int runningHashVersion = receipt.getTopicRunningHashVersion() == 0 ? 1 : (int) receipt.getTopicRunningHashVersion();
TopicMessage topicMessage = new TopicMessage();
// Handle optional fragmented topic message
if (transactionBody.hasChunkInfo()) {
ConsensusMessageChunkInfo chunkInfo = transactionBody.getChunkInfo();
topicMessage.setChunkNum(chunkInfo.getNumber());
topicMessage.setChunkTotal(chunkInfo.getTotal());
if (chunkInfo.hasInitialTransactionID()) {
topicMessage.setInitialTransactionId(chunkInfo.getInitialTransactionID().toByteArray());
}
}
topicMessage.setConsensusTimestamp(DomainUtils.timeStampInNanos(transactionRecord.getConsensusTimestamp()));
topicMessage.setMessage(DomainUtils.toBytes(transactionBody.getMessage()));
topicMessage.setPayerAccountId(recordItem.getPayerAccountId());
topicMessage.setRunningHash(DomainUtils.toBytes(receipt.getTopicRunningHash()));
topicMessage.setRunningHashVersion(runningHashVersion);
topicMessage.setSequenceNumber(receipt.getTopicSequenceNumber());
topicMessage.setTopicId(EntityId.of(topicId));
entityListener.onTopicMessage(topicMessage);
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method onItem.
@Override
public void onItem(RecordItem recordItem) throws ImporterException {
TransactionRecord txRecord = recordItem.getRecord();
TransactionBody body = recordItem.getTransactionBody();
int transactionTypeValue = recordItem.getTransactionType();
TransactionType transactionType = TransactionType.of(transactionTypeValue);
TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
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;
}
log.debug("Processing {} transaction {} for entity {}", transactionType, consensusTimestamp, entityId);
// to:do - exclude Freeze from Filter transaction type
TransactionFilterFields transactionFilterFields = new TransactionFilterFields(entityId, transactionType);
if (!transactionFilter.test(transactionFilterFields)) {
log.debug("Ignoring transaction. consensusTimestamp={}, transactionType={}, entityId={}", consensusTimestamp, transactionType, entityId);
return;
}
Transaction transaction = buildTransaction(consensusTimestamp, recordItem);
transaction.setEntityId(entityId);
transactionHandler.updateTransaction(transaction, recordItem);
if (txRecord.hasTransferList() && entityProperties.getPersist().isCryptoTransferAmounts()) {
insertTransferList(recordItem);
}
// insert staking reward transfers even on failure
insertStakingRewardTransfers(recordItem);
// handle scheduled transaction, even on failure
if (transaction.isScheduled()) {
onScheduledTransaction(recordItem);
}
if (recordItem.isSuccessful()) {
if (entityProperties.getPersist().getTransactionSignatures().contains(transactionType)) {
insertTransactionSignatures(transaction.getEntityId(), recordItem.getConsensusTimestamp(), recordItem.getSignatureMap().getSigPairList());
}
// Only add non-fee transfers on success as the data is assured to be valid
processNonFeeTransfers(consensusTimestamp, recordItem);
if (body.hasConsensusSubmitMessage()) {
insertConsensusTopicMessage(recordItem);
} else if (body.hasCryptoAddLiveHash()) {
insertCryptoAddLiveHash(consensusTimestamp, body.getCryptoAddLiveHash());
} else if (body.hasFileAppend()) {
insertFileAppend(consensusTimestamp, body.getFileAppend(), transactionTypeValue);
} else if (body.hasFileCreate()) {
insertFileData(consensusTimestamp, DomainUtils.toBytes(body.getFileCreate().getContents()), txRecord.getReceipt().getFileID(), transactionTypeValue);
} else if (body.hasFileUpdate()) {
insertFileUpdate(consensusTimestamp, body.getFileUpdate(), transactionTypeValue);
} else if (body.hasTokenAssociate()) {
insertTokenAssociate(recordItem);
} else if (body.hasTokenBurn()) {
insertTokenBurn(recordItem);
} else if (body.hasTokenCreation()) {
insertTokenCreate(recordItem);
} else if (body.hasTokenDissociate()) {
insertTokenDissociate(recordItem);
} else if (body.hasTokenFeeScheduleUpdate()) {
insertTokenFeeScheduleUpdate(recordItem);
} else if (body.hasTokenFreeze()) {
insertTokenAccountFreezeBody(recordItem);
} else if (body.hasTokenGrantKyc()) {
insertTokenAccountGrantKyc(recordItem);
} else if (body.hasTokenMint()) {
insertTokenMint(recordItem);
} else if (body.hasTokenPause()) {
insertTokenPause(recordItem);
} else if (body.hasTokenRevokeKyc()) {
insertTokenAccountRevokeKyc(recordItem);
} else if (body.hasTokenUnfreeze()) {
insertTokenAccountUnfreeze(recordItem);
} else if (body.hasTokenUnpause()) {
insertTokenUnpause(recordItem);
} else if (body.hasTokenUpdate()) {
insertTokenUpdate(recordItem);
} else if (body.hasTokenWipe()) {
insertTokenAccountWipe(recordItem);
}
// Record token transfers can be populated for multiple transaction types
insertTokenTransfers(recordItem);
insertAssessedCustomFees(recordItem);
insertAutomaticTokenAssociations(recordItem);
}
contractResultService.process(recordItem, transaction);
entityListener.onTransaction(transaction);
log.debug("Storing transaction: {}", transaction);
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.
the class ContractSysDelTransitionLogicTest method capturesBadDelete.
@Test
void capturesBadDelete() {
// setup:
TransactionRecord sysDelRec = TransactionRecord.newBuilder().setReceipt(TransactionReceipt.newBuilder().setStatus(INVALID_CONTRACT_ID).build()).build();
givenValidTxnCtx();
// and:
given(delegate.perform(contractSysDelTxn, consensusTime)).willReturn(sysDelRec);
// when:
subject.doStateTransition();
// then:
verify(txnCtx).setStatus(INVALID_CONTRACT_ID);
}
Aggregations