| 31 | |
| 32 | |
| 33 | string FormatScript(const CScript& script) |
| 34 | { |
| 35 | string ret; |
| 36 | CScript::const_iterator it = script.begin(); |
| 37 | opcodetype op; |
| 38 | while (it != script.end()) { |
| 39 | CScript::const_iterator it2 = it; |
| 40 | vector<unsigned char> vch; |
| 41 | if (script.GetOp2(it, op, &vch)) { |
| 42 | if (op == OP_0) { |
| 43 | ret += "0 "; |
| 44 | continue; |
| 45 | } else if ((op >= OP_1 && op <= OP_16) || op == OP_1NEGATE) { |
| 46 | ret += strprintf("%i ", op - OP_1NEGATE - 1); |
| 47 | continue; |
| 48 | } else if (op >= OP_NOP && op <= OP_CHECKMULTISIGVERIFY) { |
| 49 | string str(GetOpName(op)); |
| 50 | if (str.substr(0, 3) == string("OP_")) { |
| 51 | ret += str.substr(3, string::npos) + " "; |
| 52 | continue; |
| 53 | } |
| 54 | } |
| 55 | if (vch.size() > 0) { |
| 56 | ret += strprintf("0x%x 0x%x ", HexStr(it2, it - vch.size()), HexStr(it - vch.size(), it)); |
| 57 | } else { |
| 58 | ret += strprintf("0x%x", HexStr(it2, it)); |
| 59 | } |
| 60 | continue; |
| 61 | } |
| 62 | ret += strprintf("0x%x ", HexStr(it2, script.end())); |
| 63 | break; |
| 64 | } |
| 65 | return ret.substr(0, ret.size() - 1); |
| 66 | } |
| 67 | |
| 68 | string EncodeHexTx(const CTransaction& tx) |
| 69 | { |