aboutsummaryrefslogtreecommitdiff
path: root/src/core_write.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-29 18:00:10 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-09-29 18:36:04 +0200
commit2884b9a4aef53245798e4f50793eb3e70aa73a6d (patch)
treea158e359f766ece2fe8b567830ed90d64efd91ae /src/core_write.cpp
parent28fb5f388da2243386c26ab8793383db40715ea5 (diff)
parent8138cbea3c405e142d70b43b6c452e1738de3332 (diff)
Merge pull request #4960
8138cbe Add automatic script test generation, and actual checksig tests (Pieter Wuille)
Diffstat (limited to 'src/core_write.cpp')
-rw-r--r--src/core_write.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/core_write.cpp b/src/core_write.cpp
index cd64aabf63..40d547fb33 100644
--- a/src/core_write.cpp
+++ b/src/core_write.cpp
@@ -17,6 +17,41 @@
using namespace std;
+string FormatScript(const CScript& script)
+{
+ string ret;
+ CScript::const_iterator it = script.begin();
+ opcodetype op;
+ while (it != script.end()) {
+ CScript::const_iterator it2 = it;
+ vector<unsigned char> vch;
+ if (script.GetOp2(it, op, &vch)) {
+ if (op == OP_0) {
+ ret += "0 ";
+ continue;
+ } else if ((op >= OP_1 && op <= OP_16) || op == OP_1NEGATE) {
+ ret += strprintf("%i ", op - OP_1NEGATE - 1);
+ continue;
+ } else if (op >= OP_NOP && op <= OP_CHECKMULTISIGVERIFY) {
+ string str(GetOpName(op));
+ if (str.substr(0, 3) == string("OP_")) {
+ ret += str.substr(3, string::npos) + " ";
+ continue;
+ }
+ }
+ if (vch.size() > 0) {
+ ret += strprintf("0x%x 0x%x ", HexStr(it2, it - vch.size()), HexStr(it - vch.size(), it));
+ } else {
+ ret += strprintf("0x%x", HexStr(it2, it));
+ }
+ continue;
+ }
+ ret += strprintf("0x%x ", HexStr(it2, script.end()));
+ break;
+ }
+ return ret.substr(0, ret.size() - 1);
+}
+
string EncodeHexTx(const CTransaction& tx)
{
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);