aboutsummaryrefslogtreecommitdiff
path: root/src/core_write.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-20 03:13:04 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-09-26 21:58:48 +0200
commit8138cbea3c405e142d70b43b6c452e1738de3332 (patch)
tree0e472b02e62a705b34954d2f8a8eff61cf4c21a3 /src/core_write.cpp
parent64cfaf891fe539b36f6be37dac6c28a712d70b96 (diff)
downloadbitcoin-8138cbea3c405e142d70b43b6c452e1738de3332.tar.xz
Add automatic script test generation, and actual checksig tests
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);