Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.h
Show First 20 Lines • Show All 450 Lines • ▼ Show 20 Lines | public: | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITEAS(CScriptBase, *this); | READWRITEAS(CScriptBase, *this); | ||||
} | } | ||||
CScript &operator+=(const CScript &b) { | |||||
reserve(size() + b.size()); | |||||
insert(end(), b.begin(), b.end()); | |||||
return *this; | |||||
} | |||||
friend CScript operator+(const CScript &a, const CScript &b) { | |||||
CScript ret = a; | |||||
ret += b; | |||||
return ret; | |||||
} | |||||
explicit CScript(int64_t b) { operator<<(b); } | explicit CScript(int64_t b) { operator<<(b); } | ||||
explicit CScript(opcodetype b) { operator<<(b); } | explicit CScript(opcodetype b) { operator<<(b); } | ||||
explicit CScript(const CScriptNum &b) { operator<<(b); } | explicit CScript(const CScriptNum &b) { operator<<(b); } | ||||
// delete non-existent constructor to defend against future introduction | // delete non-existent constructor to defend against future introduction | ||||
// e.g. via prevector | // e.g. via prevector | ||||
explicit CScript(const std::vector<uint8_t> &b) = delete; | explicit CScript(const std::vector<uint8_t> &b) = delete; | ||||
/** Delete non-existent operator to defend against future introduction */ | |||||
CScript &operator<<(const CScript &b) = delete; | |||||
CScript &operator<<(int64_t b) { return push_int64(b); } | CScript &operator<<(int64_t b) { return push_int64(b); } | ||||
CScript &operator<<(opcodetype opcode) { | CScript &operator<<(opcodetype opcode) { | ||||
if (opcode < 0 || opcode > 0xff) { | if (opcode < 0 || opcode > 0xff) { | ||||
throw std::runtime_error("CScript::operator<<(): invalid opcode"); | throw std::runtime_error("CScript::operator<<(): invalid opcode"); | ||||
} | } | ||||
insert(end(), uint8_t(opcode)); | insert(end(), uint8_t(opcode)); | ||||
return *this; | return *this; | ||||
Show All 20 Lines | CScript &operator<<(const std::vector<uint8_t> &b) { | ||||
uint8_t _data[4]; | uint8_t _data[4]; | ||||
WriteLE32(_data, b.size()); | WriteLE32(_data, b.size()); | ||||
insert(end(), _data, _data + sizeof(_data)); | insert(end(), _data, _data + sizeof(_data)); | ||||
} | } | ||||
insert(end(), b.begin(), b.end()); | insert(end(), b.begin(), b.end()); | ||||
return *this; | return *this; | ||||
} | } | ||||
CScript &operator<<(const CScript &b) { | |||||
// I'm not sure if this should push the script or concatenate scripts. | |||||
// If there's ever a use for pushing a script onto a script, delete this | |||||
// member fn. | |||||
assert(!"Warning: Pushing a CScript onto a CScript with << is probably " | |||||
"not intended, use + to concatenate!"); | |||||
return *this; | |||||
} | |||||
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, | bool GetOp(const_iterator &pc, opcodetype &opcodeRet, | ||||
std::vector<uint8_t> &vchRet) const { | std::vector<uint8_t> &vchRet) const { | ||||
return GetScriptOp(pc, end(), opcodeRet, &vchRet); | return GetScriptOp(pc, end(), opcodeRet, &vchRet); | ||||
} | } | ||||
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const { | bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const { | ||||
return GetScriptOp(pc, end(), opcodeRet, nullptr); | return GetScriptOp(pc, end(), opcodeRet, nullptr); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |