// TODO: Move this into bitcoinj post-0.12
private DefaultRiskAnalysis.RuleViolation isInputStandard(TransactionInput input, Script scriptPubKey) {
DefaultRiskAnalysis.RuleViolation violation = input.isStandard();
if (violation != DefaultRiskAnalysis.RuleViolation.NONE)
return violation;
Script scriptSig = input.getScriptSig();
int args = getNumExpectedScriptSigArgs(scriptPubKey);
LinkedList<byte[]> stack = Lists.newLinkedList();
// This is fast and cannot execute any signature checks, because we already verified with the previous
// isStandard() call that it only contains data pushes.
Script.executeScript(null, -1, scriptSig, stack, true);
if (scriptPubKey.isPayToScriptHash()) {
Script redeemScript = null;
try {
if (stack.isEmpty())
throw new VerificationException("Empty stack"); // Should never happen: can't have empty scripts.
redeemScript = new Script(stack.getLast());
args += getNumExpectedScriptSigArgs(redeemScript);
} catch (VerificationException e) {
// We can get here if the redeem script is corrupted or unparseable in some way, or if the script type
// simply isn't recognised by getNumExpected... - Bitcoin Core appears to simply treat any garbage
// script as non-standard.