Do not pass over xmrAutoConfirmationManager to ProcessModel but use a

getter from tradeManager. Avoids boilerplate code (I know there is more
in the existing code to optimize here ;-))
This commit is contained in:
chimp1984 2020-08-30 16:43:32 -05:00
parent 219094e9d1
commit 67723fa1a7
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
4 changed files with 28 additions and 32 deletions

View file

@ -39,7 +39,6 @@ import bisq.core.support.dispute.refund.RefundResultState;
import bisq.core.support.dispute.refund.refundagent.RefundAgentManager;
import bisq.core.support.messages.ChatMessage;
import bisq.core.trade.autoconf.AutoConfirmResult;
import bisq.core.trade.autoconf.xmr.XmrAutoConfirmationManager;
import bisq.core.trade.protocol.ProcessModel;
import bisq.core.trade.protocol.TradeProtocol;
import bisq.core.trade.statistics.ReferralIdService;
@ -431,24 +430,16 @@ public abstract class Trade implements Tradable, Model {
private long refreshInterval;
private static final long MAX_REFRESH_INTERVAL = 4 * ChronoUnit.HOURS.getDuration().toMillis();
// Added after v1.3.7
// Added at v1.3.8
// We use that for the XMR txKey but want to keep it generic to be flexible for other payment methods or assets.
@Getter
@Setter
private String counterCurrencyExtraData;
public AutoConfirmResult getAutoConfirmResult() {
return autoConfirmResult != null ? autoConfirmResult : AutoConfirmResult.fromCurrencyCode(checkNotNull(offer).getCurrencyCode());
}
// Added at v1.3.8
@Nullable
private AutoConfirmResult autoConfirmResult;
public void setAutoConfirmResult(AutoConfirmResult autoConfirmResult) {
this.autoConfirmResult = autoConfirmResult;
autoConfirmResultProperty.setValue(autoConfirmResult);
}
@Getter
// This observable property can be used for UI to show a notification to user of the XMR proof status
transient final private ObjectProperty<AutoConfirmResult> autoConfirmResultProperty = new SimpleObjectProperty<>();
@ -630,7 +621,6 @@ public abstract class Trade implements Tradable, Model {
User user,
FilterManager filterManager,
AccountAgeWitnessService accountAgeWitnessService,
XmrAutoConfirmationManager xmrAutoConfirmationManager,
TradeStatisticsManager tradeStatisticsManager,
ArbitratorManager arbitratorManager,
MediatorManager mediatorManager,
@ -650,7 +640,6 @@ public abstract class Trade implements Tradable, Model {
user,
filterManager,
accountAgeWitnessService,
xmrAutoConfirmationManager,
tradeStatisticsManager,
arbitratorManager,
mediatorManager,
@ -764,6 +753,20 @@ public abstract class Trade implements Tradable, Model {
errorMessage = errorMessage == null ? msg : errorMessage + "\n" + msg;
}
public boolean allowedRefresh() {
var allowRefresh = new Date().getTime() > lastRefreshRequestDate + getRefreshInterval();
if (!allowRefresh) {
log.info("Refresh not allowed, last refresh at {}", lastRefreshRequestDate);
}
return allowRefresh;
}
public void logRefresh() {
var time = new Date().getTime();
log.debug("Log refresh at {}", time);
lastRefreshRequestDate = time;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Model implementation
@ -872,6 +875,11 @@ public abstract class Trade implements Tradable, Model {
errorMessageProperty.set(errorMessage);
}
public void setAutoConfirmResult(AutoConfirmResult autoConfirmResult) {
this.autoConfirmResult = autoConfirmResult;
autoConfirmResultProperty.setValue(autoConfirmResult);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter
@ -1084,6 +1092,11 @@ public abstract class Trade implements Tradable, Model {
return errorMessageProperty.get();
}
public AutoConfirmResult getAutoConfirmResult() {
return autoConfirmResult != null ? autoConfirmResult : AutoConfirmResult.fromCurrencyCode(checkNotNull(offer).getCurrencyCode());
}
public byte[] getArbitratorBtcPubKey() {
// In case we are already in a trade the arbitrator can have been revoked and we still can complete the trade
// Only new trades cannot start without any arbitrator
@ -1097,19 +1110,6 @@ public abstract class Trade implements Tradable, Model {
return arbitratorBtcPubKey;
}
public boolean allowedRefresh() {
var allowRefresh = new Date().getTime() > lastRefreshRequestDate + getRefreshInterval();
if (!allowRefresh) {
log.info("Refresh not allowed, last refresh at {}", lastRefreshRequestDate);
}
return allowRefresh;
}
public void logRefresh() {
var time = new Date().getTime();
log.debug("Log refresh at {}", time);
lastRefreshRequestDate = time;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private

View file

@ -127,6 +127,7 @@ public class TradeManager implements PersistedDataHost {
private final TradeStatisticsManager tradeStatisticsManager;
private final ReferralIdService referralIdService;
private final AccountAgeWitnessService accountAgeWitnessService;
@Getter
private final XmrAutoConfirmationManager xmrAutoConfirmationManager;
private final ArbitratorManager arbitratorManager;
private final MediatorManager mediatorManager;
@ -437,7 +438,6 @@ public class TradeManager implements PersistedDataHost {
user,
filterManager,
accountAgeWitnessService,
xmrAutoConfirmationManager,
tradeStatisticsManager,
arbitratorManager,
mediatorManager,

View file

@ -36,7 +36,6 @@ import bisq.core.support.dispute.refund.refundagent.RefundAgentManager;
import bisq.core.trade.MakerTrade;
import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager;
import bisq.core.trade.autoconf.xmr.XmrAutoConfirmationManager;
import bisq.core.trade.messages.TradeMessage;
import bisq.core.trade.statistics.ReferralIdService;
import bisq.core.trade.statistics.TradeStatisticsManager;
@ -90,7 +89,6 @@ public class ProcessModel implements Model, PersistablePayload {
transient private User user;
transient private FilterManager filterManager;
transient private AccountAgeWitnessService accountAgeWitnessService;
transient private XmrAutoConfirmationManager xmrAutoConfirmationManager;
transient private TradeStatisticsManager tradeStatisticsManager;
transient private ArbitratorManager arbitratorManager;
transient private MediatorManager mediatorManager;
@ -247,7 +245,6 @@ public class ProcessModel implements Model, PersistablePayload {
User user,
FilterManager filterManager,
AccountAgeWitnessService accountAgeWitnessService,
XmrAutoConfirmationManager xmrAutoConfirmationManager,
TradeStatisticsManager tradeStatisticsManager,
ArbitratorManager arbitratorManager,
MediatorManager mediatorManager,
@ -266,7 +263,6 @@ public class ProcessModel implements Model, PersistablePayload {
this.user = user;
this.filterManager = filterManager;
this.accountAgeWitnessService = accountAgeWitnessService;
this.xmrAutoConfirmationManager = xmrAutoConfirmationManager;
this.tradeStatisticsManager = tradeStatisticsManager;
this.arbitratorManager = arbitratorManager;
this.mediatorManager = mediatorManager;

View file

@ -58,7 +58,7 @@ public class SellerProcessCounterCurrencyTransferStartedMessage extends TradeTas
String counterCurrencyExtraData = message.getCounterCurrencyExtraData();
if (counterCurrencyExtraData != null && counterCurrencyExtraData.length() < 100) {
trade.setCounterCurrencyExtraData(counterCurrencyExtraData);
processModel.getXmrAutoConfirmationManager().processCounterCurrencyExtraData(
processModel.getTradeManager().getXmrAutoConfirmationManager().processCounterCurrencyExtraData(
trade, processModel.getTradeManager().getTradableList().stream());
}
processModel.removeMailboxMessageAfterProcessing(trade);