use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTransactionSuccessful.
@Test
void updateTransactionSuccessful() {
RecordItem recordItem = recordItemBuilder.tokenUpdate().build();
var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
var timestamp = recordItem.getConsensusTimestamp();
var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
when(entityIdService.lookup(any(AccountID.class))).thenReturn(EntityIdEndec.decode(10, EntityType.ACCOUNT));
transactionHandler.updateTransaction(transaction, recordItem);
assertTokenUpdate(timestamp, tokenId, id -> assertEquals(10L, id));
}
use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.
the class TransactionRepositoryTest method transaction.
private Transaction transaction() {
Transaction transaction = new Transaction();
transaction.setChargedTxFee(100L);
transaction.setConsensusTimestamp(++count);
transaction.setEntityId(EntityId.of(0, 0, 1, EntityType.ACCOUNT));
transaction.setInitialBalance(1000L);
transaction.setMemo("transaction memo".getBytes());
transaction.setNodeAccountId(EntityId.of(0, 0, 2, EntityType.ACCOUNT));
transaction.setNonce(0);
transaction.setPayerAccountId(EntityId.of(0, 0, 3, EntityType.ACCOUNT));
transaction.setResult(ResponseCodeEnum.SUCCESS.getNumber());
transaction.setType(TransactionType.CRYPTOCREATEACCOUNT.getProtoId());
transaction.setValidStartNs(20L);
transaction.setValidDurationSeconds(11L);
transaction.setMaxFee(33L);
return transaction;
}
use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.
the class TransactionRepositoryTest method save.
@Test
void save() {
Transaction transaction = transactionRepository.save(transaction());
assertThat(transactionRepository.findById(transaction.getConsensusTimestamp())).get().isEqualTo(transaction);
}
use of com.hedera.mirror.common.domain.transaction.Transaction 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.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.
the class NodeStakeUpdateTransactionHandler method updateTransaction.
@Override
public void updateTransaction(Transaction transaction, RecordItem recordItem) {
long consensusTimestamp = recordItem.getConsensusTimestamp();
if (!recordItem.isSuccessful()) {
var record = recordItem.getRecord();
log.warn("NodeStakeUpdateTransaction at consensus timestamp {} failed with status {}", consensusTimestamp, record.getReceipt().getStatus());
return;
}
// We subtract one since we get stake update in current day, but it applies to previous day
long epochDay = Utility.getEpochDay(consensusTimestamp) - 1L;
var transactionBody = recordItem.getTransactionBody().getNodeStakeUpdate();
long stakingPeriod = DomainUtils.timestampInNanosMax(transactionBody.getEndOfStakingPeriod());
long stakeTotal = transactionBody.getNodeStakeList().stream().map(n -> n.getStake()).reduce(0L, Long::sum);
for (var nodeStakeProto : transactionBody.getNodeStakeList()) {
NodeStake nodeStake = new NodeStake();
nodeStake.setConsensusTimestamp(consensusTimestamp);
nodeStake.setEpochDay(epochDay);
nodeStake.setNodeId(nodeStakeProto.getNodeId());
nodeStake.setRewardRate(nodeStakeProto.getRewardRate());
nodeStake.setStake(nodeStakeProto.getStake());
nodeStake.setStakeRewarded(nodeStakeProto.getStakeRewarded());
nodeStake.setStakeTotal(stakeTotal);
nodeStake.setStakingPeriod(stakingPeriod);
entityListener.onNodeStake(nodeStake);
}
}
Aggregations