mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 01:56:44 +00:00
refactor supported bip47 script type lists
This commit is contained in:
parent
ddaf698c10
commit
8cdea77562
3 changed files with 10 additions and 3 deletions
|
@ -38,6 +38,9 @@ public class PaymentCode {
|
||||||
private final byte[] pubkey;
|
private final byte[] pubkey;
|
||||||
private final byte[] chain;
|
private final byte[] chain;
|
||||||
|
|
||||||
|
public static final List<ScriptType> SEGWIT_SCRIPT_TYPES = List.of(ScriptType.P2PKH, ScriptType.P2SH_P2WPKH, ScriptType.P2WPKH);
|
||||||
|
public static final List<ScriptType> V1_SCRIPT_TYPES = List.of(ScriptType.P2PKH);
|
||||||
|
|
||||||
private PaymentCode(String strPaymentCode, byte[] pubkey, byte[] chain) {
|
private PaymentCode(String strPaymentCode, byte[] pubkey, byte[] chain) {
|
||||||
this.strPaymentCode = strPaymentCode;
|
this.strPaymentCode = strPaymentCode;
|
||||||
this.pubkey = pubkey;
|
this.pubkey = pubkey;
|
||||||
|
|
|
@ -150,10 +150,14 @@ public class Bech32 {
|
||||||
|
|
||||||
/** Decode a Bech32 string. */
|
/** Decode a Bech32 string. */
|
||||||
public static Bech32Data decode(final String str) {
|
public static Bech32Data decode(final String str) {
|
||||||
|
return decode(str, 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Bech32Data decode(final String str, int limit) {
|
||||||
boolean lower = false, upper = false;
|
boolean lower = false, upper = false;
|
||||||
if (str.length() < 8)
|
if (str.length() < 8)
|
||||||
throw new ProtocolException("Input too short: " + str.length());
|
throw new ProtocolException("Input too short: " + str.length());
|
||||||
if (str.length() > 90)
|
if (str.length() > limit)
|
||||||
throw new ProtocolException("Input too long: " + str.length());
|
throw new ProtocolException("Input too long: " + str.length());
|
||||||
for (int i = 0; i < str.length(); ++i) {
|
for (int i = 0; i < str.length(); ++i) {
|
||||||
char c = str.charAt(i);
|
char c = str.charAt(i);
|
||||||
|
|
|
@ -185,7 +185,7 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
|
||||||
throw new IllegalStateException("Cannot add payment code wallet to " + policyType.getName() + " wallet");
|
throw new IllegalStateException("Cannot add payment code wallet to " + policyType.getName() + " wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scriptType != P2PKH && scriptType != P2SH_P2WPKH && scriptType != P2WPKH) {
|
if(!PaymentCode.SEGWIT_SCRIPT_TYPES.contains(scriptType)) {
|
||||||
throw new IllegalStateException("Cannot add payment code wallet to " + scriptType.getName() + " wallet");
|
throw new IllegalStateException("Cannot add payment code wallet to " + scriptType.getName() + " wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
|
||||||
|
|
||||||
public boolean hasPaymentCode() {
|
public boolean hasPaymentCode() {
|
||||||
return getKeystores().size() == 1 && getKeystores().get(0).getBip47ExtendedPrivateKey() != null && policyType == PolicyType.SINGLE
|
return getKeystores().size() == 1 && getKeystores().get(0).getBip47ExtendedPrivateKey() != null && policyType == PolicyType.SINGLE
|
||||||
&& (scriptType == P2PKH || scriptType == P2SH_P2WPKH || scriptType == P2WPKH);
|
&& PaymentCode.SEGWIT_SCRIPT_TYPES.contains(scriptType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaymentCode getPaymentCode() {
|
public PaymentCode getPaymentCode() {
|
||||||
|
|
Loading…
Reference in a new issue