mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Have CalculateMaximumSignedTxSize also compute tx weight
This commit is contained in:
parent
81d5af42f4
commit
51e2cd322c
3 changed files with 15 additions and 9 deletions
|
@ -190,7 +190,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
|
||||||
if (coin_control.m_feerate) {
|
if (coin_control.m_feerate) {
|
||||||
// The user provided a feeRate argument.
|
// The user provided a feeRate argument.
|
||||||
// We calculate this here to avoid compiler warning on the cs_wallet lock
|
// We calculate this here to avoid compiler warning on the cs_wallet lock
|
||||||
const int64_t maxTxSize = CalculateMaximumSignedTxSize(*wtx.tx, &wallet);
|
const int64_t maxTxSize = CalculateMaximumSignedTxSize(*wtx.tx, &wallet).first;
|
||||||
Result res = CheckFeeRate(wallet, wtx, *new_coin_control.m_feerate, maxTxSize, errors);
|
Result res = CheckFeeRate(wallet, wtx, *new_coin_control.m_feerate, maxTxSize, errors);
|
||||||
if (res != Result::OK) {
|
if (res != Result::OK) {
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -1594,14 +1594,15 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
|
// Returns pair of vsize and weight
|
||||||
|
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
|
||||||
{
|
{
|
||||||
std::vector<CTxOut> txouts;
|
std::vector<CTxOut> txouts;
|
||||||
for (const CTxIn& input : tx.vin) {
|
for (const CTxIn& input : tx.vin) {
|
||||||
const auto mi = wallet->mapWallet.find(input.prevout.hash);
|
const auto mi = wallet->mapWallet.find(input.prevout.hash);
|
||||||
// Can not estimate size without knowing the input details
|
// Can not estimate size without knowing the input details
|
||||||
if (mi == wallet->mapWallet.end()) {
|
if (mi == wallet->mapWallet.end()) {
|
||||||
return -1;
|
return std::make_pair(-1, -1);
|
||||||
}
|
}
|
||||||
assert(input.prevout.n < mi->second.tx->vout.size());
|
assert(input.prevout.n < mi->second.tx->vout.size());
|
||||||
txouts.emplace_back(mi->second.tx->vout[input.prevout.n]);
|
txouts.emplace_back(mi->second.tx->vout[input.prevout.n]);
|
||||||
|
@ -1610,13 +1611,16 @@ int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wall
|
||||||
}
|
}
|
||||||
|
|
||||||
// txouts needs to be in the order of tx.vin
|
// txouts needs to be in the order of tx.vin
|
||||||
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
|
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
|
||||||
{
|
{
|
||||||
CMutableTransaction txNew(tx);
|
CMutableTransaction txNew(tx);
|
||||||
if (!wallet->DummySignTx(txNew, txouts, use_max_sig)) {
|
if (!wallet->DummySignTx(txNew, txouts, use_max_sig)) {
|
||||||
return -1;
|
return std::make_pair(-1, -1);
|
||||||
}
|
}
|
||||||
return GetVirtualTransactionSize(CTransaction(txNew));
|
CTransaction ctx(txNew);
|
||||||
|
int64_t vsize = GetVirtualTransactionSize(ctx);
|
||||||
|
int64_t weight = GetTransactionWeight(ctx);
|
||||||
|
return std::make_pair(vsize, weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* wallet, bool use_max_sig)
|
int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* wallet, bool use_max_sig)
|
||||||
|
@ -2770,6 +2774,7 @@ bool CWallet::CreateTransactionInternal(
|
||||||
CMutableTransaction txNew;
|
CMutableTransaction txNew;
|
||||||
FeeCalculation feeCalc;
|
FeeCalculation feeCalc;
|
||||||
CAmount nFeeNeeded;
|
CAmount nFeeNeeded;
|
||||||
|
std::pair<int64_t, int64_t> tx_sizes;
|
||||||
int nBytes;
|
int nBytes;
|
||||||
{
|
{
|
||||||
std::set<CInputCoin> setCoins;
|
std::set<CInputCoin> setCoins;
|
||||||
|
@ -2952,7 +2957,8 @@ bool CWallet::CreateTransactionInternal(
|
||||||
txNew.vin.push_back(CTxIn(coin.outpoint,CScript()));
|
txNew.vin.push_back(CTxIn(coin.outpoint,CScript()));
|
||||||
}
|
}
|
||||||
|
|
||||||
nBytes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
|
tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
|
||||||
|
nBytes = tx_sizes.first;
|
||||||
if (nBytes < 0) {
|
if (nBytes < 0) {
|
||||||
error = _("Signing transaction failed");
|
error = _("Signing transaction failed");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1321,8 +1321,8 @@ public:
|
||||||
// Use DummySignatureCreator, which inserts 71 byte signatures everywhere.
|
// Use DummySignatureCreator, which inserts 71 byte signatures everywhere.
|
||||||
// NOTE: this requires that all inputs must be in mapWallet (eg the tx should
|
// NOTE: this requires that all inputs must be in mapWallet (eg the tx should
|
||||||
// be IsAllFromMe).
|
// be IsAllFromMe).
|
||||||
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig = false) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
|
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig = false) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
|
||||||
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false);
|
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false);
|
||||||
|
|
||||||
//! Add wallet name to persistent configuration so it will be loaded on startup.
|
//! Add wallet name to persistent configuration so it will be loaded on startup.
|
||||||
bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
|
bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue