- convenience function to parse address from any network

- rearrange Network enum to make BITCOIN the first and default
This commit is contained in:
Daniel Newton 2020-09-28 16:06:48 +13:00
parent 6833096c58
commit 6d15650558
5 changed files with 17 additions and 4 deletions

View file

@ -56,6 +56,17 @@ public abstract class Address {
public int hashCode() {
return getAddress().hashCode();
}
/* Convienience function to try all valid network types when parsing address string */
public static Address fromStringAnyNetwork(String address) throws InvalidAddressException {
for (Network network : Network.values()) {
try {
return Address.fromString(network, address);
} catch (InvalidAddressException e) {
}
}
throw new InvalidAddressException("Could not parse invalid address " + address);
}
public static Address fromString(Network network, String address) throws InvalidAddressException {
Exception nested = null;

View file

@ -1,8 +1,8 @@
package com.sparrowwallet.drongo.protocol;
public enum Network {
TESTNET("tb", "mn2", 111, 196),
BITCOIN("bc", "13", 0, 5);
BITCOIN("bc", "13", 0, 5),
TESTNET("tb", "mn2", 111, 196);
public final String hrp;
public final String legacyPrefixes;

View file

@ -3,7 +3,6 @@ package com.sparrowwallet.drongo.protocol;
import com.sparrowwallet.drongo.Utils;
import com.sparrowwallet.drongo.address.*;
import com.sparrowwallet.drongo.crypto.ECKey;
import com.sparrowwallet.drongo.protocol.Network;
import org.bouncycastle.util.encoders.Hex;
import java.io.ByteArrayInputStream;

View file

@ -6,7 +6,6 @@ import com.sparrowwallet.drongo.address.*;
import com.sparrowwallet.drongo.crypto.ChildNumber;
import com.sparrowwallet.drongo.crypto.ECKey;
import com.sparrowwallet.drongo.policy.PolicyType;
import com.sparrowwallet.drongo.protocol.Network;
import java.util.*;
import java.util.stream.Collectors;

View file

@ -355,6 +355,10 @@ public class PSBT {
return null;
}
public Network getNetwork() {
return network;
}
public Long getFee() {
long fee = 0L;