fix trade initialization error handling and run off trade thread
This commit is contained in:
parent
ea4359d164
commit
892eaa440a
@ -590,10 +590,9 @@ public abstract class Trade implements Tradable, Model {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initialize(ProcessModelServiceProvider serviceProvider) {
|
||||
ThreadUtils.await(() -> {
|
||||
if (isInitialized) throw new IllegalStateException(getClass().getSimpleName() + " " + getId() + " is already initialized");
|
||||
|
||||
// check if done
|
||||
// done if payout unlocked
|
||||
if (isPayoutUnlocked()) {
|
||||
clearAndShutDown();
|
||||
return;
|
||||
@ -625,7 +624,7 @@ public abstract class Trade implements Tradable, Model {
|
||||
|
||||
// handle trade state events
|
||||
tradeStateSubscription = EasyBind.subscribe(stateProperty, newValue -> {
|
||||
if (isShutDownStarted) return;
|
||||
if (!isInitialized || isShutDownStarted) return;
|
||||
ThreadUtils.execute(() -> {
|
||||
if (newValue == Trade.State.MULTISIG_COMPLETED) {
|
||||
updateWalletRefreshPeriod();
|
||||
@ -636,7 +635,7 @@ public abstract class Trade implements Tradable, Model {
|
||||
|
||||
// handle trade phase events
|
||||
tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> {
|
||||
if (isShutDownStarted) return;
|
||||
if (!isInitialized || isShutDownStarted) return;
|
||||
ThreadUtils.execute(() -> {
|
||||
if (isDepositsPublished() && !isPayoutUnlocked()) updateWalletRefreshPeriod();
|
||||
if (isPaymentReceived()) {
|
||||
@ -652,7 +651,7 @@ public abstract class Trade implements Tradable, Model {
|
||||
|
||||
// handle payout events
|
||||
payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> {
|
||||
if (isShutDownStarted) return;
|
||||
if (!isInitialized || isShutDownStarted) return;
|
||||
ThreadUtils.execute(() -> {
|
||||
if (isPayoutPublished()) updateWalletRefreshPeriod();
|
||||
|
||||
@ -707,11 +706,12 @@ public abstract class Trade implements Tradable, Model {
|
||||
// trade is initialized
|
||||
isInitialized = true;
|
||||
|
||||
// done if payout unlocked or deposit not requested
|
||||
// done if deposit not requested or payout unlocked
|
||||
if (!isDepositRequested() || isPayoutUnlocked()) return;
|
||||
|
||||
// done if wallet does not exist
|
||||
if (!walletExists()) {
|
||||
// open wallet or done if wallet does not exist
|
||||
if (walletExists()) getWallet();
|
||||
else {
|
||||
MoneroTx payoutTx = getPayoutTx();
|
||||
if (payoutTx != null && payoutTx.getNumConfirmations() >= 10) {
|
||||
log.warn("Payout state for {} {} is {} but payout is unlocked, updating state", getClass().getSimpleName(), getId(), getPayoutState());
|
||||
@ -723,8 +723,7 @@ public abstract class Trade implements Tradable, Model {
|
||||
}
|
||||
|
||||
// initialize syncing and polling
|
||||
initSyncing();
|
||||
}, getId());
|
||||
tryInitSyncing();
|
||||
}
|
||||
|
||||
public void requestPersistence() {
|
||||
@ -1940,12 +1939,12 @@ public abstract class Trade implements Tradable, Model {
|
||||
|
||||
// sync and reprocess messages on new thread
|
||||
if (isInitialized && connection != null && !Boolean.FALSE.equals(connection.isConnected())) {
|
||||
ThreadUtils.execute(() -> initSyncing(), getId());
|
||||
ThreadUtils.execute(() -> tryInitSyncing(), getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initSyncing() {
|
||||
private void tryInitSyncing() {
|
||||
if (isShutDownStarted) return;
|
||||
if (!isIdling()) {
|
||||
initSyncingAux();
|
||||
|
Loading…
Reference in New Issue
Block a user