From 826148c2f0946354b924a24581d9cfe9a899b4bd Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Tue, 13 Sep 2022 11:18:24 +0200 Subject: [PATCH 1/2] Bitcoind: Force native descriptor wallet creation See https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-23.0.md --- .../wallets/bitcoind/rpc/calls/BitcoindCreateWalletRpcCall.java | 1 + 1 file changed, 1 insertion(+) diff --git a/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindCreateWalletRpcCall.java b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindCreateWalletRpcCall.java index 0b37818537..b014bdbf6c 100644 --- a/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindCreateWalletRpcCall.java +++ b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindCreateWalletRpcCall.java @@ -32,6 +32,7 @@ public static class Request { @JsonProperty("wallet_name") private String walletName; private String passphrase; + private final boolean descriptors = true; } public BitcoindCreateWalletRpcCall(Request request) { From a56cff22c942bccb2989cd844f79ced1ffda378f Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Wed, 14 Sep 2022 13:14:25 +0200 Subject: [PATCH 2/2] Bitcoind: Add listdescriptors RPC call Bitcoin Core creates by default native descriptor wallets now. Currently, we cannot access the descriptors. --- .../wallets/bitcoind/rpc/BitcoindWallet.java | 5 ++ .../calls/BitcoindListDescriptorsRpcCall.java | 44 +++++++++++++++++ .../rpc/responses/BitcoindDescriptor.java | 34 +++++++++++++ .../BitcoindListDescriptorResponse.java | 32 +++++++++++++ ...itcoindListDescriptorsIntegrationTest.java | 48 +++++++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindListDescriptorsRpcCall.java create mode 100644 wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindDescriptor.java create mode 100644 wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListDescriptorResponse.java create mode 100644 wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindListDescriptorsIntegrationTest.java diff --git a/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/BitcoindWallet.java b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/BitcoindWallet.java index bcb922f007..30a97b4445 100644 --- a/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/BitcoindWallet.java +++ b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/BitcoindWallet.java @@ -114,6 +114,11 @@ public List importMulti(List listTransactions(int count) { var request = BitcoindListTransactionsRpcCall.Request.builder() .count(count) diff --git a/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindListDescriptorsRpcCall.java b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindListDescriptorsRpcCall.java new file mode 100644 index 0000000000..c6c7d62c3a --- /dev/null +++ b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/calls/BitcoindListDescriptorsRpcCall.java @@ -0,0 +1,44 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.wallets.bitcoind.rpc.calls; + +import bisq.wallets.bitcoind.rpc.responses.BitcoindListDescriptorResponse; +import bisq.wallets.core.rpc.call.WalletRpcCall; + +public class BitcoindListDescriptorsRpcCall + extends WalletRpcCall { + + public BitcoindListDescriptorsRpcCall() { + super(null); + } + + @Override + public String getRpcMethodName() { + return "listdescriptors"; + } + + @Override + public boolean isResponseValid(BitcoindListDescriptorResponse response) { + return true; + } + + @Override + public Class getRpcResponseClass() { + return BitcoindListDescriptorResponse.class; + } +} diff --git a/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindDescriptor.java b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindDescriptor.java new file mode 100644 index 0000000000..7b03502aaf --- /dev/null +++ b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindDescriptor.java @@ -0,0 +1,34 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.wallets.bitcoind.rpc.responses; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class BitcoindDescriptor { + private String desc; + private long timestamp; + private boolean active; + private boolean internal; + private List range; + private Integer next; +} diff --git a/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListDescriptorResponse.java b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListDescriptorResponse.java new file mode 100644 index 0000000000..c177692528 --- /dev/null +++ b/wallets/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListDescriptorResponse.java @@ -0,0 +1,32 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.wallets.bitcoind.rpc.responses; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class BitcoindListDescriptorResponse { + @JsonProperty("wallet_name") + private String walletName; + private List descriptors; +} diff --git a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindListDescriptorsIntegrationTest.java b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindListDescriptorsIntegrationTest.java new file mode 100644 index 0000000000..f14bfb9da7 --- /dev/null +++ b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindListDescriptorsIntegrationTest.java @@ -0,0 +1,48 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.wallets.bitcoind; + +import bisq.wallets.bitcoind.regtest.BitcoindExtension; +import bisq.wallets.bitcoind.rpc.BitcoindWallet; +import bisq.wallets.bitcoind.rpc.responses.BitcoindDescriptor; +import bisq.wallets.bitcoind.rpc.responses.BitcoindListDescriptorResponse; +import bisq.wallets.regtest.bitcoind.BitcoindRegtestSetup; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(BitcoindExtension.class) +public class BitcoindListDescriptorsIntegrationTest { + private final BitcoindWallet minerWallet; + + public BitcoindListDescriptorsIntegrationTest(BitcoindRegtestSetup regtestSetup) { + this.minerWallet = regtestSetup.getMinerWallet(); + } + + @Test + void listDescriptorsTest() { + BitcoindListDescriptorResponse response = minerWallet.listDescriptors(); + List descriptorList = response.getDescriptors(); + + assertThat(descriptorList).isNotEmpty() + .anySatisfy(descriptor -> assertThat(descriptor.getDesc()).startsWith("pkh([")); + } +}