use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class CryptoUpdateTransactionHandlerTest method updateTransactionDeclineReward.
@Test
void updateTransactionDeclineReward() {
RecordItem withDeclineValueSet = recordItemBuilder.cryptoUpdate().transactionBody(body -> body.clear().setDeclineReward(BoolValue.of(true))).build();
setupForCrytoUpdateTransactionTest(withDeclineValueSet, t -> assertThat(t).returns(true, Entity::isDeclineReward).returns(null, Entity::getStakedNodeId).returns(null, Entity::getStakedAccountId).extracting(Entity::getStakePeriodStart).isNotNull());
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class CryptoUpdateTransactionHandlerTest method updateTransactionStakedAccountId.
@Test
void updateTransactionStakedAccountId() {
AccountID accountId = AccountID.newBuilder().setAccountNum(1L).build();
RecordItem withStakedNodeIdSet = recordItemBuilder.cryptoUpdate().transactionBody(body -> body.clear().setStakedAccountId(accountId)).build();
setupForCrytoUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Entity::getStakedAccountId).returns(false, Entity::isDeclineReward).returns(-1L, Entity::getStakedNodeId).returns(Utility.getEpochDay(withStakedNodeIdSet.getConsensusTimestamp()), Entity::getStakePeriodStart));
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class SystemUndeleteTransactionHandlerTest method testSystemUndeleteForContract.
// SystemUndelete for file is tested by common test case in AbstractTransactionHandlerTest.
// Test SystemUndelete for contract here.
@Test
void testSystemUndeleteForContract() {
TransactionBody transactionBody = TransactionBody.newBuilder().setSystemUndelete(SystemUndeleteTransactionBody.newBuilder().setContractID(ContractID.newBuilder().setContractNum(DEFAULT_ENTITY_NUM).build())).build();
testGetEntityIdHelper(transactionBody, getDefaultTransactionRecord().build(), EntityId.of(0L, 0L, DEFAULT_ENTITY_NUM, EntityType.CONTRACT));
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method buildTransaction.
private Transaction buildTransaction(long consensusTimestamp, RecordItem recordItem) {
TransactionBody body = recordItem.getTransactionBody();
TransactionRecord txRecord = recordItem.getRecord();
Long validDurationSeconds = body.hasTransactionValidDuration() ? body.getTransactionValidDuration().getSeconds() : null;
// transactions in stream always have valid node account id.
var nodeAccount = EntityId.of(body.getNodeAccountID());
var transactionId = body.getTransactionID();
// build transaction
Transaction transaction = new Transaction();
transaction.setChargedTxFee(txRecord.getTransactionFee());
transaction.setConsensusTimestamp(consensusTimestamp);
transaction.setIndex(recordItem.getTransactionIndex());
transaction.setInitialBalance(0L);
transaction.setMaxFee(body.getTransactionFee());
transaction.setMemo(DomainUtils.toBytes(body.getMemoBytes()));
transaction.setNodeAccountId(nodeAccount);
transaction.setNonce(transactionId.getNonce());
transaction.setPayerAccountId(recordItem.getPayerAccountId());
transaction.setResult(txRecord.getReceipt().getStatusValue());
transaction.setScheduled(txRecord.hasScheduleRef());
transaction.setTransactionBytes(entityProperties.getPersist().isTransactionBytes() ? recordItem.getTransactionBytes() : null);
transaction.setTransactionHash(DomainUtils.toBytes(txRecord.getTransactionHash()));
transaction.setType(recordItem.getTransactionType());
transaction.setValidDurationSeconds(validDurationSeconds);
transaction.setValidStartNs(DomainUtils.timeStampInNanos(transactionId.getTransactionValidStart()));
if (txRecord.hasParentConsensusTimestamp()) {
transaction.setParentConsensusTimestamp(DomainUtils.timestampInNanosMax(txRecord.getParentConsensusTimestamp()));
}
return transaction;
}
use of com.hederahashgraph.api.proto.java.TransactionBody 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