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

Function MutateTxAddOutScript

src/bitcoin-tx.cpp:435–478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

433}
434
435static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
436{
437 // separate VALUE:SCRIPT[:FLAGS]
438 std::vector<std::string> vStrInputParts;
439 boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
440 if (vStrInputParts.size() < 2)
441 throw std::runtime_error("TX output missing separator");
442
443 // Extract and validate VALUE
444 CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
445
446 // extract and validate script
447 std::string strScript = vStrInputParts[1];
448 CScript scriptPubKey = ParseScript(strScript);
449
450 // Extract FLAGS
451 bool bSegWit = false;
452 bool bScriptHash = false;
453 if (vStrInputParts.size() == 3) {
454 std::string flags = vStrInputParts.back();
455 bSegWit = (flags.find('W') != std::string::npos);
456 bScriptHash = (flags.find('S') != std::string::npos);
457 }
458
459 if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
460 throw std::runtime_error(strprintf(
461 "script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
462 }
463
464 if (bSegWit) {
465 scriptPubKey = GetScriptForWitness(scriptPubKey);
466 }
467 if (bScriptHash) {
468 if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
469 throw std::runtime_error(strprintf(
470 "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
471 }
472 scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
473 }
474
475 // construct TxOut, append to transaction output list
476 CTxOut txout(value, scriptPubKey);
477 tx.vout.push_back(txout);
478}
479
480static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInIdx)
481{

Callers 1

MutateTxFunction · 0.85

Calls 8

ExtractAndValidateValueFunction · 0.85
GetScriptForWitnessFunction · 0.85
GetScriptForDestinationFunction · 0.85
ParseScriptFunction · 0.70
CScriptIDClass · 0.70
sizeMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected