Skip to content

Commit

Permalink
class CScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Sep 21, 2018
1 parent e2285b0 commit 26f1b8f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "crypto/common.h"
#include "prevector.h"
#include "utilstrencodings.h"
#include "pubkey.h"

#include <assert.h>
#include <climits>
Expand Down Expand Up @@ -370,6 +372,11 @@ class CScriptNum
int64_t m_value;
};

inline std::string ValueString(const std::vector<unsigned char>& vch)
{
return HexStr(vch);
}

typedef prevector<28, unsigned char> CScriptBase;

/** Serialized script, used inside transaction inputs and outputs */
Expand Down Expand Up @@ -464,6 +471,14 @@ class CScript : public CScriptBase
return *this;
}

CScript& operator<<(const CPubKey& key)
{
assert(key.size() < OP_PUSHDATA1);
insert(end(), (unsigned char)key.size());
insert(end(), key.begin(), key.end());
return *this;
}

CScript& operator<<(const CScript& b)
{
// I'm not sure if this should push the script or concatenate scripts.
Expand Down Expand Up @@ -605,6 +620,29 @@ class CScript : public CScriptBase
return nFound;
}

std::string ToString(bool fShort=false) 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 += fShort? ValueString(vch).substr(0, 10) : ValueString(vch);
else
str += GetOpName(opcode);
}
return str;
}

/**
* Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs
* as 20 sigops. With pay-to-script-hash, that changed:
Expand Down

0 comments on commit 26f1b8f

Please sign in to comment.