detect if output descriptor represents a cosigner

This commit is contained in:
Craig Raw 2021-12-14 11:20:45 +02:00
parent 60e989b946
commit 6ac593f161

View file

@ -132,6 +132,10 @@ public class OutputDescriptor {
return extendedPublicKeys.size() > 1; return extendedPublicKeys.size() > 1;
} }
public boolean isCosigner() {
return !isMultisig() && scriptType.isAllowed(PolicyType.MULTI);
}
public ExtendedKey getSingletonExtendedPublicKey() { public ExtendedKey getSingletonExtendedPublicKey() {
if(isMultisig()) { if(isMultisig()) {
throw new IllegalStateException("Output descriptor contains multiple public keys but singleton requested"); throw new IllegalStateException("Output descriptor contains multiple public keys but singleton requested");
@ -233,7 +237,7 @@ public class OutputDescriptor {
public Wallet toWallet() { public Wallet toWallet() {
Wallet wallet = new Wallet(); Wallet wallet = new Wallet();
wallet.setPolicyType(isMultisig() ? PolicyType.MULTI : PolicyType.SINGLE); wallet.setPolicyType(isMultisig() || isCosigner() ? PolicyType.MULTI : PolicyType.SINGLE);
wallet.setScriptType(scriptType); wallet.setScriptType(scriptType);
for(Map.Entry<ExtendedKey,KeyDerivation> extKeyEntry : extendedPublicKeys.entrySet()) { for(Map.Entry<ExtendedKey,KeyDerivation> extKeyEntry : extendedPublicKeys.entrySet()) {
@ -469,7 +473,7 @@ public class OutputDescriptor {
private List<ExtendedKey> sortExtendedPubKeys(Collection<ExtendedKey> keys) { private List<ExtendedKey> sortExtendedPubKeys(Collection<ExtendedKey> keys) {
List<ExtendedKey> sortedKeys = new ArrayList<>(keys); List<ExtendedKey> sortedKeys = new ArrayList<>(keys);
if(mapChildrenDerivations == null || mapChildrenDerivations.isEmpty()) { if(mapChildrenDerivations == null || mapChildrenDerivations.isEmpty() || mapChildrenDerivations.containsKey(null)) {
return sortedKeys; return sortedKeys;
} }