You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// check if any outputs spent (observed on payout published)
2913
-
booleanhasSpentOutput = false;
2914
-
booleanhasFailedTx = false;
2919
+
// update payout state
2920
+
booleanhasValidPayout = false;
2921
+
booleanhasFailedPayout = false;
2915
2922
for (MoneroTxWallettx : txs) {
2916
-
if (tx.isFailed()) {
2917
-
hasFailedTx = true;
2923
+
booleanisOutgoing = !Boolean.TRUE.equals(tx.isIncoming()); // outgoing tx observed after wallet submits payout or on first confirmation
2924
+
if (isOutgoing) {
2925
+
if (tx.isFailed()) hasFailedPayout = true;
2926
+
else {
2927
+
hasValidPayout = true;
2928
+
updatePayout(tx);
2929
+
setPayoutStatePublished();
2930
+
if (tx.isConfirmed()) setPayoutStateConfirmed();
2931
+
if (!tx.isLocked()) setPayoutStateUnlocked();
2932
+
if (tx.getNumConfirmations() != null && tx.getNumConfirmations() >= NUM_BLOCKS_PAYOUT_FINALIZED) setPayoutStateFinalized();
2933
+
}
2918
2934
} else {
2919
2935
for (MoneroOutputWalletoutput : tx.getOutputsWallet()) {
2920
-
if (Boolean.TRUE.equals(output.isSpent())) hasSpentOutput = true;
2936
+
if (Boolean.TRUE.equals(output.isSpent())) hasValidPayout = true;// spent outputs observed on payout published (after rescanning)
2921
2937
}
2922
2938
}
2923
2939
}
2924
-
if (hasSpentOutput) setPayoutStatePublished();
2925
-
elseif (hasFailedTx && isPayoutPublished()) {
2926
-
log.warn("{} {} is in payout published state but has failed tx and no spent outputs, resetting payout state to unpublished", getClass().getSimpleName(), getShortId());
2927
-
ThreadUtils.execute(() -> {
2928
-
setPayoutState(PayoutState.PAYOUT_UNPUBLISHED);
2929
-
onPayoutError(false, isSeller());
2930
-
}, getId());
2931
-
}
2932
2940
2933
-
// check for outgoing txs (appears after wallet submits payout tx or on payout confirmed)
2934
-
for (MoneroTxWallettx : txs) {
2935
-
if (tx.isOutgoing() && !tx.isFailed()) {
2936
-
updatePayout(tx);
2937
-
setPayoutStatePublished();
2938
-
if (tx.isConfirmed()) setPayoutStateConfirmed();
2939
-
if (!tx.isLocked()) setPayoutStateUnlocked();
2940
-
if (tx.getNumConfirmations() != null && tx.getNumConfirmations() >= NUM_BLOCKS_PAYOUT_FINALIZED) setPayoutStateFinalized();
2941
-
}
2941
+
// handle payout validity
2942
+
if (hasValidPayout) {
2943
+
onValidPayoutTxPoll();
2944
+
} elseif (hasFailedPayout) {
2945
+
onFailedPayoutTxPoll();
2942
2946
}
2943
2947
}
2944
2948
} catch (Exceptione) {
@@ -2964,8 +2968,47 @@ else if (hasFailedTx && isPayoutPublished()) {
2964
2968
}
2965
2969
}
2966
2970
2967
-
publicbooleanonPayoutError(booleansyncAndPoll) {
2968
-
returnonPayoutError(syncAndPoll, false);
2971
+
privatevoidonValidPayoutTxPoll() {
2972
+
setPayoutStatePublished();
2973
+
synchronized (failedPayoutLock) {
2974
+
handleFailedPayoutTxOnNextPoll = false;
2975
+
if (failedPayoutTimer == null) return;
2976
+
log.warn("Received valid payout after previous payout failure for {} {}. Unscheduling failed payout tx handling", getClass().getSimpleName(), getId());
2977
+
failedPayoutTimer.stop();
2978
+
failedPayoutTimer = null;
2979
+
}
2980
+
}
2981
+
2982
+
privatevoidonFailedPayoutTxPoll() {
2983
+
if (!isPayoutPublished()) return; // ignore if payout unpublished
2984
+
log.warn("The payout tx has failed for {} {} with payout state {}", getClass().getSimpleName(), getShortId(), getPayoutState());
@@ -2997,11 +3040,12 @@ public boolean onPayoutError(boolean syncAndPoll, boolean autoMarkPaymentReceive
2997
3040
// automatically mark payment received
2998
3041
if (autoMarkPaymentReceived) {
2999
3042
if (!isSeller()) thrownewIllegalArgumentException("Must be the seller to auto mark payment received for " + getClass().getSimpleName() + " " + getId());
3000
-
log.warn("Auto confirming payment received for {} {} after failure", getClass().getSimpleName(), getId());
3043
+
log.warn("Auto confirming payment received for {} {} after payout error", getClass().getSimpleName(), getId());
3044
+
getProtocol().setAutoMarkPaymentReceived(false); // only auto mark payment received once until restart
0 commit comments