3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-14 19:25:51 +00:00

Address: Add fromKey() helper method.

This commit is contained in:
Andreas Schildbach 2019-01-27 00:54:59 +01:00
parent 9e46997159
commit 47659e73d7

View File

@ -18,6 +18,7 @@ package org.bitcoinj.core;
import javax.annotation.Nullable;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.Script.ScriptType;
/**
@ -67,6 +68,26 @@ public abstract class Address extends PrefixedChecksummedBytes {
}
}
/**
* Construct an {@link Address} that represents the public part of the given {@link ECKey}.
*
* @param params
* network this address is valid for
* @param key
* only the public part is used
* @param outputScriptType
* script type the address should use
* @return constructed address
*/
public static Address fromKey(final NetworkParameters params, final ECKey key, final ScriptType outputScriptType) {
if (outputScriptType == Script.ScriptType.P2PKH)
return LegacyAddress.fromKey(params, key);
else if (outputScriptType == Script.ScriptType.P2WPKH)
return SegwitAddress.fromKey(params, key);
else
throw new IllegalArgumentException(outputScriptType.toString());
}
/**
* Get either the public key hash or script hash that is encoded in the address.
*