From 710b83938ab5bbc4bd324d8b2e69461a2a1d2eec Mon Sep 17 00:00:00 2001 From: Harris Date: Mon, 27 Apr 2020 10:45:03 +0200 Subject: [PATCH] rpc: return block hash & height in getbalances, gettransaction & getwalletinfo JSONs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aurèle Oulès --- doc/release-notes-26094.md | 6 ++++ src/wallet/rpc/coins.cpp | 3 ++ src/wallet/rpc/transactions.cpp | 2 ++ src/wallet/rpc/util.cpp | 10 +++++++ src/wallet/rpc/util.h | 10 +++++-- src/wallet/rpc/wallet.cpp | 3 ++ test/functional/wallet_balance.py | 35 ++++++++++++++++++++++-- test/functional/wallet_basic.py | 2 +- test/functional/wallet_orphanedreward.py | 5 +++- 9 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 doc/release-notes-26094.md diff --git a/doc/release-notes-26094.md b/doc/release-notes-26094.md new file mode 100644 index 00000000000..ba73f2707e7 --- /dev/null +++ b/doc/release-notes-26094.md @@ -0,0 +1,6 @@ +- The `getbalances` RPC now returns a `lastprocessedblock` JSON object which contains the wallet's last processed block + hash and height at the time the balances were calculated. This result shouldn't be cached because importing new keys could invalidate it. +- The `gettransaction` RPC now returns a `lastprocessedblock` JSON object which contains the wallet's last processed block + hash and height at the time the transaction information was generated. +- The `getwalletinfo` RPC now returns a `lastprocessedblock` JSON object which contains the wallet's last processed block + hash and height at the time the wallet information was generated. \ No newline at end of file diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index 4c386789f1d..750ef69f6ea 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -448,6 +448,7 @@ RPCHelpMan getbalances() {RPCResult::Type::STR_AMOUNT, "untrusted_pending", "untrusted pending balance (outputs created by others that are in the mempool)"}, {RPCResult::Type::STR_AMOUNT, "immature", "balance from immature coinbase outputs"}, }}, + RESULT_LAST_PROCESSED_BLOCK, } }, RPCExamples{ @@ -488,6 +489,8 @@ RPCHelpMan getbalances() balances_watchonly.pushKV("immature", ValueFromAmount(bal.m_watchonly_immature)); balances.pushKV("watchonly", balances_watchonly); } + + AppendLastProcessedBlock(balances, wallet); return balances; }, }; diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index eb4f4c87ae8..c34391e6e86 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -731,6 +731,7 @@ RPCHelpMan gettransaction() { {RPCResult::Type::ELISION, "", "Equivalent to the RPC decoderawtransaction method, or the RPC getrawtransaction method when `verbose` is passed."}, }}, + RESULT_LAST_PROCESSED_BLOCK, }) }, RPCExamples{ @@ -791,6 +792,7 @@ RPCHelpMan gettransaction() entry.pushKV("decoded", decoded); } + AppendLastProcessedBlock(entry, *pwallet); return entry; }, }; diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp index 4d82e0a41f3..4ff44b84b07 100644 --- a/src/wallet/rpc/util.cpp +++ b/src/wallet/rpc/util.cpp @@ -177,4 +177,14 @@ void HandleWalletError(const std::shared_ptr wallet, DatabaseStatus& st throw JSONRPCError(code, error.original); } } + +void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) +{ + AssertLockHeld(wallet.cs_wallet); + UniValue lastprocessedblock{UniValue::VOBJ}; + lastprocessedblock.pushKV("hash", wallet.GetLastBlockHash().GetHex()); + lastprocessedblock.pushKV("height", wallet.GetLastBlockHeight()); + entry.pushKV("lastprocessedblock", lastprocessedblock); +} + } // namespace wallet diff --git a/src/wallet/rpc/util.h b/src/wallet/rpc/util.h index d5d6ac0dfa8..2fdba043522 100644 --- a/src/wallet/rpc/util.h +++ b/src/wallet/rpc/util.h @@ -5,7 +5,9 @@ #ifndef BITCOIN_WALLET_RPC_UTIL_H #define BITCOIN_WALLET_RPC_UTIL_H +#include #include