Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-tx.cpp
Show First 20 Lines • Show All 553 Lines • ▼ Show 20 Lines | static void MutateTxSign(CMutableTransaction &tx, const std::string &flagStr) { | ||||
} | } | ||||
std::vector<CTransaction> txVariants; | std::vector<CTransaction> txVariants; | ||||
txVariants.push_back(CTransaction(tx)); | txVariants.push_back(CTransaction(tx)); | ||||
// mergedTx will end up with all the signatures; it starts as a clone of the | // mergedTx will end up with all the signatures; it starts as a clone of the | ||||
// raw tx: | // raw tx: | ||||
CMutableTransaction mergedTx(txVariants[0]); | CMutableTransaction mergedTx(txVariants[0]); | ||||
bool fComplete = true; | |||||
CCoinsView viewDummy; | CCoinsView viewDummy; | ||||
CCoinsViewCache view(&viewDummy); | CCoinsViewCache view(&viewDummy); | ||||
if (!registers.count("privatekeys")) { | if (!registers.count("privatekeys")) { | ||||
throw std::runtime_error("privatekeys register variable must be set."); | throw std::runtime_error("privatekeys register variable must be set."); | ||||
} | } | ||||
CBasicKeyStore tempKeystore; | CBasicKeyStore tempKeystore; | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | static void MutateTxSign(CMutableTransaction &tx, const std::string &flagStr) { | ||||
const CKeyStore &keystore = tempKeystore; | const CKeyStore &keystore = tempKeystore; | ||||
// Sign what we can: | // Sign what we can: | ||||
for (size_t i = 0; i < mergedTx.vin.size(); i++) { | for (size_t i = 0; i < mergedTx.vin.size(); i++) { | ||||
CTxIn &txin = mergedTx.vin[i]; | CTxIn &txin = mergedTx.vin[i]; | ||||
const Coin &coin = view.AccessCoin(txin.prevout); | const Coin &coin = view.AccessCoin(txin.prevout); | ||||
if (coin.IsSpent()) { | if (coin.IsSpent()) { | ||||
fComplete = false; | |||||
continue; | continue; | ||||
} | } | ||||
const CScript &prevPubKey = coin.GetTxOut().scriptPubKey; | const CScript &prevPubKey = coin.GetTxOut().scriptPubKey; | ||||
const Amount amount = coin.GetTxOut().nValue; | const Amount amount = coin.GetTxOut().nValue; | ||||
SignatureData sigdata; | SignatureData sigdata; | ||||
// Only sign SIGHASH_SINGLE if there's a corresponding output: | // Only sign SIGHASH_SINGLE if there's a corresponding output: | ||||
if ((sigHashType.getBaseType() != BaseSigHashType::SINGLE) || | if ((sigHashType.getBaseType() != BaseSigHashType::SINGLE) || | ||||
(i < mergedTx.vout.size())) { | (i < mergedTx.vout.size())) { | ||||
ProduceSignature(MutableTransactionSignatureCreator( | ProduceSignature(MutableTransactionSignatureCreator( | ||||
&keystore, &mergedTx, i, amount, sigHashType), | &keystore, &mergedTx, i, amount, sigHashType), | ||||
prevPubKey, sigdata); | prevPubKey, sigdata); | ||||
} | } | ||||
// ... and merge in other signatures: | // ... and merge in other signatures: | ||||
for (const CTransaction &txv : txVariants) { | for (const CTransaction &txv : txVariants) { | ||||
sigdata = CombineSignatures( | sigdata = CombineSignatures( | ||||
prevPubKey, | prevPubKey, | ||||
MutableTransactionSignatureChecker(&mergedTx, i, amount), | MutableTransactionSignatureChecker(&mergedTx, i, amount), | ||||
sigdata, DataFromTransaction(txv, i)); | sigdata, DataFromTransaction(txv, i)); | ||||
} | } | ||||
UpdateTransaction(mergedTx, i, sigdata); | UpdateTransaction(mergedTx, i, sigdata); | ||||
if (!VerifyScript( | |||||
txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, | |||||
MutableTransactionSignatureChecker(&mergedTx, i, amount))) { | |||||
fComplete = false; | |||||
} | |||||
} | |||||
if (fComplete) { | |||||
// do nothing... for now | |||||
// perhaps store this for later optional JSON output | |||||
} | } | ||||
tx = mergedTx; | tx = mergedTx; | ||||
} | } | ||||
class Secp256k1Init { | class Secp256k1Init { | ||||
ECCVerifyHandle globalVerifyHandle; | ECCVerifyHandle globalVerifyHandle; | ||||
▲ Show 20 Lines • Show All 192 Lines • Show Last 20 Lines |