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

Function MutateTxAddOutScript

src/bitcoin-tx.cpp:465–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

463}
464
465static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
466{
467 // separate VALUE:SCRIPT[:FLAGS]
468 std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
469 if (vStrInputParts.size() < 2)
470 throw std::runtime_error("TX output missing separator");
471
472 // Extract and validate VALUE
473 CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
474
475 // extract and validate script
476 const std::string& strScript = vStrInputParts[1];
477 CScript scriptPubKey = ParseScript(strScript);
478
479 // Extract FLAGS
480 bool bSegWit = false;
481 bool bScriptHash = false;
482 if (vStrInputParts.size() == 3) {
483 const std::string& flags = vStrInputParts.back();
484 bSegWit = (flags.find('W') != std::string::npos);
485 bScriptHash = (flags.find('S') != std::string::npos);
486 }
487
488 if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
489 throw std::runtime_error(strprintf(
490 "script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
491 }
492
493 if (bSegWit) {
494 scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(scriptPubKey));
495 }
496 if (bScriptHash) {
497 if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
498 throw std::runtime_error(strprintf(
499 "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
500 }
501 scriptPubKey = GetScriptForDestination(ScriptHash(scriptPubKey));
502 }
503
504 // construct TxOut, append to transaction output list
505 CTxOut txout(value, scriptPubKey);
506 tx.vout.push_back(txout);
507}
508
509static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInIdx)
510{

Callers 1

MutateTxFunction · 0.85

Calls 10

SplitStringFunction · 0.85
ExtractAndValidateValueFunction · 0.85
GetScriptForDestinationFunction · 0.85
WitnessV0ScriptHashClass · 0.85
ScriptHashClass · 0.85
findMethod · 0.80
ParseScriptFunction · 0.70
sizeMethod · 0.45
backMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected