fix account export and import without key ring #1221

This commit is contained in:
woodser 2024-09-26 12:58:19 -04:00
parent 3e3f3085f8
commit 3ffda0fdd1
3 changed files with 10 additions and 21 deletions

View File

@ -18,7 +18,6 @@
package haveno.desktop.main.account.content.cryptoaccounts; package haveno.desktop.main.account.content.cryptoaccounts;
import com.google.inject.Inject; import com.google.inject.Inject;
import haveno.common.crypto.KeyRing;
import haveno.common.file.CorruptedStorageFileHandler; import haveno.common.file.CorruptedStorageFileHandler;
import haveno.common.proto.persistable.PersistenceProtoResolver; import haveno.common.proto.persistable.PersistenceProtoResolver;
import haveno.core.account.witness.AccountAgeWitnessService; import haveno.core.account.witness.AccountAgeWitnessService;
@ -55,7 +54,6 @@ class CryptoAccountsDataModel extends ActivatableDataModel {
private final String accountsFileName = "CryptoPaymentAccounts"; private final String accountsFileName = "CryptoPaymentAccounts";
private final PersistenceProtoResolver persistenceProtoResolver; private final PersistenceProtoResolver persistenceProtoResolver;
private final CorruptedStorageFileHandler corruptedStorageFileHandler; private final CorruptedStorageFileHandler corruptedStorageFileHandler;
private final KeyRing keyRing;
@Inject @Inject
public CryptoAccountsDataModel(User user, public CryptoAccountsDataModel(User user,
@ -64,8 +62,7 @@ class CryptoAccountsDataModel extends ActivatableDataModel {
TradeManager tradeManager, TradeManager tradeManager,
AccountAgeWitnessService accountAgeWitnessService, AccountAgeWitnessService accountAgeWitnessService,
PersistenceProtoResolver persistenceProtoResolver, PersistenceProtoResolver persistenceProtoResolver,
CorruptedStorageFileHandler corruptedStorageFileHandler, CorruptedStorageFileHandler corruptedStorageFileHandler) {
KeyRing keyRing) {
this.user = user; this.user = user;
this.preferences = preferences; this.preferences = preferences;
this.openOfferManager = openOfferManager; this.openOfferManager = openOfferManager;
@ -73,7 +70,6 @@ class CryptoAccountsDataModel extends ActivatableDataModel {
this.accountAgeWitnessService = accountAgeWitnessService; this.accountAgeWitnessService = accountAgeWitnessService;
this.persistenceProtoResolver = persistenceProtoResolver; this.persistenceProtoResolver = persistenceProtoResolver;
this.corruptedStorageFileHandler = corruptedStorageFileHandler; this.corruptedStorageFileHandler = corruptedStorageFileHandler;
this.keyRing = keyRing;
setChangeListener = change -> fillAndSortPaymentAccounts(); setChangeListener = change -> fillAndSortPaymentAccounts();
} }
@ -157,12 +153,12 @@ class CryptoAccountsDataModel extends ActivatableDataModel {
ArrayList<PaymentAccount> accounts = new ArrayList<>(user.getPaymentAccounts().stream() ArrayList<PaymentAccount> accounts = new ArrayList<>(user.getPaymentAccounts().stream()
.filter(paymentAccount -> paymentAccount instanceof AssetAccount) .filter(paymentAccount -> paymentAccount instanceof AssetAccount)
.collect(Collectors.toList())); .collect(Collectors.toList()));
GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler, keyRing); GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler);
} }
} }
public void importAccounts(Stage stage) { public void importAccounts(Stage stage) {
GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler, keyRing); GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler);
} }
public int getNumPaymentAccounts() { public int getNumPaymentAccounts() {

View File

@ -18,7 +18,6 @@
package haveno.desktop.main.account.content.traditionalaccounts; package haveno.desktop.main.account.content.traditionalaccounts;
import com.google.inject.Inject; import com.google.inject.Inject;
import haveno.common.crypto.KeyRing;
import haveno.common.file.CorruptedStorageFileHandler; import haveno.common.file.CorruptedStorageFileHandler;
import haveno.common.proto.persistable.PersistenceProtoResolver; import haveno.common.proto.persistable.PersistenceProtoResolver;
import haveno.core.account.witness.AccountAgeWitnessService; import haveno.core.account.witness.AccountAgeWitnessService;
@ -56,7 +55,6 @@ class TraditionalAccountsDataModel extends ActivatableDataModel {
private final String accountsFileName = "FiatPaymentAccounts"; private final String accountsFileName = "FiatPaymentAccounts";
private final PersistenceProtoResolver persistenceProtoResolver; private final PersistenceProtoResolver persistenceProtoResolver;
private final CorruptedStorageFileHandler corruptedStorageFileHandler; private final CorruptedStorageFileHandler corruptedStorageFileHandler;
private final KeyRing keyRing;
@Inject @Inject
public TraditionalAccountsDataModel(User user, public TraditionalAccountsDataModel(User user,
@ -65,8 +63,7 @@ class TraditionalAccountsDataModel extends ActivatableDataModel {
TradeManager tradeManager, TradeManager tradeManager,
AccountAgeWitnessService accountAgeWitnessService, AccountAgeWitnessService accountAgeWitnessService,
PersistenceProtoResolver persistenceProtoResolver, PersistenceProtoResolver persistenceProtoResolver,
CorruptedStorageFileHandler corruptedStorageFileHandler, CorruptedStorageFileHandler corruptedStorageFileHandler) {
KeyRing keyRing) {
this.user = user; this.user = user;
this.preferences = preferences; this.preferences = preferences;
this.openOfferManager = openOfferManager; this.openOfferManager = openOfferManager;
@ -74,7 +71,6 @@ class TraditionalAccountsDataModel extends ActivatableDataModel {
this.accountAgeWitnessService = accountAgeWitnessService; this.accountAgeWitnessService = accountAgeWitnessService;
this.persistenceProtoResolver = persistenceProtoResolver; this.persistenceProtoResolver = persistenceProtoResolver;
this.corruptedStorageFileHandler = corruptedStorageFileHandler; this.corruptedStorageFileHandler = corruptedStorageFileHandler;
this.keyRing = keyRing;
setChangeListener = change -> fillAndSortPaymentAccounts(); setChangeListener = change -> fillAndSortPaymentAccounts();
} }
@ -159,12 +155,12 @@ class TraditionalAccountsDataModel extends ActivatableDataModel {
ArrayList<PaymentAccount> accounts = new ArrayList<>(user.getPaymentAccounts().stream() ArrayList<PaymentAccount> accounts = new ArrayList<>(user.getPaymentAccounts().stream()
.filter(paymentAccount -> !(paymentAccount instanceof AssetAccount)) .filter(paymentAccount -> !(paymentAccount instanceof AssetAccount))
.collect(Collectors.toList())); .collect(Collectors.toList()));
GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler, keyRing); GUIUtil.exportAccounts(accounts, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler);
} }
} }
public void importAccounts(Stage stage) { public void importAccounts(Stage stage) {
GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler, keyRing); GUIUtil.importAccounts(user, accountsFileName, preferences, stage, persistenceProtoResolver, corruptedStorageFileHandler);
} }
public int getNumPaymentAccounts() { public int getNumPaymentAccounts() {

View File

@ -28,7 +28,6 @@ import com.googlecode.jcsv.writer.internal.CSVWriterBuilder;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import haveno.common.UserThread; import haveno.common.UserThread;
import haveno.common.config.Config; import haveno.common.config.Config;
import haveno.common.crypto.KeyRing;
import haveno.common.file.CorruptedStorageFileHandler; import haveno.common.file.CorruptedStorageFileHandler;
import haveno.common.persistence.PersistenceManager; import haveno.common.persistence.PersistenceManager;
import haveno.common.proto.persistable.PersistableEnvelope; import haveno.common.proto.persistable.PersistableEnvelope;
@ -168,12 +167,11 @@ public class GUIUtil {
Preferences preferences, Preferences preferences,
Stage stage, Stage stage,
PersistenceProtoResolver persistenceProtoResolver, PersistenceProtoResolver persistenceProtoResolver,
CorruptedStorageFileHandler corruptedStorageFileHandler, CorruptedStorageFileHandler corruptedStorageFileHandler) {
KeyRing keyRing) {
if (!accounts.isEmpty()) { if (!accounts.isEmpty()) {
String directory = getDirectoryFromChooser(preferences, stage); String directory = getDirectoryFromChooser(preferences, stage);
if (!directory.isEmpty()) { if (!directory.isEmpty()) {
PersistenceManager<PersistableEnvelope> persistenceManager = new PersistenceManager<>(new File(directory), persistenceProtoResolver, corruptedStorageFileHandler, keyRing); PersistenceManager<PersistableEnvelope> persistenceManager = new PersistenceManager<>(new File(directory), persistenceProtoResolver, corruptedStorageFileHandler, null);
PaymentAccountList paymentAccounts = new PaymentAccountList(accounts); PaymentAccountList paymentAccounts = new PaymentAccountList(accounts);
persistenceManager.initialize(paymentAccounts, fileName, PersistenceManager.Source.PRIVATE_LOW_PRIO); persistenceManager.initialize(paymentAccounts, fileName, PersistenceManager.Source.PRIVATE_LOW_PRIO);
persistenceManager.persistNow(() -> { persistenceManager.persistNow(() -> {
@ -193,8 +191,7 @@ public class GUIUtil {
Preferences preferences, Preferences preferences,
Stage stage, Stage stage,
PersistenceProtoResolver persistenceProtoResolver, PersistenceProtoResolver persistenceProtoResolver,
CorruptedStorageFileHandler corruptedStorageFileHandler, CorruptedStorageFileHandler corruptedStorageFileHandler) {
KeyRing keyRing) {
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
File initDir = new File(preferences.getDirectoryChooserPath()); File initDir = new File(preferences.getDirectoryChooserPath());
if (initDir.isDirectory()) { if (initDir.isDirectory()) {
@ -207,7 +204,7 @@ public class GUIUtil {
if (Paths.get(path).getFileName().toString().equals(fileName)) { if (Paths.get(path).getFileName().toString().equals(fileName)) {
String directory = Paths.get(path).getParent().toString(); String directory = Paths.get(path).getParent().toString();
preferences.setDirectoryChooserPath(directory); preferences.setDirectoryChooserPath(directory);
PersistenceManager<PaymentAccountList> persistenceManager = new PersistenceManager<>(new File(directory), persistenceProtoResolver, corruptedStorageFileHandler, keyRing); PersistenceManager<PaymentAccountList> persistenceManager = new PersistenceManager<>(new File(directory), persistenceProtoResolver, corruptedStorageFileHandler, null);
persistenceManager.readPersisted(fileName, persisted -> { persistenceManager.readPersisted(fileName, persisted -> {
StringBuilder msg = new StringBuilder(); StringBuilder msg = new StringBuilder();
HashSet<PaymentAccount> paymentAccounts = new HashSet<>(); HashSet<PaymentAccount> paymentAccounts = new HashSet<>();