Search in sources :

Example 1 with WrongNetworkException

use of org.bitcoinj.core.WrongNetworkException in project sentinel-android by Samourai-Wallet.

the class FormatsUtil method isValidBitcoinAddress.

public boolean isValidBitcoinAddress(final String address) {
    boolean ret = false;
    Address addr = null;
    if (address.toLowerCase().startsWith("bc")) {
        try {
            Pair<Byte, byte[]> pair = Bech32Segwit.decode(address.substring(0, 2), address);
            if (pair.getLeft() == null || pair.getRight() == null) {
                ;
            } else {
                ret = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        try {
            addr = new Address(MainNetParams.get(), address);
            if (addr != null) {
                ret = true;
            }
        } catch (WrongNetworkException wne) {
            ret = false;
        } catch (AddressFormatException afe) {
            ret = false;
        }
    }
    return ret;
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) Address(org.bitcoinj.core.Address) AddressFormatException(org.bitcoinj.core.AddressFormatException) BitcoinURIParseException(org.bitcoinj.uri.BitcoinURIParseException) WrongNetworkException(org.bitcoinj.core.WrongNetworkException) WrongNetworkException(org.bitcoinj.core.WrongNetworkException)

Example 2 with WrongNetworkException

use of org.bitcoinj.core.WrongNetworkException in project samourai-wallet-android by Samourai-Wallet.

the class FormatsUtil method isValidBitcoinAddress.

public boolean isValidBitcoinAddress(final String address) {
    boolean ret = false;
    Address addr = null;
    if ((!SamouraiWallet.getInstance().isTestNet() && address.toLowerCase().startsWith("bc")) || (SamouraiWallet.getInstance().isTestNet() && address.toLowerCase().startsWith("tb"))) {
        try {
            Pair<Byte, byte[]> pair = Bech32Segwit.decode(address.substring(0, 2), address);
            if (pair.getLeft() == null || pair.getRight() == null) {
                ;
            } else {
                ret = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        try {
            addr = new Address(SamouraiWallet.getInstance().getCurrentNetworkParams(), address);
            if (addr != null) {
                ret = true;
            }
        } catch (WrongNetworkException wne) {
            ret = false;
        } catch (AddressFormatException afe) {
            ret = false;
        }
    }
    return ret;
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) Address(org.bitcoinj.core.Address) AddressFormatException(org.bitcoinj.core.AddressFormatException) BitcoinURIParseException(org.bitcoinj.uri.BitcoinURIParseException) WrongNetworkException(org.bitcoinj.core.WrongNetworkException) ParseException(java.text.ParseException) WrongNetworkException(org.bitcoinj.core.WrongNetworkException)

Aggregations

Address (org.bitcoinj.core.Address)2 AddressFormatException (org.bitcoinj.core.AddressFormatException)2 WrongNetworkException (org.bitcoinj.core.WrongNetworkException)2 BitcoinURIParseException (org.bitcoinj.uri.BitcoinURIParseException)2 ParseException (java.text.ParseException)1