support network dependent block height taproot activation

This commit is contained in:
Craig Raw 2021-09-08 13:21:04 +02:00
parent 0b40c20ab2
commit 38783d68a4
3 changed files with 10 additions and 3 deletions

View file

@ -6,6 +6,8 @@ public enum Network {
REGTEST("regtest", 111, "mn", 196, "2", "bcrt", ExtendedKey.Header.tprv, ExtendedKey.Header.tpub, 18443),
SIGNET("signet", 111, "mn", 196, "2", "tb", ExtendedKey.Header.tprv, ExtendedKey.Header.tpub, 38332);
public static final String BLOCK_HEIGHT_PROPERTY = "com.sparrowwallet.blockHeight";
Network(String name, int p2pkhAddressHeader, String p2pkhAddressPrefix, int p2shAddressHeader, String p2shAddressPrefix, String bech32AddressHrp, ExtendedKey.Header xprvHeader, ExtendedKey.Header xpubHeader, int defaultPort) {
this.name = name;
this.p2pkhAddressHeader = p2pkhAddressHeader;

View file

@ -1134,12 +1134,13 @@ public enum ScriptType {
@Override
public List<PolicyType> getAllowedPolicyTypes() {
return (Network.get() == Network.MAINNET && LocalDate.now().isAfter(TAPROOT_MAINNET_ACTIVATION_DATE)) || Network.get() == Network.TESTNET || Network.get() == Network.REGTEST || Network.get() == Network.SIGNET ? List.of(SINGLE) : Collections.emptyList();
return (Network.get() == Network.MAINNET && LocalDate.now().isAfter(TAPROOT_MAINNET_ACTIVATION_DATE) || (System.getProperty(Network.BLOCK_HEIGHT_PROPERTY) != null && Integer.parseInt(System.getProperty(Network.BLOCK_HEIGHT_PROPERTY)) >= 709632))
|| Network.get() == Network.TESTNET || Network.get() == Network.REGTEST || Network.get() == Network.SIGNET ? List.of(SINGLE) : Collections.emptyList();
}
};
//To avoid relying on a network-dependent block height >= 709632 check, use a approximate activation date. This can be removed once Taproot has activated on mainnet.
private static final LocalDate TAPROOT_MAINNET_ACTIVATION_DATE = LocalDate.of(2021, Month.NOVEMBER, 22);
//To avoid relying solely on a network-dependent block height >= 709632 check, use a approximate activation date. This can be removed once Taproot has activated on mainnet.
private static final LocalDate TAPROOT_MAINNET_ACTIVATION_DATE = LocalDate.of(2021, Month.NOVEMBER, 17);
private final String name;
private final String description;

View file

@ -174,6 +174,10 @@ public class Wallet extends Persistable {
return whirlpoolAccounts.isEmpty();
}
public boolean isWhirlpoolChildWallet() {
return !isMasterWallet() && StandardAccount.WHIRLPOOL_ACCOUNTS.contains(getStandardAccountType());
}
public boolean isWhirlpoolMixWallet() {
return !isMasterWallet() && StandardAccount.WHIRLPOOL_MIX_ACCOUNTS.contains(getStandardAccountType());
}