diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-10-22 12:08:51 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-10-22 12:16:50 +0200 |
commit | 25cc1cf8dc03b9ba0ae886d354855adc207b5b6e (patch) | |
tree | 9298713771596e3ef2c45eb98b3564a995af7978 /src/script/script.cpp | |
parent | 13bddef87019f6608f40031619bee93479d27cd0 (diff) | |
parent | 85c579e3a63cf505d6cedc454755265572e97d3e (diff) | |
download | bitcoin-25cc1cf8dc03b9ba0ae886d354855adc207b5b6e.tar.xz |
Merge pull request #4981
85c579e script: add a slew of includes all around and drop includes from script.h (Cory Fields)
db8eb54 script: move ToString and ValueString out of the header (Cory Fields)
e9ca428 script: add ToByteVector() for converting anything with begin/end (Cory Fields)
066e2a1 script: move CScriptID to standard.h and add a ctor for creating them from CScripts (Cory Fields)
Diffstat (limited to 'src/script/script.cpp')
-rw-r--r-- | src/script/script.cpp | 36 |
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; +} |