wallet: Refactor dummy signature signing for reusability
This commit is contained in:
parent
e99f0d7ad4
commit
d625b907a1
2 changed files with 30 additions and 15 deletions
|
@ -2583,21 +2583,9 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
|
||||||
std::numeric_limits<unsigned int>::max() - (fWalletRbf ? 2 : 1)));
|
std::numeric_limits<unsigned int>::max() - (fWalletRbf ? 2 : 1)));
|
||||||
|
|
||||||
// Fill in dummy signatures for fee calculation.
|
// Fill in dummy signatures for fee calculation.
|
||||||
int nIn = 0;
|
if (!DummySignTx(txNew, setCoins)) {
|
||||||
for (const auto& coin : setCoins)
|
strFailReason = _("Signing transaction failed");
|
||||||
{
|
return false;
|
||||||
const CScript& scriptPubKey = coin.first->tx->vout[coin.second].scriptPubKey;
|
|
||||||
SignatureData sigdata;
|
|
||||||
|
|
||||||
if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, sigdata))
|
|
||||||
{
|
|
||||||
strFailReason = _("Signing transaction failed");
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
UpdateTransaction(txNew, nIn, sigdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
nIn++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int nBytes = GetVirtualTransactionSize(txNew);
|
unsigned int nBytes = GetVirtualTransactionSize(txNew);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "utilstrencodings.h"
|
#include "utilstrencodings.h"
|
||||||
#include "validationinterface.h"
|
#include "validationinterface.h"
|
||||||
#include "script/ismine.h"
|
#include "script/ismine.h"
|
||||||
|
#include "script/sign.h"
|
||||||
#include "wallet/crypter.h"
|
#include "wallet/crypter.h"
|
||||||
#include "wallet/walletdb.h"
|
#include "wallet/walletdb.h"
|
||||||
#include "wallet/rpcwallet.h"
|
#include "wallet/rpcwallet.h"
|
||||||
|
@ -796,6 +797,8 @@ public:
|
||||||
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
|
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
|
||||||
bool AddAccountingEntry(const CAccountingEntry&);
|
bool AddAccountingEntry(const CAccountingEntry&);
|
||||||
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
|
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
|
||||||
|
template <typename ContainerType>
|
||||||
|
bool DummySignTx(CMutableTransaction &txNew, const ContainerType &coins);
|
||||||
|
|
||||||
static CFeeRate minTxFee;
|
static CFeeRate minTxFee;
|
||||||
static CFeeRate fallbackFee;
|
static CFeeRate fallbackFee;
|
||||||
|
@ -1028,4 +1031,28 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper for producing a bunch of max-sized low-S signatures (eg 72 bytes)
|
||||||
|
// ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable
|
||||||
|
// so that each entry corresponds to each vIn, in order.
|
||||||
|
template <typename ContainerType>
|
||||||
|
bool CWallet::DummySignTx(CMutableTransaction &txNew, const ContainerType &coins)
|
||||||
|
{
|
||||||
|
// Fill in dummy signatures for fee calculation.
|
||||||
|
int nIn = 0;
|
||||||
|
for (const auto& coin : coins)
|
||||||
|
{
|
||||||
|
const CScript& scriptPubKey = coin.first->tx->vout[coin.second].scriptPubKey;
|
||||||
|
SignatureData sigdata;
|
||||||
|
|
||||||
|
if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, sigdata))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
UpdateTransaction(txNew, nIn, sigdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
nIn++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif // BITCOIN_WALLET_WALLET_H
|
#endif // BITCOIN_WALLET_WALLET_H
|
||||||
|
|
Loading…
Reference in a new issue