From 710b83938ab5bbc4bd324d8b2e69461a2a1d2eec Mon Sep 17 00:00:00 2001 From: Harris Date: Mon, 27 Apr 2020 10:45:03 +0200 Subject: 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 --- 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 +++ 5 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index 4c386789f1..750ef69f6e 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 eb4f4c87ae..c34391e6e8 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 4d82e0a41f..4ff44b84b0 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 d5d6ac0dfa..2fdba04352 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