| 601 | } |
| 602 | |
| 603 | static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) |
| 604 | { |
| 605 | int nHashType = SIGHASH_ALL; |
| 606 | |
| 607 | if (flagStr.size() > 0) |
| 608 | if (!findSighashFlags(nHashType, flagStr)) |
| 609 | throw std::runtime_error("unknown sighash flag/sign option"); |
| 610 | |
| 611 | // mergedTx will end up with all the signatures; it |
| 612 | // starts as a clone of the raw tx: |
| 613 | CMutableTransaction mergedTx{tx}; |
| 614 | const CMutableTransaction txv{tx}; |
| 615 | CCoinsView viewDummy; |
| 616 | CCoinsViewCache view(&viewDummy); |
| 617 | |
| 618 | if (!registers.count("privatekeys")) |
| 619 | throw std::runtime_error("privatekeys register variable must be set."); |
| 620 | FillableSigningProvider tempKeystore; |
| 621 | UniValue keysObj = registers["privatekeys"]; |
| 622 | |
| 623 | for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) { |
| 624 | if (!keysObj[kidx].isStr()) |
| 625 | throw std::runtime_error("privatekey not a std::string"); |
| 626 | CKey key = DecodeSecret(keysObj[kidx].getValStr()); |
| 627 | if (!key.IsValid()) { |
| 628 | throw std::runtime_error("privatekey not valid"); |
| 629 | } |
| 630 | tempKeystore.AddKey(key); |
| 631 | } |
| 632 | |
| 633 | // Add previous txouts given in the RPC call: |
| 634 | if (!registers.count("prevtxs")) |
| 635 | throw std::runtime_error("prevtxs register variable must be set."); |
| 636 | UniValue prevtxsObj = registers["prevtxs"]; |
| 637 | { |
| 638 | for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) { |
| 639 | UniValue prevOut = prevtxsObj[previdx]; |
| 640 | if (!prevOut.isObject()) |
| 641 | throw std::runtime_error("expected prevtxs internal object"); |
| 642 | |
| 643 | std::map<std::string, UniValue::VType> types = { |
| 644 | {"txid", UniValue::VSTR}, |
| 645 | {"vout", UniValue::VNUM}, |
| 646 | {"scriptPubKey", UniValue::VSTR}, |
| 647 | }; |
| 648 | if (!prevOut.checkObject(types)) |
| 649 | throw std::runtime_error("prevtxs internal object typecheck fail"); |
| 650 | |
| 651 | uint256 txid; |
| 652 | if (!ParseHashStr(prevOut["txid"].get_str(), txid)) { |
| 653 | throw std::runtime_error("txid must be hexadecimal string (not '" + prevOut["txid"].get_str() + "')"); |
| 654 | } |
| 655 | |
| 656 | const int nOut = prevOut["vout"].get_int(); |
| 657 | if (nOut < 0) |
| 658 | throw std::runtime_error("vout cannot be negative"); |
| 659 | |
| 660 | COutPoint out(txid, nOut); |
no test coverage detected