4141import javafx .collections .ObservableList ;
4242
4343import java .util .Set ;
44+ import java .util .function .Predicate ;
4445import java .util .stream .IntStream ;
4546
4647import lombok .extern .slf4j .Slf4j ;
4748
49+ import javax .annotation .Nullable ;
50+
4851import static bisq .desktop .main .funds .transactions .TransactionAwareTradable .bucketIndex ;
4952import static com .google .common .base .Preconditions .checkNotNull ;
5053
@@ -88,28 +91,26 @@ public boolean isRelatedToTransaction(Transaction transaction) {
8891 boolean isTakerOfferFeeTx = txId .equals (trade .getTakerFeeTxId ());
8992 boolean isOfferFeeTx = isOfferFeeTx (txId );
9093 boolean isDepositTx = isDepositTx (txId );
91- boolean isPayoutTx = isPayoutTx (txId );
94+ boolean isPayoutTx = isPayoutTx (trade , txId );
9295 boolean isDisputedPayoutTx = isDisputedPayoutTx (txId );
93- boolean isDelayedPayoutTx = transaction .getLockTime () != 0 && isDelayedPayoutTx (txId );
96+ boolean isDelayedPayoutOrWarningTx = isDelayedPayoutOrWarningTx (transaction , txId );
97+ boolean isRedirectOrClaimTx = isRedirectOrClaimTx (transaction , txId );
9498 boolean isRefundPayoutTx = isRefundPayoutTx (trade , txId );
9599 tradeRelated = isTakerOfferFeeTx ||
96100 isOfferFeeTx ||
97101 isDepositTx ||
98102 isPayoutTx ||
99103 isDisputedPayoutTx ||
100- isDelayedPayoutTx ||
104+ isDelayedPayoutOrWarningTx ||
105+ isRedirectOrClaimTx ||
101106 isRefundPayoutTx ;
102107 }
103108 boolean isBsqSwapTrade = isBsqSwapTrade (txId );
104109
105110 return tradeRelated || isBsqSwapTrade ;
106111 }
107112
108- private boolean isPayoutTx (String txId ) {
109- if (isBsqSwapTrade ())
110- return false ;
111-
112- Trade trade = (Trade ) tradeModel ;
113+ private boolean isPayoutTx (Trade trade , String txId ) {
113114 return txId .equals (trade .getPayoutTxId ());
114115 }
115116
@@ -122,17 +123,11 @@ private boolean isDepositTx(String txId) {
122123 }
123124
124125 private boolean isOfferFeeTx (String txId ) {
125- if (isBsqSwapTrade ())
126- return false ;
127-
128126 Offer offer = tradeModel .getOffer ();
129127 return offer != null && txId .equals (offer .getOfferFeePaymentTxId ());
130128 }
131129
132130 private boolean isDisputedPayoutTx (String txId ) {
133- if (isBsqSwapTrade ())
134- return false ;
135-
136131 String delegateId = tradeModel .getId ();
137132 ObservableList <Dispute > disputes = arbitrationManager .getDisputesAsObservableList ();
138133
@@ -151,37 +146,58 @@ private boolean isDisputedPayoutTx(String txId) {
151146 }
152147
153148 boolean isDelayedPayoutTx (String txId ) {
154- if ( isBsqSwapTrade ())
155- return false ;
149+ return isDelayedPayoutOrWarningTx ( txId ) && !(( Trade ) tradeModel ). hasV5Protocol ();
150+ }
156151
157- Transaction transaction = btcWalletService . getTransaction ( txId );
158- if ( transaction == null )
159- return false ;
152+ private boolean isWarningTx ( String txId ) {
153+ return isDelayedPayoutOrWarningTx ( txId ) && (( Trade ) tradeModel ). hasV5Protocol ();
154+ }
160155
161- if (transaction .getLockTime () == 0 )
156+ private boolean isDelayedPayoutOrWarningTx (String txId ) {
157+ if (isBsqSwapTrade ()) {
162158 return false ;
159+ }
160+ Transaction transaction = btcWalletService .getTransaction (txId );
161+ return transaction != null && isDelayedPayoutOrWarningTx (transaction , null );
162+ }
163163
164- if (transaction .getInputs () == null || transaction .getInputs ().size () != 1 )
164+ private boolean isDelayedPayoutOrWarningTx (Transaction transaction , @ Nullable String txId ) {
165+ if (transaction .getLockTime () == 0 || transaction .getInputs ().size () != 1 ) {
166+ return false ;
167+ }
168+ if (!TransactionAwareTradable .isPossibleEscrowSpend (transaction .getInput (0 ))) {
165169 return false ;
170+ }
171+ return firstParent (this ::isDepositTx , transaction , txId );
172+ }
166173
167- return transaction .getInputs ().stream ()
168- .anyMatch (input -> {
169- TransactionOutput connectedOutput = input .getConnectedOutput ();
170- if (connectedOutput == null ) {
171- return false ;
172- }
173- Transaction parentTransaction = connectedOutput .getParentTransaction ();
174- if (parentTransaction == null ) {
175- return false ;
176- }
177- return isDepositTx (parentTransaction .getTxId ().toString ());
178- });
174+ private boolean isRedirectOrClaimTx (Transaction transaction , @ Nullable String txId ) {
175+ if (transaction .getInputs ().size () != 1 ) {
176+ return false ;
177+ }
178+ if (!TransactionAwareTradable .isPossibleRedirectOrClaimTx (transaction )) {
179+ return false ;
180+ }
181+ return firstParent (this ::isWarningTx , transaction , txId );
179182 }
180183
181- private boolean isRefundPayoutTx (Trade trade , String txId ) {
182- if (isBsqSwapTrade ())
184+ private boolean firstParent (Predicate <String > parentPredicate , Transaction transaction , @ Nullable String txId ) {
185+ Transaction walletTransaction = txId != null ? btcWalletService .getTransaction (txId ) : transaction ;
186+ if (walletTransaction == null ) {
183187 return false ;
188+ }
189+ TransactionOutput connectedOutput = walletTransaction .getInput (0 ).getConnectedOutput ();
190+ if (connectedOutput == null ) {
191+ return false ;
192+ }
193+ Transaction parentTransaction = connectedOutput .getParentTransaction ();
194+ if (parentTransaction == null ) {
195+ return false ;
196+ }
197+ return parentPredicate .test (parentTransaction .getTxId ().toString ());
198+ }
184199
200+ private boolean isRefundPayoutTx (Trade trade , String txId ) {
185201 String tradeId = tradeModel .getId ();
186202 boolean isAnyDisputeRelatedToThis = refundManager .getDisputedTradeIds ().contains (tradeId );
187203
0 commit comments