BitAddress extends Address implements AbstractAddress { public static BitAddress from(CoinType type, String address) throws AddressMalformedException { try { return new BitAddress(type, address); } catch (AddressFormatException e) { throw new AddressMalformedException(e); } } BitAddress(Address address);   BitAddress(CoinType type, byte[] hash160);   BitAddress(CoinType type, int version, byte[] hash160);   BitAddress(CoinType type, String address); static BitAddress from(CoinType type, String address); static BitAddress from(CoinType type, int version, byte[] hash160); static BitAddress from(CoinType type, byte[] publicKeyHash160); static BitAddress from(CoinType type, Script script); static BitAddress from(CoinType type, ECKey key); static BitAddress from(AbstractAddress address); static BitAddress from(Address address); @Override CoinType getType(); @Override long getId();  }
@Test public void testFromMethods() throws AddressFormatException, AddressMalformedException { Address address = new Address(BTC, BTC_P2PKH_ADDR); AbstractAddress abstractAddress = new AbstractAddress() { @Override public CoinType getType() { return BTC; } @Override public long getId() { return 0; } @Override public String toString() { return BTC_P2PKH_ADDR; } }; assertEquals(BTC_P2PKH_ADDR, BitAddress.from(BTC, BTC_P2PKH_ADDR).toString()); assertEquals(BTC_P2PKH_ADDR, BitAddress.from(BTC, BTC.getAddressHeader(), HASH160).toString()); assertEquals(BTC_P2PKH_ADDR, BitAddress.from(BTC, new Script(P2PKH_SCRIPT)).toString()); assertEquals(BTC_P2PKH_ADDR, BitAddress.from(BTC, pubKey).toString()); assertEquals(BTC_P2PKH_ADDR, BitAddress.from(abstractAddress).toString()); assertEquals(BTC_P2PKH_ADDR, BitAddress.from(address).toString()); address = new Address(BTC, BTC_P2SH_ADDR); abstractAddress = new AbstractAddress() { @Override public CoinType getType() { return BTC; } @Override public long getId() { return 0; } @Override public String toString() { return BTC_P2SH_ADDR; } }; assertEquals(BTC_P2SH_ADDR, BitAddress.from(BTC, BTC_P2SH_ADDR).toString()); assertEquals(BTC_P2SH_ADDR, BitAddress.from(BTC, BTC.getP2SHHeader(), HASH160).toString()); assertEquals(BTC_P2SH_ADDR, BitAddress.from(BTC, new Script(P2SH_SCRIPT)).toString()); assertEquals(BTC_P2SH_ADDR, BitAddress.from(abstractAddress).toString()); assertEquals(BTC_P2SH_ADDR, BitAddress.from(address).toString()); address = new Address(LTC, LTC_P2PKH_ADDR); abstractAddress = new AbstractAddress() { @Override public CoinType getType() { return LTC; } @Override public long getId() { return 0; } @Override public String toString() { return LTC_P2PKH_ADDR; } }; assertEquals(LTC_P2PKH_ADDR, BitAddress.from(LTC, LTC_P2PKH_ADDR).toString()); assertEquals(LTC_P2PKH_ADDR, BitAddress.from(LTC, LTC.getAddressHeader(), HASH160).toString()); assertEquals(LTC_P2PKH_ADDR, BitAddress.from(LTC, new Script(P2PKH_SCRIPT)).toString()); assertEquals(LTC_P2PKH_ADDR, BitAddress.from(LTC, pubKey).toString()); assertEquals(LTC_P2PKH_ADDR, BitAddress.from(abstractAddress).toString()); assertEquals(LTC_P2PKH_ADDR, BitAddress.from(address).toString()); address = new Address(LTC, LTC_P2SH_ADDR); abstractAddress = new AbstractAddress() { @Override public CoinType getType() { return LTC; } @Override public long getId() { return 0; } @Override public String toString() { return LTC_P2SH_ADDR; } }; assertEquals(LTC_P2SH_ADDR, BitAddress.from(LTC, LTC_P2SH_ADDR).toString()); assertEquals(LTC_P2SH_ADDR, BitAddress.from(LTC, LTC.getP2SHHeader(), HASH160).toString()); assertEquals(LTC_P2SH_ADDR, BitAddress.from(LTC, new Script(P2SH_SCRIPT)).toString()); assertEquals(LTC_P2SH_ADDR, BitAddress.from(abstractAddress).toString()); assertEquals(LTC_P2SH_ADDR, BitAddress.from(address).toString()); }