mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
support required script types on child wallets
This commit is contained in:
parent
94d22b8758
commit
0b40c20ab2
2 changed files with 22 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.sparrowwallet.drongo.wallet;
|
||||
|
||||
import com.sparrowwallet.drongo.crypto.ChildNumber;
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,9 +16,9 @@ public enum StandardAccount {
|
|||
ACCOUNT_7("Account #7", new ChildNumber(7, true)),
|
||||
ACCOUNT_8("Account #8", new ChildNumber(8, true)),
|
||||
ACCOUNT_9("Account #9", new ChildNumber(9, true)),
|
||||
WHIRLPOOL_PREMIX("Premix", new ChildNumber(2147483645, true)),
|
||||
WHIRLPOOL_POSTMIX("Postmix", new ChildNumber(2147483646, true)),
|
||||
WHIRLPOOL_BADBANK("Badbank", new ChildNumber(2147483644, true));
|
||||
WHIRLPOOL_PREMIX("Premix", new ChildNumber(2147483645, true), ScriptType.P2WPKH),
|
||||
WHIRLPOOL_POSTMIX("Postmix", new ChildNumber(2147483646, true), ScriptType.P2WPKH),
|
||||
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_MIX_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX);
|
||||
|
@ -25,10 +26,18 @@ public enum StandardAccount {
|
|||
StandardAccount(String name, ChildNumber childNumber) {
|
||||
this.name = name;
|
||||
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 ChildNumber childNumber;
|
||||
private final ScriptType requiredScriptType;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -42,6 +51,10 @@ public enum StandardAccount {
|
|||
return childNumber.num();
|
||||
}
|
||||
|
||||
public ScriptType getRequiredScriptType() {
|
||||
return requiredScriptType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
|
|
@ -105,9 +105,13 @@ public class Wallet extends Persistable {
|
|||
childWallet.gapLimit = null;
|
||||
childWallet.birthDate = null;
|
||||
|
||||
if(standardAccount.getRequiredScriptType() != null) {
|
||||
childWallet.setScriptType(standardAccount.getRequiredScriptType());
|
||||
}
|
||||
|
||||
for(Keystore keystore : childWallet.getKeystores()) {
|
||||
KeyDerivation keyDerivation = keystore.getKeyDerivation();
|
||||
List<ChildNumber> childDerivation = new ArrayList<>(keyDerivation.getDerivation().subList(0, keyDerivation.getDerivation().size() - 1));
|
||||
List<ChildNumber> derivation = standardAccount.getRequiredScriptType() != null ? standardAccount.getRequiredScriptType().getDefaultDerivation() : keystore.getKeyDerivation().getDerivation();
|
||||
List<ChildNumber> childDerivation = new ArrayList<>(derivation.subList(0, derivation.size() - 1));
|
||||
childDerivation.add(standardAccount.getChildNumber());
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue