mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
add wallet birth date and network default ports
This commit is contained in:
parent
68f7c6850e
commit
6ad3f53731
2 changed files with 29 additions and 4 deletions
|
@ -1,11 +1,11 @@
|
||||||
package com.sparrowwallet.drongo;
|
package com.sparrowwallet.drongo;
|
||||||
|
|
||||||
public enum Network {
|
public enum Network {
|
||||||
MAINNET("mainnet", 0, "1", 5, "3", "bc", ExtendedKey.Header.xprv, ExtendedKey.Header.xpub),
|
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),
|
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);
|
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.name = name;
|
||||||
this.p2pkhAddressHeader = p2pkhAddressHeader;
|
this.p2pkhAddressHeader = p2pkhAddressHeader;
|
||||||
this.p2pkhAddressPrefix = p2pkhAddressPrefix;
|
this.p2pkhAddressPrefix = p2pkhAddressPrefix;
|
||||||
|
@ -14,6 +14,7 @@ public enum Network {
|
||||||
this.bech32AddressHrp = bech32AddressHrp;
|
this.bech32AddressHrp = bech32AddressHrp;
|
||||||
this.xprvHeader = xprvHeader;
|
this.xprvHeader = xprvHeader;
|
||||||
this.xpubHeader = xpubHeader;
|
this.xpubHeader = xpubHeader;
|
||||||
|
this.defaultPort = defaultPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -24,6 +25,7 @@ public enum Network {
|
||||||
private final String bech32AddressHrp;
|
private final String bech32AddressHrp;
|
||||||
private final ExtendedKey.Header xprvHeader;
|
private final ExtendedKey.Header xprvHeader;
|
||||||
private final ExtendedKey.Header xpubHeader;
|
private final ExtendedKey.Header xpubHeader;
|
||||||
|
private final int defaultPort;
|
||||||
|
|
||||||
private static Network currentNetwork;
|
private static Network currentNetwork;
|
||||||
|
|
||||||
|
@ -51,6 +53,10 @@ public enum Network {
|
||||||
return xpubHeader;
|
return xpubHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDefaultPort() {
|
||||||
|
return defaultPort;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasP2PKHAddressPrefix(String address) {
|
public boolean hasP2PKHAddressPrefix(String address) {
|
||||||
for(String prefix : p2pkhAddressPrefix.split("")) {
|
for(String prefix : p2pkhAddressPrefix.split("")) {
|
||||||
if(address.startsWith(prefix)) {
|
if(address.startsWith(prefix)) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class Wallet {
|
||||||
private final Map<Sha256Hash, BlockTransaction> transactions = new HashMap<>();
|
private final Map<Sha256Hash, BlockTransaction> transactions = new HashMap<>();
|
||||||
private Integer storedBlockHeight;
|
private Integer storedBlockHeight;
|
||||||
private Integer gapLimit;
|
private Integer gapLimit;
|
||||||
|
private Date birthDate;
|
||||||
|
|
||||||
public Wallet() {
|
public Wallet() {
|
||||||
}
|
}
|
||||||
|
@ -40,9 +41,14 @@ public class Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Wallet(String name, PolicyType policyType, ScriptType scriptType) {
|
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.name = name;
|
||||||
this.policyType = policyType;
|
this.policyType = policyType;
|
||||||
this.scriptType = scriptType;
|
this.scriptType = scriptType;
|
||||||
|
this.birthDate = birthDate;
|
||||||
this.keystores = Collections.singletonList(new Keystore());
|
this.keystores = Collections.singletonList(new Keystore());
|
||||||
this.defaultPolicy = Policy.getPolicy(policyType, scriptType, keystores, null);
|
this.defaultPolicy = Policy.getPolicy(policyType, scriptType, keystores, null);
|
||||||
}
|
}
|
||||||
|
@ -102,6 +108,10 @@ public class Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
transactions.putAll(updatedTransactions);
|
transactions.putAll(updatedTransactions);
|
||||||
|
|
||||||
|
if(!transactions.isEmpty()) {
|
||||||
|
birthDate = transactions.values().stream().map(BlockTransactionHash::getDate).filter(Objects::nonNull).min(Date::compareTo).orElse(birthDate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getStoredBlockHeight() {
|
public Integer getStoredBlockHeight() {
|
||||||
|
@ -120,6 +130,14 @@ public class Wallet {
|
||||||
this.gapLimit = gapLimit;
|
this.gapLimit = gapLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getBirthDate() {
|
||||||
|
return birthDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBirthDate(Date birthDate) {
|
||||||
|
this.birthDate = birthDate;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized WalletNode getNode(KeyPurpose keyPurpose) {
|
public synchronized WalletNode getNode(KeyPurpose keyPurpose) {
|
||||||
WalletNode purposeNode;
|
WalletNode purposeNode;
|
||||||
Optional<WalletNode> optionalPurposeNode = purposeNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst();
|
Optional<WalletNode> optionalPurposeNode = purposeNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst();
|
||||||
|
@ -933,6 +951,7 @@ public class Wallet {
|
||||||
}
|
}
|
||||||
copy.setStoredBlockHeight(getStoredBlockHeight());
|
copy.setStoredBlockHeight(getStoredBlockHeight());
|
||||||
copy.gapLimit = gapLimit;
|
copy.gapLimit = gapLimit;
|
||||||
|
copy.birthDate = birthDate;
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue