mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 14:42:37 +01:00
Refactor parser classes
- Use commitUTXOCandidates for processGenesisTxOutput - Cleanup
This commit is contained in:
parent
886272d6ce
commit
40177dd52c
3 changed files with 20 additions and 22 deletions
|
@ -35,6 +35,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
*/
|
||||
@Slf4j
|
||||
public class TxInputParser {
|
||||
private final BsqStateService bsqStateService;
|
||||
|
||||
// Getters
|
||||
@Getter
|
||||
private long accumulatedInputValue = 0;
|
||||
|
@ -48,7 +50,6 @@ public class TxInputParser {
|
|||
private boolean isUnLockInputValid = true;
|
||||
|
||||
// Private
|
||||
private final BsqStateService bsqStateService;
|
||||
private int numVoteRevealInputs = 0;
|
||||
|
||||
|
||||
|
|
|
@ -91,21 +91,10 @@ public class TxOutputParser {
|
|||
for (int i = 0; i < genesisTx.getTempTxOutputs().size(); ++i) {
|
||||
TempTxOutput tempTxOutput = genesisTx.getTempTxOutputs().get(i);
|
||||
utxoCandidates.add(tempTxOutput);
|
||||
bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(tempTxOutput));
|
||||
bsqOutputFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
void commitUTXOCandidates() {
|
||||
utxoCandidates.forEach(output -> bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(output)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets all outputs to BTC_OUTPUT and doesn't add any txOutputs to the unspentTxOutput map in bsqStateService
|
||||
*/
|
||||
void invalidateUTXOCandidates() {
|
||||
utxoCandidates.forEach(output -> output.setTxOutputType(TxOutputType.BTC_OUTPUT));
|
||||
}
|
||||
|
||||
void processOpReturnOutput(TempTxOutput tempTxOutput) {
|
||||
byte[] opReturnData = tempTxOutput.getOpReturnData();
|
||||
checkNotNull(opReturnData, "opReturnData must not be null");
|
||||
|
@ -120,13 +109,9 @@ public class TxOutputParser {
|
|||
.ifPresent(opReturnType -> lockTime = BondingConsensus.getLockTime(opReturnData));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a transaction output.
|
||||
*
|
||||
* @param tempTxOutput The TempTxOutput we are parsing
|
||||
*/
|
||||
void processTxOutput(TempTxOutput tempTxOutput) {
|
||||
// An opReturn output which is not at the last index is invalid.
|
||||
// We don not expect here an opReturn output as we do not get called on the last output. Any opReturn at
|
||||
// another output index is invalid.
|
||||
if (tempTxOutput.isOpReturnOutput()) {
|
||||
tempTxOutput.setTxOutputType(TxOutputType.INVALID_OUTPUT);
|
||||
return;
|
||||
|
@ -146,6 +131,17 @@ public class TxOutputParser {
|
|||
}
|
||||
}
|
||||
|
||||
void commitUTXOCandidates() {
|
||||
utxoCandidates.forEach(output -> bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(output)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets all outputs to BTC_OUTPUT and doesn't add any txOutputs to the unspentTxOutput map in bsqStateService
|
||||
*/
|
||||
void invalidateUTXOCandidates() {
|
||||
utxoCandidates.forEach(output -> output.setTxOutputType(TxOutputType.BTC_OUTPUT));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
|
|
|
@ -83,7 +83,6 @@ public class TxParser {
|
|||
// Parse Genesis
|
||||
// ****************************************************************************************
|
||||
|
||||
// Let's see if we have a genesis tx
|
||||
Optional<TempTx> optionalGenesisTx = findGenesisTx(
|
||||
genesisTxId,
|
||||
genesisBlockHeight,
|
||||
|
@ -92,6 +91,7 @@ public class TxParser {
|
|||
if (optionalGenesisTx.isPresent()) {
|
||||
TempTx genesisTx = optionalGenesisTx.get();
|
||||
txOutputParser.processGenesisTxOutput(genesisTx);
|
||||
txOutputParser.commitUTXOCandidates();
|
||||
return Optional.of(Tx.fromTempTx(genesisTx));
|
||||
}
|
||||
|
||||
|
@ -458,8 +458,9 @@ public class TxParser {
|
|||
TempTx tempTx = TempTx.fromRawTx(rawTx);
|
||||
tempTx.setTxType(TxType.GENESIS);
|
||||
long remainingInputValue = genesisTotalSupply.getValue();
|
||||
for (int i = 0; i < tempTx.getTempTxOutputs().size(); ++i) {
|
||||
TempTxOutput txOutput = tempTx.getTempTxOutputs().get(i);
|
||||
List<TempTxOutput> tempTxOutputs = tempTx.getTempTxOutputs();
|
||||
for (int i = 0; i < tempTxOutputs.size(); ++i) {
|
||||
TempTxOutput txOutput = tempTxOutputs.get(i);
|
||||
long value = txOutput.getValue();
|
||||
boolean isValid = value <= remainingInputValue;
|
||||
if (!isValid)
|
||||
|
|
Loading…
Add table
Reference in a new issue