Skip to content

Commit

Permalink
Bitcoind: Add listdescriptors RPC call
Browse files Browse the repository at this point in the history
Bitcoin Core creates by default native descriptor wallets now. Currently,
we cannot access the descriptors.
  • Loading branch information
alvasw committed Sep 27, 2022
1 parent 826148c commit a56cff2
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public List<BitcoinImportMultiEntryResponse> importMulti(List<BitcoindImportMult
return Arrays.asList(response);
}

public BitcoindListDescriptorResponse listDescriptors() {
var rpcCall = new BitcoindListDescriptorsRpcCall();
return rpcClient.invokeAndValidate(rpcCall);
}

public List<BitcoindListTransactionsResponseEntry> listTransactions(int count) {
var request = BitcoindListTransactionsRpcCall.Request.builder()
.count(count)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<Void, BitcoindListDescriptorResponse> {

public BitcoindListDescriptorsRpcCall() {
super(null);
}

@Override
public String getRpcMethodName() {
return "listdescriptors";
}

@Override
public boolean isResponseValid(BitcoindListDescriptorResponse response) {
return true;
}

@Override
public Class<BitcoindListDescriptorResponse> getRpcResponseClass() {
return BitcoindListDescriptorResponse.class;
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<Integer> range;
private Integer next;
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<BitcoindDescriptor> descriptors;
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<BitcoindDescriptor> descriptorList = response.getDescriptors();

assertThat(descriptorList).isNotEmpty()
.anySatisfy(descriptor -> assertThat(descriptor.getDesc()).startsWith("pkh(["));
}
}

0 comments on commit a56cff2

Please sign in to comment.