Skip to content

Commit d625b90

Browse files
committed
wallet: Refactor dummy signature signing for reusability
1 parent e99f0d7 commit d625b90

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,21 +2583,9 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
25832583
std::numeric_limits<unsigned int>::max() - (fWalletRbf ? 2 : 1)));
25842584

25852585
// Fill in dummy signatures for fee calculation.
2586-
int nIn = 0;
2587-
for (const auto& coin : setCoins)
2588-
{
2589-
const CScript& scriptPubKey = coin.first->tx->vout[coin.second].scriptPubKey;
2590-
SignatureData sigdata;
2591-
2592-
if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, sigdata))
2593-
{
2594-
strFailReason = _("Signing transaction failed");
2595-
return false;
2596-
} else {
2597-
UpdateTransaction(txNew, nIn, sigdata);
2598-
}
2599-
2600-
nIn++;
2586+
if (!DummySignTx(txNew, setCoins)) {
2587+
strFailReason = _("Signing transaction failed");
2588+
return false;
26012589
}
26022590

26032591
unsigned int nBytes = GetVirtualTransactionSize(txNew);

src/wallet/wallet.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "utilstrencodings.h"
1414
#include "validationinterface.h"
1515
#include "script/ismine.h"
16+
#include "script/sign.h"
1617
#include "wallet/crypter.h"
1718
#include "wallet/walletdb.h"
1819
#include "wallet/rpcwallet.h"
@@ -796,6 +797,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
796797
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
797798
bool AddAccountingEntry(const CAccountingEntry&);
798799
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
800+
template <typename ContainerType>
801+
bool DummySignTx(CMutableTransaction &txNew, const ContainerType &coins);
799802

800803
static CFeeRate minTxFee;
801804
static CFeeRate fallbackFee;
@@ -1028,4 +1031,28 @@ class CAccount
10281031
}
10291032
};
10301033

1034+
// Helper for producing a bunch of max-sized low-S signatures (eg 72 bytes)
1035+
// ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable
1036+
// so that each entry corresponds to each vIn, in order.
1037+
template <typename ContainerType>
1038+
bool CWallet::DummySignTx(CMutableTransaction &txNew, const ContainerType &coins)
1039+
{
1040+
// Fill in dummy signatures for fee calculation.
1041+
int nIn = 0;
1042+
for (const auto& coin : coins)
1043+
{
1044+
const CScript& scriptPubKey = coin.first->tx->vout[coin.second].scriptPubKey;
1045+
SignatureData sigdata;
1046+
1047+
if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, sigdata))
1048+
{
1049+
return false;
1050+
} else {
1051+
UpdateTransaction(txNew, nIn, sigdata);
1052+
}
1053+
1054+
nIn++;
1055+
}
1056+
return true;
1057+
}
10311058
#endif // BITCOIN_WALLET_WALLET_H

0 commit comments

Comments
 (0)