Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet: Save WalletFile by default in data directory #280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public DefaultApplicationService(String[] args) {
protocolService = new ProtocolService(networkService, identityService, persistenceService, openOfferService);

Optional<WalletConfig> walletConfig = !isRegtestRun() ? Optional.empty() : createRegtestWalletConfig();
walletService = new WalletService(persistenceService, walletConfig);
Path walletsDataDir = Path.of(applicationConfig.baseDir() + File.separator + "wallets");
alvasw marked this conversation as resolved.
Show resolved Hide resolved
walletService = new WalletService(persistenceService, walletsDataDir, walletConfig);

daoBridgeService = new DaoBridgeService(networkService, identityService, getConfig("bisq.oracle.daoBridge"));
}
Expand Down Expand Up @@ -253,9 +254,6 @@ private boolean isRegtestRun() {
}

private Optional<WalletConfig> createRegtestWalletConfig() {
String walletsDataDir = applicationConfig.baseDir() + File.separator + "wallets";
Path walletsDataDirPath = FileSystems.getDefault().getPath(walletsDataDir);

WalletBackend walletBackend = applicationConfig.isBitcoindRegtest() ?
WalletBackend.BITCOIND : WalletBackend.ELEMENTSD;

Expand All @@ -266,7 +264,6 @@ private Optional<WalletConfig> createRegtestWalletConfig() {
.port(Optional.empty())
.user("bisq")
.password("bisq")
.walletsDataDirPath(walletsDataDirPath)
.build();
return Optional.of(walletConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ private Controller(DefaultApplicationService applicationService, Popup popup, Ru

model = new Model();
view = new View(model, this, popup);
model.walletsDataDirPathProperty.set(applicationService.getApplicationConfig().baseDir() + File.separator + "wallets");
}

@Override
Expand Down Expand Up @@ -109,14 +108,6 @@ private void onConnectToWallet() {
});
}

private void onSelectWalletPath() {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setInitialDirectory(new File(model.walletsDataDirPathProperty.get()));
directoryChooser.setTitle(Res.get("wallet.config.walletsDataDirPath"));
File file = directoryChooser.showDialog(popup.getGridPane().getScene().getWindow());
model.walletsDataDirPathProperty.set(file.getAbsolutePath());
}

private WalletConfig createWalletConfigFromModel() {
return WalletConfig.builder()
.walletBackend(model.selectedWalletBackend.get())
Expand All @@ -125,7 +116,6 @@ private WalletConfig createWalletConfigFromModel() {
.port(Optional.of(Integer.parseInt(model.portProperty.get())))
.user(model.usernameProperty.get())
.password(model.passwordProperty.get())
.walletsDataDirPath(Path.of(model.walletsDataDirPathProperty.get()))
.build();
}

Expand All @@ -140,7 +130,6 @@ private static class Model implements bisq.desktop.common.view.Model {
private final ObjectProperty<WalletBackend> selectedWalletBackend =
new SimpleObjectProperty<>(this, "selectedWalletBackend", WalletBackend.BITCOIND);

private final StringProperty walletsDataDirPathProperty = new SimpleStringProperty(this, "walletPath");
private final StringProperty hostnameProperty = new SimpleStringProperty(this, "hostname", "127.0.0.1");
private final StringProperty portProperty = new SimpleStringProperty(this, "port", "18443");
private final StringProperty usernameProperty = new SimpleStringProperty(this, "username", "bisq");
Expand Down Expand Up @@ -173,9 +162,6 @@ protected void onViewDetached() {
private void addContent() {
BisqGridPane gridPane = popup.getGridPane();

gridPane.addButton(Res.get("wallet.config.selectWalletPath"), controller::onSelectWalletPath);
gridPane.addTextField(Res.get("wallet.config.walletsDataDirPath"), model.walletsDataDirPathProperty);

AutoCompleteComboBox<WalletBackend> walletBackendComboBox = gridPane.addComboBox(model.walletBackends);
walletBackendComboBox.setPromptText(Res.get("wallet.config.selectWallet"));
walletBackendComboBox.valueProperty().bindBidirectional(model.selectedWalletBackend);
Expand Down
2 changes: 0 additions & 2 deletions i18n/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ wallet.availableBalance=Available Balance
# Wallet Configuration Dialog
wallet.config.title=Wallet Configuration
wallet.config.header=Connect to External Wallet
wallet.config.selectWalletPath=Select wallet path
wallet.config.walletsDataDirPath=Wallets data dir path
wallet.config.selectWallet=Select a Wallet:
wallet.config.enterHostname=Enter hostname of host running the wallet (e.g. 127.0.0.1):
wallet.config.enterPort=Enter the RPC port (default: 8332, regtest: 18443):
Expand Down
1 change: 0 additions & 1 deletion wallets/src/main/java/bisq/wallets/WalletConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ public class WalletConfig {
private final Optional<Integer> port;
private final String user;
private final String password;
private final Path walletsDataDirPath;
}
5 changes: 3 additions & 2 deletions wallets/src/main/java/bisq/wallets/WalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class WalletService implements PersistenceClient<WalletStore> {
private final WalletStore persistableStore = new WalletStore();
@Getter
private final Persistence<WalletStore> persistence;

private final Path walletsDataDir;
private final Optional<WalletConfig> walletConfig;
@Getter
private Optional<Wallet> wallet = Optional.empty();
Expand All @@ -59,8 +59,10 @@ public class WalletService implements PersistenceClient<WalletStore> {
private final Observable<Coin> observableBalanceAsCoin = new Observable<>(Coin.of(0, "BTC"));

public WalletService(PersistenceService persistenceService,
Path walletsDataDir,
Optional<WalletConfig> walletConfig) {
persistence = persistenceService.getOrCreatePersistence(this, persistableStore);
this.walletsDataDir = walletsDataDir;
this.walletConfig = walletConfig;
}

Expand All @@ -76,7 +78,6 @@ public CompletableFuture<Boolean> initialize() {

public CompletableFuture<Boolean> loadOrCreateWallet(WalletConfig walletConfig, Optional<String> walletPassphrase) {
if (wallet.isEmpty()) {
Path walletsDataDir = walletConfig.getWalletsDataDirPath();
walletsDataDir.toFile().mkdirs();

Wallet wallet = switch (walletConfig.getWalletBackend()) {
Expand Down