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