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