@Test public void testJavaSerialization() throws Exception { LegacyAddress testAddress = LegacyAddress.fromBase58(TESTNET, "n4eA2nbYqErp7H6jebchxAN59DmNpksexv"); ByteArrayOutputStream os = new ByteArrayOutputStream(); new ObjectOutputStream(os).writeObject(testAddress); LegacyAddress testAddressCopy = (LegacyAddress) new ObjectInputStream(new ByteArrayInputStream(os.toByteArray())) .readObject(); assertEquals(testAddress, testAddressCopy); LegacyAddress mainAddress = LegacyAddress.fromBase58(MAINNET, "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"); os = new ByteArrayOutputStream(); new ObjectOutputStream(os).writeObject(mainAddress); LegacyAddress mainAddressCopy = (LegacyAddress) new ObjectInputStream(new ByteArrayInputStream(os.toByteArray())) .readObject(); assertEquals(mainAddress, mainAddressCopy); }
public static LegacyAddress fromBase58(@Nullable NetworkParameters params, String base58) throws AddressFormatException, AddressFormatException.WrongNetwork { byte[] versionAndDataBytes = Base58.decodeChecked(base58); int version = versionAndDataBytes[0] & 0xFF; byte[] bytes = Arrays.copyOfRange(versionAndDataBytes, 1, versionAndDataBytes.length); if (params == null) { for (NetworkParameters p : Networks.get()) { if (version == p.getAddressHeader()) return new LegacyAddress(p, false, bytes); else if (version == p.getP2SHHeader()) return new LegacyAddress(p, true, bytes); } throw new AddressFormatException.InvalidPrefix("No network found for " + base58); } else { if (version == params.getAddressHeader()) return new LegacyAddress(params, false, bytes); else if (version == params.getP2SHHeader()) return new LegacyAddress(params, true, bytes); throw new AddressFormatException.WrongNetwork(version); } }
LegacyAddress extends Address { public static LegacyAddress fromBase58(@Nullable NetworkParameters params, String base58) throws AddressFormatException, AddressFormatException.WrongNetwork { byte[] versionAndDataBytes = Base58.decodeChecked(base58); int version = versionAndDataBytes[0] & 0xFF; byte[] bytes = Arrays.copyOfRange(versionAndDataBytes, 1, versionAndDataBytes.length); if (params == null) { for (NetworkParameters p : Networks.get()) { if (version == p.getAddressHeader()) return new LegacyAddress(p, false, bytes); else if (version == p.getP2SHHeader()) return new LegacyAddress(p, true, bytes); } throw new AddressFormatException.InvalidPrefix("No network found for " + base58); } else { if (version == params.getAddressHeader()) return new LegacyAddress(params, false, bytes); else if (version == params.getP2SHHeader()) return new LegacyAddress(params, true, bytes); throw new AddressFormatException.WrongNetwork(version); } } }
LegacyAddress extends Address { public static LegacyAddress fromBase58(@Nullable NetworkParameters params, String base58) throws AddressFormatException, AddressFormatException.WrongNetwork { byte[] versionAndDataBytes = Base58.decodeChecked(base58); int version = versionAndDataBytes[0] & 0xFF; byte[] bytes = Arrays.copyOfRange(versionAndDataBytes, 1, versionAndDataBytes.length); if (params == null) { for (NetworkParameters p : Networks.get()) { if (version == p.getAddressHeader()) return new LegacyAddress(p, false, bytes); else if (version == p.getP2SHHeader()) return new LegacyAddress(p, true, bytes); } throw new AddressFormatException.InvalidPrefix("No network found for " + base58); } else { if (version == params.getAddressHeader()) return new LegacyAddress(params, false, bytes); else if (version == params.getP2SHHeader()) return new LegacyAddress(params, true, bytes); throw new AddressFormatException.WrongNetwork(version); } } private  LegacyAddress(NetworkParameters params, boolean p2sh, byte[] hash160); }
LegacyAddress extends Address { public static LegacyAddress fromBase58(@Nullable NetworkParameters params, String base58) throws AddressFormatException, AddressFormatException.WrongNetwork { byte[] versionAndDataBytes = Base58.decodeChecked(base58); int version = versionAndDataBytes[0] & 0xFF; byte[] bytes = Arrays.copyOfRange(versionAndDataBytes, 1, versionAndDataBytes.length); if (params == null) { for (NetworkParameters p : Networks.get()) { if (version == p.getAddressHeader()) return new LegacyAddress(p, false, bytes); else if (version == p.getP2SHHeader()) return new LegacyAddress(p, true, bytes); } throw new AddressFormatException.InvalidPrefix("No network found for " + base58); } else { if (version == params.getAddressHeader()) return new LegacyAddress(params, false, bytes); else if (version == params.getP2SHHeader()) return new LegacyAddress(params, true, bytes); throw new AddressFormatException.WrongNetwork(version); } } private  LegacyAddress(NetworkParameters params, boolean p2sh, byte[] hash160); static LegacyAddress fromPubKeyHash(NetworkParameters params, byte[] hash160); static LegacyAddress fromKey(NetworkParameters params, ECKey key); static LegacyAddress fromScriptHash(NetworkParameters params, byte[] hash160); static LegacyAddress fromBase58(@Nullable NetworkParameters params, String base58); int getVersion(); String toBase58(); @Override byte[] getHash(); @Override ScriptType getOutputScriptType(); static NetworkParameters getParametersFromAddress(String address); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override LegacyAddress clone(); @Override int compareTo(Address o); }
LegacyAddress extends Address { public static LegacyAddress fromBase58(@Nullable NetworkParameters params, String base58) throws AddressFormatException, AddressFormatException.WrongNetwork { byte[] versionAndDataBytes = Base58.decodeChecked(base58); int version = versionAndDataBytes[0] & 0xFF; byte[] bytes = Arrays.copyOfRange(versionAndDataBytes, 1, versionAndDataBytes.length); if (params == null) { for (NetworkParameters p : Networks.get()) { if (version == p.getAddressHeader()) return new LegacyAddress(p, false, bytes); else if (version == p.getP2SHHeader()) return new LegacyAddress(p, true, bytes); } throw new AddressFormatException.InvalidPrefix("No network found for " + base58); } else { if (version == params.getAddressHeader()) return new LegacyAddress(params, false, bytes); else if (version == params.getP2SHHeader()) return new LegacyAddress(params, true, bytes); throw new AddressFormatException.WrongNetwork(version); } } private  LegacyAddress(NetworkParameters params, boolean p2sh, byte[] hash160); static LegacyAddress fromPubKeyHash(NetworkParameters params, byte[] hash160); static LegacyAddress fromKey(NetworkParameters params, ECKey key); static LegacyAddress fromScriptHash(NetworkParameters params, byte[] hash160); static LegacyAddress fromBase58(@Nullable NetworkParameters params, String base58); int getVersion(); String toBase58(); @Override byte[] getHash(); @Override ScriptType getOutputScriptType(); static NetworkParameters getParametersFromAddress(String address); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override LegacyAddress clone(); @Override int compareTo(Address o); static final int LENGTH; final boolean p2sh; }