Search in sources :

Example 1 with TxOutputType

use of bisq.core.dao.state.blockchain.TxOutputType in project bisq-core by bisq-network.

the class TxInputParser method process.

@SuppressWarnings("IfCanBeSwitch")
void process(TxOutputKey txOutputKey, int blockHeight, String txId, int inputIndex) {
    bsqStateService.getUnspentTxOutput(txOutputKey).ifPresent(connectedTxOutput -> {
        long inputValue = connectedTxOutput.getValue();
        accumulatedInputValue += inputValue;
        // If we are spending an output from a blind vote tx marked as VOTE_STAKE_OUTPUT we save it in our parsingModel
        // for later verification at the outputs of a reveal tx.
        TxOutputType connectedTxOutputType = connectedTxOutput.getTxOutputType();
        switch(connectedTxOutputType) {
            case UNDEFINED:
            case GENESIS_OUTPUT:
            case BSQ_OUTPUT:
            case BTC_OUTPUT:
            case PROPOSAL_OP_RETURN_OUTPUT:
            case COMP_REQ_OP_RETURN_OUTPUT:
            case CONFISCATE_BOND_OP_RETURN_OUTPUT:
            case ISSUANCE_CANDIDATE_OUTPUT:
                break;
            case BLIND_VOTE_LOCK_STAKE_OUTPUT:
                if (voteRevealInputState == TxInputParser.VoteRevealInputState.UNKNOWN) {
                    // The connected tx output of the blind vote tx is our input for the reveal tx.
                    // We allow only one input from any blind vote tx otherwise the vote reveal tx is invalid.
                    voteRevealInputState = TxInputParser.VoteRevealInputState.VALID;
                } else {
                    log.warn("We have a tx which has >1 connected txOutputs marked as BLIND_VOTE_LOCK_STAKE_OUTPUT. " + "This is not a valid BSQ tx.");
                    voteRevealInputState = TxInputParser.VoteRevealInputState.INVALID;
                }
                break;
            case BLIND_VOTE_OP_RETURN_OUTPUT:
            case VOTE_REVEAL_UNLOCK_STAKE_OUTPUT:
            case VOTE_REVEAL_OP_RETURN_OUTPUT:
                break;
            case LOCKUP:
                // txOutput. The UNLOCK can only be spent after lockTime blocks has passed.
                if (!optionalSpentLockupTxOutput.isPresent()) {
                    optionalSpentLockupTxOutput = Optional.of(connectedTxOutput);
                    unlockBlockHeight = blockHeight + connectedTxOutput.getLockTime();
                }
                break;
            case LOCKUP_OP_RETURN_OUTPUT:
                break;
            case UNLOCK:
                // This txInput is Spending an UNLOCK txOutput
                spentUnlockConnectedTxOutputs.add(connectedTxOutput);
                // TODO  We should add unlockBlockHeight to TempTxOutput and remove unlockBlockHeight from tempTx
                // then we can use connectedTxOutput to access the unlockBlockHeight instead of the tx
                bsqStateService.getTx(connectedTxOutput.getTxId()).ifPresent(unlockTx -> {
                    // Only count the input as BSQ input if spent after unlock time
                    if (blockHeight < unlockTx.getUnlockBlockHeight()) {
                        accumulatedInputValue -= inputValue;
                        burntBondValue += inputValue;
                    }
                });
                break;
            case INVALID_OUTPUT:
            default:
                break;
        }
        bsqStateService.setSpentInfo(connectedTxOutput.getKey(), new SpentInfo(blockHeight, txId, inputIndex));
        bsqStateService.removeUnspentTxOutput(connectedTxOutput);
    });
}
Also used : TxOutputType(bisq.core.dao.state.blockchain.TxOutputType) SpentInfo(bisq.core.dao.state.blockchain.SpentInfo)

Example 2 with TxOutputType

use of bisq.core.dao.state.blockchain.TxOutputType in project bisq-core by bisq-network.

the class TxOutputParser method handleOpReturnOutput.

private void handleOpReturnOutput(TempTxOutput tempTxOutput, boolean isLastOutput) {
    TxOutputType txOutputType = OpReturnParser.getTxOutputType(tempTxOutput, isLastOutput);
    tempTxOutput.setTxOutputType(txOutputType);
    optionalVerifiedOpReturnType = getMappedOpReturnType(txOutputType);
    optionalVerifiedOpReturnType.filter(verifiedOpReturnType -> verifiedOpReturnType == OpReturnType.LOCKUP).ifPresent(verifiedOpReturnType -> {
        byte[] opReturnData = tempTxOutput.getOpReturnData();
        checkNotNull(opReturnData, "opReturnData must not be null");
        int lockTime = BondingConsensus.getLockTime(opReturnData);
        tempTxOutput.setLockTime(lockTime);
    });
}
Also used : TempTx(bisq.core.dao.state.blockchain.TempTx) Setter(lombok.Setter) TempTxOutput(bisq.core.dao.state.blockchain.TempTxOutput) Getter(lombok.Getter) TxOutput(bisq.core.dao.state.blockchain.TxOutput) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BsqStateService(bisq.core.dao.state.BsqStateService) BondingConsensus(bisq.core.dao.bonding.BondingConsensus) TxOutputType(bisq.core.dao.state.blockchain.TxOutputType) OpReturnType(bisq.core.dao.state.blockchain.OpReturnType) Slf4j(lombok.extern.slf4j.Slf4j) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TxOutputType(bisq.core.dao.state.blockchain.TxOutputType)

Example 3 with TxOutputType

use of bisq.core.dao.state.blockchain.TxOutputType in project bisq-core by bisq-network.

the class TxOutputParser method handleBsqOutput.

private void handleBsqOutput(TempTxOutput txOutput, int index, long txOutputValue) {
    // Update the input balance.
    availableInputValue -= txOutputValue;
    boolean isFirstOutput = index == 0;
    OpReturnType opReturnTypeCandidate = null;
    if (optionalOpReturnTypeCandidate.isPresent())
        opReturnTypeCandidate = optionalOpReturnTypeCandidate.get();
    TxOutputType bsqOutput;
    if (isFirstOutput && opReturnTypeCandidate == OpReturnType.BLIND_VOTE) {
        bsqOutput = TxOutputType.BLIND_VOTE_LOCK_STAKE_OUTPUT;
        optionalBlindVoteLockStakeOutput = Optional.of(txOutput);
    } else if (isFirstOutput && opReturnTypeCandidate == OpReturnType.VOTE_REVEAL) {
        bsqOutput = TxOutputType.VOTE_REVEAL_UNLOCK_STAKE_OUTPUT;
        optionalVoteRevealUnlockStakeOutput = Optional.of(txOutput);
    } else if (isFirstOutput && opReturnTypeCandidate == OpReturnType.LOCKUP) {
        bsqOutput = TxOutputType.LOCKUP;
        optionalLockupOutput = Optional.of(txOutput);
    } else {
        bsqOutput = TxOutputType.BSQ_OUTPUT;
    }
    txOutput.setTxOutputType(bsqOutput);
    bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(txOutput));
    bsqOutputFound = true;
}
Also used : OpReturnType(bisq.core.dao.state.blockchain.OpReturnType) TxOutputType(bisq.core.dao.state.blockchain.TxOutputType)

Aggregations

TxOutputType (bisq.core.dao.state.blockchain.TxOutputType)3 OpReturnType (bisq.core.dao.state.blockchain.OpReturnType)2 BondingConsensus (bisq.core.dao.bonding.BondingConsensus)1 BsqStateService (bisq.core.dao.state.BsqStateService)1 SpentInfo (bisq.core.dao.state.blockchain.SpentInfo)1 TempTx (bisq.core.dao.state.blockchain.TempTx)1 TempTxOutput (bisq.core.dao.state.blockchain.TempTxOutput)1 TxOutput (bisq.core.dao.state.blockchain.TxOutput)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Optional (java.util.Optional)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1 Slf4j (lombok.extern.slf4j.Slf4j)1