Page MenuHomePhabricator

wallet/refactor: refer to CWallet immutably when possible
ClosedPublic

Authored by deadalnix on Oct 25 2020, 16:50.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABCfceefb59cf19: wallet/refactor: refer to CWallet immutably when possible
Summary
  • make BlockUntilSyncedToCurrentChain() const

The method checks the chain tip for the best block, and calls SyncWithValidationInterfaceQueue() (a standalone function) if necessary.

  • wallet: make CanGenerateKeys() const

This method simply checks if HD is or can be enabled and does not require mutability.

  • wallet: make KeypoolCountExternalKeys() const

This method returns the sum of the key pool sizes. It does no modification.

  • wallet: make CanGetAddresses() const

CWallet::CanGetAddresses() is used to check whether the wallet has available or is able to produce keys for addresses. It uses the ScriptPubKeyMan::CanGetAddresses(), which in turn uses the const KeypoolCountExternalKeys() method, all which do counting and no modifications.

  • wallet/db: make IsDummy() const

This method does a simple check and no modifications.

  • wallet/db: make Backup() const

This method is the to-disk equivalent of serialize methods which are also const.

  • wallet: use constant CWallets in rpcdump.cpp
  • GetWalletAddressesForKey is, as the name implies, immutable; the one change besides the parameter constness is a [] -> .at() change, to a verified-existing key.
  • dumpprivkey and dumpwallet are both similarly immutable, for obvious reasons.
    • wallet/spkm: make GetOldestKeyPoolTime() const

The method checks the oldest key time for key pools and returns the oldest. It does no modifications.

  • wallet: make getters const
  • wallet: make BackupWallet() const
  • wallet: make ReserveDestination pwallet ivar const
  • wallet: use constant CWallets in rpcwallet.cpp
  • GetAvoidReuseFlag: simply gets the flag, without modifying the wallet
  • ListReceived: helper function to produce lists
  • ListTransactions: produces a list of transactions, without modifications; two cases of map [] -> .at() for verified-existing keys
  • DescribeWalletAddress: generates a description of a given wallet address without changing the wallet
  • The following functions produce a list without making any modifications to the wallet:
    • listaddressgroupings
    • listreceivedbyaddress
    • listreceivedbylabel
    • listtransactions
    • listsinceblock
    • listlockunspent
    • listunspent
    • listlabels
    • getreceivedbyaddress
    • getreceivedbylabel
    • getaddressesbylabel
  • signmessage: uses the wallet to procure a private key for signing, but does no modifications
  • getbalance, getunconfirmedbalance: calculates the wallet balance, without any modifications
  • gettransaction: procures transaction without any modifications
  • backupwallet: makes a backup of the wallet to disk, without changing said wallet
  • getwalletinfo: produces info about wallet without any modifications
  • signrawtransactionwithwallet: modifies incoming transaction on the fly by signing with private key procured from within wallet; no modifications to wallet
  • getaddressinfo: gets information about the given address, with no modifications done to the wallet; one case of [] -> .at() and one ::iterator -> ::const_iterator
  • walletprocesspsbt: processes the given PSBT on the fly, without modifying the wallet

This is a backport of Core PR18241

Test Plan
ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable