diff options
| author | Cory Fields <[email protected]> | 2014-09-30 19:45:20 -0400 |
|---|---|---|
| committer | Cory Fields <[email protected]> | 2014-10-17 13:44:14 -0400 |
| commit | db8eb54bd7239ff2b046fe34b1c8d692860c6b5b (patch) | |
| tree | 1e7f930b2adeb44df71e1c32d55a8bdc71aff485 /src/script/script.cpp | |
| parent | script: add ToByteVector() for converting anything with begin/end (diff) | |
| download | discoin-db8eb54bd7239ff2b046fe34b1c8d692860c6b5b.tar.xz discoin-db8eb54bd7239ff2b046fe34b1c8d692860c6b5b.zip | |
script: move ToString and ValueString out of the header
Diffstat (limited to 'src/script/script.cpp')
| -rw-r--r-- | src/script/script.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/script/script.cpp b/src/script/script.cpp index a5126e7cc..1ce8ddb6d 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -7,6 +7,16 @@ #include <boost/foreach.hpp> +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; const char* GetOpName(opcodetype opcode) @@ -253,3 +263,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; +} |