MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / CScript

Class CScript

src/script/script.h:405–575  ·  view source on GitHub ↗

Serialized script, used inside transaction inputs and outputs */

Source from the content-addressed store, hash-verified

403
404/** Serialized script, used inside transaction inputs and outputs */
405class CScript : public CScriptBase
406{
407private:
408 inline void AppendDataSize(const uint32_t size)
409 {
410 if (size < OP_PUSHDATA1) {
411 insert(end(), static_cast<value_type>(size));
412 } else if (size <= 0xff) {
413 insert(end(), OP_PUSHDATA1);
414 insert(end(), static_cast<value_type>(size));
415 } else if (size <= 0xffff) {
416 insert(end(), OP_PUSHDATA2);
417 value_type data[2];
418 WriteLE16(data, size);
419 insert(end(), std::cbegin(data), std::cend(data));
420 } else {
421 insert(end(), OP_PUSHDATA4);
422 value_type data[4];
423 WriteLE32(data, size);
424 insert(end(), std::cbegin(data), std::cend(data));
425 }
426 }
427
428 void AppendData(std::span<const value_type> data)
429 {
430 insert(end(), data.begin(), data.end());
431 }
432
433protected:
434 CScript& push_int64(int64_t n)
435 {
436 if (n == -1 || (n >= 1 && n <= 16))
437 {
438 push_back(n + (OP_1 - 1));
439 }
440 else if (n == 0)
441 {
442 push_back(OP_0);
443 }
444 else
445 {
446 *this << CScriptNum::serialize(n);
447 }
448 return *this;
449 }
450
451public:
452 CScript() = default;
453 template <std::input_iterator InputIterator>
454 CScript(InputIterator first, InputIterator last) : CScriptBase{first, last} { }
455
456 SERIALIZE_METHODS(CScript, obj) { READWRITE(AsBase<CScriptBase>(obj)); }
457
458 explicit CScript(int64_t b) { operator<<(b); }
459 explicit CScript(opcodetype b) { operator<<(b); }
460 explicit CScript(const CScriptNum& b) { operator<<(b); }
461 // delete non-existent constructor to defend against future introduction
462 // e.g. via prevector

Callers 11

MakeScriptsMethod · 0.70
ParseScriptFunction · 0.70
InferScriptFunction · 0.70
GetScriptForRawPubKeyFunction · 0.70
EvalChecksigPreTapscriptFunction · 0.70
EvalScriptFunction · 0.70
SerializeInputMethod · 0.70
VerifyWitnessProgramFunction · 0.70
VerifyScriptFunction · 0.70
SignTaprootScriptFunction · 0.70
ProduceSignatureFunction · 0.70

Calls 5

insertFunction · 0.85
endFunction · 0.85
getvchMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected