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

Function MutateTxAddOutScript

src/bitcoin-tx.cpp:494–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

492}
493
494static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
495{
496 // separate VALUE:SCRIPT[:FLAGS]
497 std::vector<std::string> vStrInputParts;
498 boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
499 if (vStrInputParts.size() < 2)
500 throw std::runtime_error("TX output missing separator");
501
502 // Extract and validate VALUE
503 CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
504
505 // extract and validate script
506 std::string strScript = vStrInputParts[1];
507 CScript scriptPubKey = ParseScript(strScript);
508
509 // Extract FLAGS
510 bool bSegWit = false;
511 bool bScriptHash = false;
512 if (vStrInputParts.size() == 3) {
513 std::string flags = vStrInputParts.back();
514 bSegWit = (flags.find('W') != std::string::npos);
515 bScriptHash = (flags.find('S') != std::string::npos);
516 }
517
518 if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
519 throw std::runtime_error(strprintf(
520 "script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
521 }
522
523 if (bSegWit) {
524 scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(scriptPubKey));
525 }
526 if (bScriptHash) {
527 if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
528 throw std::runtime_error(strprintf(
529 "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
530 }
531 scriptPubKey = GetScriptForDestination(ScriptHash(scriptPubKey));
532 }
533
534 // construct TxOut, append to transaction output list
535 CTxOut txout(Params().GetConsensus().pegged_asset, CConfidentialValue(value), scriptPubKey);
536 tx.vout.push_back(txout);
537}
538
539static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInIdx)
540{

Callers 1

MutateTxFunction · 0.85

Calls 10

ExtractAndValidateValueFunction · 0.85
GetScriptForDestinationFunction · 0.85
WitnessV0ScriptHashClass · 0.85
ScriptHashClass · 0.85
CConfidentialValueClass · 0.85
findMethod · 0.80
ParseScriptFunction · 0.70
ParamsClass · 0.70
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected