Skip to content

Commit

Permalink
Merge pull request #577 from alvasw/fix_elements_core_legacy_wallet
Browse files Browse the repository at this point in the history
ElementsDaemon: Create/Use legacy wallet
  • Loading branch information
alvasw authored Nov 30, 2022
2 parents 699a728 + c677550 commit f81beac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ public BitcoindDaemon(DaemonRpcClient rpcClient) {
}

public void createOrLoadWallet(String walletName, Optional<String> passphrase) {
createOrLoadWallet(walletName, passphrase, false, false);
createOrLoadWallet(walletName, passphrase, true, false, false);
}

public void createOrLoadLegacyWallet(String walletName, Optional<String> passphrase) {
createOrLoadWallet(walletName, passphrase, false, false, false);
}

public void createOrLoadWatchOnlyWallet(String walletName) {
createOrLoadWallet(walletName, Optional.empty(), true, true);
createOrLoadWallet(walletName, Optional.empty(), true, true, true);
}

private void createOrLoadWallet(String walletName, Optional<String> passphrase, boolean disablePrivateKeys, boolean blank) {
private void createOrLoadWallet(String walletName, Optional<String> passphrase, boolean descriptors, boolean disablePrivateKeys, boolean blank) {
try {
createWallet(walletName, passphrase.orElse(""), disablePrivateKeys, blank);
createWallet(walletName, passphrase.orElse(""), descriptors, disablePrivateKeys, blank);
} catch (RpcCallFailureException e) {
if (doesWalletExist(e)) {
List<String> loadedWallets = listWallets();
Expand Down Expand Up @@ -146,9 +150,10 @@ private boolean doesWalletExist(RpcCallFailureException e) {
return e.getCause().getMessage().contains("Database already exists.");
}

private void createWallet(String walletName, String passphrase, boolean disablePrivateKeys, boolean blank) {
private void createWallet(String walletName, String passphrase, boolean descriptors, boolean disablePrivateKeys, boolean blank) {
var request = BitcoindCreateWalletRpcCall.Request.builder()
.walletName(walletName)
.descriptors(descriptors)
.disablePrivateKeys(disablePrivateKeys)
.blank(blank)
.passphrase(passphrase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class Request {
private String passphrase;
@JsonProperty("avoid_reuse")
private Boolean avoidReuse;
private final boolean descriptors = true;
private boolean descriptors;
}

public BitcoindCreateWalletRpcCall(Request request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ElementsdDaemon(DaemonRpcClient rpcClient) {
}

public void createOrLoadWallet(String walletName, Optional<String> passphrase) {
bitcoindDaemon.createOrLoadWallet(walletName, passphrase);
bitcoindDaemon.createOrLoadLegacyWallet(walletName, passphrase);
}

public ElementsdDecodeRawTransactionResponse decodeRawTransaction(String txInHex) {
Expand Down

0 comments on commit f81beac

Please sign in to comment.