mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-25 15:29:23 -05:00
delete trade wallet backup if empty and payout unlocked, else schedule
This commit is contained in:
parent
7658b3a508
commit
d0a489198b
@ -903,26 +903,46 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
if (walletExists()) {
|
if (walletExists()) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
// ensure wallet is initialized
|
||||||
|
if (wallet == null) {
|
||||||
|
log.warn("Wallet is not initialized for {} {}, opening", getClass().getSimpleName(), getId());
|
||||||
|
getWallet();
|
||||||
|
syncWallet(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// wallet must be synced
|
||||||
|
if (!isSyncedWithinTolerance()) {
|
||||||
|
log.warn("Wallet is not synced for {} {}, syncing", getClass().getSimpleName(), getId());
|
||||||
|
syncWallet(true);
|
||||||
|
}
|
||||||
|
|
||||||
// check if deposits published and payout not unlocked
|
// check if deposits published and payout not unlocked
|
||||||
if (isDepositsPublished() && !isPayoutUnlocked()) {
|
if (isDepositsPublished() && !isPayoutUnlocked()) {
|
||||||
throw new RuntimeException("Refusing to delete wallet for " + getClass().getSimpleName() + " " + getId() + " because the deposit txs have been published but payout tx has not unlocked");
|
throw new IllegalStateException("Refusing to delete wallet for " + getClass().getSimpleName() + " " + getId() + " because the deposit txs have been published but payout tx has not unlocked");
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for balance
|
// check for balance
|
||||||
if (wallet != null && wallet.getBalance().compareTo(BigInteger.ZERO) > 0) {
|
if (wallet.getBalance().compareTo(BigInteger.ZERO) > 0) {
|
||||||
throw new RuntimeException("Refusing to delete wallet for " + getClass().getSimpleName() + " " + getId() + " because it has a balance");
|
throw new IllegalStateException("Refusing to delete wallet for " + getClass().getSimpleName() + " " + getId() + " because it has a balance");
|
||||||
}
|
}
|
||||||
|
|
||||||
// force stop wallet
|
// force stop wallet
|
||||||
if (wallet != null) stopWallet();
|
stopWallet();
|
||||||
|
|
||||||
// delete wallet
|
// delete wallet
|
||||||
log.info("Deleting wallet for {} {}", getClass().getSimpleName(), getId());
|
log.info("Deleting wallet for {} {}", getClass().getSimpleName(), getId());
|
||||||
xmrWalletService.deleteWallet(getWalletName());
|
xmrWalletService.deleteWallet(getWalletName());
|
||||||
|
|
||||||
// record delete height and schedule backup deletion
|
// delete trade wallet backups if empty and payout unlocked, else schedule
|
||||||
processModel.setDeleteBackupsHeight(xmrConnectionService.getLastInfo().getHeight() + DELETE_BACKUPS_AFTER_NUM_BLOCKS);
|
if (isPayoutUnlocked() || !isDepositRequested() || isDepositFailed()) {
|
||||||
maybeScheduleDeleteBackups();
|
xmrWalletService.deleteWalletBackups(getWalletName());
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// schedule backup deletion by recording delete height
|
||||||
|
log.warn("Scheduling to delete backup wallet for " + getClass().getSimpleName() + " " + getId() + " in the small chance it becomes funded");
|
||||||
|
processModel.setDeleteBackupsHeight(xmrConnectionService.getLastInfo().getHeight() + DELETE_BACKUPS_AFTER_NUM_BLOCKS);
|
||||||
|
maybeScheduleDeleteBackups();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn(e.getMessage());
|
log.warn(e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1194,8 +1214,10 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearAndShutDown() {
|
public void clearAndShutDown() {
|
||||||
ThreadUtils.execute(() -> clearProcessData(), getId());
|
ThreadUtils.execute(() -> {
|
||||||
ThreadUtils.submitToPool(() -> shutDown()); // run off trade thread
|
clearProcessData();
|
||||||
|
ThreadUtils.submitToPool(() -> shutDown()); // run off trade thread
|
||||||
|
}, getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearProcessData() {
|
private void clearProcessData() {
|
||||||
|
Loading…
Reference in New Issue
Block a user