mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-11-05 11:56:38 +00:00
- convenience function to parse address from any network
- rearrange Network enum to make BITCOIN the first and default
This commit is contained in:
parent
6833096c58
commit
6d15650558
5 changed files with 17 additions and 4 deletions
|
|
@ -57,6 +57,17 @@ public abstract class Address {
|
||||||
return getAddress().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 {
|
public static Address fromString(Network network, String address) throws InvalidAddressException {
|
||||||
Exception nested = null;
|
Exception nested = null;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.sparrowwallet.drongo.protocol;
|
package com.sparrowwallet.drongo.protocol;
|
||||||
|
|
||||||
public enum Network {
|
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 hrp;
|
||||||
public final String legacyPrefixes;
|
public final String legacyPrefixes;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.sparrowwallet.drongo.protocol;
|
||||||
import com.sparrowwallet.drongo.Utils;
|
import com.sparrowwallet.drongo.Utils;
|
||||||
import com.sparrowwallet.drongo.address.*;
|
import com.sparrowwallet.drongo.address.*;
|
||||||
import com.sparrowwallet.drongo.crypto.ECKey;
|
import com.sparrowwallet.drongo.crypto.ECKey;
|
||||||
import com.sparrowwallet.drongo.protocol.Network;
|
|
||||||
import org.bouncycastle.util.encoders.Hex;
|
import org.bouncycastle.util.encoders.Hex;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import com.sparrowwallet.drongo.address.*;
|
||||||
import com.sparrowwallet.drongo.crypto.ChildNumber;
|
import com.sparrowwallet.drongo.crypto.ChildNumber;
|
||||||
import com.sparrowwallet.drongo.crypto.ECKey;
|
import com.sparrowwallet.drongo.crypto.ECKey;
|
||||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||||
import com.sparrowwallet.drongo.protocol.Network;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
|
||||||
|
|
@ -356,6 +356,10 @@ public class PSBT {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Network getNetwork() {
|
||||||
|
return network;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getFee() {
|
public Long getFee() {
|
||||||
long fee = 0L;
|
long fee = 0L;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue