Address extends VersionedChecksummedBytes { public static NetworkParameters getParametersFromAddress(String address) throws AddressFormatException { try { return Address.fromBase58(null, address).getParameters(); } catch (WrongNetworkException e) { throw new RuntimeException(e); } } Address(NetworkParameters params, int version, byte[] hash160);  Address(NetworkParameters params, byte[] hash160); @Deprecated  Address(@Nullable NetworkParameters params, String address); static Address fromP2SHHash(NetworkParameters params, byte[] hash160); static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey); static Address fromBase58(@Nullable NetworkParameters params, String base58); byte[] getHash160(); boolean isP2SHAddress(); NetworkParameters getParameters(); static NetworkParameters getParametersFromAddress(String address); @Override Address clone(); static final int LENGTH; }
@Test public void getNetwork() throws Exception { NetworkParameters params = Address.getParametersFromAddress(CoinDefinition.UNITTEST_ADDRESS); assertEquals(MainNetParams.get().getId(), params.getId()); if(CoinDefinition.supportsTestNet) { params = Address.getParametersFromAddress("ydzm4Uvr2GkLxTwQnwiyijYUukk1eweBo4"); assertEquals(TestNet3Params.get().getId(), params.getId()); } }
@Test public void getAltNetwork() throws Exception { class AltNetwork extends MainNetParams { AltNetwork() { super(); id = "alt.network"; addressHeader = 48; p2shHeader = 5; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; } } AltNetwork altNetwork = new AltNetwork(); Networks.register(altNetwork); NetworkParameters params = Address.getParametersFromAddress("LLxSnHLN2CYyzB5eWTR9K9rS9uWtbTQFb6"); assertEquals(altNetwork.getId(), params.getId()); params = Address.getParametersFromAddress("Xtqn4ks8sJS7iG7S7r1Jf37eFFSJGwh8a8"); assertEquals(MainNetParams.get().getId(), params.getId()); Networks.unregister(altNetwork); try { Address.getParametersFromAddress("LLxSnHLN2CYyzB5eWTR9K9rS9uWtbTQFb6"); fail(); } catch (AddressFormatException e) { } }
@Test public void getNetwork() throws Exception { NetworkParameters params = Address.getParametersFromAddress("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"); assertEquals(MainNetParams.get().getId(), params.getId()); params = Address.getParametersFromAddress("n4eA2nbYqErp7H6jebchxAN59DmNpksexv"); assertEquals(TestNet3Params.get().getId(), params.getId()); }
@Test public void getAltNetwork() throws Exception { class AltNetwork extends MainNetParams { AltNetwork() { super(); id = "alt.network"; addressHeader = 48; p2shHeader = 5; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; } } AltNetwork altNetwork = new AltNetwork(); Networks.register(altNetwork); NetworkParameters params = Address.getParametersFromAddress("LLxSnHLN2CYyzB5eWTR9K9rS9uWtbTQFb6"); assertEquals(altNetwork.getId(), params.getId()); params = Address.getParametersFromAddress("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"); assertEquals(MainNetParams.get().getId(), params.getId()); Networks.unregister(altNetwork); try { Address.getParametersFromAddress("LLxSnHLN2CYyzB5eWTR9K9rS9uWtbTQFb6"); fail(); } catch (AddressFormatException e) { } }