diff --git a/core/src/main/java/org/bitcoinj/core/Utils.java b/core/src/main/java/org/bitcoinj/core/Utils.java index 6ccc748e..0489f956 100644 --- a/core/src/main/java/org/bitcoinj/core/Utils.java +++ b/core/src/main/java/org/bitcoinj/core/Utils.java @@ -609,4 +609,11 @@ public class Utils { public static boolean isMac() { return os == OS.MAC_OS; } + + public static String toString(List stack) { + List parts = new ArrayList(stack.size()); + for (byte[] push : stack) + parts.add('[' + HEX.encode(push) + ']'); + return SPACE_JOINER.join(parts); + } } diff --git a/core/src/main/java/org/bitcoinj/script/Script.java b/core/src/main/java/org/bitcoinj/script/Script.java index f4cc0cb5..d099f9db 100644 --- a/core/src/main/java/org/bitcoinj/script/Script.java +++ b/core/src/main/java/org/bitcoinj/script/Script.java @@ -1567,9 +1567,11 @@ public class Script { if (stack.size() == 0) throw new ScriptException(ScriptError.SCRIPT_ERR_EVAL_FALSE, "Stack empty at end of script execution."); - + + List stackCopy = new LinkedList(stack); if (!castToBool(stack.pollLast())) - throw new ScriptException(ScriptError.SCRIPT_ERR_EVAL_FALSE, "Script resulted in a non-true stack: " + stack); + throw new ScriptException(ScriptError.SCRIPT_ERR_EVAL_FALSE, + "Script resulted in a non-true stack: " + Utils.toString(stackCopy)); // P2SH is pay to script hash. It means that the scriptPubKey has a special form which is a valid // program but it has "useless" form that if evaluated as a normal program always returns true. @@ -1597,8 +1599,10 @@ public class Script { if (p2shStack.size() == 0) throw new ScriptException(ScriptError.SCRIPT_ERR_EVAL_FALSE, "P2SH stack empty at end of script execution."); + List p2shStackCopy = new LinkedList(p2shStack); if (!castToBool(p2shStack.pollLast())) - throw new ScriptException(ScriptError.SCRIPT_ERR_EVAL_FALSE, "P2SH script execution resulted in a non-true stack"); + throw new ScriptException(ScriptError.SCRIPT_ERR_EVAL_FALSE, + "P2SH script execution resulted in a non-true stack: " + Utils.toString(p2shStackCopy)); } }