6 #ifndef FABCOIN_SCRIPT_SCRIPT_H 7 #define FABCOIN_SCRIPT_SCRIPT_H 23 static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 128000;
26 static const int MAX_OPS_PER_SCRIPT = 201;
29 static const int MAX_PUBKEYS_PER_MULTISIG = 20;
32 static const int MAX_SCRIPT_SIZE = 129000;
35 static const int MAX_STACK_SIZE = 1000;
39 static const unsigned int LOCKTIME_THRESHOLD = 500000000;
44 return std::vector<unsigned char>(in.begin(), in.end());
205 static const unsigned int MAX_OPCODE =
OP_NOP10;
232 static const size_t nDefaultMaxNumSize = 4;
234 explicit CScriptNum(
const std::vector<unsigned char>& vch,
bool fRequireMinimal,
235 const size_t nMaxNumSize = nDefaultMaxNumSize)
237 if (vch.size() > nMaxNumSize) {
240 if (fRequireMinimal && vch.size() > 0) {
247 if ((vch.back() & 0x7f) == 0) {
253 if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
258 m_value = set_vch(vch);
261 inline bool operator==(
const int64_t& rhs)
const {
return m_value == rhs; }
262 inline bool operator!=(
const int64_t& rhs)
const {
return m_value != rhs; }
263 inline bool operator<=(
const int64_t& rhs)
const {
return m_value <= rhs; }
264 inline bool operator< (
const int64_t& rhs)
const {
return m_value < rhs; }
265 inline bool operator>=(
const int64_t& rhs)
const {
return m_value >= rhs; }
266 inline bool operator> (
const int64_t& rhs)
const {
return m_value > rhs; }
331 std::vector<unsigned char>
getvch()
const 333 return serialize(m_value);
339 if (vch.size() > 8) {
347 for (
size_t i = 0; i != vch.size(); ++i)
348 result |= static_cast<uint64_t>(vch[i]) << 8*i;
352 if (vch.back() & 0x80)
360 static std::vector<unsigned char>
serialize(
const int64_t& value)
363 return std::vector<unsigned char>();
365 std::vector<unsigned char> result;
366 const bool neg = value < 0;
367 uint64_t absvalue = neg ? -value : value;
371 result.push_back(absvalue & 0xff);
385 if (result.back() & 0x80)
386 result.push_back(neg ? 0x80 : 0);
388 result.back() |= 0x80;
394 static int64_t
set_vch(
const std::vector<unsigned char>& vch)
400 for (
size_t i = 0; i != vch.size(); ++i)
401 result |= static_cast<int64_t>(vch[i]) << 8*i;
405 if (vch.back() & 0x80)
406 return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
422 if (n == -1 || (n >= 1 && n <= 16))
424 push_back(n + (
OP_1 - 1));
439 CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) :
CScriptBase(pbegin, pend) { }
444 template <
typename Stream,
typename Operation>
446 READWRITE(static_cast<CScriptBase&>(*
this));
473 if (opcode < 0 || opcode > 0xff)
474 throw std::runtime_error(
"CScript::operator<<(): invalid opcode");
475 insert(end(), (
unsigned char)opcode);
485 CScript& operator<<(const std::vector<unsigned char>&
b)
489 insert(end(), (
unsigned char)
b.size());
491 else if (
b.size() <= 0xff)
494 insert(end(), (
unsigned char)
b.size());
496 else if (
b.size() <= 0xffff)
500 WriteLE16(_data,
b.size());
501 insert(end(), _data, _data +
sizeof(_data));
507 WriteLE32(_data,
b.size());
508 insert(end(), _data, _data +
sizeof(_data));
510 insert(end(),
b.begin(),
b.end());
518 assert(!
"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
527 bool fRet = GetOp2(pc2, opcodeRet, &vchRet);
528 pc = begin() + (pc2 - begin());
535 bool fRet = GetOp2(pc2, opcodeRet,
nullptr);
536 pc = begin() + (pc2 - begin());
542 return GetOp2(pc, opcodeRet, &vchRet);
547 return GetOp2(pc, opcodeRet,
nullptr);
561 unsigned int opcode = *pc++;
566 unsigned int nSize = 0;
581 nSize = ReadLE16(&pc[0]);
588 nSize = ReadLE32(&pc[0]);
591 if (end() - pc < 0 || (
unsigned int)(end() - pc) < nSize)
594 pvchRet->assign(pc, pc + nSize);
608 return (
int)opcode - (int)(
OP_1 - 1);
612 assert(n >= 0 && n <= 16);
624 iterator pc = begin(), pc2 = begin();
629 while (static_cast<size_t>(end() - pc) >= b.
size() && std::equal(b.
begin(), b.
end(), pc))
636 while (GetOp(pc, opcode));
649 for (
const_iterator pc = begin(); pc != end() && GetOp(pc, opcode);)
662 unsigned int GetSigOpCount(
bool fAccurate)
const;
668 unsigned int GetSigOpCount(
const CScript& scriptSig)
const;
670 bool IsPayToScriptHash()
const;
672 bool IsPayToPubkey()
const;
673 bool IsPayToPubkeyHash()
const;
675 bool IsPayToWitnessScriptHash()
const;
676 bool IsWitnessProgram(
int&
version, std::vector<unsigned char>& program)
const;
680 bool IsPushOnly()
const;
683 bool HasValidOps()
const;
724 std::vector<std::vector<unsigned char> >
stack;
729 bool IsNull()
const {
return stack.empty(); }
731 void SetNull() { stack.clear(); stack.shrink_to_fit(); }
733 std::string ToString()
const;
745 #endif // FABCOIN_SCRIPT_SCRIPT_H
bool operator!=(const int64_t &rhs) const
static int64_t set_vch(const std::vector< unsigned char > &vch)
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
bool GetOp2(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet) const
CScriptNum operator-() const
iterator insert(iterator pos, const T &value)
virtual ~CReserveScript()
CScriptNum(const int64_t &n)
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
CScriptNum & operator-=(const int64_t &rhs)
CScriptNum operator&(const CScriptNum &rhs) const
CScript & push_int64(int64_t n)
std::vector< std::vector< unsigned char > > stack
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
friend CScript operator+(const CScript &a, const CScript &b)
CScriptNum operator-(const CScriptNum &rhs) const
CScriptNum & operator=(const int64_t &rhs)
CScript(const std::vector< unsigned char > &b)
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
static std::vector< unsigned char > serialize(const int64_t &value)
CScriptNum operator+(const CScriptNum &rhs) const
const char * GetOpName(opcodetype opcode)
CScriptNum & operator+=(const CScriptNum &rhs)
bool operator==(const CScriptNum &rhs) const
bool operator<=(const int64_t &rhs) const
CScriptNum & operator&=(const CScriptNum &rhs)
CScript & operator<<(const CScriptNum &b)
CScript & operator<<(opcodetype opcode)
opcodetype
Script opcodes.
CScript(const CScriptNum &b)
CScript & operator<<(const CScript &b)
static uint64_t vch_to_uint64(const std::vector< unsigned char > &vch)
prevector< 28, unsigned char > CScriptBase
CScriptNum operator-(const int64_t &rhs) const
CScript(const unsigned char *pbegin, const unsigned char *pend)
bool operator==(const int64_t &rhs) const
bool operator>=(const int64_t &rhs) const
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack...
scriptnum_error(const std::string &str)
CScriptNum(const std::vector< unsigned char > &vch, bool fRequireMinimal, const size_t nMaxNumSize=nDefaultMaxNumSize)
bool GetOp(iterator &pc, opcodetype &opcodeRet)
CScriptNum & operator&=(const int64_t &rhs)
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
CScriptNum operator&(const int64_t &rhs) const
std::ostream & operator<<(std::ostream &_out, bytes const &_e)
CScriptNum & operator-=(const CScriptNum &rhs)
CScript(const_iterator pbegin, const_iterator pend)
static opcodetype EncodeOP_N(int n)
uint8_t const size_t const size
bool operator<=(const CScriptNum &rhs) const
Serialized script, used inside transaction inputs and outputs.
CScript & operator+=(const CScript &b)
bool operator>(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
compares degree
CScriptNum operator+(const int64_t &rhs) const
std::vector< unsigned char > getvch() const
int FindAndDelete(const CScript &b)
CScript & operator<<(int64_t b)
virtual void KeepScript()
CScriptNum & operator+=(const int64_t &rhs)
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
bool operator!=(const CScriptNum &rhs) const
void SerializationOp(Stream &s, Operation ser_action)
bool operator>=(const CScriptNum &rhs) const
CScript(std::vector< unsigned char >::const_iterator pbegin, std::vector< unsigned char >::const_iterator pend)
int Find(opcodetype op) const
bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
std::vector< unsigned char > ToByteVector(const T &in)