| 317 | } |
| 318 | |
| 319 | static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& strInput) |
| 320 | { |
| 321 | // Separate into VALUE:PUBKEY[:FLAGS] |
| 322 | std::vector<std::string> vStrInputParts = SplitString(strInput, ':'); |
| 323 | |
| 324 | if (vStrInputParts.size() < 2 || vStrInputParts.size() > 3) |
| 325 | throw std::runtime_error("TX output missing or too many separators"); |
| 326 | |
| 327 | // Extract and validate VALUE |
| 328 | CAmount value = ExtractAndValidateValue(vStrInputParts[0]); |
| 329 | |
| 330 | // Extract and validate PUBKEY |
| 331 | CPubKey pubkey(ParseHex(vStrInputParts[1])); |
| 332 | if (!pubkey.IsFullyValid()) |
| 333 | throw std::runtime_error("invalid TX output pubkey"); |
| 334 | CScript scriptPubKey = GetScriptForRawPubKey(pubkey); |
| 335 | |
| 336 | // Extract and validate FLAGS |
| 337 | bool bSegWit = false; |
| 338 | bool bScriptHash = false; |
| 339 | if (vStrInputParts.size() == 3) { |
| 340 | const std::string& flags = vStrInputParts[2]; |
| 341 | bSegWit = (flags.find('W') != std::string::npos); |
| 342 | bScriptHash = (flags.find('S') != std::string::npos); |
| 343 | } |
| 344 | |
| 345 | if (bSegWit) { |
| 346 | if (!pubkey.IsCompressed()) { |
| 347 | throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs"); |
| 348 | } |
| 349 | // Build a P2WPKH script |
| 350 | scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkey)); |
| 351 | } |
| 352 | if (bScriptHash) { |
| 353 | // Get the ID for the script, and then construct a P2SH destination for it. |
| 354 | scriptPubKey = GetScriptForDestination(ScriptHash(scriptPubKey)); |
| 355 | } |
| 356 | |
| 357 | // construct TxOut, append to transaction output list |
| 358 | CTxOut txout(value, scriptPubKey); |
| 359 | tx.vout.push_back(txout); |
| 360 | } |
| 361 | |
| 362 | static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& strInput) |
| 363 | { |
no test coverage detected