/** * Construct an address from parameters and the hash160 form. Example:<p> * * <pre>new Address(MainNetParams.get(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));</pre> */ public Address(NetworkParameters params, byte[] hash160) { super(params.getAddressHeader(), hash160); checkArgument(hash160.length == 20, "Addresses are 160-bit hashes, so you must provide 20 bytes"); this.params = params; }
/** * Construct an address from parameters and the hash160 form. Example:<p> * * <pre>new Address(MainNetParams.get(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));</pre> */ public Address(NetworkParameters params, byte[] hash160) { super(params.getAddressHeader(), hash160); checkArgument(hash160.length == 20, "Addresses are 160-bit hashes, so you must provide 20 bytes"); this.params = params; }
/** * Construct an address from parameters and the hash160 form. Example:<p> * * <pre>new Address(MainNetParams.get(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));</pre> */ public Address(NetworkParameters params, byte[] hash160) { super(params.getAddressHeader(), hash160); checkArgument(hash160.length == 20, "Addresses are 160-bit hashes, so you must provide 20 bytes"); this.params = params; }
/** * Construct an address from parameters and the hash160 form. Example:<p> * * <pre>new Address(MainNetParams.get(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));</pre> */ public Address(NetworkParameters params, byte[] hash160) { super(params.getAddressHeader(), hash160); checkArgument(hash160.length == 20, "Addresses are 160-bit hashes, so you must provide 20 bytes"); this.params = params; }
private static byte[] getBytes(final NetworkParameters params, final int version, final byte[] hash) { if (version == params.getAddressHeader()) return hash; if (version == params.getP2SHHeader()) return hash; if (version == params.getP2WPKHHeader() || version == params.getP2WSHHeader()) { final byte[] bytes = new byte[hash.length + 2]; System.arraycopy(hash, 0, bytes, 2, hash.length); return bytes; } throw new IllegalArgumentException("Could not figure out how to serialize address"); } }
private BitcoinData createBitcoinData(Object data, DATA_TYPE type) throws DataOverSizeException, IOException { switch (this.networkParameters.getAddressHeader()) { case TEST_ADDR: if (data instanceof InputStream) { return new BitcoinData(NETWORK.TEST, (InputStream)data, type, this.encryptor, this.compressor); } else { return new BitcoinData(NETWORK.TEST, (byte[])data, type, this.encryptor, this.compressor); } case MAIN_ADDR: default: if (data instanceof InputStream) { return new BitcoinData(NETWORK.MAIN, (InputStream)data, type, this.encryptor, this.compressor); } else { return new BitcoinData(NETWORK.MAIN, (byte[])data, type, this.encryptor, this.compressor); } } }
@Test public void stringification() throws Exception { // Test a testnet address. VersionedChecksummedBytes a = new VersionedChecksummedBytes(testParams.getAddressHeader(), HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc")); assertEquals("n4eA2nbYqErp7H6jebchxAN59DmNpksexv", a.toString()); VersionedChecksummedBytes b = new VersionedChecksummedBytes(mainParams.getAddressHeader(), HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a")); assertEquals("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL", b.toString()); }
@Test public void comparisonCloneEqualTo() throws Exception { VersionedChecksummedBytes a = new VersionedChecksummedBytes(testParams.getAddressHeader(), HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc")); VersionedChecksummedBytes b = a.clone(); assertTrue(a.compareTo(b) == 0); } }
@Test public void cloning() throws Exception { VersionedChecksummedBytes a = new VersionedChecksummedBytes(testParams.getAddressHeader(), HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc")); VersionedChecksummedBytes b = a.clone(); assertEquals(a, b); assertNotSame(a, b); }