mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-01 03:16:09 +02:00
rpc: return block hash & height in getbalances, gettransaction & getwalletinfo JSONs
Co-authored-by: Aurèle Oulès <aurele@oules.com>
This commit is contained in:
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user