| 433 | } |
| 434 | |
| 435 | static 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 | |
| 480 | static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInIdx) |
| 481 | { |
no test coverage detected