Skip to content

Commit

Permalink
Merge pull request #495 from alvasw/bitcoind_add_createmulti_rpc_call
Browse files Browse the repository at this point in the history
Bitcoind: Add createmulti RPC call
  • Loading branch information
chimp1984 authored Sep 18, 2022
2 parents 24a0f07 + 5bcfee1 commit cf1e035
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,22 @@ public void shutdown() {
daemon.unloadWallet(walletPath);
}

public BitcoindAddMultisigAddressResponse addMultiSigAddress(int nRequired, List<String> keys) {
public BitcoindAddOrCreateMultiSigAddressResponse createMultiSig(int nRequired, List<String> keys) {
var request = BitcoindCreateMultiSigRpcCall.Request.builder()
.nRequired(nRequired)
.keys(keys)
.build();
var rpcCall = new BitcoindCreateMultiSigRpcCall(request);
return rpcClient.invokeAndValidate(rpcCall);
}

public BitcoindAddOrCreateMultiSigAddressResponse addMultiSigAddress(int nRequired, List<String> keys) {
var request = BitcoindAddMultiSigAddressRpcCall.Request.builder()
.nRequired(nRequired)
.keys(keys)
.build();
var rpcCall = new BitcoindAddMultiSigAddressRpcCall(request);
return rpcClient.invokeAndValidate(rpcCall);

}

public BitcoindGetAddressInfoResponse getAddressInfo(String address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package bisq.wallets.bitcoind.rpc.calls;

import bisq.wallets.bitcoind.rpc.responses.BitcoindAddMultisigAddressResponse;
import bisq.wallets.bitcoind.rpc.responses.BitcoindAddOrCreateMultiSigAddressResponse;
import bisq.wallets.core.rpc.call.WalletRpcCall;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
Expand All @@ -26,7 +26,7 @@
import java.util.List;

public class BitcoindAddMultiSigAddressRpcCall
extends WalletRpcCall<BitcoindAddMultiSigAddressRpcCall.Request, BitcoindAddMultisigAddressResponse> {
extends WalletRpcCall<BitcoindAddMultiSigAddressRpcCall.Request, BitcoindAddOrCreateMultiSigAddressResponse> {
@Builder
@Getter
public static class Request {
Expand All @@ -45,12 +45,12 @@ public String getRpcMethodName() {
}

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

@Override
public Class<BitcoindAddMultisigAddressResponse> getRpcResponseClass() {
return BitcoindAddMultisigAddressResponse.class;
public Class<BitcoindAddOrCreateMultiSigAddressResponse> getRpcResponseClass() {
return BitcoindAddOrCreateMultiSigAddressResponse.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.BitcoindAddOrCreateMultiSigAddressResponse;
import bisq.wallets.core.rpc.call.WalletRpcCall;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Getter;

import java.util.List;

public class BitcoindCreateMultiSigRpcCall
extends WalletRpcCall<BitcoindCreateMultiSigRpcCall.Request, BitcoindAddOrCreateMultiSigAddressResponse> {

@Builder
@Getter
public static class Request {
@JsonProperty("nrequired")
private int nRequired;
private List<String> keys;
@JsonProperty("address_type")
private String addressType;
}

public BitcoindCreateMultiSigRpcCall(Request request) {
super(request);
}

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

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

@Override
public Class<BitcoindAddOrCreateMultiSigAddressResponse> getRpcResponseClass() {
return BitcoindAddOrCreateMultiSigAddressResponse.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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;

@Getter
@Setter
public class BitcoindAddOrCreateMultiSigAddressResponse {
private String address;
private String redeemScript;
private String descriptor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@Getter
@Setter
public class BitcoindAddMultisigAddressResponse {
public class BitcoindCreateMultiSigResponse {
private String address;
private String redeemScript;
private String descriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public void psbtMultiSigTest() throws MalformedURLException, InterruptedExceptio
keys.add(bobAddrInfo.getPubkey());
keys.add(charlieAddrInfo.getPubkey());

BitcoindAddMultisigAddressResponse aliceMultiSigAddrResponse = aliceBackend.addMultiSigAddress(2, keys);
BitcoindAddMultisigAddressResponse bobMultiSigAddrResponse = bobBackend.addMultiSigAddress(2, keys);
BitcoindAddMultisigAddressResponse charlieMultiSigAddrResponse = charlieBackend.addMultiSigAddress(2, keys);
BitcoindAddOrCreateMultiSigAddressResponse aliceMultiSigAddrResponse = aliceBackend.addMultiSigAddress(2, keys);
BitcoindAddOrCreateMultiSigAddressResponse bobMultiSigAddrResponse = bobBackend.addMultiSigAddress(2, keys);
BitcoindAddOrCreateMultiSigAddressResponse charlieMultiSigAddrResponse = charlieBackend.addMultiSigAddress(2, keys);

aliceBackend.importAddress(aliceMultiSigAddrResponse.getAddress(), "");
bobBackend.importAddress(bobMultiSigAddrResponse.getAddress(), "");
Expand Down

0 comments on commit cf1e035

Please sign in to comment.