use of com.hedera.mirror.common.domain.transaction.NonFeeTransfer in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferWithUnknownAlias.
@ParameterizedTest
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "SKIP" })
void cryptoTransferWithUnknownAlias(PartialDataAction partialDataAction) {
// given
// both accounts have alias, and only account2's alias is in db
entityProperties.getPersist().setCryptoTransferAmounts(true);
entityProperties.getPersist().setNonFeeTransfers(true);
parserProperties.setPartialDataAction(partialDataAction);
Entity account1 = domainBuilder.entity().get();
Entity account2 = domainBuilder.entity().persist();
// crypto transfer from unknown account1 alias to account2 alias
Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(accountAliasAmount(DomainUtils.fromBytes(account1.getAlias()), 100)).addAccountAmounts(accountAliasAmount(DomainUtils.fromBytes(account2.getAlias()), -100)));
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord transactionRecord = buildTransactionRecord(r -> r.getTransferListBuilder().addAccountAmounts(accountAmount(account1.getNum(), 100)).addAccountAmounts(accountAmount(account2.getNum(), -100)), transactionBody, ResponseCodeEnum.SUCCESS.getNumber());
List<EntityId> expectedEntityIds = partialDataAction == PartialDataAction.DEFAULT ? Arrays.asList(account2.toEntityId(), null) : List.of(account2.toEntityId());
// when
parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
// then
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(5, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, transactionRecord), () -> assertThat(findNonFeeTransfers()).extracting(NonFeeTransfer::getEntityId).containsExactlyInAnyOrderElementsOf(expectedEntityIds));
}
use of com.hedera.mirror.common.domain.transaction.NonFeeTransfer in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onNonFeeTransfer.
@Test
void onNonFeeTransfer() {
// given
NonFeeTransfer nonFeeTransfer1 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(1L).consensusTimestamp(1L).entityId(EntityId.of(1L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
NonFeeTransfer nonFeeTransfer2 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(2L).consensusTimestamp(2L).entityId(EntityId.of(2L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
// when
sqlEntityListener.onNonFeeTransfer(nonFeeTransfer1);
sqlEntityListener.onNonFeeTransfer(nonFeeTransfer2);
completeFileAndCommit();
// then
assertThat(findNonFeeTransfers()).containsExactlyInAnyOrder(nonFeeTransfer1, nonFeeTransfer2);
}
use of com.hedera.mirror.common.domain.transaction.NonFeeTransfer in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method processNonFeeTransfers.
/**
* Additionally store rows in the non_fee_transactions table if applicable. This will allow the rest-api to create
* an itemized set of transfers that reflects non-fees (explicit transfers), threshold records, node fee, and
* network+service fee (paid to treasury).
*/
private void processNonFeeTransfers(long consensusTimestamp, RecordItem recordItem) {
if (!entityProperties.getPersist().isNonFeeTransfers()) {
return;
}
var body = recordItem.getTransactionBody();
var partialDataAction = parserProperties.getPartialDataAction();
var transactionRecord = recordItem.getRecord();
for (var aa : nonFeeTransfersExtractor.extractNonFeeTransfers(body, transactionRecord)) {
var entityId = EntityId.EMPTY;
if (aa.getAmount() != 0) {
try {
entityId = entityIdService.lookup(aa.getAccountID());
} catch (AliasNotFoundException ex) {
switch(partialDataAction) {
case DEFAULT:
log.warn("Setting non-fee transfer account to default value due to partial data issue");
break;
case ERROR:
throw ex;
case SKIP:
log.warn("Skipping non-fee transfer due to partial data issue");
continue;
}
}
NonFeeTransfer nonFeeTransfer = new NonFeeTransfer();
nonFeeTransfer.setAmount(aa.getAmount());
nonFeeTransfer.setConsensusTimestamp(consensusTimestamp);
nonFeeTransfer.setEntityId(entityId);
nonFeeTransfer.setIsApproval(aa.getIsApproval());
nonFeeTransfer.setPayerAccountId(recordItem.getPayerAccountId());
entityListener.onNonFeeTransfer(nonFeeTransfer);
}
}
}
use of com.hedera.mirror.common.domain.transaction.NonFeeTransfer in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferWithEvmAddressAlias.
@Test
void cryptoTransferWithEvmAddressAlias() {
Contract contract = domainBuilder.contract().persist();
assertThat(contractRepository.findByEvmAddress(contract.getEvmAddress())).isPresent();
entityProperties.getPersist().setNonFeeTransfers(true);
long transferAmount = 123;
var transfer1 = accountAliasAmount(DomainUtils.fromBytes(contract.getEvmAddress()), transferAmount).build();
Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(transfer1));
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord transactionRecord = transactionRecordSuccess(transactionBody);
RecordItem recordItem = new RecordItem(transaction, transactionRecord);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, transactionRecord), () -> assertThat(findNonFeeTransfers()).allSatisfy(nonFeeTransfer -> {
assertThat(nonFeeTransfer.getEntityId()).isEqualTo(contract.toEntityId());
assertThat(nonFeeTransfer.getAmount()).isEqualTo(transferAmount);
assertThat(nonFeeTransfer.getPayerAccountId()).isEqualTo(recordItem.getPayerAccountId());
}));
}
use of com.hedera.mirror.common.domain.transaction.NonFeeTransfer in project hedera-mirror-node by hashgraph.
the class TransferTransactionPayerMigrationTest method persistNonFeeTransfers.
private void persistNonFeeTransfers(List<NonFeeTransfer> nonFeeTransfers) {
for (NonFeeTransfer nonFeeTransfer : nonFeeTransfers) {
var id = nonFeeTransfer.getId();
jdbcOperations.update("insert into non_fee_transfer (amount, entity_id, consensus_timestamp)" + " values (?,?,?)", nonFeeTransfer.getAmount(), nonFeeTransfer.getEntityId().getId(), nonFeeTransfer.getConsensusTimestamp());
}
}
Aggregations