Skip to content

Commit

Permalink
Merge pull request #7351 from thecockatiel/fix_short_id_and_pre_condi…
Browse files Browse the repository at this point in the history
…tion

fix: Utilities.getShortId and FluentProtocol.preCondition usage
  • Loading branch information
alejandrogarcia83 authored Jan 15, 2025
2 parents c8e05fc + 61c90bf commit c079407
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/bisq/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public static String getShortId(String id) {
@SuppressWarnings("SameParameterValue")
public static String getShortId(String id, String sep) {
String[] chunks = id.split(sep);
if (chunks.length > 0)
if (chunks.length > 1 && chunks[0].length() <= 8)
return chunks[0];
else
return id.substring(0, Math.min(8, id.length()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,16 @@ public Condition preCondition(boolean preCondition) {
return this;
}

/** Calling this more than once discards the previous conditionFailedHandler */
public Condition preCondition(boolean preCondition, Runnable conditionFailedHandler) {
checkArgument(result == null);
preCondition(preCondition);

// warn if we are replacing it with another preConditionHandler:
if (this.preConditionFailedHandler != null) {
log.warn("preCondition with conditionFailedHandler was called more than once." +
"previous conditionFailedHandler will be discarded.");
}
this.preConditionFailedHandler = conditionFailedHandler;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ public void onAcceptMediationResult(ResultHandler resultHandler, ErrorMessageHan
Trade.Phase.FIAT_SENT,
Trade.Phase.FIAT_RECEIVED)
.with(event)
.preCondition(trade.getProcessModel().getTradePeer().getMediatedPayoutTxSignature() == null,
() -> errorMessageHandler.handleErrorMessage("We have received already the signature from the peer."))
.preCondition(trade.getPayoutTx() == null,
() -> errorMessageHandler.handleErrorMessage("Payout tx is already published.")))
.preCondition(
(trade.getProcessModel().getTradePeer().getMediatedPayoutTxSignature() == null) ||
(trade.getPayoutTx() == null),
() -> errorMessageHandler.handleErrorMessage("We either have received already the signature from the peer or payout tx is already published."))
)
.setup(tasks(ApplyFilter.class,
SignMediatedPayoutTx.class,
SendMediatedPayoutSignatureMessage.class,
Expand Down

0 comments on commit c079407

Please sign in to comment.