Search in sources :

Example 1 with OpReturnType

use of bisq.core.dao.consensus.OpReturnType in project bisq-core by bisq-network.

the class BsqTxController method getTxType.

// TODO add tests
@SuppressWarnings("WeakerAccess")
@VisibleForTesting
TxType getTxType(Tx tx, Model model) {
    TxType txType;
    // We need to have at least one BSQ output
    Optional<OpReturnType> optionalOpReturnType = getOptionalOpReturnType(tx, model);
    final boolean bsqFeesBurnt = model.isInputValuePositive();
    // noinspection OptionalIsPresent
    if (optionalOpReturnType.isPresent()) {
        txType = getTxTypeForOpReturn(tx, optionalOpReturnType.get());
    } else {
        if (bsqFeesBurnt) {
            // Burned fee but no opReturn
            txType = TxType.PAY_TRADE_FEE;
        } else {
            // No burned fee and no opReturn.
            txType = TxType.TRANSFER_BSQ;
        }
    }
    return txType;
}
Also used : TxType(bisq.core.dao.blockchain.vo.TxType) OpReturnType(bisq.core.dao.consensus.OpReturnType) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with OpReturnType

use of bisq.core.dao.consensus.OpReturnType in project bisq-core by bisq-network.

the class BsqTxController method getOptionalOpReturnType.

private Optional<OpReturnType> getOptionalOpReturnType(Tx tx, Model model) {
    if (model.isBsqOutputFound()) {
        // validation.
        if (model.getOpReturnTypeCandidate() == model.getVerifiedOpReturnType()) {
            final OpReturnType verifiedOpReturnType = model.getVerifiedOpReturnType();
            return verifiedOpReturnType != null ? Optional.of(verifiedOpReturnType) : Optional.empty();
        } else {
            final String msg = "We got a different opReturn type after validation as we expected initially. tx=" + tx;
            log.warn(msg);
            if (DevEnv.isDevMode())
                throw new RuntimeException(msg);
        }
    } else {
        final String msg = "We got a tx without any valid BSQ output but with burned BSQ. tx={}" + tx;
        log.warn(msg);
        if (DevEnv.isDevMode())
            throw new RuntimeException(msg);
    }
    return Optional.empty();
}
Also used : OpReturnType(bisq.core.dao.consensus.OpReturnType)

Aggregations

OpReturnType (bisq.core.dao.consensus.OpReturnType)2 TxType (bisq.core.dao.blockchain.vo.TxType)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1