| 492 | } |
| 493 | |
| 494 | static 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 | |
| 539 | static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInIdx) |
| 540 | { |
no test coverage detected