use of com.hederahashgraph.api.proto.java.TransferList in project hedera-services by hashgraph.
the class HapiQueryOp method opDef.
private Consumer<TransactionBody.Builder> opDef(HapiApiSpec spec, long amount) throws Throwable {
TransferList transfers = asTransferList(tinyBarsFromTo(amount, spec.registry().getAccountID(effectivePayer(spec)), targetNodeFor(spec)));
CryptoTransferTransactionBody opBody = spec.txns().<CryptoTransferTransactionBody, CryptoTransferTransactionBody.Builder>body(CryptoTransferTransactionBody.class, b -> b.setTransfers(transfers));
return b -> b.setCryptoTransfer(opBody);
}
use of com.hederahashgraph.api.proto.java.TransferList in project hedera-services by hashgraph.
the class QueryFeeCheck method validateQueryPaymentTransfers.
/**
* Validates query payment transfer transaction before reaching consensus.
* Validate each payer has enough balance that is needed for transfer.
* If one of the payer for query is also paying transactionFee validate the payer has balance to pay both
*
* @param txn the transaction body to validate
* @return the corresponding {@link ResponseCodeEnum} after the validation
*/
public ResponseCodeEnum validateQueryPaymentTransfers(TransactionBody txn) {
AccountID transactionPayer = txn.getTransactionID().getAccountID();
TransferList transferList = txn.getCryptoTransfer().getTransfers();
List<AccountAmount> transfers = transferList.getAccountAmountsList();
long transactionFee = txn.getTransactionFee();
final var currentAccounts = accounts.get();
ResponseCodeEnum status;
for (AccountAmount accountAmount : transfers) {
var id = accountAmount.getAccountID();
long amount = accountAmount.getAmount();
if (amount < 0) {
amount = -1 * amount;
if (id.equals(transactionPayer)) {
try {
amount = Math.addExact(amount, transactionFee);
} catch (ArithmeticException e) {
return INSUFFICIENT_PAYER_BALANCE;
}
}
if ((status = balanceCheck(currentAccounts.get(fromAccountId(id)), amount)) != OK) {
return status;
}
}
}
return OK;
}
use of com.hederahashgraph.api.proto.java.TransferList in project hedera-services by hashgraph.
the class ContextOptionValidatorTest method rejectsUnreasonableLength.
@Test
void rejectsUnreasonableLength() {
// setup:
TransferList wrapper = withAdjustments(a, 2L, b, -3L, d, 1L);
given(dynamicProperties.maxTransferListSize()).willReturn(2);
// expect:
assertFalse(subject.isAcceptableTransfersLength(wrapper));
}
use of com.hederahashgraph.api.proto.java.TransferList in project hedera-services by hashgraph.
the class BasicTransactionContextTest method buildExpectedRecord.
private ExpirableTxnRecord.Builder buildExpectedRecord(long otherNonThresholdFees, byte[] hash, TxnAccessor accessor, Instant consensusTime, TxnReceipt receipt) {
long amount = narratedCharging.totalFeesChargedToPayer() + otherNonThresholdFees;
TransferList transfersList = transfers;
List<TokenTransferList> tokenTransferList = List.of(tokenTransfers);
var builder = ExpirableTxnRecord.newBuilder().setReceipt(receipt).setTxnHash(hash).setTxnId(TxnId.fromGrpc(accessor.getTxnId())).setConsensusTime(RichInstant.fromJava(consensusTime)).setMemo(accessor.getTxn().getMemo()).setFee(amount).setTransferList(!transfersList.getAccountAmountsList().isEmpty() ? CurrencyAdjustments.fromGrpc(transfersList) : null).setScheduleRef(accessor.isTriggeredTxn() ? fromGrpcScheduleId(accessor.getScheduleRef()) : null).setNewTokenAssociations(newTokenAssociations);
List<EntityId> tokens = new ArrayList<>();
List<CurrencyAdjustments> tokenAdjustments = new ArrayList<>();
for (TokenTransferList tokenTransfers : tokenTransferList) {
tokens.add(EntityId.fromGrpcTokenId(tokenTransfers.getToken()));
tokenAdjustments.add(CurrencyAdjustments.fromGrpc(tokenTransfers.getTransfersList()));
}
builder.setTokens(tokens).setTokenAdjustments(tokenAdjustments);
return builder;
}
use of com.hederahashgraph.api.proto.java.TransferList in project hedera-mirror-node by hashgraph.
the class AbstractEntityRecordItemListenerTest method assertRecordTransfers.
protected void assertRecordTransfers(TransactionRecord record) {
long consensusTimestamp = DomainUtils.timeStampInNanos(record.getConsensusTimestamp());
if (entityProperties.getPersist().isCryptoTransferAmounts()) {
TransferList transferList = record.getTransferList();
for (AccountAmount accountAmount : transferList.getAccountAmountsList()) {
EntityId account = EntityId.of(accountAmount.getAccountID());
assertThat(cryptoTransferRepository.findById(new CryptoTransfer.Id(accountAmount.getAmount(), consensusTimestamp, account.getId()))).isPresent();
}
} else {
assertThat(cryptoTransferRepository.count()).isEqualTo(0L);
}
}
Aggregations