Page MenuHomePhabricator

MOVEONLY: CWallet transaction code out of wallet.cpp/.h
ClosedPublic

Authored by PiRK on Dec 5 2022, 16:33.

Details

Reviewers
sdulfari
Group Reviewers
Restricted Project
Commits
rABCe93f86221e4a: MOVEONLY: CWallet transaction code out of wallet.cpp/.h
Summary

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 #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.

This is a backport of core#21207

Test Plan

ninja all check-all

Event Timeline

PiRK requested review of this revision.Dec 5 2022, 16:33
sdulfari added a subscriber: sdulfari.
sdulfari added inline comments.
src/wallet/receive.cpp
6 ↗(On Diff #37006)

nit: this include should be in its own group above this one

src/wallet/spend.cpp
14 ↗(On Diff #37006)

same

This revision is now accepted and ready to land.Dec 5 2022, 20:43

move main includes to top of file. I also removed an unused include that was detected by my IDE as a result of changing the includes' order

while working on the follow up (core#22100) I noticed that I forgot to move a function