diff options
author | Harris <brakmic@gmail.com> | 2020-04-27 10:45:03 +0200 |
---|---|---|
committer | Aurèle Oulès <aurele@oules.com> | 2023-04-26 16:07:47 +0200 |
commit | 710b83938ab5bbc4bd324d8b2e69461a2a1d2eec (patch) | |
tree | e78465394ff8286c4969d565209f18bd8252c5a3 /src/wallet | |
parent | 91ccb62faab21b2b52b089cc04f3a5c1bf6989cc (diff) |
rpc: return block hash & height in getbalances, gettransaction & getwalletinfo JSONs
Co-authored-by: Aurèle Oulès <aurele@oules.com>
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/rpc/coins.cpp | 3 | ||||
-rw-r--r-- | src/wallet/rpc/transactions.cpp | 2 | ||||
-rw-r--r-- | src/wallet/rpc/util.cpp | 10 | ||||
-rw-r--r-- | src/wallet/rpc/util.h | 10 | ||||
-rw-r--r-- | src/wallet/rpc/wallet.cpp | 3 |
5 files changed, 26 insertions, 2 deletions
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<CWallet> 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 <rpc/util.h> #include <script/script.h> +#include <wallet/wallet.h> #include <any> #include <memory> @@ -17,13 +19,17 @@ class UniValue; struct bilingual_str; namespace wallet { -class CWallet; class LegacyScriptPubKeyMan; enum class DatabaseStatus; struct WalletContext; extern const std::string HELP_REQUIRING_PASSPHRASE; +static const RPCResult RESULT_LAST_PROCESSED_BLOCK { RPCResult::Type::OBJ, "lastprocessedblock", "hash and height of the block this information was generated on",{ + {RPCResult::Type::STR_HEX, "hash", "hash of the block this information was generated on"}, + {RPCResult::Type::NUM, "height", "height of the block this information was generated on"}} +}; + /** * Figures out what wallet, if any, to use for a JSONRPCRequest. * @@ -45,8 +51,8 @@ std::string LabelFromValue(const UniValue& value); void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry); void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& status, bilingual_str& error); - int64_t ParseISO8601DateTime(const std::string& str); +void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); } // namespace wallet #endif // BITCOIN_WALLET_RPC_UTIL_H diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index ea3507bc75..a3a2a7b89c 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -68,6 +68,7 @@ static RPCHelpMan getwalletinfo() }, /*skip_type_check=*/true}, {RPCResult::Type::BOOL, "descriptors", "whether this wallet uses descriptors for scriptPubKey management"}, {RPCResult::Type::BOOL, "external_signer", "whether this wallet is configured to use an external signer such as a hardware wallet"}, + RESULT_LAST_PROCESSED_BLOCK, }}, }, RPCExamples{ @@ -129,6 +130,8 @@ static RPCHelpMan getwalletinfo() } obj.pushKV("descriptors", pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); obj.pushKV("external_signer", pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)); + + AppendLastProcessedBlock(obj, *pwallet); return obj; }, }; |