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

Function MutateTxAddOutData

src/bitcoin-tx.cpp:447–492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445}
446
447static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strInput)
448{
449 CAmount value = 0;
450
451 // separate [VALUE:]DATA[:ASSET] in string
452 std::vector<std::string> vStrInputParts;
453 boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
454
455 // Check that there are enough parameters
456 if (vStrInputParts[0].empty())
457 throw std::runtime_error("TX output value not specified");
458
459 if (vStrInputParts.size()>3)
460 throw std::runtime_error("too many separators");
461
462 std::vector<unsigned char> data;
463 CAsset asset(Params().GetConsensus().pegged_asset);
464
465 if (vStrInputParts.size()==1) {
466 std::string strData = vStrInputParts[0];
467 if (!IsHex(strData))
468 throw std::runtime_error("invalid TX output data");
469 data = ParseHex(strData);
470
471 } else {
472 value = ExtractAndValidateValue(vStrInputParts[0]);
473 std::string strData = vStrInputParts[1];
474 if (!IsHex(strData))
475 throw std::runtime_error("invalid TX output data");
476 data = ParseHex(strData);
477
478 if (vStrInputParts.size()==3) {
479 std::string strAsset = vStrInputParts[2];
480 if (!IsHex(strAsset))
481 throw std::runtime_error("invalid TX output asset type");
482
483 asset.SetHex(strAsset);
484 if (asset.IsNull()) {
485 throw std::runtime_error("invalid TX output asset type");
486 }
487 }
488 }
489
490 CTxOut txout(asset, CConfidentialValue(value), CScript() << OP_RETURN << data);
491 tx.vout.push_back(txout);
492}
493
494static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
495{

Callers 1

MutateTxFunction · 0.85

Calls 11

IsHexFunction · 0.85
ParseHexFunction · 0.85
ExtractAndValidateValueFunction · 0.85
CConfidentialValueClass · 0.85
ParamsClass · 0.70
CScriptClass · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
SetHexMethod · 0.45
IsNullMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected