diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-12-06 19:48:40 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-12-03 11:13:00 +0100 |
commit | fa5362a9a0c5665c1a4de51c3ce4758c93a9449e (patch) | |
tree | 58bec45f4b722e1d9c991ab08a79b989a70e628b /src/wallet | |
parent | 8b1de78577a02300340cec37e26cd6418ef6e645 (diff) | |
download | bitcoin-fa5362a9a0c5665c1a4de51c3ce4758c93a9449e.tar.xz |
rpc: Add missing BlockUntilSyncedToCurrentChain to wallet RPCs
Wallet RPCs that allow a rescan based on block-timestamp or block-height
need to sync with the active chain first, because the user might assume
the wallet is up-to-date with the latest block they got reported via a
blockchain RPC.
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/rpc/backup.cpp | 10 | ||||
-rw-r--r-- | src/wallet/rpcwallet.cpp | 5 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index a61ebb26b3..7e06ff0e4f 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1346,6 +1346,11 @@ RPCHelpMan importmulti() { std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(mainRequest); if (!pwallet) return NullUniValue; + CWallet& wallet{*pwallet}; + + // Make sure the results are valid at least up to the most recent block + // the user could have gotten from another RPC command prior to now + wallet.BlockUntilSyncedToCurrentChain(); RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ}); @@ -1649,6 +1654,11 @@ RPCHelpMan importdescriptors() { std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(main_request); if (!pwallet) return NullUniValue; + CWallet& wallet{*pwallet}; + + // Make sure the results are valid at least up to the most recent block + // the user could have gotten from another RPC command prior to now + wallet.BlockUntilSyncedToCurrentChain(); // Make sure wallet is a descriptor wallet if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 181dd1bd54..e83f335de2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3304,6 +3304,11 @@ static RPCHelpMan rescanblockchain() { std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request); if (!pwallet) return NullUniValue; + CWallet& wallet{*pwallet}; + + // Make sure the results are valid at least up to the most recent block + // the user could have gotten from another RPC command prior to now + wallet.BlockUntilSyncedToCurrentChain(); WalletRescanReserver reserver(*pwallet); if (!reserver.reserve()) { |