Skip to content

Commit

Permalink
Check live Tx as part of BSQ fee validation process.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacxx committed Dec 7, 2023
1 parent 0ad71fc commit 265ca17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
42 changes: 20 additions & 22 deletions core/src/main/java/bisq/core/provider/mempool/MempoolService.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,12 @@ public void validateOfferMakerTx(OfferPayload offerPayload, Consumer<TxValidator
}

public void validateOfferMakerTx(TxValidator txValidator, Consumer<TxValidator> resultHandler) {
if (txValidator.getIsFeeCurrencyBtc() != null && txValidator.getIsFeeCurrencyBtc()) {
if (!isServiceSupported()) {
UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult(FeeValidationStatus.ACK_CHECK_BYPASSED)), 1);
return;
}
MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider);
validateOfferMakerTx(mempoolRequest, txValidator, resultHandler);
} else {
// using BSQ for fees
UserThread.runAfter(() -> resultHandler.accept(txValidator.validateBsqFeeTx(true)), 1);
if (!isServiceSupported()) {
UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult(FeeValidationStatus.ACK_CHECK_BYPASSED)), 1);
return;
}
MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider);
validateOfferMakerTx(mempoolRequest, txValidator, resultHandler);
}

public void validateOfferTakerTx(Trade trade, Consumer<TxValidator> resultHandler) {
Expand All @@ -121,17 +116,12 @@ public void validateOfferTakerTx(Trade trade, Consumer<TxValidator> resultHandle
}

public void validateOfferTakerTx(TxValidator txValidator, Consumer<TxValidator> resultHandler) {
if (txValidator.getIsFeeCurrencyBtc() != null && txValidator.getIsFeeCurrencyBtc()) {
if (!isServiceSupported()) {
UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult(FeeValidationStatus.ACK_CHECK_BYPASSED)), 1);
return;
}
MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider);
validateOfferTakerTx(mempoolRequest, txValidator, resultHandler);
} else {
// using BSQ for fees
resultHandler.accept(txValidator.validateBsqFeeTx(false));
if (!isServiceSupported()) {
UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult(FeeValidationStatus.ACK_CHECK_BYPASSED)), 1);
return;
}
MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider);
validateOfferTakerTx(mempoolRequest, txValidator, resultHandler);
}

public void checkTxIsConfirmed(String txId, Consumer<TxValidator> resultHandler) {
Expand Down Expand Up @@ -178,7 +168,11 @@ private FutureCallback<String> callbackForMakerTxValidation(MempoolRequest theRe
public void onSuccess(@Nullable String jsonTxt) {
UserThread.execute(() -> {
outstandingRequests--;
resultHandler.accept(txValidator.parseJsonValidateMakerFeeTx(jsonTxt, getAllBtcFeeReceivers()));
if (txValidator.getIsFeeCurrencyBtc() != null && txValidator.getIsFeeCurrencyBtc()) {
resultHandler.accept(txValidator.parseJsonValidateMakerFeeTx(jsonTxt, getAllBtcFeeReceivers()));
} else {
resultHandler.accept(txValidator.validateBsqFeeTx(true));
}
});
}

Expand Down Expand Up @@ -208,7 +202,11 @@ private FutureCallback<String> callbackForTakerTxValidation(MempoolRequest theRe
public void onSuccess(@Nullable String jsonTxt) {
UserThread.execute(() -> {
outstandingRequests--;
resultHandler.accept(txValidator.parseJsonValidateTakerFeeTx(jsonTxt, getAllBtcFeeReceivers()));
if (txValidator.getIsFeeCurrencyBtc() != null && txValidator.getIsFeeCurrencyBtc()) {
resultHandler.accept(txValidator.parseJsonValidateTakerFeeTx(jsonTxt, getAllBtcFeeReceivers()));
} else {
resultHandler.accept(txValidator.validateBsqFeeTx(false));
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public TxValidator parseJsonValidateMakerFeeTx(String jsonTxt, List<String> btcF
log.info(s);
status = FeeValidationStatus.NACK_JSON_ERROR;
}
return endResult("Maker tx validation", status);
return endResult("Maker tx validation (BTC)", status);
}

public TxValidator validateBsqFeeTx(boolean isMaker) {
Optional<Tx> tx = daoStateService.getTx(txId);
String statusStr = (isMaker ? "Maker" : "Taker") + " tx validation";
String statusStr = (isMaker ? "Maker" : "Taker") + " tx validation (BSQ)";
if (tx.isEmpty()) {
long txAge = this.chainHeight - this.feePaymentBlockHeight;
if (txAge > 48) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public TxValidator parseJsonValidateTakerFeeTx(String jsonTxt, List<String> btcF
log.info(s);
status = FeeValidationStatus.NACK_JSON_ERROR;
}
return endResult("Taker tx validation", status);
return endResult("Taker tx validation (BTC)", status);
}

public long parseJsonValidateTx() {
Expand Down

0 comments on commit 265ca17

Please sign in to comment.