aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/spend.cpp
AgeCommit message (Collapse)Author
2021-08-20wallet: Assert that enough was selected to cover the feesAndrew Chow
When the fee is not subtracted from the outputs, the amount that has been reserved for the fee (change_and_fee - change_amount) must be enough to cover the fee that is needed. It would be a bug to not do so, so use an assert to make this obvious if such a situation were to occur. Github-Pull: bitcoin/bitcoin#22686 Rebased-From: d9262324e80da32725e21d4e0fbfee56f25490b1
2021-06-22wallet: Add error message to GetReservedDestinationAndrew Chow
Adds an error output parameter to all GetReservedDestination functions so that callers can get the actual reason that a change address could not be fetched. This more closely matches GetNewDestination. This allows for more granular error messages, such as one that indicates that bech32m addresses cannot be generated yet.
2021-05-30scripted-diff: Rename SelectCoinsMinConf to AttemptSelectionAndrew Chow
SelectCoinsMinConf is a bit of a misnomer now since it really just does all of the coin selection given some parameters. So rename this to something less annoying to say and makes a bit more sense. -BEGIN VERIFY SCRIPT- sed -i 's/SelectCoinsMinConf/AttemptSelection/g' $(git grep -l SelectCoinsMinConf ./src) -END VERIFY SCRIPT-
2021-05-30Move vin filling to before final fee settingAndrew Chow
It's unnecessary to fill in the vin with dummy inputs, calculate the fee, then fill in the vin with the actual inputs. Just fill the vin with the actual inputs the first time.
2021-05-30Set m_subtract_fee_outputs during recipients vector loopAndrew Chow
Instead of setting this afterwards based on the results from the loop, just do it inside of the loop itself. Fixed some styling nearby
2021-05-30Move variable initializations to where they are usedAndrew Chow
- txNew nLockTime setting to txNew init - FeeCalc to the fee estimation fetching - setCoins to prior to SelectCoins - nBytes to CalculateMaximumSignedTxSize call - tx_sizes to CalculateMaximumSignedTxSize call - coin_selection_params.m_avoid_partial_spends to params init
2021-05-30Move recipients vector checks to beginning of CreateTransactionAndrew Chow
Ensuring that the recipients vector is not empty and that the amounts are non-negative can be done in CreateTransaction rather than CreateTransactionInternal. Additionally, these checks should happen as soon as possible, so they are done at the beginning of CreateTransaction.
2021-05-30Rename nSubtractFeeFromAmount in CreateTransactionAndrew Chow
Renamed to outputs_to_subtract_fee_from for clarity.
2021-05-30Rename nValue and nValueToSelectAndrew Chow
nValue is the sum of the intended recipient amounts, so name it that for clarity. nValueToSelect is the coin selection target value, so name it selection_target for clarity.
2021-05-30Remove extraneous scope in CreateTransactionInternalAndrew Chow
These brackets were restricting a scope for no apparent reason. Remove them and dedent.
2021-05-30Move cs_wallet lock in CreateTransactionInternal to top of functionAndrew Chow
It isn't necessary to not lock parts of this function. Just lock the whole thing and get rid of an indent.
2021-05-26MOVEONLY: CWallet transaction code out of wallet.cpp/.hRussell Yanofsky
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After #20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in https://github.com/bitcoin/bitcoin/pull/21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.