support required script types on child wallets

This commit is contained in:
Craig Raw 2021-09-03 17:12:58 +02:00
parent 94d22b8758
commit 0b40c20ab2
2 changed files with 22 additions and 5 deletions

View file

@ -1,6 +1,7 @@
package com.sparrowwallet.drongo.wallet; package com.sparrowwallet.drongo.wallet;
import com.sparrowwallet.drongo.crypto.ChildNumber; import com.sparrowwallet.drongo.crypto.ChildNumber;
import com.sparrowwallet.drongo.protocol.ScriptType;
import java.util.List; import java.util.List;
@ -15,9 +16,9 @@ public enum StandardAccount {
ACCOUNT_7("Account #7", new ChildNumber(7, true)), ACCOUNT_7("Account #7", new ChildNumber(7, true)),
ACCOUNT_8("Account #8", new ChildNumber(8, true)), ACCOUNT_8("Account #8", new ChildNumber(8, true)),
ACCOUNT_9("Account #9", new ChildNumber(9, true)), ACCOUNT_9("Account #9", new ChildNumber(9, true)),
WHIRLPOOL_PREMIX("Premix", new ChildNumber(2147483645, true)), WHIRLPOOL_PREMIX("Premix", new ChildNumber(2147483645, true), ScriptType.P2WPKH),
WHIRLPOOL_POSTMIX("Postmix", new ChildNumber(2147483646, true)), WHIRLPOOL_POSTMIX("Postmix", new ChildNumber(2147483646, true), ScriptType.P2WPKH),
WHIRLPOOL_BADBANK("Badbank", new ChildNumber(2147483644, true)); WHIRLPOOL_BADBANK("Badbank", new ChildNumber(2147483644, true), ScriptType.P2WPKH);
public static final List<StandardAccount> WHIRLPOOL_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX, WHIRLPOOL_BADBANK); public static final List<StandardAccount> WHIRLPOOL_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX, WHIRLPOOL_BADBANK);
public static final List<StandardAccount> WHIRLPOOL_MIX_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX); public static final List<StandardAccount> WHIRLPOOL_MIX_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX);
@ -25,10 +26,18 @@ public enum StandardAccount {
StandardAccount(String name, ChildNumber childNumber) { StandardAccount(String name, ChildNumber childNumber) {
this.name = name; this.name = name;
this.childNumber = childNumber; this.childNumber = childNumber;
this.requiredScriptType = null;
}
StandardAccount(String name, ChildNumber childNumber, ScriptType requiredScriptType) {
this.name = name;
this.childNumber = childNumber;
this.requiredScriptType = requiredScriptType;
} }
private final String name; private final String name;
private final ChildNumber childNumber; private final ChildNumber childNumber;
private final ScriptType requiredScriptType;
public String getName() { public String getName() {
return name; return name;
@ -42,6 +51,10 @@ public enum StandardAccount {
return childNumber.num(); return childNumber.num();
} }
public ScriptType getRequiredScriptType() {
return requiredScriptType;
}
@Override @Override
public String toString() { public String toString() {
return name; return name;

View file

@ -105,9 +105,13 @@ public class Wallet extends Persistable {
childWallet.gapLimit = null; childWallet.gapLimit = null;
childWallet.birthDate = null; childWallet.birthDate = null;
if(standardAccount.getRequiredScriptType() != null) {
childWallet.setScriptType(standardAccount.getRequiredScriptType());
}
for(Keystore keystore : childWallet.getKeystores()) { for(Keystore keystore : childWallet.getKeystores()) {
KeyDerivation keyDerivation = keystore.getKeyDerivation(); List<ChildNumber> derivation = standardAccount.getRequiredScriptType() != null ? standardAccount.getRequiredScriptType().getDefaultDerivation() : keystore.getKeyDerivation().getDerivation();
List<ChildNumber> childDerivation = new ArrayList<>(keyDerivation.getDerivation().subList(0, keyDerivation.getDerivation().size() - 1)); List<ChildNumber> childDerivation = new ArrayList<>(derivation.subList(0, derivation.size() - 1));
childDerivation.add(standardAccount.getChildNumber()); childDerivation.add(standardAccount.getChildNumber());
try { try {