diff --git a/src/main/java/com/sparrowwallet/drongo/Network.java b/src/main/java/com/sparrowwallet/drongo/Network.java index a6a2815..ab389ac 100644 --- a/src/main/java/com/sparrowwallet/drongo/Network.java +++ b/src/main/java/com/sparrowwallet/drongo/Network.java @@ -1,11 +1,11 @@ package com.sparrowwallet.drongo; public enum Network { - MAINNET("mainnet", 0, "1", 5, "3", "bc", ExtendedKey.Header.xprv, ExtendedKey.Header.xpub), - TESTNET("testnet", 111, "mn", 196, "2", "tb", ExtendedKey.Header.tprv, ExtendedKey.Header.tpub), - REGTEST("regtest", 111, "mn", 196, "2", "bcrt", ExtendedKey.Header.tprv, ExtendedKey.Header.tpub); + MAINNET("mainnet", 0, "1", 5, "3", "bc", ExtendedKey.Header.xprv, ExtendedKey.Header.xpub, 8332), + TESTNET("testnet", 111, "mn", 196, "2", "tb", ExtendedKey.Header.tprv, ExtendedKey.Header.tpub, 18332), + REGTEST("regtest", 111, "mn", 196, "2", "bcrt", ExtendedKey.Header.tprv, ExtendedKey.Header.tpub, 18443); - Network(String name, int p2pkhAddressHeader, String p2pkhAddressPrefix, int p2shAddressHeader, String p2shAddressPrefix, String bech32AddressHrp, ExtendedKey.Header xprvHeader, ExtendedKey.Header xpubHeader) { + 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; this.p2pkhAddressPrefix = p2pkhAddressPrefix; @@ -14,6 +14,7 @@ public enum Network { this.bech32AddressHrp = bech32AddressHrp; this.xprvHeader = xprvHeader; this.xpubHeader = xpubHeader; + this.defaultPort = defaultPort; } private final String name; @@ -24,6 +25,7 @@ public enum Network { private final String bech32AddressHrp; private final ExtendedKey.Header xprvHeader; private final ExtendedKey.Header xpubHeader; + private final int defaultPort; private static Network currentNetwork; @@ -51,6 +53,10 @@ public enum Network { return xpubHeader; } + public int getDefaultPort() { + return defaultPort; + } + public boolean hasP2PKHAddressPrefix(String address) { for(String prefix : p2pkhAddressPrefix.split("")) { if(address.startsWith(prefix)) { diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index 8cf5d2e..fb86635 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -31,6 +31,7 @@ public class Wallet { private final Map transactions = new HashMap<>(); private Integer storedBlockHeight; private Integer gapLimit; + private Date birthDate; public Wallet() { } @@ -40,9 +41,14 @@ public class Wallet { } public Wallet(String name, PolicyType policyType, ScriptType scriptType) { + this(name, policyType, scriptType, null); + } + + public Wallet(String name, PolicyType policyType, ScriptType scriptType, Date birthDate) { this.name = name; this.policyType = policyType; this.scriptType = scriptType; + this.birthDate = birthDate; this.keystores = Collections.singletonList(new Keystore()); this.defaultPolicy = Policy.getPolicy(policyType, scriptType, keystores, null); } @@ -102,6 +108,10 @@ public class Wallet { } transactions.putAll(updatedTransactions); + + if(!transactions.isEmpty()) { + birthDate = transactions.values().stream().map(BlockTransactionHash::getDate).filter(Objects::nonNull).min(Date::compareTo).orElse(birthDate); + } } public Integer getStoredBlockHeight() { @@ -120,6 +130,14 @@ public class Wallet { this.gapLimit = gapLimit; } + public Date getBirthDate() { + return birthDate; + } + + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; + } + public synchronized WalletNode getNode(KeyPurpose keyPurpose) { WalletNode purposeNode; Optional optionalPurposeNode = purposeNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst(); @@ -933,6 +951,7 @@ public class Wallet { } copy.setStoredBlockHeight(getStoredBlockHeight()); copy.gapLimit = gapLimit; + copy.birthDate = birthDate; return copy; }