| 445 | } |
| 446 | |
| 447 | static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strInput) |
| 448 | { |
| 449 | CAmount value = 0; |
| 450 | |
| 451 | // separate [VALUE:]DATA[:ASSET] in string |
| 452 | std::vector<std::string> vStrInputParts; |
| 453 | boost::split(vStrInputParts, strInput, boost::is_any_of(":")); |
| 454 | |
| 455 | // Check that there are enough parameters |
| 456 | if (vStrInputParts[0].empty()) |
| 457 | throw std::runtime_error("TX output value not specified"); |
| 458 | |
| 459 | if (vStrInputParts.size()>3) |
| 460 | throw std::runtime_error("too many separators"); |
| 461 | |
| 462 | std::vector<unsigned char> data; |
| 463 | CAsset asset(Params().GetConsensus().pegged_asset); |
| 464 | |
| 465 | if (vStrInputParts.size()==1) { |
| 466 | std::string strData = vStrInputParts[0]; |
| 467 | if (!IsHex(strData)) |
| 468 | throw std::runtime_error("invalid TX output data"); |
| 469 | data = ParseHex(strData); |
| 470 | |
| 471 | } else { |
| 472 | value = ExtractAndValidateValue(vStrInputParts[0]); |
| 473 | std::string strData = vStrInputParts[1]; |
| 474 | if (!IsHex(strData)) |
| 475 | throw std::runtime_error("invalid TX output data"); |
| 476 | data = ParseHex(strData); |
| 477 | |
| 478 | if (vStrInputParts.size()==3) { |
| 479 | std::string strAsset = vStrInputParts[2]; |
| 480 | if (!IsHex(strAsset)) |
| 481 | throw std::runtime_error("invalid TX output asset type"); |
| 482 | |
| 483 | asset.SetHex(strAsset); |
| 484 | if (asset.IsNull()) { |
| 485 | throw std::runtime_error("invalid TX output asset type"); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | CTxOut txout(asset, CConfidentialValue(value), CScript() << OP_RETURN << data); |
| 491 | tx.vout.push_back(txout); |
| 492 | } |
| 493 | |
| 494 | static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput) |
| 495 | { |
no test coverage detected