ScriptPattern: Rename the matchers and extraction helpers for "pay to" script types into an abbreviated form.

This commit is contained in:
Andreas Schildbach
2019-02-14 20:17:47 +01:00
parent 05efa7e69e
commit fffa4c06fe
25 changed files with 164 additions and 164 deletions

View File

@@ -342,7 +342,7 @@ public class BloomFilter extends Message {
if (!chunk.isPushData())
continue;
if (contains(chunk.data)) {
boolean isSendingToPubKeys = ScriptPattern.isPayToPubKey(script) || ScriptPattern.isSentToMultisig(script);
boolean isSendingToPubKeys = ScriptPattern.isP2PK(script) || ScriptPattern.isSentToMultisig(script);
if (flag == BloomUpdate.UPDATE_ALL || (flag == BloomUpdate.UPDATE_P2PUBKEY_ONLY && isSendingToPubKeys))
insert(output.getOutPointFor());
found = true;

View File

@@ -272,7 +272,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
// TODO: Check we're not spending the genesis transaction here. Bitcoin Core won't allow it.
valueIn = valueIn.add(prevOut.getValue());
if (verifyFlags.contains(VerifyFlag.P2SH)) {
if (ScriptPattern.isPayToScriptHash(prevOut.getScript()))
if (ScriptPattern.isP2SH(prevOut.getScript()))
sigOps += Script.getP2SHSigOpCount(in.getScriptBytes());
if (sigOps > Block.MAX_BLOCK_SIGOPS)
throw new VerificationException("Too many P2SH SigOps in block");
@@ -400,7 +400,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
throw new VerificationException("Tried to spend coinbase at depth " + (newBlock.getHeight() - prevOut.getHeight()));
valueIn = valueIn.add(prevOut.getValue());
if (verifyFlags.contains(VerifyFlag.P2SH)) {
if (ScriptPattern.isPayToScriptHash(prevOut.getScript()))
if (ScriptPattern.isP2SH(prevOut.getScript()))
sigOps += Script.getP2SHSigOpCount(in.getScriptBytes());
if (sigOps > Block.MAX_BLOCK_SIGOPS)
throw new VerificationException("Too many P2SH SigOps in block");

View File

@@ -120,12 +120,12 @@ public class LegacyAddress extends Address {
/**
* @deprecated use {@link #fromScriptHash(NetworkParameters, byte[])} in combination with
* {@link ScriptPattern#extractHashFromPayToScriptHash(Script)}
* {@link ScriptPattern#extractHashFromP2SH(Script)}
*/
@Deprecated
public static LegacyAddress fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
checkArgument(ScriptPattern.isPayToScriptHash(scriptPubKey), "Not a P2SH script");
return fromScriptHash(params, ScriptPattern.extractHashFromPayToScriptHash(scriptPubKey));
checkArgument(ScriptPattern.isP2SH(scriptPubKey), "Not a P2SH script");
return fromScriptHash(params, ScriptPattern.extractHashFromP2SH(scriptPubKey));
}
/**

View File

@@ -199,7 +199,7 @@ public class PeerGroup implements TransactionBroadcaster {
// filter. In case (1), we need to retransmit the filter to the connected peers. In case (2), we don't
// and shouldn't, we should just recalculate and cache the new filter for next time.
for (TransactionOutput output : tx.getOutputs()) {
if (ScriptPattern.isPayToPubKey(output.getScriptPubKey()) && output.isMine(wallet)) {
if (ScriptPattern.isP2PK(output.getScriptPubKey()) && output.isMine(wallet)) {
if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
recalculateFastCatchupAndFilter(FilterRecalculateMode.SEND_IF_CHANGED);
else

View File

@@ -924,17 +924,17 @@ public class Transaction extends ChildMessage {
TransactionInput input = new TransactionInput(params, this, new byte[] {}, prevOut);
addInput(input);
int inputIndex = inputs.size() - 1;
if (ScriptPattern.isPayToPubKey(scriptPubKey)) {
if (ScriptPattern.isP2PK(scriptPubKey)) {
TransactionSignature signature = calculateSignature(inputIndex, sigKey, scriptPubKey, sigHash,
anyoneCanPay);
input.setScriptSig(ScriptBuilder.createInputScript(signature));
input.setWitness(null);
} else if (ScriptPattern.isPayToPubKeyHash(scriptPubKey)) {
} else if (ScriptPattern.isP2PKH(scriptPubKey)) {
TransactionSignature signature = calculateSignature(inputIndex, sigKey, scriptPubKey, sigHash,
anyoneCanPay);
input.setScriptSig(ScriptBuilder.createInputScript(signature, sigKey));
input.setWitness(null);
} else if (ScriptPattern.isPayToWitnessPubKeyHash(scriptPubKey)) {
} else if (ScriptPattern.isP2WPKH(scriptPubKey)) {
Script scriptCode = new ScriptBuilder()
.data(ScriptBuilder.createOutputScript(LegacyAddress.fromKey(params, sigKey)).getProgram()).build();
TransactionSignature signature = calculateWitnessSignature(inputIndex, sigKey, scriptCode, input.getValue(),

View File

@@ -141,14 +141,14 @@ public class TransactionOutPoint extends ChildMessage {
TransactionOutput connectedOutput = getConnectedOutput();
checkNotNull(connectedOutput, "Input is not connected so cannot retrieve key");
Script connectedScript = connectedOutput.getScriptPubKey();
if (ScriptPattern.isPayToPubKeyHash(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromPayToPubKeyHash(connectedScript);
if (ScriptPattern.isP2PKH(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromP2PKH(connectedScript);
return keyBag.findKeyFromPubKeyHash(addressBytes, Script.ScriptType.P2PKH);
} else if (ScriptPattern.isPayToWitnessPubKeyHash(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromPayToWitnessHash(connectedScript);
} else if (ScriptPattern.isP2WPKH(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromP2WH(connectedScript);
return keyBag.findKeyFromPubKeyHash(addressBytes, Script.ScriptType.P2WPKH);
} else if (ScriptPattern.isPayToPubKey(connectedScript)) {
byte[] pubkeyBytes = ScriptPattern.extractKeyFromPayToPubKey(connectedScript);
} else if (ScriptPattern.isP2PK(connectedScript)) {
byte[] pubkeyBytes = ScriptPattern.extractKeyFromP2PK(connectedScript);
return keyBag.findKeyFromPubKey(pubkeyBytes);
} else {
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Could not understand form of connected output script: " + connectedScript);
@@ -167,17 +167,17 @@ public class TransactionOutPoint extends ChildMessage {
TransactionOutput connectedOutput = getConnectedOutput();
checkNotNull(connectedOutput, "Input is not connected so cannot retrieve key");
Script connectedScript = connectedOutput.getScriptPubKey();
if (ScriptPattern.isPayToPubKeyHash(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromPayToPubKeyHash(connectedScript);
if (ScriptPattern.isP2PKH(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromP2PKH(connectedScript);
return RedeemData.of(keyBag.findKeyFromPubKeyHash(addressBytes, Script.ScriptType.P2PKH), connectedScript);
} else if (ScriptPattern.isPayToWitnessPubKeyHash(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromPayToWitnessHash(connectedScript);
} else if (ScriptPattern.isP2WPKH(connectedScript)) {
byte[] addressBytes = ScriptPattern.extractHashFromP2WH(connectedScript);
return RedeemData.of(keyBag.findKeyFromPubKeyHash(addressBytes, Script.ScriptType.P2WPKH), connectedScript);
} else if (ScriptPattern.isPayToPubKey(connectedScript)) {
byte[] pubkeyBytes = ScriptPattern.extractKeyFromPayToPubKey(connectedScript);
} else if (ScriptPattern.isP2PK(connectedScript)) {
byte[] pubkeyBytes = ScriptPattern.extractKeyFromP2PK(connectedScript);
return RedeemData.of(keyBag.findKeyFromPubKey(pubkeyBytes), connectedScript);
} else if (ScriptPattern.isPayToScriptHash(connectedScript)) {
byte[] scriptHash = ScriptPattern.extractHashFromPayToScriptHash(connectedScript);
} else if (ScriptPattern.isP2SH(connectedScript)) {
byte[] scriptHash = ScriptPattern.extractHashFromP2SH(connectedScript);
return keyBag.findRedeemDataFromScriptHash(scriptHash);
} else {
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Could not understand form of connected output script: " + connectedScript);

View File

@@ -122,17 +122,17 @@ public class TransactionOutput extends ChildMessage {
@Nullable
@Deprecated
public LegacyAddress getAddressFromP2PKHScript(NetworkParameters params) throws ScriptException {
if (ScriptPattern.isPayToPubKeyHash(getScriptPubKey()))
if (ScriptPattern.isP2PKH(getScriptPubKey()))
return LegacyAddress.fromPubKeyHash(params,
ScriptPattern.extractHashFromPayToPubKeyHash(getScriptPubKey()));
ScriptPattern.extractHashFromP2PKH(getScriptPubKey()));
return null;
}
@Nullable
@Deprecated
public LegacyAddress getAddressFromP2SH(NetworkParameters params) throws ScriptException {
if (ScriptPattern.isPayToScriptHash(getScriptPubKey()))
return LegacyAddress.fromScriptHash(params, ScriptPattern.extractHashFromPayToScriptHash(getScriptPubKey()));
if (ScriptPattern.isP2SH(getScriptPubKey()))
return LegacyAddress.fromScriptHash(params, ScriptPattern.extractHashFromP2SH(getScriptPubKey()));
return null;
}
@@ -301,15 +301,15 @@ public class TransactionOutput extends ChildMessage {
public boolean isMine(TransactionBag transactionBag) {
try {
Script script = getScriptPubKey();
if (ScriptPattern.isPayToPubKey(script))
return transactionBag.isPubKeyMine(ScriptPattern.extractKeyFromPayToPubKey(script));
else if (ScriptPattern.isPayToScriptHash(script))
return transactionBag.isPayToScriptHashMine(ScriptPattern.extractHashFromPayToScriptHash(script));
else if (ScriptPattern.isPayToPubKeyHash(script))
return transactionBag.isPubKeyHashMine(ScriptPattern.extractHashFromPayToPubKeyHash(script),
if (ScriptPattern.isP2PK(script))
return transactionBag.isPubKeyMine(ScriptPattern.extractKeyFromP2PK(script));
else if (ScriptPattern.isP2SH(script))
return transactionBag.isPayToScriptHashMine(ScriptPattern.extractHashFromP2SH(script));
else if (ScriptPattern.isP2PKH(script))
return transactionBag.isPubKeyHashMine(ScriptPattern.extractHashFromP2PKH(script),
Script.ScriptType.P2PKH);
else if (ScriptPattern.isPayToWitnessPubKeyHash(script))
return transactionBag.isPubKeyHashMine(ScriptPattern.extractHashFromPayToWitnessHash(script),
else if (ScriptPattern.isP2WPKH(script))
return transactionBag.isPubKeyHashMine(ScriptPattern.extractHashFromP2WH(script),
Script.ScriptType.P2WPKH);
else
return false;
@@ -329,11 +329,11 @@ public class TransactionOutput extends ChildMessage {
Script script = getScriptPubKey();
StringBuilder buf = new StringBuilder("TxOut of ");
buf.append(Coin.valueOf(value).toFriendlyString());
if (ScriptPattern.isPayToPubKeyHash(script) || ScriptPattern.isPayToWitnessPubKeyHash(script)
|| ScriptPattern.isPayToScriptHash(script))
if (ScriptPattern.isP2PKH(script) || ScriptPattern.isP2WPKH(script)
|| ScriptPattern.isP2SH(script))
buf.append(" to ").append(script.getToAddress(params));
else if (ScriptPattern.isPayToPubKey(script))
buf.append(" to pubkey ").append(Utils.HEX.encode(ScriptPattern.extractKeyFromPayToPubKey(script)));
else if (ScriptPattern.isP2PK(script))
buf.append(" to pubkey ").append(Utils.HEX.encode(ScriptPattern.extractKeyFromP2PK(script)));
else if (ScriptPattern.isSentToMultisig(script))
buf.append(" to multisig");
else

View File

@@ -237,12 +237,12 @@ public class Script {
@Deprecated
public boolean isSentToRawPubKey() {
return ScriptPattern.isPayToPubKey(this);
return ScriptPattern.isP2PK(this);
}
@Deprecated
public boolean isSentToAddress() {
return ScriptPattern.isPayToPubKeyHash(this);
return ScriptPattern.isP2PKH(this);
}
/**
@@ -251,12 +251,12 @@ public class Script {
* <p>Otherwise this method throws a ScriptException.</p>
*/
public byte[] getPubKeyHash() throws ScriptException {
if (ScriptPattern.isPayToPubKeyHash(this))
return ScriptPattern.extractHashFromPayToPubKeyHash(this);
else if (ScriptPattern.isPayToScriptHash(this))
return ScriptPattern.extractHashFromPayToScriptHash(this);
else if (ScriptPattern.isPayToWitnessHash(this))
return ScriptPattern.extractHashFromPayToWitnessHash(this);
if (ScriptPattern.isP2PKH(this))
return ScriptPattern.extractHashFromP2PKH(this);
else if (ScriptPattern.isP2SH(this))
return ScriptPattern.extractHashFromP2SH(this);
else if (ScriptPattern.isP2WH(this))
return ScriptPattern.extractHashFromP2WH(this);
else
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not in the standard scriptPubKey form");
}
@@ -297,14 +297,14 @@ public class Script {
* showing addresses rather than pubkeys.
*/
public Address getToAddress(NetworkParameters params, boolean forcePayToPubKey) throws ScriptException {
if (ScriptPattern.isPayToPubKeyHash(this))
return LegacyAddress.fromPubKeyHash(params, ScriptPattern.extractHashFromPayToPubKeyHash(this));
else if (ScriptPattern.isPayToScriptHash(this))
return LegacyAddress.fromScriptHash(params, ScriptPattern.extractHashFromPayToScriptHash(this));
else if (forcePayToPubKey && ScriptPattern.isPayToPubKey(this))
return LegacyAddress.fromKey(params, ECKey.fromPublicOnly(ScriptPattern.extractKeyFromPayToPubKey(this)));
else if (ScriptPattern.isPayToWitnessHash(this))
return SegwitAddress.fromHash(params, ScriptPattern.extractHashFromPayToWitnessHash(this));
if (ScriptPattern.isP2PKH(this))
return LegacyAddress.fromPubKeyHash(params, ScriptPattern.extractHashFromP2PKH(this));
else if (ScriptPattern.isP2SH(this))
return LegacyAddress.fromScriptHash(params, ScriptPattern.extractHashFromP2SH(this));
else if (forcePayToPubKey && ScriptPattern.isP2PK(this))
return LegacyAddress.fromKey(params, ECKey.fromPublicOnly(ScriptPattern.extractKeyFromP2PK(this)));
else if (ScriptPattern.isP2WH(this))
return SegwitAddress.fromHash(params, ScriptPattern.extractHashFromP2WH(this));
else
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Cannot cast this script to an address");
}
@@ -384,14 +384,14 @@ public class Script {
* It is expected that this program later on will be updated with proper signatures.
*/
public Script createEmptyInputScript(@Nullable ECKey key, @Nullable Script redeemScript) {
if (ScriptPattern.isPayToPubKeyHash(this)) {
if (ScriptPattern.isP2PKH(this)) {
checkArgument(key != null, "Key required to create P2PKH input script");
return ScriptBuilder.createInputScript(null, key);
} else if (ScriptPattern.isPayToWitnessPubKeyHash(this)) {
} else if (ScriptPattern.isP2WPKH(this)) {
return ScriptBuilder.createEmpty();
} else if (ScriptPattern.isPayToPubKey(this)) {
} else if (ScriptPattern.isP2PK(this)) {
return ScriptBuilder.createInputScript(null);
} else if (ScriptPattern.isPayToScriptHash(this)) {
} else if (ScriptPattern.isP2SH(this)) {
checkArgument(redeemScript != null, "Redeem script required to create P2SH input script");
return ScriptBuilder.createP2SHMultiSigInputScript(null, redeemScript);
} else {
@@ -400,11 +400,11 @@ public class Script {
}
public TransactionWitness createEmptyWitness(ECKey key) {
if (ScriptPattern.isPayToWitnessPubKeyHash(this)) {
if (ScriptPattern.isP2WPKH(this)) {
checkArgument(key != null, "Key required to create P2WPKH witness");
return TransactionWitness.EMPTY;
} else if (ScriptPattern.isPayToPubKey(this) || ScriptPattern.isPayToPubKeyHash(this)
|| ScriptPattern.isPayToScriptHash(this)) {
} else if (ScriptPattern.isP2PK(this) || ScriptPattern.isP2PKH(this)
|| ScriptPattern.isP2SH(this)) {
return null; // no witness
} else {
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Do not understand script type: " + this);
@@ -417,12 +417,12 @@ public class Script {
public Script getScriptSigWithSignature(Script scriptSig, byte[] sigBytes, int index) {
int sigsPrefixCount = 0;
int sigsSuffixCount = 0;
if (ScriptPattern.isPayToScriptHash(this)) {
if (ScriptPattern.isP2SH(this)) {
sigsPrefixCount = 1; // OP_0 <sig>* <redeemScript>
sigsSuffixCount = 1;
} else if (ScriptPattern.isSentToMultisig(this)) {
sigsPrefixCount = 1; // OP_0 <sig>*
} else if (ScriptPattern.isPayToPubKeyHash(this)) {
} else if (ScriptPattern.isP2PKH(this)) {
sigsSuffixCount = 1; // <sig> <pubkey>
}
return ScriptBuilder.updateScriptWithSignature(scriptSig, sigBytes, index, sigsPrefixCount, sigsSuffixCount);
@@ -592,10 +592,10 @@ public class Script {
// for N of M CHECKMULTISIG script we will need N signatures to spend
ScriptChunk nChunk = chunks.get(0);
return Script.decodeFromOpN(nChunk.opcode);
} else if (ScriptPattern.isPayToPubKeyHash(this) || ScriptPattern.isPayToPubKey(this)) {
} else if (ScriptPattern.isP2PKH(this) || ScriptPattern.isP2PK(this)) {
// P2PKH and P2PK require single sig
return 1;
} else if (ScriptPattern.isPayToScriptHash(this)) {
} else if (ScriptPattern.isP2SH(this)) {
throw new IllegalStateException("For P2SH number of signatures depends on redeem script");
} else {
throw new IllegalStateException("Unsupported script type");
@@ -607,21 +607,21 @@ public class Script {
* be required for certain types of script to estimate target size.
*/
public int getNumberOfBytesRequiredToSpend(@Nullable ECKey pubKey, @Nullable Script redeemScript) {
if (ScriptPattern.isPayToScriptHash(this)) {
if (ScriptPattern.isP2SH(this)) {
// scriptSig: <sig> [sig] [sig...] <redeemscript>
checkArgument(redeemScript != null, "P2SH script requires redeemScript to be spent");
return redeemScript.getNumberOfSignaturesRequiredToSpend() * SIG_SIZE + redeemScript.getProgram().length;
} else if (ScriptPattern.isSentToMultisig(this)) {
// scriptSig: OP_0 <sig> [sig] [sig...]
return getNumberOfSignaturesRequiredToSpend() * SIG_SIZE + 1;
} else if (ScriptPattern.isPayToPubKey(this)) {
} else if (ScriptPattern.isP2PK(this)) {
// scriptSig: <sig>
return SIG_SIZE;
} else if (ScriptPattern.isPayToPubKeyHash(this)) {
} else if (ScriptPattern.isP2PKH(this)) {
// scriptSig: <sig> <pubkey>
int uncompressedPubKeySize = 65;
return SIG_SIZE + (pubKey != null ? pubKey.getPubKey().length : uncompressedPubKeySize);
} else if (ScriptPattern.isPayToWitnessPubKeyHash(this)) {
} else if (ScriptPattern.isP2WPKH(this)) {
// scriptSig is empty
return 0;
} else {
@@ -631,7 +631,7 @@ public class Script {
@Deprecated
public boolean isPayToScriptHash() {
return ScriptPattern.isPayToScriptHash(this);
return ScriptPattern.isP2SH(this);
}
@Deprecated
@@ -1565,7 +1565,7 @@ public class Script {
*/
public void correctlySpends(Transaction txContainingThis, int scriptSigIndex, @Nullable TransactionWitness witness, @Nullable Coin value,
Script scriptPubKey, Set<VerifyFlag> verifyFlags) throws ScriptException {
if (ScriptPattern.isPayToWitnessPubKeyHash(scriptPubKey)) {
if (ScriptPattern.isP2WPKH(scriptPubKey)) {
// For SegWit, full validation isn't implemented. So we simply check the signature. P2SH_P2WPKH is handled
// by the P2SH code for now.
if (witness.getPushCount() < 2)
@@ -1638,7 +1638,7 @@ public class Script {
// overall scalability and performance.
// TODO: Check if we can take out enforceP2SH if there's a checkpoint at the enforcement block.
if (verifyFlags.contains(VerifyFlag.P2SH) && ScriptPattern.isPayToScriptHash(scriptPubKey)) {
if (verifyFlags.contains(VerifyFlag.P2SH) && ScriptPattern.isP2SH(scriptPubKey)) {
for (ScriptChunk chunk : chunks)
if (chunk.isOpCode() && chunk.opcode > OP_16)
throw new ScriptException(ScriptError.SCRIPT_ERR_SIG_PUSHONLY, "Attempted to spend a P2SH scriptPubKey with a script that contained script ops");
@@ -1670,15 +1670,15 @@ public class Script {
* @return The script type, or null if the script is of unknown type
*/
public @Nullable ScriptType getScriptType() {
if (ScriptPattern.isPayToPubKeyHash(this))
if (ScriptPattern.isP2PKH(this))
return ScriptType.P2PKH;
if (ScriptPattern.isPayToPubKey(this))
if (ScriptPattern.isP2PK(this))
return ScriptType.P2PK;
if (ScriptPattern.isPayToScriptHash(this))
if (ScriptPattern.isP2SH(this))
return ScriptType.P2SH;
if (ScriptPattern.isPayToWitnessPubKeyHash(this))
if (ScriptPattern.isP2WPKH(this))
return ScriptType.P2WPKH;
if (ScriptPattern.isPayToWitnessScriptHash(this))
if (ScriptPattern.isP2WSH(this))
return ScriptType.P2WSH;
return null;
}

View File

@@ -40,7 +40,7 @@ public class ScriptPattern {
* to send somebody money with a written code because their node is offline, but over time has become the standard
* way to make payments due to the short and recognizable base58 form addresses come in.
*/
public static boolean isPayToPubKeyHash(Script script) {
public static boolean isP2PKH(Script script) {
List<ScriptChunk> chunks = script.chunks;
if (chunks.size() != 5)
return false;
@@ -62,9 +62,9 @@ public class ScriptPattern {
/**
* Extract the pubkey hash from a P2PKH scriptPubKey. It's important that the script is in the correct form, so you
* will want to guard calls to this method with {@link #isPayToPubKeyHash(Script)}.
* will want to guard calls to this method with {@link #isP2PKH(Script)}.
*/
public static byte[] extractHashFromPayToPubKeyHash(Script script) {
public static byte[] extractHashFromP2PKH(Script script) {
return script.chunks.get(2).data;
}
@@ -78,7 +78,7 @@ public class ScriptPattern {
* P2SH is described by <a href="https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki">BIP16</a>.
* </p>
*/
public static boolean isPayToScriptHash(Script script) {
public static boolean isP2SH(Script script) {
List<ScriptChunk> chunks = script.chunks;
// We check for the effective serialized form because BIP16 defines a P2SH output using an exact byte
// template, not the logical program structure. Thus you can have two programs that look identical when
@@ -104,9 +104,9 @@ public class ScriptPattern {
/**
* Extract the script hash from a P2SH scriptPubKey. It's important that the script is in the correct form, so you
* will want to guard calls to this method with {@link #isPayToScriptHash(Script)}.
* will want to guard calls to this method with {@link #isP2SH(Script)}.
*/
public static byte[] extractHashFromPayToScriptHash(Script script) {
public static byte[] extractHashFromP2SH(Script script) {
return script.chunks.get(1).data;
}
@@ -116,7 +116,7 @@ public class ScriptPattern {
* of operation being susceptible to man-in-the-middle attacks. It is still used in coinbase outputs and can be
* useful more exotic types of transaction, but today most payments are to addresses.
*/
public static boolean isPayToPubKey(Script script) {
public static boolean isP2PK(Script script) {
List<ScriptChunk> chunks = script.chunks;
if (chunks.size() != 2)
return false;
@@ -135,9 +135,9 @@ public class ScriptPattern {
/**
* Extract the pubkey from a P2SH scriptPubKey. It's important that the script is in the correct form, so you will
* want to guard calls to this method with {@link #isPayToPubKey(Script)}.
* want to guard calls to this method with {@link #isP2PK(Script)}.
*/
public static byte[] extractKeyFromPayToPubKey(Script script) {
public static byte[] extractKeyFromP2PK(Script script) {
return script.chunks.get(0).data;
}
@@ -145,7 +145,7 @@ public class ScriptPattern {
* Returns true if this script is of the form {@code OP_0 <hash>}. This can either be a P2WPKH or P2WSH scriptPubKey. These
* two script types were introduced with segwit.
*/
public static boolean isPayToWitnessHash(Script script) {
public static boolean isP2WH(Script script) {
List<ScriptChunk> chunks = script.chunks;
if (chunks.size() != 2)
return false;
@@ -164,8 +164,8 @@ public class ScriptPattern {
* Returns true if this script is of the form {@code OP_0 <hash>} and hash is 20 bytes long. This can only be a P2WPKH
* scriptPubKey. This script type was introduced with segwit.
*/
public static boolean isPayToWitnessPubKeyHash(Script script) {
if (!isPayToWitnessHash(script))
public static boolean isP2WPKH(Script script) {
if (!isP2WH(script))
return false;
List<ScriptChunk> chunks = script.chunks;
if (!chunks.get(0).equalsOpCode(OP_0))
@@ -178,8 +178,8 @@ public class ScriptPattern {
* Returns true if this script is of the form {@code OP_0 <hash>} and hash is 32 bytes long. This can only be a P2WSH
* scriptPubKey. This script type was introduced with segwit.
*/
public static boolean isPayToWitnessScriptHash(Script script) {
if (!isPayToWitnessHash(script))
public static boolean isP2WSH(Script script) {
if (!isP2WH(script))
return false;
List<ScriptChunk> chunks = script.chunks;
if (!chunks.get(0).equalsOpCode(OP_0))
@@ -191,9 +191,9 @@ public class ScriptPattern {
/**
* Extract the pubkey hash from a P2WPKH or the script hash from a P2WSH scriptPubKey. It's important that the
* script is in the correct form, so you will want to guard calls to this method with
* {@link #isPayToWitnessHash(Script)}.
* {@link #isP2WH(Script)}.
*/
public static byte[] extractHashFromPayToWitnessHash(Script script) {
public static byte[] extractHashFromP2WH(Script script) {
return script.chunks.get(1).data;
}

View File

@@ -60,7 +60,7 @@ public abstract class CustomTransactionSigner implements TransactionSigner {
continue;
}
Script scriptPubKey = txOut.getScriptPubKey();
if (!ScriptPattern.isPayToScriptHash(scriptPubKey)) {
if (!ScriptPattern.isP2SH(scriptPubKey)) {
log.warn("CustomTransactionSigner works only with P2SH transactions");
return false;
}

View File

@@ -113,8 +113,8 @@ public class LocalTransactionSigner implements TransactionSigner {
// a CHECKMULTISIG program for P2SH inputs
byte[] script = redeemData.redeemScript.getProgram();
try {
if (ScriptPattern.isPayToPubKey(scriptPubKey) || ScriptPattern.isPayToPubKeyHash(scriptPubKey)
|| ScriptPattern.isPayToScriptHash(scriptPubKey)) {
if (ScriptPattern.isP2PK(scriptPubKey) || ScriptPattern.isP2PKH(scriptPubKey)
|| ScriptPattern.isP2SH(scriptPubKey)) {
TransactionSignature signature = tx.calculateSignature(i, key, script, Transaction.SigHash.ALL,
false);
@@ -130,7 +130,7 @@ public class LocalTransactionSigner implements TransactionSigner {
sigIndex);
txIn.setScriptSig(inputScript);
txIn.setWitness(null);
} else if (ScriptPattern.isPayToWitnessPubKeyHash(scriptPubKey)) {
} else if (ScriptPattern.isP2WPKH(scriptPubKey)) {
Script scriptCode = new ScriptBuilder().data(
ScriptBuilder.createOutputScript(LegacyAddress.fromKey(tx.getParams(), key)).getProgram())
.build();

View File

@@ -69,8 +69,8 @@ public class MissingSigResolutionSigner implements TransactionSigner {
Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
Script inputScript = txIn.getScriptSig();
if (ScriptPattern.isPayToScriptHash(scriptPubKey) || ScriptPattern.isSentToMultisig(scriptPubKey)) {
int sigSuffixCount = ScriptPattern.isPayToScriptHash(scriptPubKey) ? 1 : 0;
if (ScriptPattern.isP2SH(scriptPubKey) || ScriptPattern.isSentToMultisig(scriptPubKey)) {
int sigSuffixCount = ScriptPattern.isP2SH(scriptPubKey) ? 1 : 0;
// all chunks except the first one (OP_0) and the last (redeem script) are signatures
for (int j = 1; j < inputScript.getChunks().size() - sigSuffixCount; j++) {
ScriptChunk scriptChunk = inputScript.getChunks().get(j);
@@ -82,7 +82,7 @@ public class MissingSigResolutionSigner implements TransactionSigner {
}
}
}
} else if (ScriptPattern.isPayToPubKey(scriptPubKey) || ScriptPattern.isPayToPubKeyHash(scriptPubKey)) {
} else if (ScriptPattern.isP2PK(scriptPubKey) || ScriptPattern.isP2PKH(scriptPubKey)) {
if (inputScript.getChunks().get(0).equalsOpCode(0)) {
if (missingSigsMode == Wallet.MissingSigsMode.THROW) {
throw new ECKey.MissingPrivateKeyException();
@@ -90,14 +90,14 @@ public class MissingSigResolutionSigner implements TransactionSigner {
txIn.setScriptSig(scriptPubKey.getScriptSigWithSignature(inputScript, dummySig, 0));
}
}
} else if (ScriptPattern.isPayToWitnessPubKeyHash(scriptPubKey)) {
} else if (ScriptPattern.isP2WPKH(scriptPubKey)) {
if (txIn.getWitness() == null || txIn.getWitness().equals(TransactionWitness.EMPTY)
|| txIn.getWitness().getPush(0).length == 0) {
if (missingSigsMode == Wallet.MissingSigsMode.THROW) {
throw new ECKey.MissingPrivateKeyException();
} else if (missingSigsMode == Wallet.MissingSigsMode.USE_DUMMY_SIG) {
ECKey key = keyBag.findKeyFromPubKeyHash(
ScriptPattern.extractHashFromPayToWitnessHash(scriptPubKey), Script.ScriptType.P2WPKH);
ScriptPattern.extractHashFromP2WH(scriptPubKey), Script.ScriptType.P2WPKH);
txIn.setWitness(TransactionWitness.redeemP2WPKH(TransactionSignature.dummy(), key));
}
}

View File

@@ -376,9 +376,9 @@ public class KeyChainGroup implements KeyBag {
Script.ScriptType outputScriptType = chain.getOutputScriptType();
if (chain.isMarried()) {
Script outputScript = chain.freshOutputScript(purpose);
checkState(ScriptPattern.isPayToScriptHash(outputScript)); // Only handle P2SH for now
checkState(ScriptPattern.isP2SH(outputScript)); // Only handle P2SH for now
Address freshAddress = LegacyAddress.fromScriptHash(params,
ScriptPattern.extractHashFromPayToScriptHash(outputScript));
ScriptPattern.extractHashFromP2SH(outputScript));
maybeLookaheadScripts();
currentAddresses.put(purpose, freshAddress);
return freshAddress;

View File

@@ -63,12 +63,12 @@ public class KeyTimeCoinSelector implements CoinSelector {
// We ignore any other kind of exotic output on the assumption we can't spend it ourselves.
final Script scriptPubKey = output.getScriptPubKey();
ECKey controllingKey;
if (ScriptPattern.isPayToPubKey(scriptPubKey)) {
controllingKey = wallet.findKeyFromPubKey(ScriptPattern.extractKeyFromPayToPubKey(scriptPubKey));
} else if (ScriptPattern.isPayToPubKeyHash(scriptPubKey)) {
controllingKey = wallet.findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToPubKeyHash(scriptPubKey), Script.ScriptType.P2PKH);
} else if (ScriptPattern.isPayToWitnessPubKeyHash(scriptPubKey)) {
controllingKey = wallet.findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToWitnessHash(scriptPubKey), Script.ScriptType.P2WPKH);
if (ScriptPattern.isP2PK(scriptPubKey)) {
controllingKey = wallet.findKeyFromPubKey(ScriptPattern.extractKeyFromP2PK(scriptPubKey));
} else if (ScriptPattern.isP2PKH(scriptPubKey)) {
controllingKey = wallet.findKeyFromPubKeyHash(ScriptPattern.extractHashFromP2PKH(scriptPubKey), Script.ScriptType.P2PKH);
} else if (ScriptPattern.isP2WPKH(scriptPubKey)) {
controllingKey = wallet.findKeyFromPubKeyHash(ScriptPattern.extractHashFromP2WH(scriptPubKey), Script.ScriptType.P2WPKH);
} else {
log.info("Skipping tx output {} because it's not of simple form.", output);
continue;

View File

@@ -57,8 +57,8 @@ public class RedeemData {
* to spend such inputs.
*/
public static RedeemData of(ECKey key, Script redeemScript) {
checkArgument(ScriptPattern.isPayToPubKeyHash(redeemScript)
|| ScriptPattern.isPayToWitnessPubKeyHash(redeemScript) || ScriptPattern.isPayToPubKey(redeemScript));
checkArgument(ScriptPattern.isP2PKH(redeemScript)
|| ScriptPattern.isP2WPKH(redeemScript) || ScriptPattern.isP2PK(redeemScript));
return key != null ? new RedeemData(Collections.singletonList(key), redeemScript) : null;
}

View File

@@ -1108,7 +1108,7 @@ public class Wallet extends BaseTaggableObject
try {
List<Address> addresses = new LinkedList<>();
for (Script script : watchedScripts)
if (ScriptPattern.isPayToPubKeyHash(script))
if (ScriptPattern.isP2PKH(script))
addresses.add(script.getToAddress(params));
return addresses;
} finally {
@@ -1231,18 +1231,18 @@ public class Wallet extends BaseTaggableObject
for (TransactionOutput o : tx.getOutputs()) {
try {
Script script = o.getScriptPubKey();
if (ScriptPattern.isPayToPubKey(script)) {
byte[] pubkey = ScriptPattern.extractKeyFromPayToPubKey(script);
if (ScriptPattern.isP2PK(script)) {
byte[] pubkey = ScriptPattern.extractKeyFromP2PK(script);
keyChainGroup.markPubKeyAsUsed(pubkey);
} else if (ScriptPattern.isPayToPubKeyHash(script)) {
byte[] pubkeyHash = ScriptPattern.extractHashFromPayToPubKeyHash(script);
} else if (ScriptPattern.isP2PKH(script)) {
byte[] pubkeyHash = ScriptPattern.extractHashFromP2PKH(script);
keyChainGroup.markPubKeyHashAsUsed(pubkeyHash);
} else if (ScriptPattern.isPayToScriptHash(script)) {
} else if (ScriptPattern.isP2SH(script)) {
LegacyAddress a = LegacyAddress.fromScriptHash(tx.getParams(),
ScriptPattern.extractHashFromPayToScriptHash(script));
ScriptPattern.extractHashFromP2SH(script));
keyChainGroup.markP2SHAddressAsUsed(a);
} else if (ScriptPattern.isPayToWitnessHash(script)) {
byte[] pubkeyHash = ScriptPattern.extractHashFromPayToWitnessHash(script);
} else if (ScriptPattern.isP2WH(script)) {
byte[] pubkeyHash = ScriptPattern.extractHashFromP2WH(script);
keyChainGroup.markPubKeyHashAsUsed(pubkeyHash);
}
} catch (ScriptException e) {
@@ -4287,19 +4287,19 @@ public class Wallet extends BaseTaggableObject
* false if the form of the script is not known or if the script is OP_RETURN.
*/
public boolean canSignFor(Script script) {
if (ScriptPattern.isPayToPubKey(script)) {
byte[] pubkey = ScriptPattern.extractKeyFromPayToPubKey(script);
if (ScriptPattern.isP2PK(script)) {
byte[] pubkey = ScriptPattern.extractKeyFromP2PK(script);
ECKey key = findKeyFromPubKey(pubkey);
return key != null && (key.isEncrypted() || key.hasPrivKey());
} else if (ScriptPattern.isPayToScriptHash(script)) {
RedeemData data = findRedeemDataFromScriptHash(ScriptPattern.extractHashFromPayToScriptHash(script));
} else if (ScriptPattern.isP2SH(script)) {
RedeemData data = findRedeemDataFromScriptHash(ScriptPattern.extractHashFromP2SH(script));
return data != null && canSignFor(data.redeemScript);
} else if (ScriptPattern.isPayToPubKeyHash(script)) {
ECKey key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToPubKeyHash(script),
} else if (ScriptPattern.isP2PKH(script)) {
ECKey key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromP2PKH(script),
Script.ScriptType.P2PKH);
return key != null && (key.isEncrypted() || key.hasPrivKey());
} else if (ScriptPattern.isPayToWitnessPubKeyHash(script)) {
ECKey key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToWitnessHash(script),
} else if (ScriptPattern.isP2WPKH(script)) {
ECKey key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromP2WH(script),
Script.ScriptType.P2WPKH);
return key != null && (key.isEncrypted() || key.hasPrivKey()) && key.isCompressed();
} else if (ScriptPattern.isSentToMultisig(script)) {
@@ -4825,8 +4825,8 @@ public class Wallet extends BaseTaggableObject
// Returns true if the output is one that won't be selected by a data element matching in the scriptSig.
private boolean isTxOutputBloomFilterable(TransactionOutput out) {
Script script = out.getScriptPubKey();
boolean isScriptTypeSupported = ScriptPattern.isPayToPubKey(script) || ScriptPattern.isPayToScriptHash(script)
|| ScriptPattern.isPayToWitnessPubKeyHash(script) || ScriptPattern.isPayToWitnessScriptHash(script);
boolean isScriptTypeSupported = ScriptPattern.isP2PK(script) || ScriptPattern.isP2SH(script)
|| ScriptPattern.isP2WPKH(script) || ScriptPattern.isP2WSH(script);
return (isScriptTypeSupported && myUnspents.contains(out)) || watchedScripts.contains(script);
}
@@ -5083,16 +5083,16 @@ public class Wallet extends BaseTaggableObject
Script script = output.getScriptPubKey();
ECKey key = null;
Script redeemScript = null;
if (ScriptPattern.isPayToPubKeyHash(script)) {
key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToPubKeyHash(script),
if (ScriptPattern.isP2PKH(script)) {
key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromP2PKH(script),
Script.ScriptType.P2PKH);
checkNotNull(key, "Coin selection includes unspendable outputs");
} else if (ScriptPattern.isPayToWitnessPubKeyHash(script)) {
key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToWitnessHash(script),
} else if (ScriptPattern.isP2WPKH(script)) {
key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromP2WH(script),
Script.ScriptType.P2WPKH);
checkNotNull(key, "Coin selection includes unspendable outputs");
} else if (ScriptPattern.isPayToScriptHash(script)) {
redeemScript = findRedeemDataFromScriptHash(ScriptPattern.extractHashFromPayToScriptHash(script)).redeemScript;
} else if (ScriptPattern.isP2SH(script)) {
redeemScript = findRedeemDataFromScriptHash(ScriptPattern.extractHashFromP2SH(script)).redeemScript;
checkNotNull(redeemScript, "Coin selection includes unspendable outputs");
}
size += script.getNumberOfBytesRequiredToSpend(key, redeemScript);

View File

@@ -1819,7 +1819,7 @@ public class FullBlockTestGenerator {
input.setScriptSig(new ScriptBuilder().op(OP_1).build());
} else {
// Sign input
checkState(ScriptPattern.isPayToPubKey(prevOut.scriptPubKey));
checkState(ScriptPattern.isP2PK(prevOut.scriptPubKey));
Sha256Hash hash = t.hashForSignature(0, prevOut.scriptPubKey, SigHash.ALL, false);
input.setScriptSig(ScriptBuilder.createInputScript(
new TransactionSignature(coinbaseOutKey.sign(hash), SigHash.ALL, false))

View File

@@ -172,7 +172,7 @@ public class LegacyAddressTest {
LegacyAddress b = LegacyAddress.fromScriptHash(TESTNET, HEX.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
assertEquals("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe", b.toString());
LegacyAddress c = LegacyAddress.fromScriptHash(MAINNET,
ScriptPattern.extractHashFromPayToScriptHash(ScriptBuilder.createP2SHOutputScript(hex)));
ScriptPattern.extractHashFromP2SH(ScriptBuilder.createP2SHOutputScript(hex)));
assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", c.toString());
}
@@ -189,7 +189,7 @@ public class LegacyAddressTest {
List<ECKey> keys = Arrays.asList(key1, key2, key3);
Script p2shScript = ScriptBuilder.createP2SHOutputScript(2, keys);
LegacyAddress address = LegacyAddress.fromScriptHash(MAINNET,
ScriptPattern.extractHashFromPayToScriptHash(p2shScript));
ScriptPattern.extractHashFromP2SH(p2shScript));
assertEquals("3N25saC4dT24RphDAwLtD8LUN4E2gZPJke", address.toString());
}

View File

@@ -108,7 +108,7 @@ public class SegwitAddressTest {
if (valid.expectedWitnessVersion == 0) {
Script expectedScriptPubKey = new Script(Utils.HEX.decode(valid.expectedScriptPubKey));
assertEquals(address, SegwitAddress.fromHash(valid.expectedParams,
ScriptPattern.extractHashFromPayToWitnessHash(expectedScriptPubKey)));
ScriptPattern.extractHashFromP2WH(expectedScriptPubKey)));
}
assertEquals(valid.expectedWitnessVersion, address.getWitnessVersion());
}

View File

@@ -80,8 +80,8 @@ public class TransactionOutputTest extends TestWithWallet {
Transaction tx = new Transaction(MAINNET);
tx.addOutput(Coin.CENT, ScriptBuilder.createOpReturnScript("hello world!".getBytes()));
assertTrue(ScriptPattern.isOpReturn(tx.getOutput(0).getScriptPubKey()));
assertFalse(ScriptPattern.isPayToPubKey(tx.getOutput(0).getScriptPubKey()));
assertFalse(ScriptPattern.isPayToPubKeyHash(tx.getOutput(0).getScriptPubKey()));
assertFalse(ScriptPattern.isP2PK(tx.getOutput(0).getScriptPubKey()));
assertFalse(ScriptPattern.isP2PKH(tx.getOutput(0).getScriptPubKey()));
}
@Test

View File

@@ -543,7 +543,7 @@ public class ChannelConnectionTest extends TestWithWallet {
if (isMultiSigContract()) {
assertTrue(ScriptPattern.isSentToMultisig(broadcasts.take().getOutput(0).getScriptPubKey()));
} else {
assertTrue(ScriptPattern.isPayToScriptHash(broadcasts.take().getOutput(0).getScriptPubKey()));
assertTrue(ScriptPattern.isP2SH(broadcasts.take().getOutput(0).getScriptPubKey()));
}
broadcastTxPause.release();
assertEquals(TransactionConfidence.Source.SELF, broadcasts.take().getConfidence().getSource());

View File

@@ -258,10 +258,10 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (versionSelector == PaymentChannelClient.VersionSelector.VERSION_1) {
assertTrue(ScriptPattern.isSentToMultisig(script));
} else {
assertTrue(ScriptPattern.isPayToScriptHash(script));
assertTrue(ScriptPattern.isP2SH(script));
}
script = multisigContract.getOutput(1).getScriptPubKey();
assertTrue(ScriptPattern.isPayToPubKeyHash(script));
assertTrue(ScriptPattern.isP2PKH(script));
assertTrue(wallet.getPendingTransactions().contains(multisigContract));
// Provide the server with the multisig contract and simulate successful propagation/acceptance.
@@ -383,10 +383,10 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (versionSelector == PaymentChannelClient.VersionSelector.VERSION_1) {
assertTrue(ScriptPattern.isSentToMultisig(script));
} else {
assertTrue(ScriptPattern.isPayToScriptHash(script));
assertTrue(ScriptPattern.isP2SH(script));
}
script = multisigContract.getOutput(1).getScriptPubKey();
assertTrue(ScriptPattern.isPayToPubKeyHash(script));
assertTrue(ScriptPattern.isP2PKH(script));
assertTrue(wallet.getPendingTransactions().contains(multisigContract));
// Provide the server with the multisig contract and simulate successful propagation/acceptance.
@@ -859,10 +859,10 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (versionSelector == PaymentChannelClient.VersionSelector.VERSION_1) {
assertTrue(ScriptPattern.isSentToMultisig(script));
} else {
assertTrue(ScriptPattern.isPayToScriptHash(script));
assertTrue(ScriptPattern.isP2SH(script));
}
script = multisigContract.getOutput(1).getScriptPubKey();
assertTrue(ScriptPattern.isPayToPubKeyHash(script));
assertTrue(ScriptPattern.isP2PKH(script));
assertTrue(wallet.getPendingTransactions().contains(multisigContract));
// Provide the server with the multisig contract and simulate successful propagation/acceptance.
@@ -953,10 +953,10 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (versionSelector == PaymentChannelClient.VersionSelector.VERSION_1) {
assertTrue(ScriptPattern.isSentToMultisig(script));
} else {
assertTrue(ScriptPattern.isPayToScriptHash(script));
assertTrue(ScriptPattern.isP2SH(script));
}
script = multisigContract.getOutput(1).getScriptPubKey();
assertTrue(ScriptPattern.isPayToPubKeyHash(script));
assertTrue(ScriptPattern.isP2PKH(script));
assertTrue(wallet.getPendingTransactions().contains(multisigContract));
// Provide the server with the multisig contract and simulate successful propagation/acceptance.

View File

@@ -32,19 +32,19 @@ public class ScriptPatternTest {
@Test
public void testCommonScripts() {
assertTrue(ScriptPattern.isPayToPubKeyHash(
assertTrue(ScriptPattern.isP2PKH(
ScriptBuilder.createP2PKHOutputScript(keys.get(0))
));
assertTrue(ScriptPattern.isPayToScriptHash(
assertTrue(ScriptPattern.isP2SH(
ScriptBuilder.createP2SHOutputScript(2, keys)
));
assertTrue(ScriptPattern.isPayToPubKey(
assertTrue(ScriptPattern.isP2PK(
ScriptBuilder.createP2PKOutputScript(keys.get(0))
));
assertTrue(ScriptPattern.isPayToWitnessPubKeyHash(
assertTrue(ScriptPattern.isP2WPKH(
ScriptBuilder.createP2WPKHOutputScript(keys.get(0))
));
assertTrue(ScriptPattern.isPayToWitnessScriptHash(
assertTrue(ScriptPattern.isP2WSH(
ScriptBuilder.createP2WSHOutputScript(new ScriptBuilder().build())
));
assertTrue(ScriptPattern.isSentToMultisig(

View File

@@ -80,7 +80,7 @@ public class ScriptTest {
byte[] pubkeyBytes = HEX.decode(pubkeyProg);
Script pubkey = new Script(pubkeyBytes);
assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString());
Address toAddr = LegacyAddress.fromPubKeyHash(TESTNET, ScriptPattern.extractHashFromPayToPubKeyHash(pubkey));
Address toAddr = LegacyAddress.fromPubKeyHash(TESTNET, ScriptPattern.extractHashFromP2PKH(pubkey));
assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString());
}
@@ -113,14 +113,14 @@ public class ScriptTest {
@Test
public void testP2SHOutputScript() throws Exception {
Address p2shAddress = LegacyAddress.fromBase58(MAINNET, "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
assertTrue(ScriptPattern.isPayToScriptHash(ScriptBuilder.createOutputScript(p2shAddress)));
assertTrue(ScriptPattern.isP2SH(ScriptBuilder.createOutputScript(p2shAddress)));
}
@Test
public void testIp() throws Exception {
byte[] bytes = HEX.decode("41043e96222332ea7848323c08116dddafbfa917b8e37f0bdf63841628267148588a09a43540942d58d49717ad3fabfe14978cf4f0a8b84d2435dad16e9aa4d7f935ac");
Script s = new Script(bytes);
assertTrue(ScriptPattern.isPayToPubKey(s));
assertTrue(ScriptPattern.isP2PK(s));
}
@Test
@@ -446,7 +446,7 @@ public class ScriptTest {
// pay to script hash
Script p2shScript = ScriptBuilder.createP2SHOutputScript(new byte[20]);
Address scriptAddress = LegacyAddress.fromScriptHash(TESTNET,
ScriptPattern.extractHashFromPayToScriptHash(p2shScript));
ScriptPattern.extractHashFromP2SH(p2shScript));
assertEquals(scriptAddress, p2shScript.getToAddress(TESTNET, true));
}

View File

@@ -2299,7 +2299,7 @@ public class WalletTest extends TestWithWallet {
ECKey key = new ECKey();
SendRequest req = SendRequest.to(UNITTEST, key, SATOSHI.multiply(12));
assertArrayEquals(key.getPubKey(),
ScriptPattern.extractKeyFromPayToPubKey(req.tx.getOutputs().get(0).getScriptPubKey()));
ScriptPattern.extractKeyFromP2PK(req.tx.getOutputs().get(0).getScriptPubKey()));
}
@Test