support invalid script type warnings

This commit is contained in:
Craig Raw 2025-03-04 11:47:22 +02:00
parent 5fd8e9416a
commit 66ff275f46
2 changed files with 11 additions and 3 deletions

View file

@ -1154,6 +1154,10 @@ public enum ScriptType {
return description;
}
public String getDescription(boolean includePolicyType) {
return includePolicyType && !getAllowedPolicyTypes().isEmpty() ? getAllowedPolicyTypes().getFirst().getName().toLowerCase(Locale.ROOT) + " " + description : description;
}
public String getDefaultDerivationPath() {
return Network.get() != Network.MAINNET ? defaultDerivationPath.replace("/0'/0'", "/1'/0'") : defaultDerivationPath;
}

View file

@ -1812,15 +1812,19 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
}
public boolean derivationMatchesAnotherScriptType(String derivationPath) {
return getOtherScriptTypeMatchingDerivation(derivationPath).isPresent();
}
public Optional<ScriptType> getOtherScriptTypeMatchingDerivation(String derivationPath) {
if(Boolean.TRUE.toString().equals(System.getProperty(ALLOW_DERIVATIONS_MATCHING_OTHER_SCRIPT_TYPES_PROPERTY))) {
return false;
return Optional.empty();
}
if(scriptType != null && scriptType.getAccount(derivationPath) > -1) {
return false;
return Optional.empty();
}
return Arrays.stream(ScriptType.values()).anyMatch(scriptType -> !scriptType.equals(this.scriptType) && scriptType.getAccount(derivationPath, true) > -1);
return Arrays.stream(ScriptType.values()).filter(scriptType -> !scriptType.equals(this.scriptType) && scriptType.getAccount(derivationPath, true) > -1).findFirst();
}
public boolean derivationMatchesAnotherNetwork(String derivationPath) {