/** Get hash of Bitcoin address. */ public byte[] getHash() { return getHash(params); }
/** Creates a scriptPubKey that encodes payment to the given address. */ public static Script createOutputScript(Address to) { if (to.isP2SHAddress()) { // OP_HASH160 <scriptHash> OP_EQUAL return new ScriptBuilder() .op(OP_HASH160) .data(to.getHash160()) .op(OP_EQUAL) .build(); } else if (to.isP2WPKHAddress() || to.isP2WSHAddress()) { return new ScriptBuilder() .smallNum(0) .data(to.getHash()) .build(); } else { // OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG return new ScriptBuilder() .op(OP_DUP) .op(OP_HASH160) .data(to.getHash160()) .op(OP_EQUALVERIFY) .op(OP_CHECKSIG) .build(); } }
/** The (big endian) 20 byte hash that is the core of a Bitcoin address. */ public byte[] getHash160() { final byte[] hash = getHash(); checkArgument(hash.length == 20, "Expcted RIPMED160 hash does not have 20 bytes"); return hash; }
/** @deprecated Use {@link #fromBase58(NetworkParameters, String)} */ @Deprecated public Address(@Nullable NetworkParameters params, String address) throws AddressFormatException { super(address); if (params != null) { if (!isAcceptableVersion(params, version)) { throw new WrongNetworkException(version, params.getAcceptableAddressCodes()); } final byte[] hash = getHash(); if (!isAcceptableLength(params, version, hash.length)) { throw new WrongLengthException(hash.length); } this.params = params; } else { NetworkParameters paramsFound = null; for (NetworkParameters p : Networks.get()) { if (isAcceptableVersion(p, version) && isAcceptableLength(p, version, getHash(p).length)) { paramsFound = p; break; } } if (paramsFound == null) throw new AddressFormatException("No network found for " + address); this.params = paramsFound; } }