diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-01-18 21:04:26 -0500 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2022-03-23 14:32:05 -0400 |
commit | 0ba4d1916e26e2a5d603edcdb7625463989d25b6 (patch) | |
tree | ef3f9a7fddf9ed5216f26cc5e72059f61af4985c /src/wallet | |
parent | d51f27d3bb0d6e3ca55bcd23ce53e4fe413a9360 (diff) |
wallet: Provide input bytes to COutput
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/spend.cpp | 4 | ||||
-rw-r--r-- | src/wallet/spend.h | 20 | ||||
-rw-r--r-- | src/wallet/test/coinselector_tests.cpp | 2 |
3 files changed, 9 insertions, 17 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index cc987e7e65..0dc79e9c80 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -193,7 +193,7 @@ void AvailableCoins(const CWallet& wallet, std::vector<COutput>& vCoins, const C bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false; bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable)); - vCoins.emplace_back(wallet, wtx, i, nDepth, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, /*use_max_sig_in=*/ (coinControl && coinControl->fAllowWatchOnly)); + vCoins.emplace_back(wallet, wtx, i, nDepth, GetTxSpendSize(wallet, wtx, i, /*use_max_sig=*/ (coinControl && coinControl->fAllowWatchOnly)), spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me); // Checks the sum amount of all UTXO's. if (nMinimumSumAmount != MAX_MONEY) { @@ -278,7 +278,7 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet) CTxDestination address; if (ExtractDestination(FindNonChangeParentOutput(wallet, *wtx.tx, output.n).scriptPubKey, address)) { result[address].emplace_back( - wallet, wtx, output.n, depth, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), CachedTxIsFromMe(wallet, wtx, ISMINE_ALL), /*use_max_sig_in=*/ false); + wallet, wtx, output.n, depth, GetTxSpendSize(wallet, wtx, output.n), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), CachedTxIsFromMe(wallet, wtx, ISMINE_ALL)); } } } diff --git a/src/wallet/spend.h b/src/wallet/spend.h index e71e90eaca..029560a16c 100644 --- a/src/wallet/spend.h +++ b/src/wallet/spend.h @@ -11,7 +11,9 @@ #include <wallet/wallet.h> namespace wallet { -/** Get the marginal bytes if spending the specified output from this transaction */ +/** Get the marginal bytes if spending the specified output from this transaction. + * use_max_sig indicates whether to use the maximum sized, 72 byte signature when calculating the + * size of the input spend. This should only be set when watch-only outputs are allowed */ int GetTxSpendSize(const CWallet& wallet, const CWalletTx& wtx, unsigned int out, bool use_max_sig = false); class COutput @@ -38,9 +40,6 @@ public: /** Whether we know how to spend this output, ignoring the lack of keys */ bool solvable; - /** Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend. This should only be set when watch-only outputs are allowed */ - bool use_max_sig; - /** * Whether this output is considered safe to spend. Unconfirmed transactions * from outside keys and unconfirmed replacement transactions are considered @@ -54,24 +53,17 @@ public: /** Whether the transaction containing this output is sent from the owning wallet */ bool from_me; - COutput(const CWallet& wallet, const CWalletTx& wtx, int iIn, int depth, bool spendable, bool solvable, bool safe, int64_t time, bool from_me, bool use_max_sig_in) + COutput(const CWallet& wallet, const CWalletTx& wtx, int iIn, int depth, int input_bytes, bool spendable, bool solvable, bool safe, int64_t time, bool from_me) : tx(&wtx), i(iIn), depth(depth), - input_bytes(-1), + input_bytes(input_bytes), spendable(spendable), solvable(solvable), - use_max_sig(use_max_sig_in), safe(safe), time(time), from_me(from_me) - { - // If known and signable by the given wallet, compute input_bytes - // Failure will keep this value -1 - if (spendable) { - input_bytes = GetTxSpendSize(wallet, wtx, i, use_max_sig); - } - } + {} std::string ToString() const; diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index 2293f5793c..ebeb50bace 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -88,7 +88,7 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)), TxStateInactive{})); assert(ret.second); CWalletTx& wtx = (*ret.first).second; - coins.emplace_back(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe, /*use_max_sig_in=*/ false); + coins.emplace_back(wallet, wtx, nInput, nAge, GetTxSpendSize(wallet, wtx, nInput), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe); } /** Check if SelectionResult a is equivalent to SelectionResult b. |