MCPcopy Create free account
hub / github.com/ElementsProject/elements / CScript

Class CScript

src/script/script.h:467–629  ·  view source on GitHub ↗

Serialized script, used inside transaction inputs and outputs */

Source from the content-addressed store, hash-verified

465
466/** Serialized script, used inside transaction inputs and outputs */
467class CScript : public CScriptBase
468{
469protected:
470 CScript& push_int64(int64_t n)
471 {
472 if (n == -1 || (n >= 1 && n <= 16))
473 {
474 push_back(n + (OP_1 - 1));
475 }
476 else if (n == 0)
477 {
478 push_back(OP_0);
479 }
480 else
481 {
482 *this << CScriptNum::serialize(n);
483 }
484 return *this;
485 }
486public:
487 CScript() { }
488 CScript(const_iterator pbegin, const_iterator pend) : CScriptBase(pbegin, pend) { }
489 CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { }
490 CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { }
491
492 SERIALIZE_METHODS(CScript, obj) { READWRITEAS(CScriptBase, obj); }
493
494 explicit CScript(int64_t b) { operator<<(b); }
495 explicit CScript(opcodetype b) { operator<<(b); }
496 explicit CScript(const CScriptNum& b) { operator<<(b); }
497 // delete non-existent constructor to defend against future introduction
498 // e.g. via prevector
499 explicit CScript(const std::vector<unsigned char>& b) = delete;
500
501 /** Delete non-existent operator to defend against future introduction */
502 CScript& operator<<(const CScript& b) = delete;
503
504 CScript& operator<<(int64_t b) LIFETIMEBOUND { return push_int64(b); }
505
506 CScript& operator<<(opcodetype opcode) LIFETIMEBOUND
507 {
508 if (opcode < 0 || opcode > 0xff)
509 throw std::runtime_error("CScript::operator<<(): invalid opcode");
510 insert(end(), (unsigned char)opcode);
511 return *this;
512 }
513
514 CScript& operator<<(const CScriptNum& b) LIFETIMEBOUND
515 {
516 *this << b.getvch();
517 return *this;
518 }
519
520 CScript& operator<<(const std::vector<unsigned char>& b) LIFETIMEBOUND
521 {
522 if (b.size() < OP_PUSHDATA1)
523 {
524 insert(end(), (unsigned char)b.size());

Callers

nothing calls this directly

Calls 8

insertFunction · 0.85
endFunction · 0.85
WriteLE16Function · 0.85
WriteLE32Function · 0.50
getvchMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected