public static boolean isValidAddress(String address, NetworkParameters params) { try { new Address(params, address); return true; } catch (AddressFormatException e) { return false; } }
/** Returns an Address that represents the given P2SH script hash. */ public static Address fromP2SHHash(NetworkParameters params, byte[] hash160) { try { return new Address(params, params.getP2SHHeader(), hash160); } catch (WrongNetworkException e) { throw new RuntimeException(e); // Cannot happen. } }
/** Returns an Address that represents the given P2SH script hash. */ public static Address fromP2SHHash(NetworkParameters params, byte[] hash160) { try { return new Address(params, params.getP2SHHeader(), hash160); } catch (WrongNetworkException e) { throw new RuntimeException(e); // Cannot happen. } }
/** * Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from * the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). */ public Address toAddress(NetworkParameters params) { return new Address(params, getPubKeyHash()); }
/** * Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from * the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). */ public Address toAddress(NetworkParameters params) { return new Address(params, getPubKeyHash()); }
/** * Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from * the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). */ public Address toAddress(NetworkParameters params) { return new Address(params, getPubKeyHash()); }
/** Returns an Address that represents the given P2WPKH public key hash. */ public static Address fromP2WPKHHash(NetworkParameters params, byte[] hash) { try { return new Address(params, params.getP2WPKHHeader(), hash); } catch (WrongNetworkException e) { throw new RuntimeException(e); } catch (WrongLengthException e) { throw new RuntimeException(e); } }
/** Returns an Address that represents the given P2SH script hash. */ public static Address fromP2SHHash(NetworkParameters params, byte[] hash160) { try { return new Address(params, params.getP2SHHeader(), hash160); } catch (WrongNetworkException e) { throw new RuntimeException(e); // Cannot happen. } }
/** * @param rawAddress The raw address as provided by the device */ public MainNetAddress(String rawAddress) { try { this.address = Optional.of(new Address(MainNetParams.get(), rawAddress)); } catch (AddressFormatException e) { log.warn("Invalid MainNet address. Ignoring."); } }
/** Returns an Address that represents the given P2SH script hash. */ public static Address fromP2SHHash(NetworkParameters params, byte[] hash160) { try { return new Address(params, params.getP2SHHeader(), hash160); } catch (WrongNetworkException e) { throw new RuntimeException(e); // Cannot happen. } }
/** Returns an Address that represents the given P2WSH script hash. */ public static Address fromP2WSHHash(NetworkParameters params, byte[] hash) { try { return new Address(params, params.getP2WSHHeader(), hash); } catch (WrongNetworkException e) { throw new RuntimeException(e); } catch (WrongLengthException e) { throw new RuntimeException(e); } }
/** * For 2-element [input] scripts assumes that the paid-to-address can be derived from the public key. * The concept of a "from address" isn't well defined in Bitcoin and you should not assume the sender of a * transaction can actually receive coins on it. This method may be removed in future. */ @Deprecated public Address getFromAddress(NetworkParameters params) throws ScriptException { return new Address(params, Utils.sha256hash160(getPubKey())); }
/** * For 2-element [input] scripts assumes that the paid-to-address can be derived from the public key. * The concept of a "from address" isn't well defined in Bitcoin and you should not assume the sender of a * transaction can actually receive coins on it. This method may be removed in future. */ @Deprecated public Address getFromAddress(NetworkParameters params) throws ScriptException { return new Address(params, Utils.sha256hash160(getPubKey())); }
/** * For 2-element [input] scripts assumes that the paid-to-address can be derived from the public key. * The concept of a "from address" isn't well defined in Bitcoin and you should not assume the sender of a * transaction can actually receive coins on it. This method may be removed in future. */ @Deprecated public Address getFromAddress(NetworkParameters params) throws ScriptException { return new Address(params, Utils.sha256hash160(getPubKey())); }
/** * For 2-element [input] scripts assumes that the paid-to-address can be derived from the public key. * The concept of a "from address" isn't well defined in Bitcoin and you should not assume the sender of a * transaction can actually receive coins on it. This method may be removed in future. */ @Deprecated public Address getFromAddress(NetworkParameters params) throws ScriptException { return new Address(params, Utils.sha256hash160(getPubKey())); }
public AddressImpl(String address) throws FormatException { try { this.address = new org.bitcoinj.core.Address( org.bitcoinj.core.Address.getParametersFromAddress(address), address); } catch (AddressFormatException e) { throw new FormatException("Could not parse address " + address); } }
@Test public void basicSpendingToP2SH() throws Exception { Address destination = new Address(PARAMS, PARAMS.getP2SHHeader(), HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a")); basicSpendingCommon(wallet, myAddress, destination, null); }
@Test public void cloning() throws Exception { Address a = new Address(testParams, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc")); Address b = a.clone(); assertEquals(a, b); assertNotSame(a, b); }
@Test public void stringification() throws Exception { // Test a testnet address. Address a = new Address(testParams, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc")); assertEquals("n4eA2nbYqErp7H6jebchxAN59DmNpksexv", a.toString()); assertFalse(a.isP2SHAddress()); Address b = new Address(mainParams, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a")); assertEquals("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL", b.toString()); assertFalse(b.isP2SHAddress()); }
@Test public void testScriptPubKey() throws Exception { // Check we can extract the to address byte[] pubkeyBytes = HEX.decode(pubkeyProg); Script pubkey = new Script(pubkeyBytes); assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString()); Address toAddr = new Address(PARAMS, pubkey.getPubKeyHash()); assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString()); }