-
+ D5CCCEDB7EE0B15E1A48A87F058E8263420CE9603484120D6E3D0859BFBD9DCB93F1F332EF26814E605005A2906E5156D20B0867700D251E3CFB2EB160E41D09
bitcoin/src/script.h
(0 . 0)(1 . 734)
20386 // /****************************\
20387 // * EXPERIMENTAL BRANCH. *
20388 // * FOR LABORATORY USE ONLY. *
20389 // ********************************
20390 // ************
20391 // **************
20392 // ****************
20393 // **** **** ****
20394 // *** *** ***
20395 // *** *** ***
20396 // *** * * **
20397 // ******** ********
20398 // ******* ******
20399 // *** **
20400 // * ******* **
20401 // ** * * * * *
20402 // ** * * ***
20403 // **** * * * * ****
20404 // **** *** * * ** ***
20405 // **** ********* ******
20406 // ******* ***** *******
20407 // ********* ****** **
20408 // ** ****** ******
20409 // ** ******* **
20410 // ** ******* ***
20411 // **** ******** ************
20412 // ************ ************
20413 // ******** *******
20414 // ****** ****
20415 // *** ***
20416 // ********************************
20417 // Copyright (c) 2009-2010 Satoshi Nakamoto
20418 // Copyright (c) 2011 The Bitcoin developers
20419 // Distributed under the MIT/X11 software license, see the accompanying
20420 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
20421 #ifndef H_BITCOIN_SCRIPT
20422 #define H_BITCOIN_SCRIPT
20423
20424 #include "base58.h"
20425 #include "keystore.h"
20426
20427 #include <string>
20428 #include <vector>
20429
20430 #include <boost/foreach.hpp>
20431
20432 class CTransaction;
20433
20434 enum
20435 {
20436 SIGHASH_ALL = 1,
20437 SIGHASH_NONE = 2,
20438 SIGHASH_SINGLE = 3,
20439 SIGHASH_ANYONECANPAY = 0x80,
20440 };
20441
20442
20443
20444 enum opcodetype
20445 {
20446 // push value
20447 OP_0=0,
20448 OP_FALSE=OP_0,
20449 OP_PUSHDATA1=76,
20450 OP_PUSHDATA2,
20451 OP_PUSHDATA4,
20452 OP_1NEGATE,
20453 OP_RESERVED,
20454 OP_1,
20455 OP_TRUE=OP_1,
20456 OP_2,
20457 OP_3,
20458 OP_4,
20459 OP_5,
20460 OP_6,
20461 OP_7,
20462 OP_8,
20463 OP_9,
20464 OP_10,
20465 OP_11,
20466 OP_12,
20467 OP_13,
20468 OP_14,
20469 OP_15,
20470 OP_16,
20471
20472 // control
20473 OP_NOP,
20474 OP_VER,
20475 OP_IF,
20476 OP_NOTIF,
20477 OP_VERIF,
20478 OP_VERNOTIF,
20479 OP_ELSE,
20480 OP_ENDIF,
20481 OP_VERIFY,
20482 OP_RETURN,
20483
20484 // stack ops
20485 OP_TOALTSTACK,
20486 OP_FROMALTSTACK,
20487 OP_2DROP,
20488 OP_2DUP,
20489 OP_3DUP,
20490 OP_2OVER,
20491 OP_2ROT,
20492 OP_2SWAP,
20493 OP_IFDUP,
20494 OP_DEPTH,
20495 OP_DROP,
20496 OP_DUP,
20497 OP_NIP,
20498 OP_OVER,
20499 OP_PICK,
20500 OP_ROLL,
20501 OP_ROT,
20502 OP_SWAP,
20503 OP_TUCK,
20504
20505 // splice ops
20506 OP_CAT,
20507 OP_SUBSTR,
20508 OP_LEFT,
20509 OP_RIGHT,
20510 OP_SIZE,
20511
20512 // bit logic
20513 OP_INVERT,
20514 OP_AND,
20515 OP_OR,
20516 OP_XOR,
20517 OP_EQUAL,
20518 OP_EQUALVERIFY,
20519 OP_RESERVED1,
20520 OP_RESERVED2,
20521
20522 // numeric
20523 OP_1ADD,
20524 OP_1SUB,
20525 OP_2MUL,
20526 OP_2DIV,
20527 OP_NEGATE,
20528 OP_ABS,
20529 OP_NOT,
20530 OP_0NOTEQUAL,
20531
20532 OP_ADD,
20533 OP_SUB,
20534 OP_MUL,
20535 OP_DIV,
20536 OP_MOD,
20537 OP_LSHIFT,
20538 OP_RSHIFT,
20539
20540 OP_BOOLAND,
20541 OP_BOOLOR,
20542 OP_NUMEQUAL,
20543 OP_NUMEQUALVERIFY,
20544 OP_NUMNOTEQUAL,
20545 OP_LESSTHAN,
20546 OP_GREATERTHAN,
20547 OP_LESSTHANOREQUAL,
20548 OP_GREATERTHANOREQUAL,
20549 OP_MIN,
20550 OP_MAX,
20551
20552 OP_WITHIN,
20553
20554 // crypto
20555 OP_RIPEMD160,
20556 OP_SHA1,
20557 OP_SHA256,
20558 OP_HASH160,
20559 OP_HASH256,
20560 OP_CODESEPARATOR,
20561 OP_CHECKSIG,
20562 OP_CHECKSIGVERIFY,
20563 OP_CHECKMULTISIG,
20564 OP_CHECKMULTISIGVERIFY,
20565
20566 // expansion
20567 OP_NOP1,
20568 OP_NOP2,
20569 OP_NOP3,
20570 OP_NOP4,
20571 OP_NOP5,
20572 OP_NOP6,
20573 OP_NOP7,
20574 OP_NOP8,
20575 OP_NOP9,
20576 OP_NOP10,
20577
20578
20579
20580 // template matching params
20581 OP_PUBKEYHASH = 0xfd,
20582 OP_PUBKEY = 0xfe,
20583
20584 OP_INVALIDOPCODE = 0xff,
20585 };
20586
20587
20588
20589
20590
20591
20592
20593
20594 inline const char* GetOpName(opcodetype opcode)
20595 {
20596 switch (opcode)
20597 {
20598 // push value
20599 case OP_0 : return "0";
20600 case OP_PUSHDATA1 : return "OP_PUSHDATA1";
20601 case OP_PUSHDATA2 : return "OP_PUSHDATA2";
20602 case OP_PUSHDATA4 : return "OP_PUSHDATA4";
20603 case OP_1NEGATE : return "-1";
20604 case OP_RESERVED : return "OP_RESERVED";
20605 case OP_1 : return "1";
20606 case OP_2 : return "2";
20607 case OP_3 : return "3";
20608 case OP_4 : return "4";
20609 case OP_5 : return "5";
20610 case OP_6 : return "6";
20611 case OP_7 : return "7";
20612 case OP_8 : return "8";
20613 case OP_9 : return "9";
20614 case OP_10 : return "10";
20615 case OP_11 : return "11";
20616 case OP_12 : return "12";
20617 case OP_13 : return "13";
20618 case OP_14 : return "14";
20619 case OP_15 : return "15";
20620 case OP_16 : return "16";
20621
20622 // control
20623 case OP_NOP : return "OP_NOP";
20624 case OP_VER : return "OP_VER";
20625 case OP_IF : return "OP_IF";
20626 case OP_NOTIF : return "OP_NOTIF";
20627 case OP_VERIF : return "OP_VERIF";
20628 case OP_VERNOTIF : return "OP_VERNOTIF";
20629 case OP_ELSE : return "OP_ELSE";
20630 case OP_ENDIF : return "OP_ENDIF";
20631 case OP_VERIFY : return "OP_VERIFY";
20632 case OP_RETURN : return "OP_RETURN";
20633
20634 // stack ops
20635 case OP_TOALTSTACK : return "OP_TOALTSTACK";
20636 case OP_FROMALTSTACK : return "OP_FROMALTSTACK";
20637 case OP_2DROP : return "OP_2DROP";
20638 case OP_2DUP : return "OP_2DUP";
20639 case OP_3DUP : return "OP_3DUP";
20640 case OP_2OVER : return "OP_2OVER";
20641 case OP_2ROT : return "OP_2ROT";
20642 case OP_2SWAP : return "OP_2SWAP";
20643 case OP_IFDUP : return "OP_IFDUP";
20644 case OP_DEPTH : return "OP_DEPTH";
20645 case OP_DROP : return "OP_DROP";
20646 case OP_DUP : return "OP_DUP";
20647 case OP_NIP : return "OP_NIP";
20648 case OP_OVER : return "OP_OVER";
20649 case OP_PICK : return "OP_PICK";
20650 case OP_ROLL : return "OP_ROLL";
20651 case OP_ROT : return "OP_ROT";
20652 case OP_SWAP : return "OP_SWAP";
20653 case OP_TUCK : return "OP_TUCK";
20654
20655 // splice ops
20656 case OP_CAT : return "OP_CAT";
20657 case OP_SUBSTR : return "OP_SUBSTR";
20658 case OP_LEFT : return "OP_LEFT";
20659 case OP_RIGHT : return "OP_RIGHT";
20660 case OP_SIZE : return "OP_SIZE";
20661
20662 // bit logic
20663 case OP_INVERT : return "OP_INVERT";
20664 case OP_AND : return "OP_AND";
20665 case OP_OR : return "OP_OR";
20666 case OP_XOR : return "OP_XOR";
20667 case OP_EQUAL : return "OP_EQUAL";
20668 case OP_EQUALVERIFY : return "OP_EQUALVERIFY";
20669 case OP_RESERVED1 : return "OP_RESERVED1";
20670 case OP_RESERVED2 : return "OP_RESERVED2";
20671
20672 // numeric
20673 case OP_1ADD : return "OP_1ADD";
20674 case OP_1SUB : return "OP_1SUB";
20675 case OP_2MUL : return "OP_2MUL";
20676 case OP_2DIV : return "OP_2DIV";
20677 case OP_NEGATE : return "OP_NEGATE";
20678 case OP_ABS : return "OP_ABS";
20679 case OP_NOT : return "OP_NOT";
20680 case OP_0NOTEQUAL : return "OP_0NOTEQUAL";
20681 case OP_ADD : return "OP_ADD";
20682 case OP_SUB : return "OP_SUB";
20683 case OP_MUL : return "OP_MUL";
20684 case OP_DIV : return "OP_DIV";
20685 case OP_MOD : return "OP_MOD";
20686 case OP_LSHIFT : return "OP_LSHIFT";
20687 case OP_RSHIFT : return "OP_RSHIFT";
20688 case OP_BOOLAND : return "OP_BOOLAND";
20689 case OP_BOOLOR : return "OP_BOOLOR";
20690 case OP_NUMEQUAL : return "OP_NUMEQUAL";
20691 case OP_NUMEQUALVERIFY : return "OP_NUMEQUALVERIFY";
20692 case OP_NUMNOTEQUAL : return "OP_NUMNOTEQUAL";
20693 case OP_LESSTHAN : return "OP_LESSTHAN";
20694 case OP_GREATERTHAN : return "OP_GREATERTHAN";
20695 case OP_LESSTHANOREQUAL : return "OP_LESSTHANOREQUAL";
20696 case OP_GREATERTHANOREQUAL : return "OP_GREATERTHANOREQUAL";
20697 case OP_MIN : return "OP_MIN";
20698 case OP_MAX : return "OP_MAX";
20699 case OP_WITHIN : return "OP_WITHIN";
20700
20701 // crypto
20702 case OP_RIPEMD160 : return "OP_RIPEMD160";
20703 case OP_SHA1 : return "OP_SHA1";
20704 case OP_SHA256 : return "OP_SHA256";
20705 case OP_HASH160 : return "OP_HASH160";
20706 case OP_HASH256 : return "OP_HASH256";
20707 case OP_CODESEPARATOR : return "OP_CODESEPARATOR";
20708 case OP_CHECKSIG : return "OP_CHECKSIG";
20709 case OP_CHECKSIGVERIFY : return "OP_CHECKSIGVERIFY";
20710 case OP_CHECKMULTISIG : return "OP_CHECKMULTISIG";
20711 case OP_CHECKMULTISIGVERIFY : return "OP_CHECKMULTISIGVERIFY";
20712
20713 // expanson
20714 case OP_NOP1 : return "OP_NOP1";
20715 case OP_NOP2 : return "OP_NOP2";
20716 case OP_NOP3 : return "OP_NOP3";
20717 case OP_NOP4 : return "OP_NOP4";
20718 case OP_NOP5 : return "OP_NOP5";
20719 case OP_NOP6 : return "OP_NOP6";
20720 case OP_NOP7 : return "OP_NOP7";
20721 case OP_NOP8 : return "OP_NOP8";
20722 case OP_NOP9 : return "OP_NOP9";
20723 case OP_NOP10 : return "OP_NOP10";
20724
20725
20726
20727 // template matching params
20728 case OP_PUBKEYHASH : return "OP_PUBKEYHASH";
20729 case OP_PUBKEY : return "OP_PUBKEY";
20730
20731 case OP_INVALIDOPCODE : return "OP_INVALIDOPCODE";
20732 default:
20733 return "OP_UNKNOWN";
20734 }
20735 };
20736
20737
20738
20739
20740 inline std::string ValueString(const std::vector<unsigned char>& vch)
20741 {
20742 if (vch.size() <= 4)
20743 return strprintf("%d", CBigNum(vch).getint());
20744 else
20745 return HexStr(vch);
20746 }
20747
20748 inline std::string StackString(const std::vector<std::vector<unsigned char> >& vStack)
20749 {
20750 std::string str;
20751 BOOST_FOREACH(const std::vector<unsigned char>& vch, vStack)
20752 {
20753 if (!str.empty())
20754 str += " ";
20755 str += ValueString(vch);
20756 }
20757 return str;
20758 }
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768 class CScript : public std::vector<unsigned char>
20769 {
20770 protected:
20771 CScript& push_int64(int64 n)
20772 {
20773 if (n == -1 || (n >= 1 && n <= 16))
20774 {
20775 push_back(n + (OP_1 - 1));
20776 }
20777 else
20778 {
20779 CBigNum bn(n);
20780 *this << bn.getvch();
20781 }
20782 return *this;
20783 }
20784
20785 CScript& push_uint64(uint64 n)
20786 {
20787 if (n >= 1 && n <= 16)
20788 {
20789 push_back(n + (OP_1 - 1));
20790 }
20791 else
20792 {
20793 CBigNum bn(n);
20794 *this << bn.getvch();
20795 }
20796 return *this;
20797 }
20798
20799 public:
20800 CScript() { }
20801 CScript(const CScript& b) : std::vector<unsigned char>(b.begin(), b.end()) { }
20802 CScript(const_iterator pbegin, const_iterator pend) : std::vector<unsigned char>(pbegin, pend) { }
20803 #ifndef _MSC_VER
20804 CScript(const unsigned char* pbegin, const unsigned char* pend) : std::vector<unsigned char>(pbegin, pend) { }
20805 #endif
20806
20807 CScript& operator+=(const CScript& b)
20808 {
20809 insert(end(), b.begin(), b.end());
20810 return *this;
20811 }
20812
20813 friend CScript operator+(const CScript& a, const CScript& b)
20814 {
20815 CScript ret = a;
20816 ret += b;
20817 return ret;
20818 }
20819
20820
20821 explicit CScript(char b) { operator<<(b); }
20822 explicit CScript(short b) { operator<<(b); }
20823 explicit CScript(int b) { operator<<(b); }
20824 explicit CScript(long b) { operator<<(b); }
20825 explicit CScript(int64 b) { operator<<(b); }
20826 explicit CScript(unsigned char b) { operator<<(b); }
20827 explicit CScript(unsigned int b) { operator<<(b); }
20828 explicit CScript(unsigned short b) { operator<<(b); }
20829 explicit CScript(unsigned long b) { operator<<(b); }
20830 explicit CScript(uint64 b) { operator<<(b); }
20831
20832 explicit CScript(opcodetype b) { operator<<(b); }
20833 explicit CScript(const uint256& b) { operator<<(b); }
20834 explicit CScript(const CBigNum& b) { operator<<(b); }
20835 explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
20836
20837
20838 CScript& operator<<(char b) { return push_int64(b); }
20839 CScript& operator<<(short b) { return push_int64(b); }
20840 CScript& operator<<(int b) { return push_int64(b); }
20841 CScript& operator<<(long b) { return push_int64(b); }
20842 CScript& operator<<(int64 b) { return push_int64(b); }
20843 CScript& operator<<(unsigned char b) { return push_uint64(b); }
20844 CScript& operator<<(unsigned int b) { return push_uint64(b); }
20845 CScript& operator<<(unsigned short b) { return push_uint64(b); }
20846 CScript& operator<<(unsigned long b) { return push_uint64(b); }
20847 CScript& operator<<(uint64 b) { return push_uint64(b); }
20848
20849 CScript& operator<<(opcodetype opcode)
20850 {
20851 if (opcode < 0 || opcode > 0xff)
20852 throw std::runtime_error("CScript::operator<<() : invalid opcode");
20853 insert(end(), (unsigned char)opcode);
20854 return *this;
20855 }
20856
20857 CScript& operator<<(const uint160& b)
20858 {
20859 insert(end(), sizeof(b));
20860 insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
20861 return *this;
20862 }
20863
20864 CScript& operator<<(const uint256& b)
20865 {
20866 insert(end(), sizeof(b));
20867 insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
20868 return *this;
20869 }
20870
20871 CScript& operator<<(const CBigNum& b)
20872 {
20873 *this << b.getvch();
20874 return *this;
20875 }
20876
20877 CScript& operator<<(const std::vector<unsigned char>& b)
20878 {
20879 if (b.size() < OP_PUSHDATA1)
20880 {
20881 insert(end(), (unsigned char)b.size());
20882 }
20883 else if (b.size() <= 0xff)
20884 {
20885 insert(end(), OP_PUSHDATA1);
20886 insert(end(), (unsigned char)b.size());
20887 }
20888 else if (b.size() <= 0xffff)
20889 {
20890 insert(end(), OP_PUSHDATA2);
20891 unsigned short nSize = b.size();
20892 insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
20893 }
20894 else
20895 {
20896 insert(end(), OP_PUSHDATA4);
20897 unsigned int nSize = b.size();
20898 insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
20899 }
20900 insert(end(), b.begin(), b.end());
20901 return *this;
20902 }
20903
20904 CScript& operator<<(const CScript& b)
20905 {
20906 // I'm not sure if this should push the script or concatenate scripts.
20907 // If there's ever a use for pushing a script onto a script, delete this member fn
20908 assert(!"warning: pushing a CScript onto a CScript with << is probably not intended, use + to concatenate");
20909 return *this;
20910 }
20911
20912
20913 bool GetOp(iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet)
20914 {
20915 // Wrapper so it can be called with either iterator or const_iterator
20916 const_iterator pc2 = pc;
20917 bool fRet = GetOp2(pc2, opcodeRet, &vchRet);
20918 pc = begin() + (pc2 - begin());
20919 return fRet;
20920 }
20921
20922 bool GetOp(iterator& pc, opcodetype& opcodeRet)
20923 {
20924 const_iterator pc2 = pc;
20925 bool fRet = GetOp2(pc2, opcodeRet, NULL);
20926 pc = begin() + (pc2 - begin());
20927 return fRet;
20928 }
20929
20930 bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
20931 {
20932 return GetOp2(pc, opcodeRet, &vchRet);
20933 }
20934
20935 bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
20936 {
20937 return GetOp2(pc, opcodeRet, NULL);
20938 }
20939
20940 bool GetOp2(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet) const
20941 {
20942 opcodeRet = OP_INVALIDOPCODE;
20943 if (pvchRet)
20944 pvchRet->clear();
20945 if (pc >= end())
20946 return false;
20947
20948 // Read instruction
20949 if (end() - pc < 1)
20950 return false;
20951 unsigned int opcode = *pc++;
20952
20953 // Immediate operand
20954 if (opcode <= OP_PUSHDATA4)
20955 {
20956 unsigned int nSize;
20957 if (opcode < OP_PUSHDATA1)
20958 {
20959 nSize = opcode;
20960 }
20961 else if (opcode == OP_PUSHDATA1)
20962 {
20963 if (end() - pc < 1)
20964 return false;
20965 nSize = *pc++;
20966 }
20967 else if (opcode == OP_PUSHDATA2)
20968 {
20969 if (end() - pc < 2)
20970 return false;
20971 nSize = 0;
20972 memcpy(&nSize, &pc[0], 2);
20973 pc += 2;
20974 }
20975 else if (opcode == OP_PUSHDATA4)
20976 {
20977 if (end() - pc < 4)
20978 return false;
20979 memcpy(&nSize, &pc[0], 4);
20980 pc += 4;
20981 }
20982 if (end() - pc < nSize)
20983 return false;
20984 if (pvchRet)
20985 pvchRet->assign(pc, pc + nSize);
20986 pc += nSize;
20987 }
20988
20989 opcodeRet = (opcodetype)opcode;
20990 return true;
20991 }
20992
20993
20994 void FindAndDelete(const CScript& b)
20995 {
20996 if (b.empty())
20997 return;
20998 iterator pc = begin();
20999 opcodetype opcode;
21000 do
21001 {
21002 while (end() - pc >= b.size() && memcmp(&pc[0], &b[0], b.size()) == 0)
21003 erase(pc, pc + b.size());
21004 }
21005 while (GetOp(pc, opcode));
21006 }
21007
21008
21009 int GetSigOpCount() const
21010 {
21011 int n = 0;
21012 const_iterator pc = begin();
21013 while (pc < end())
21014 {
21015 opcodetype opcode;
21016 if (!GetOp(pc, opcode))
21017 break;
21018 if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY)
21019 n++;
21020 else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY)
21021 n += 20;
21022 }
21023 return n;
21024 }
21025
21026
21027 bool IsPushOnly() const
21028 {
21029 if (size() > 200)
21030 return false;
21031 const_iterator pc = begin();
21032 while (pc < end())
21033 {
21034 opcodetype opcode;
21035 if (!GetOp(pc, opcode))
21036 return false;
21037 if (opcode > OP_16)
21038 return false;
21039 }
21040 return true;
21041 }
21042
21043
21044 CBitcoinAddress GetBitcoinAddress() const
21045 {
21046 opcodetype opcode;
21047 std::vector<unsigned char> vch;
21048 CScript::const_iterator pc = begin();
21049 if (!GetOp(pc, opcode, vch) || opcode != OP_DUP) return 0;
21050 if (!GetOp(pc, opcode, vch) || opcode != OP_HASH160) return 0;
21051 if (!GetOp(pc, opcode, vch) || vch.size() != sizeof(uint160)) return 0;
21052 uint160 hash160 = uint160(vch);
21053 if (!GetOp(pc, opcode, vch) || opcode != OP_EQUALVERIFY) return 0;
21054 if (!GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG) return 0;
21055 if (pc != end()) return 0;
21056 return CBitcoinAddress(hash160);
21057 }
21058
21059 void SetBitcoinAddress(const CBitcoinAddress& address)
21060 {
21061 this->clear();
21062 *this << OP_DUP << OP_HASH160 << address.GetHash160() << OP_EQUALVERIFY << OP_CHECKSIG;
21063 }
21064
21065 void SetBitcoinAddress(const std::vector<unsigned char>& vchPubKey)
21066 {
21067 SetBitcoinAddress(CBitcoinAddress(vchPubKey));
21068 }
21069
21070
21071 void PrintHex() const
21072 {
21073 printf("CScript(%s)\n", HexStr(begin(), end(), true).c_str());
21074 }
21075
21076 std::string ToString() const
21077 {
21078 std::string str;
21079 opcodetype opcode;
21080 std::vector<unsigned char> vch;
21081 const_iterator pc = begin();
21082 while (pc < end())
21083 {
21084 if (!str.empty())
21085 str += " ";
21086 if (!GetOp(pc, opcode, vch))
21087 {
21088 str += "[error]";
21089 return str;
21090 }
21091 if (0 <= opcode && opcode <= OP_PUSHDATA4)
21092 str += ValueString(vch);
21093 else
21094 str += GetOpName(opcode);
21095 }
21096 return str;
21097 }
21098
21099 void print() const
21100 {
21101 printf("%s\n", ToString().c_str());
21102 }
21103 };
21104
21105
21106
21107
21108
21109
21110
21111 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType);
21112
21113 bool IsStandard(const CScript& scriptPubKey);
21114 bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
21115 bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* pkeystore, CBitcoinAddress& addressRet);
21116 bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL, CScript scriptPrereq=CScript());
21117 bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, int nHashType=0);
21118
21119 #endif