From 8687a0ebbc2efcb52c72fc0e34f762a1b9448cbe Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Wed, 3 Jul 2013 11:02:29 -0400 Subject: [PATCH] RPC: add getbestblockhash, to return tip of best chain --- src/bitcoinrpc.cpp | 1 + src/bitcoinrpc.h | 1 + src/rpcblockchain.cpp | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 93b4d035d..b51a78be0 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -202,6 +202,7 @@ static const CRPCCommand vRPCCommands[] = { "help", &help, true, true }, { "stop", &stop, true, true }, { "getblockcount", &getblockcount, true, false }, + { "getbestblockhash", &getbestblockhash, true, false }, { "getconnectioncount", &getconnectioncount, true, false }, { "getpeerinfo", &getpeerinfo, true, false }, { "addnode", &addnode, true, true }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index f7f06c671..36ebb0689 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -192,6 +192,7 @@ extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, b extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp +extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value setmininput(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 49572821b..b6e962b89 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -81,6 +81,15 @@ Value getblockcount(const Array& params, bool fHelp) return nBestHeight; } +Value getbestblockhash(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getbestblockhash\n" + "Returns the hash of the best (tip) block in the longest block chain."); + + return hashBestChain.GetHex(); +} Value getdifficulty(const Array& params, bool fHelp) {