process trade state notifications off UserThread
This commit is contained in:
parent
43bbb29384
commit
e7371d1299
@ -263,8 +263,11 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
|
|||||||
// wait to sign and publish payout tx if defer flag set
|
// wait to sign and publish payout tx if defer flag set
|
||||||
if (disputeClosedMessage.isDeferPublishPayout()) {
|
if (disputeClosedMessage.isDeferPublishPayout()) {
|
||||||
log.info("Deferring signing and publishing dispute payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId());
|
log.info("Deferring signing and publishing dispute payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId());
|
||||||
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS);
|
for (int i = 0; i < 5; i++) {
|
||||||
if (!trade.isPayoutUnlocked()) trade.syncAndPollWallet();
|
if (trade.isPayoutPublished()) break;
|
||||||
|
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS / 5);
|
||||||
|
}
|
||||||
|
if (!trade.isPayoutPublished()) trade.syncAndPollWallet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// sign and publish dispute payout tx if peer still has not published
|
// sign and publish dispute payout tx if peer still has not published
|
||||||
|
@ -621,70 +621,79 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
|
|
||||||
// handle trade state events
|
// handle trade state events
|
||||||
tradeStateSubscription = EasyBind.subscribe(stateProperty, newValue -> {
|
tradeStateSubscription = EasyBind.subscribe(stateProperty, newValue -> {
|
||||||
if (newValue == Trade.State.MULTISIG_COMPLETED) {
|
HavenoUtils.submitToThread(() -> {
|
||||||
updateWalletRefreshPeriod();
|
if (newValue == Trade.State.MULTISIG_COMPLETED) {
|
||||||
startPolling();
|
updateWalletRefreshPeriod();
|
||||||
}
|
startPolling();
|
||||||
|
}
|
||||||
|
}, getId());
|
||||||
});
|
});
|
||||||
|
|
||||||
// handle trade phase events
|
// handle trade phase events
|
||||||
tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> {
|
tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> {
|
||||||
if (isDepositsPublished() && !isPayoutUnlocked()) updateWalletRefreshPeriod();
|
HavenoUtils.submitToThread(() -> {
|
||||||
if (isPaymentReceived()) {
|
if (isDepositsPublished() && !isPayoutUnlocked()) updateWalletRefreshPeriod();
|
||||||
UserThread.execute(() -> {
|
if (isPaymentReceived()) {
|
||||||
if (tradePhaseSubscription != null) {
|
UserThread.execute(() -> {
|
||||||
tradePhaseSubscription.unsubscribe();
|
if (tradePhaseSubscription != null) {
|
||||||
tradePhaseSubscription = null;
|
tradePhaseSubscription.unsubscribe();
|
||||||
}
|
tradePhaseSubscription = null;
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
}, getId());
|
||||||
});
|
});
|
||||||
|
|
||||||
// handle payout events
|
// handle payout events
|
||||||
payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> {
|
payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> {
|
||||||
if (isPayoutPublished()) updateWalletRefreshPeriod();
|
HavenoUtils.submitToThread(() -> {
|
||||||
|
if (isPayoutPublished()) updateWalletRefreshPeriod();
|
||||||
|
|
||||||
// handle when payout published
|
// handle when payout published
|
||||||
if (newValue == Trade.PayoutState.PAYOUT_PUBLISHED) {
|
if (newValue == Trade.PayoutState.PAYOUT_PUBLISHED) {
|
||||||
log.info("Payout published for {} {}", getClass().getSimpleName(), getId());
|
log.info("Payout published for {} {}", getClass().getSimpleName(), getId());
|
||||||
|
|
||||||
// sync main wallet to update pending balance
|
// sync main wallet to update pending balance
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
GenUtils.waitFor(1000);
|
GenUtils.waitFor(1000);
|
||||||
if (isShutDownStarted) return;
|
if (isShutDownStarted) return;
|
||||||
if (Boolean.TRUE.equals(xmrConnectionService.isConnected())) xmrWalletService.syncWallet(xmrWalletService.getWallet());
|
if (Boolean.TRUE.equals(xmrConnectionService.isConnected())) xmrWalletService.syncWallet(xmrWalletService.getWallet());
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
// complete disputed trade
|
// complete disputed trade
|
||||||
if (getDisputeState().isArbitrated() && !getDisputeState().isClosed()) {
|
if (getDisputeState().isArbitrated() && !getDisputeState().isClosed()) {
|
||||||
processModel.getTradeManager().closeDisputedTrade(getId(), Trade.DisputeState.DISPUTE_CLOSED);
|
processModel.getTradeManager().closeDisputedTrade(getId(), Trade.DisputeState.DISPUTE_CLOSED);
|
||||||
if (!isArbitrator()) for (Dispute dispute : getDisputes()) dispute.setIsClosed(); // auto close trader tickets
|
if (!isArbitrator()) for (Dispute dispute : getDisputes()) dispute.setIsClosed(); // auto close trader tickets
|
||||||
}
|
|
||||||
|
|
||||||
// auto complete arbitrator trade
|
|
||||||
if (isArbitrator() && !isCompleted()) processModel.getTradeManager().onTradeCompleted(this);
|
|
||||||
|
|
||||||
// reset address entries
|
|
||||||
processModel.getXmrWalletService().resetAddressEntriesForTrade(getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle when payout unlocks
|
|
||||||
if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) {
|
|
||||||
if (!isInitialized) return;
|
|
||||||
log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId());
|
|
||||||
deleteWallet();
|
|
||||||
maybeClearProcessData();
|
|
||||||
if (idlePayoutSyncer != null) {
|
|
||||||
xmrWalletService.removeWalletListener(idlePayoutSyncer);
|
|
||||||
idlePayoutSyncer = null;
|
|
||||||
}
|
|
||||||
UserThread.execute(() -> {
|
|
||||||
if (payoutStateSubscription != null) {
|
|
||||||
payoutStateSubscription.unsubscribe();
|
|
||||||
payoutStateSubscription = null;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
// auto complete arbitrator trade
|
||||||
|
if (isArbitrator() && !isCompleted()) processModel.getTradeManager().onTradeCompleted(this);
|
||||||
|
|
||||||
|
// reset address entries
|
||||||
|
processModel.getXmrWalletService().resetAddressEntriesForTrade(getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle when payout unlocks
|
||||||
|
if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) {
|
||||||
|
if (!isInitialized) return;
|
||||||
|
log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId());
|
||||||
|
HavenoUtils.submitToThread(() -> {
|
||||||
|
deleteWallet();
|
||||||
|
maybeClearProcessData();
|
||||||
|
if (idlePayoutSyncer != null) {
|
||||||
|
xmrWalletService.removeWalletListener(idlePayoutSyncer);
|
||||||
|
idlePayoutSyncer = null;
|
||||||
|
}
|
||||||
|
UserThread.execute(() -> {
|
||||||
|
if (payoutStateSubscription != null) {
|
||||||
|
payoutStateSubscription.unsubscribe();
|
||||||
|
payoutStateSubscription = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, getId());
|
||||||
|
|
||||||
|
}
|
||||||
|
}, getId());
|
||||||
});
|
});
|
||||||
|
|
||||||
// arbitrator syncs idle wallet when payout unlock expected
|
// arbitrator syncs idle wallet when payout unlock expected
|
||||||
|
@ -128,8 +128,11 @@ public class ProcessPaymentReceivedMessage extends TradeTask {
|
|||||||
boolean deferSignAndPublish = trade instanceof ArbitratorTrade && !isSigned && message.isDeferPublishPayout();
|
boolean deferSignAndPublish = trade instanceof ArbitratorTrade && !isSigned && message.isDeferPublishPayout();
|
||||||
if (deferSignAndPublish) {
|
if (deferSignAndPublish) {
|
||||||
log.info("Deferring signing and publishing payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId());
|
log.info("Deferring signing and publishing payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId());
|
||||||
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS);
|
for (int i = 0; i < 5; i++) {
|
||||||
if (!trade.isPayoutUnlocked()) trade.syncAndPollWallet();
|
if (trade.isPayoutPublished()) break;
|
||||||
|
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS / 5);
|
||||||
|
}
|
||||||
|
if (!trade.isPayoutPublished()) trade.syncAndPollWallet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify and publish payout tx
|
// verify and publish payout tx
|
||||||
|
Loading…
Reference in New Issue
Block a user