Search in sources :

Example 1 with TransferList

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);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) HapiQueryPrecheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException) Response(com.hederahashgraph.api.proto.java.Response) QueryUtils.reflectForCost(com.hedera.services.bdd.spec.queries.QueryUtils.reflectForCost) Function(java.util.function.Function) Supplier(java.util.function.Supplier) COST_ANSWER_QUERY_COST(com.hedera.services.bdd.spec.fees.Payment.Reason.COST_ANSWER_QUERY_COST) TxnUtils.asTransferList(com.hedera.services.bdd.spec.transactions.TxnUtils.asTransferList) Payment(com.hedera.services.bdd.spec.fees.Payment) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ResponseType(com.hederahashgraph.api.proto.java.ResponseType) Thread.sleep(java.lang.Thread.sleep) SigValueObj(com.hederahashgraph.fee.SigValueObj) TxnUtils.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.TxnUtils.tinyBarsFromTo) EnumSet(java.util.EnumSet) TransferList(com.hederahashgraph.api.proto.java.TransferList) SigMapGenerator(com.hedera.services.bdd.spec.keys.SigMapGenerator) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) TxnUtils.txnToString(com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString) ControlForKey(com.hedera.services.bdd.spec.keys.ControlForKey) FeeData(com.hederahashgraph.api.proto.java.FeeData) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) ANSWER_ONLY_QUERY_COST(com.hedera.services.bdd.spec.fees.Payment.Reason.ANSWER_ONLY_QUERY_COST) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) OFF(com.hedera.services.bdd.spec.HapiApiSpec.CostSnapshotMode.OFF) QueryUtils.reflectForPrecheck(com.hedera.services.bdd.spec.queries.QueryUtils.reflectForPrecheck) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) QueryObs(com.hedera.services.bdd.spec.stats.QueryObs) Optional(java.util.Optional) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) HapiCryptoTransfer(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer) LogManager(org.apache.logging.log4j.LogManager) TxnUtils.asTransferList(com.hedera.services.bdd.spec.transactions.TxnUtils.asTransferList) TransferList(com.hederahashgraph.api.proto.java.TransferList) CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody)

Example 2 with TransferList

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;
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) AccountID(com.hederahashgraph.api.proto.java.AccountID) TransferList(com.hederahashgraph.api.proto.java.TransferList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 3 with TransferList

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));
}
Also used : TransferList(com.hederahashgraph.api.proto.java.TransferList) Test(org.junit.jupiter.api.Test)

Example 4 with TransferList

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;
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) ArrayList(java.util.ArrayList) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransferList(com.hederahashgraph.api.proto.java.TransferList)

Example 5 with TransferList

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);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) TransferList(com.hederahashgraph.api.proto.java.TransferList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Aggregations

TransferList (com.hederahashgraph.api.proto.java.TransferList)9 AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)4 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)3 TxnUtils.asTransferList (com.hedera.services.bdd.spec.transactions.TxnUtils.asTransferList)2 CryptoTransferTransactionBody (com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody)2 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 OFF (com.hedera.services.bdd.spec.HapiApiSpec.CostSnapshotMode.OFF)1 HapiPropertySource (com.hedera.services.bdd.spec.HapiPropertySource)1 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)1 HapiQueryCheckStateException (com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException)1 HapiQueryPrecheckStateException (com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException)1 Payment (com.hedera.services.bdd.spec.fees.Payment)1 ANSWER_ONLY_QUERY_COST (com.hedera.services.bdd.spec.fees.Payment.Reason.ANSWER_ONLY_QUERY_COST)1 COST_ANSWER_QUERY_COST (com.hedera.services.bdd.spec.fees.Payment.Reason.COST_ANSWER_QUERY_COST)1 ControlForKey (com.hedera.services.bdd.spec.keys.ControlForKey)1 SigMapGenerator (com.hedera.services.bdd.spec.keys.SigMapGenerator)1