elements/src/wallet
MarcoFalke afdfd3c8c1
Merge #20403: wallet: upgradewallet fixes, improvements, test coverage
3eb6f8b2e6 wallet (not for backport): improve upgradewallet error messages (Jon Atack)
ca8cd893bb wallet: fix and improve upgradewallet error responses (Jon Atack)
99d56e3571 wallet: fix and improve upgradewallet result responses (Jon Atack)
2498b04ce8 Don't upgrade to HD split if it is already supported (Andrew Chow)
c46c18b788 wallet: refactor GetClosestWalletFeature() (Jon Atack)

Pull request description:

  This follows up on #18836 and #20282 to fix and improve the as-yet unreleased `upgradewallet` feature and also implement review follow-up in https://github.com/bitcoin/bitcoin/pull/18836#discussion_r519328607.

  This PR fixes 4 upgradewallet issues:

  - this bug: https://github.com/bitcoin/bitcoin/pull/20403#discussion_r526063920
  - it returns nothing in the absence of an RPC error, which isn't reassuring for users
  - it returns the same thing both in the case of a successful upgrade and when no upgrade took place
  - the error message object is currently dead code

  This PR fixes the above and provides:

  ...user feedback to not silently return without upgrading
  ```
  {
    "wallet_name": "disable private keys",
    "previous_version": 169900,
    "current_version": 169900,
    "result": "Already at latest version. Wallet version unchanged."
  }
  ```
  ...better feedback after successfully upgrading
  ```
  {
    "wallet_name": "watch-only",
    "previous_version": 159900,
    "current_version": 169900,
    "result": "Wallet upgraded successfully from version 159900 to version 169900."
  }
  ```
  ...helpful error responses
  ```
  {
    "wallet_name": "blank",
    "previous_version": 169900,
    "current_version": 169900,
    "error": "Cannot downgrade wallet from version 169900 to version 159900. Wallet version unchanged."
  }
  {
    "wallet_name": "blank",
    "previous_version": 130000,
    "current_version": 130000,
    "error": "Cannot upgrade a non HD split wallet from version 130000 to version 169899 without upgrading to support pre-split keypool. Please use version 169900 or no version specified."
  }
  ```
  updated help:
  ```
  upgradewallet ( version )

  Upgrade the wallet. Upgrades to the latest version if no version number is specified.
  New keys may be generated and a new wallet backup will need to be made.
  Arguments:
  1. version    (numeric, optional, default=169900) The version number to upgrade to. Default is the latest wallet version.

  Result:
  {                            (json object)
    "wallet_name" : "str",     (string) Name of wallet this operation was performed on
    "previous_version" : n,    (numeric) Version of wallet before this operation
    "current_version" : n,     (numeric) Version of wallet after this operation
    "result" : "str",          (string, optional) Description of result, if no error
    "error" : "str"            (string, optional) Error message (if there is one)
  }
  ```

ACKs for top commit:
  achow101:
    ACK  3eb6f8b
  MarcoFalke:
    review ACK 3eb6f8b2e6 🛡

Tree-SHA512: b767314069e26b5933b123acfea6aa40708507f504bdb22884da020a4ca1332af38a7072b061e36281533af9f4e236d94d3c129daf6fe5b55241127537038eed
2020-11-25 12:46:27 +01:00
..
test Merge #15710: wallet: Catch ios_base::failure specifically 2020-11-19 12:32:48 +01:00
bdb.cpp Determine wallet file type based on file magic 2020-10-14 11:28:18 -04:00
bdb.h rpc, wallet: Expose database format in getwalletinfo 2020-10-14 21:47:42 +01:00
coincontrol.cpp [rpc] walletcreatefundedpsbt: don't automatically append inputs 2020-03-12 13:07:17 +01:00
coincontrol.h [rpc] walletcreatefundedpsbt: don't automatically append inputs 2020-03-12 13:07:17 +01:00
coinselection.cpp Refactor OutputGroups to handle effective values, fees, and filtering 2020-08-11 14:25:02 -04:00
coinselection.h Refactor OutputGroups to handle effective values, fees, and filtering 2020-08-11 14:25:02 -04:00
context.cpp Remove g_rpc_chain global 2020-05-28 02:13:19 -04:00
context.h wallet: Pass unused args to StartWallets 2020-07-09 13:07:37 +02:00
crypter.cpp
crypter.h Convert wallet to new serialization 2020-05-24 10:34:52 -07:00
db.cpp refactor: Pass wallet database into CWallet::Create 2020-09-03 12:24:32 -04:00
db.h rpc, wallet: Expose database format in getwalletinfo 2020-10-14 21:47:42 +01:00
feebumper.cpp [send] Make send RPCs return fee reason 2020-09-26 17:57:26 -07:00
feebumper.h wallet: Avoid translating RPC errors when creating txs 2020-05-01 07:39:06 -04:00
fees.cpp
fees.h
init.cpp Do not compile BDB things when USE_BDB is defined 2020-11-18 11:56:08 -05:00
ismine.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
load.cpp Ignoring (but warn) on duplicate -wallet parameters 2020-11-03 12:06:32 +01:00
load.h Do not create default wallet 2020-09-08 21:02:53 -04:00
rpcdump.cpp Merge #20153: wallet: do not import a descriptor with hardened derivations into a watch-only wallet 2020-11-09 20:19:00 +01:00
rpcwallet.cpp Merge #20403: wallet: upgradewallet fixes, improvements, test coverage 2020-11-25 12:46:27 +01:00
rpcwallet.h Assert that RPCArg names are equal to CRPCCommand ones (net, rpcwallet) 2020-09-22 20:49:30 +02:00
salvage.cpp Enforce salvage is only for BDB wallets 2020-11-18 11:56:12 -05:00
salvage.h wallettool: Have RecoverDatabaseFile return errors and warnings 2020-07-26 20:22:45 -04:00
scriptpubkeyman.cpp Merge #20403: wallet: upgradewallet fixes, improvements, test coverage 2020-11-25 12:46:27 +01:00
scriptpubkeyman.h Include wallet/bdb.h where it is actually being used 2020-11-18 11:55:43 -05:00
sqlite.cpp Fix mock SQLiteDatabases 2020-11-18 11:56:12 -05:00
sqlite.h rpc, wallet: Expose database format in getwalletinfo 2020-10-14 21:47:42 +01:00
wallet.cpp Merge #20403: wallet: upgradewallet fixes, improvements, test coverage 2020-11-25 12:46:27 +01:00
wallet.h Merge #20139: Wallet: do not return warnings from UpgradeWallet() 2020-11-17 12:43:43 +01:00
walletdb.cpp Merge #20202: wallet: Make BDB support optional 2020-11-23 10:30:01 +01:00
walletdb.h Include wallet/bdb.h where it is actually being used 2020-11-18 11:55:43 -05:00
wallettool.cpp Do not compile BDB things when USE_BDB is defined 2020-11-18 11:56:08 -05:00
wallettool.h wallet: Remove path checking code from bitcoin-wallet tool 2020-09-03 12:24:32 -04:00
walletutil.cpp Merge #20403: wallet: upgradewallet fixes, improvements, test coverage 2020-11-25 12:46:27 +01:00
walletutil.h wallet: Add GetClosestWalletFeature function 2020-10-19 00:14:38 -04:00