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
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -355,6 +355,10 @@ public class PSBT {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Network getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public Long getFee() {
|
||||
long fee = 0L;
|
||||
|
|
|
|||
Loading…
Reference in a new issue