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