MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / MutateTxAddOutScript

Function MutateTxAddOutScript

src/bitcoin-tx.cpp:475–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

MutateTxFunction · 0.85

Calls 9

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

Tested by

no test coverage detected