MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MutateTxSign

Function MutateTxSign

src/bitcoin-tx.cpp:577–694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575}
576
577static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
578{
579 int nHashType = SIGHASH_ALL;
580
581 if (flagStr.size() > 0)
582 if (!findSighashFlags(nHashType, flagStr))
583 throw std::runtime_error("unknown sighash flag/sign option");
584
585 // mergedTx will end up with all the signatures; it
586 // starts as a clone of the raw tx:
587 CMutableTransaction mergedTx{tx};
588 const CMutableTransaction txv{tx};
589 CCoinsViewCache view{&CoinsViewEmpty::Get()};
590
591 if (!registers.contains("privatekeys"))
592 throw std::runtime_error("privatekeys register variable must be set.");
593 FillableSigningProvider tempKeystore;
594 UniValue keysObj = registers["privatekeys"];
595
596 for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) {
597 if (!keysObj[kidx].isStr())
598 throw std::runtime_error("privatekey not a std::string");
599 CKey key = DecodeSecret(keysObj[kidx].getValStr());
600 if (!key.IsValid()) {
601 throw std::runtime_error("privatekey not valid");
602 }
603 tempKeystore.AddKey(key);
604 }
605
606 // Add previous txouts given in the RPC call:
607 if (!registers.contains("prevtxs"))
608 throw std::runtime_error("prevtxs register variable must be set.");
609 UniValue prevtxsObj = registers["prevtxs"];
610 {
611 for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) {
612 const UniValue& prevOut = prevtxsObj[previdx];
613 if (!prevOut.isObject())
614 throw std::runtime_error("expected prevtxs internal object");
615
616 std::map<std::string, UniValue::VType> types = {
617 {"txid", UniValue::VSTR},
618 {"vout", UniValue::VNUM},
619 {"scriptPubKey", UniValue::VSTR},
620 };
621 if (!prevOut.checkObject(types))
622 throw std::runtime_error("prevtxs internal object typecheck fail");
623
624 auto txid{Txid::FromHex(prevOut["txid"].get_str())};
625 if (!txid) {
626 throw std::runtime_error("txid must be hexadecimal string (not '" + prevOut["txid"].get_str() + "')");
627 }
628
629 const int nOut = prevOut["vout"].getInt<int>();
630 if (nOut < 0)
631 throw std::runtime_error("vout cannot be negative");
632
633 COutPoint out(*txid, nOut);
634 std::vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));

Callers 1

MutateTxFunction · 0.85

Calls 15

findSighashFlagsFunction · 0.85
DecodeSecretFunction · 0.85
FromHexFunction · 0.85
ParseHexUVFunction · 0.85
ScriptToAsmStrFunction · 0.85
DataFromTransactionFunction · 0.85
ProduceSignatureFunction · 0.85
UpdateInputFunction · 0.85
isStrMethod · 0.80
isObjectMethod · 0.80
checkObjectMethod · 0.80

Tested by

no test coverage detected