diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1000,6 +1000,7 @@ const std::set &setSubtractFeeFromOutputs, bool keepReserveKey = true, const CTxDestination &destChange = CNoDestination()); + bool SignTransaction(CMutableTransaction &tx); /** * Create a new transaction paying the recipients with a set of coins @@ -1021,7 +1022,8 @@ bool AddAccountingEntry(const CAccountingEntry &); bool AddAccountingEntry(const CAccountingEntry &, CWalletDB *pwalletdb); template - bool DummySignTx(CMutableTransaction &txNew, const ContainerType &coins); + bool DummySignTx(CMutableTransaction &txNew, + const ContainerType &coins) const; static CFeeRate fallbackFee; @@ -1260,7 +1262,7 @@ // that each entry corresponds to each vIn, in order. template bool CWallet::DummySignTx(CMutableTransaction &txNew, - const ContainerType &coins) { + const ContainerType &coins) const { // Fill in dummy signatures for fee calculation. int nIn = 0; for (const auto &coin : coins) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2727,6 +2727,32 @@ return res; } +bool CWallet::SignTransaction(CMutableTransaction &tx) { + // sign the new tx + CTransaction txNewConst(tx); + int nIn = 0; + for (auto &input : tx.vin) { + auto mi = mapWallet.find(input.prevout.GetTxId()); + if (mi == mapWallet.end() || + input.prevout.GetN() >= mi->second.tx->vout.size()) { + return false; + } + const CScript &scriptPubKey = + mi->second.tx->vout[input.prevout.GetN()].scriptPubKey; + const Amount amount = mi->second.tx->vout[input.prevout.GetN()].nValue; + SignatureData sigdata; + SigHashType sigHashType = SigHashType().withForkId(); + if (!ProduceSignature(TransactionSignatureCreator( + this, &txNewConst, nIn, amount, sigHashType), + scriptPubKey, sigdata)) { + return false; + } + UpdateTransaction(tx, nIn, sigdata); + nIn++; + } + return true; +} + bool CWallet::FundTransaction(CMutableTransaction &tx, Amount &nFeeRet, bool overrideEstimatedFeeRate, const CFeeRate &specificFeeRate,