mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
inject CorruptedDataFilesHandler instead of making it static
This commit is contained in:
parent
2383d7ea50
commit
b77cff9e26
@ -52,11 +52,7 @@ public class Storage<T extends PersistableEnvelope> {
|
||||
private static final Logger log = LoggerFactory.getLogger(Storage.class);
|
||||
public static final String STORAGE_DIR = "storageDir";
|
||||
|
||||
private static CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
|
||||
|
||||
public static void setCorruptedDatabaseFilesHandler(CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
Storage.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
|
||||
}
|
||||
private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
|
||||
|
||||
private final File dir;
|
||||
private FileManager<T> fileManager;
|
||||
@ -72,9 +68,10 @@ public class Storage<T extends PersistableEnvelope> {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public Storage(@Named(STORAGE_DIR) File dir, PersistenceProtoResolver persistenceProtoResolver) {
|
||||
public Storage(@Named(STORAGE_DIR) File dir, PersistenceProtoResolver persistenceProtoResolver, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.dir = dir;
|
||||
this.persistenceProtoResolver = persistenceProtoResolver;
|
||||
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -42,8 +42,6 @@ import bisq.common.app.DevEnv;
|
||||
import bisq.common.handlers.ResultHandler;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.setup.GracefulShutDownHandler;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import org.springframework.core.env.JOptCommandLinePropertySource;
|
||||
|
||||
@ -232,8 +230,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
||||
protected void applyInjector() {
|
||||
setupDevEnv();
|
||||
|
||||
setCorruptedDataBaseFilesHandler();
|
||||
|
||||
setupPersistedDataHosts(injector);
|
||||
}
|
||||
|
||||
@ -242,11 +238,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
||||
DevEnv.setDaoActivated(BisqEnvironment.isDaoActivated(bisqEnvironment));
|
||||
}
|
||||
|
||||
private void setCorruptedDataBaseFilesHandler() {
|
||||
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler = injector.getInstance(CorruptedDatabaseFilesHandler.class);
|
||||
Storage.setCorruptedDatabaseFilesHandler(corruptedDatabaseFilesHandler);
|
||||
}
|
||||
|
||||
protected void setupPersistedDataHosts(Injector injector) {
|
||||
try {
|
||||
PersistedDataHost.apply(CorePersistedDataHost.getPersistedDataHosts(injector));
|
||||
|
@ -57,6 +57,7 @@ import bisq.common.handlers.ResultHandler;
|
||||
import bisq.common.proto.network.NetworkEnvelope;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
import bisq.common.util.Tuple2;
|
||||
|
||||
@ -137,7 +138,7 @@ public class DisputeManager implements PersistedDataHost {
|
||||
OpenOfferManager openOfferManager,
|
||||
KeyRing keyRing,
|
||||
PersistenceProtoResolver persistenceProtoResolver,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir) {
|
||||
@Named(Storage.STORAGE_DIR) File storageDir, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.p2PService = p2PService;
|
||||
this.tradeWalletService = tradeWalletService;
|
||||
this.walletService = walletService;
|
||||
@ -147,7 +148,7 @@ public class DisputeManager implements PersistedDataHost {
|
||||
this.openOfferManager = openOfferManager;
|
||||
this.keyRing = keyRing;
|
||||
|
||||
disputeStorage = new Storage<>(storageDir, persistenceProtoResolver);
|
||||
disputeStorage = new Storage<>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
|
||||
openDisputes = new HashMap<>();
|
||||
closedDisputes = new HashMap<>();
|
||||
|
@ -55,6 +55,7 @@ import bisq.common.handlers.ResultHandler;
|
||||
import bisq.common.proto.network.NetworkEnvelope;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
@ -130,7 +131,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
PersistenceProtoResolver persistenceProtoResolver,
|
||||
TradeStatisticsManager tradeStatisticsManager,
|
||||
ArbitratorManager arbitratorManager,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir) {
|
||||
@Named(Storage.STORAGE_DIR) File storageDir, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.keyRing = keyRing;
|
||||
this.user = user;
|
||||
this.p2PService = p2PService;
|
||||
@ -144,7 +145,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
this.tradeStatisticsManager = tradeStatisticsManager;
|
||||
this.arbitratorManager = arbitratorManager;
|
||||
|
||||
openOfferTradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
|
||||
openOfferTradableListStorage = new Storage<>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
|
||||
// In case the app did get killed the shutDown from the modules is not called, so we use a shutdown hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
|
@ -50,6 +50,7 @@ import bisq.common.proto.network.NetworkProtoResolver;
|
||||
import bisq.common.proto.persistable.NavigationPath;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
@ -69,15 +70,18 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
|
||||
private final Provider<BtcWalletService> btcWalletService;
|
||||
private final NetworkProtoResolver networkProtoResolver;
|
||||
private final File storageDir;
|
||||
private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
|
||||
|
||||
@Inject
|
||||
public CorePersistenceProtoResolver(Provider<BtcWalletService> btcWalletService,
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir) {
|
||||
@Named(Storage.STORAGE_DIR) File storageDir,
|
||||
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.btcWalletService = btcWalletService;
|
||||
this.networkProtoResolver = networkProtoResolver;
|
||||
this.storageDir = storageDir;
|
||||
|
||||
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -93,14 +97,14 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
|
||||
case TRADABLE_LIST:
|
||||
return TradableList.fromProto(proto.getTradableList(),
|
||||
this,
|
||||
new Storage<>(storageDir, this),
|
||||
new Storage<>(storageDir, this, corruptedDatabaseFilesHandler),
|
||||
btcWalletService.get());
|
||||
case TRADE_STATISTICS_LIST:
|
||||
throw new ProtobufferRuntimeException("TRADE_STATISTICS_LIST is not used anymore");
|
||||
case DISPUTE_LIST:
|
||||
return DisputeList.fromProto(proto.getDisputeList(),
|
||||
this,
|
||||
new Storage<>(storageDir, this));
|
||||
new Storage<>(storageDir, this, corruptedDatabaseFilesHandler));
|
||||
case PREFERENCES_PAYLOAD:
|
||||
return PreferencesPayload.fromProto(proto.getPreferencesPayload(), this);
|
||||
case USER_PAYLOAD:
|
||||
|
@ -56,6 +56,7 @@ import bisq.common.handlers.ResultHandler;
|
||||
import bisq.common.proto.network.NetworkEnvelope;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import org.bitcoinj.core.AddressFormatException;
|
||||
@ -152,7 +153,7 @@ public class TradeManager implements PersistedDataHost {
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
ArbitratorManager arbitratorManager,
|
||||
ClockWatcher clockWatcher,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir) {
|
||||
@Named(Storage.STORAGE_DIR) File storageDir, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.user = user;
|
||||
this.keyRing = keyRing;
|
||||
this.btcWalletService = btcWalletService;
|
||||
@ -170,7 +171,7 @@ public class TradeManager implements PersistedDataHost {
|
||||
this.arbitratorManager = arbitratorManager;
|
||||
this.clockWatcher = clockWatcher;
|
||||
|
||||
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
|
||||
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
|
||||
p2PService.addDecryptedDirectMessageListener((decryptedMessageWithPubKey, peerNodeAddress) -> {
|
||||
NetworkEnvelope networkEnvelope = decryptedMessageWithPubKey.getNetworkEnvelope();
|
||||
|
@ -27,6 +27,7 @@ import bisq.core.trade.Trade;
|
||||
import bisq.common.crypto.KeyRing;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
@ -55,11 +56,11 @@ public class ClosedTradableManager implements PersistedDataHost {
|
||||
public ClosedTradableManager(KeyRing keyRing, PriceFeedService priceFeedService,
|
||||
PersistenceProtoResolver persistenceProtoResolver,
|
||||
BtcWalletService btcWalletService,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir) {
|
||||
@Named(Storage.STORAGE_DIR) File storageDir, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.keyRing = keyRing;
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.btcWalletService = btcWalletService;
|
||||
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
|
||||
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
// The ClosedTrades object can become a few MB so we don't keep so many backups
|
||||
tradableListStorage.setNumMaxBackupFiles(3);
|
||||
|
||||
|
@ -26,6 +26,7 @@ import bisq.core.trade.Trade;
|
||||
import bisq.common.crypto.KeyRing;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
@ -54,11 +55,11 @@ public class FailedTradesManager implements PersistedDataHost {
|
||||
public FailedTradesManager(KeyRing keyRing, PriceFeedService priceFeedService,
|
||||
PersistenceProtoResolver persistenceProtoResolver,
|
||||
BtcWalletService btcWalletService,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir) {
|
||||
@Named(Storage.STORAGE_DIR) File storageDir, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.keyRing = keyRing;
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.btcWalletService = btcWalletService;
|
||||
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver);
|
||||
tradableListStorage = new Storage<>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,12 @@ import bisq.network.p2p.peers.PeerManager;
|
||||
|
||||
import bisq.common.handlers.ErrorMessageHandler;
|
||||
import bisq.common.handlers.ResultHandler;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.core.offer.OfferMaker.btcUsdOffer;
|
||||
@ -19,6 +21,13 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
public class OpenOfferManagerTest {
|
||||
|
||||
private CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
corruptedDatabaseFilesHandler = mock(CorruptedDatabaseFilesHandler.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartEditOfferForActiveOffer() {
|
||||
P2PService p2PService = mock(P2PService.class);
|
||||
@ -29,7 +38,7 @@ public class OpenOfferManagerTest {
|
||||
final OpenOfferManager manager = new OpenOfferManager(null, null, p2PService,
|
||||
null, null, null, offerBookService,
|
||||
null, null, null, null,
|
||||
null, null, null);
|
||||
null, null, null, corruptedDatabaseFilesHandler);
|
||||
|
||||
AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false);
|
||||
|
||||
@ -64,7 +73,7 @@ public class OpenOfferManagerTest {
|
||||
final OpenOfferManager manager = new OpenOfferManager(null, null, p2PService,
|
||||
null, null, null, offerBookService,
|
||||
null, null, null, null,
|
||||
null, null, null);
|
||||
null, null, null, corruptedDatabaseFilesHandler);
|
||||
|
||||
AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false);
|
||||
|
||||
@ -91,7 +100,7 @@ public class OpenOfferManagerTest {
|
||||
final OpenOfferManager manager = new OpenOfferManager(null, null, p2PService,
|
||||
null, null, null, offerBookService,
|
||||
null, null, null, null,
|
||||
null, null, null);
|
||||
null, null, null, corruptedDatabaseFilesHandler);
|
||||
|
||||
AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false);
|
||||
|
||||
|
@ -21,6 +21,7 @@ import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -36,7 +37,7 @@ public class TradableListTest {
|
||||
@Test
|
||||
public void protoTesting() {
|
||||
OfferPayload offerPayload = mock(OfferPayload.class, RETURNS_DEEP_STUBS);
|
||||
Storage<TradableList<OpenOffer>> storage = new Storage<>(null, null);
|
||||
Storage<TradableList<OpenOffer>> storage = new Storage<>(null, null, mock(CorruptedDatabaseFilesHandler.class));
|
||||
TradableList<OpenOffer> openOfferTradableList = new TradableList<>(storage, "filename");
|
||||
protobuf.PersistableEnvelope message = (protobuf.PersistableEnvelope) openOfferTradableList.toProtoMessage();
|
||||
assertTrue(message.getMessageCase().equals(TRADABLE_LIST));
|
||||
|
@ -32,6 +32,7 @@ import bisq.core.user.Preferences;
|
||||
import bisq.core.user.User;
|
||||
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@ -56,6 +57,7 @@ class AltCoinAccountsDataModel extends ActivatableDataModel {
|
||||
private final SetChangeListener<PaymentAccount> setChangeListener;
|
||||
private final String accountsFileName = "AltcoinPaymentAccounts";
|
||||
private final PersistenceProtoResolver persistenceProtoResolver;
|
||||
private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
|
||||
|
||||
@Inject
|
||||
public AltCoinAccountsDataModel(User user,
|
||||
@ -63,13 +65,15 @@ class AltCoinAccountsDataModel extends ActivatableDataModel {
|
||||
OpenOfferManager openOfferManager,
|
||||
TradeManager tradeManager,
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
PersistenceProtoResolver persistenceProtoResolver) {
|
||||
PersistenceProtoResolver persistenceProtoResolver,
|
||||
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.user = user;
|
||||
this.preferences = preferences;
|
||||
this.openOfferManager = openOfferManager;
|
||||
this.tradeManager = tradeManager;
|
||||
this.accountAgeWitnessService = accountAgeWitnessService;
|
||||
this.persistenceProtoResolver = persistenceProtoResolver;
|
||||
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
|
||||
setChangeListener = change -> fillAndSortPaymentAccounts();
|
||||
}
|
||||
|
||||
@ -144,11 +148,11 @@ class AltCoinAccountsDataModel extends ActivatableDataModel {
|
||||
ArrayList<PaymentAccount> accounts = new ArrayList<>(user.getPaymentAccounts().stream()
|
||||
.filter(paymentAccount -> paymentAccount instanceof AssetAccount)
|
||||
.collect(Collectors.toList()));
|
||||
GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver);
|
||||
GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
}
|
||||
}
|
||||
|
||||
public void importAccounts(Stage stage) {
|
||||
GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver);
|
||||
GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import bisq.core.user.Preferences;
|
||||
import bisq.core.user.User;
|
||||
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@ -58,6 +59,7 @@ class FiatAccountsDataModel extends ActivatableDataModel {
|
||||
private final SetChangeListener<PaymentAccount> setChangeListener;
|
||||
private final String accountsFileName = "FiatPaymentAccounts";
|
||||
private final PersistenceProtoResolver persistenceProtoResolver;
|
||||
private final CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
|
||||
|
||||
@Inject
|
||||
public FiatAccountsDataModel(User user,
|
||||
@ -65,13 +67,15 @@ class FiatAccountsDataModel extends ActivatableDataModel {
|
||||
OpenOfferManager openOfferManager,
|
||||
TradeManager tradeManager,
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
PersistenceProtoResolver persistenceProtoResolver) {
|
||||
PersistenceProtoResolver persistenceProtoResolver,
|
||||
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.user = user;
|
||||
this.preferences = preferences;
|
||||
this.openOfferManager = openOfferManager;
|
||||
this.tradeManager = tradeManager;
|
||||
this.accountAgeWitnessService = accountAgeWitnessService;
|
||||
this.persistenceProtoResolver = persistenceProtoResolver;
|
||||
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
|
||||
setChangeListener = change -> fillAndSortPaymentAccounts();
|
||||
}
|
||||
|
||||
@ -147,11 +151,11 @@ class FiatAccountsDataModel extends ActivatableDataModel {
|
||||
ArrayList<PaymentAccount> accounts = new ArrayList<>(user.getPaymentAccounts().stream()
|
||||
.filter(paymentAccount -> !(paymentAccount instanceof AssetAccount))
|
||||
.collect(Collectors.toList()));
|
||||
GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver);
|
||||
GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
}
|
||||
}
|
||||
|
||||
public void importAccounts(Stage stage) {
|
||||
GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver);
|
||||
GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ import bisq.common.UserThread;
|
||||
import bisq.common.app.DevEnv;
|
||||
import bisq.common.proto.persistable.PersistableList;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.FileUtil;
|
||||
import bisq.common.storage.Storage;
|
||||
import bisq.common.util.Tuple2;
|
||||
@ -189,11 +190,11 @@ public class GUIUtil {
|
||||
}
|
||||
|
||||
public static void exportAccounts(ArrayList<PaymentAccount> accounts, String fileName,
|
||||
Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver) {
|
||||
Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
if (!accounts.isEmpty()) {
|
||||
String directory = getDirectoryFromChooser(preferences, stage);
|
||||
if (directory != null && !directory.isEmpty()) {
|
||||
Storage<PersistableList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
|
||||
Storage<PersistableList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
paymentAccountsStorage.initAndGetPersisted(new PaymentAccountList(accounts), fileName, 100);
|
||||
paymentAccountsStorage.queueUpForSave();
|
||||
new Popup<>().feedback(Res.get("guiUtil.accountExport.savedToPath", Paths.get(directory, fileName).toAbsolutePath())).show();
|
||||
@ -204,7 +205,7 @@ public class GUIUtil {
|
||||
}
|
||||
|
||||
public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage,
|
||||
PersistenceProtoResolver persistenceProtoResolver) {
|
||||
PersistenceProtoResolver persistenceProtoResolver, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
File initDir = new File(preferences.getDirectoryChooserPath());
|
||||
if (initDir.isDirectory()) {
|
||||
@ -217,7 +218,7 @@ public class GUIUtil {
|
||||
if (Paths.get(path).getFileName().toString().equals(fileName)) {
|
||||
String directory = Paths.get(path).getParent().toString();
|
||||
preferences.setDirectoryChooserPath(directory);
|
||||
Storage<PaymentAccountList> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
|
||||
Storage<PaymentAccountList> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
PaymentAccountList persisted = paymentAccountsStorage.initAndGetPersistedWithFileName(fileName, 100);
|
||||
if (persisted != null) {
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
|
@ -45,6 +45,7 @@ import bisq.common.app.Capabilities;
|
||||
import bisq.common.app.Capability;
|
||||
import bisq.common.proto.network.NetworkEnvelope;
|
||||
import bisq.common.proto.network.NetworkProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
@ -136,13 +137,14 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
|
||||
return "";
|
||||
}
|
||||
});
|
||||
CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler = new CorruptedDatabaseFilesHandler();
|
||||
int maxConnections = Integer.parseInt(configuration.getProperty(MAX_CONNECTIONS, "12"));
|
||||
NetworkProtoResolver networkProtoResolver = new CoreNetworkProtoResolver();
|
||||
CorePersistenceProtoResolver persistenceProtoResolver = new CorePersistenceProtoResolver(null,
|
||||
networkProtoResolver, storageDir);
|
||||
networkProtoResolver, storageDir, corruptedDatabaseFilesHandler);
|
||||
DefaultSeedNodeRepository seedNodeRepository = new DefaultSeedNodeRepository(environment, null);
|
||||
PeerManager peerManager = new PeerManager(networkNode, seedNodeRepository, new ClockWatcher(),
|
||||
persistenceProtoResolver, maxConnections, storageDir);
|
||||
persistenceProtoResolver, maxConnections, storageDir, corruptedDatabaseFilesHandler);
|
||||
|
||||
// init file storage
|
||||
peerManager.readPersisted();
|
||||
|
@ -35,6 +35,7 @@ import bisq.common.UserThread;
|
||||
import bisq.common.app.Capabilities;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||
import bisq.common.storage.Storage;
|
||||
|
||||
import com.google.inject.name.Named;
|
||||
@ -135,11 +136,11 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
|
||||
ClockWatcher clockWatcher,
|
||||
PersistenceProtoResolver persistenceProtoResolver,
|
||||
@Named(NetworkOptionKeys.MAX_CONNECTIONS) int maxConnections,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir) {
|
||||
@Named(Storage.STORAGE_DIR) File storageDir, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) {
|
||||
this.networkNode = networkNode;
|
||||
this.seedNodeAddresses = new HashSet<>(seedNodeRepository.getSeedNodeAddresses());
|
||||
this.clockWatcher = clockWatcher;
|
||||
storage = new Storage<>(storageDir, persistenceProtoResolver);
|
||||
storage = new Storage<>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler);
|
||||
|
||||
this.networkNode.addConnectionListener(this);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user