aboutsummaryrefslogtreecommitdiff
path: root/src/script/script.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/script.cpp')
-rw-r--r--src/script/script.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/script/script.cpp b/src/script/script.cpp
index a5126e7cc2..3e19d0c2bf 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -5,7 +5,18 @@
#include "script.h"
-#include <boost/foreach.hpp>
+#include "tinyformat.h"
+#include "utilstrencodings.h"
+
+namespace {
+inline std::string ValueString(const std::vector<unsigned char>& vch)
+{
+ if (vch.size() <= 4)
+ return strprintf("%d", CScriptNum(vch).getint());
+ else
+ return HexStr(vch);
+}
+} // anon namespace
using namespace std;
@@ -253,3 +264,26 @@ bool CScript::HasCanonicalPushes() const
}
return true;
}
+
+std::string CScript::ToString() const
+{
+ std::string str;
+ opcodetype opcode;
+ std::vector<unsigned char> vch;
+ const_iterator pc = begin();
+ while (pc < end())
+ {
+ if (!str.empty())
+ str += " ";
+ if (!GetOp(pc, opcode, vch))
+ {
+ str += "[error]";
+ return str;
+ }
+ if (0 <= opcode && opcode <= OP_PUSHDATA4)
+ str += ValueString(vch);
+ else
+ str += GetOpName(opcode);
+ }
+ return str;
+}