From 18493205fc02ab9d2e9d1c8f28b72881e66edbac Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Fri, 14 Feb 2014 17:43:44 -0200 Subject: [PATCH] make soft checkpoint less verbose --- src/bitcoinrpc.cpp | 1 + src/bitcoinrpc.h | 1 + src/rpcblockchain.cpp | 27 +++++++++++++++++++++++++++ src/softcheckpoint.cpp | 19 +++++++++++++++++-- src/softcheckpoint.h | 2 ++ 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 1c85e8f1..918dae26 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -241,6 +241,7 @@ static const CRPCCommand vRPCCommands[] = { "sendrawtransaction", &sendrawtransaction, false, false }, { "sendnewusertransaction", &sendnewusertransaction, false, false }, { "verifychain", &verifychain, true, false }, + { "getlastsoftcheckpoint", &getlastsoftcheckpoint, true, false }, // twister dht network { "dhtput", &dhtput, false, true }, { "dhtget", &dhtget, false, true }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 6525276f..ec85f48d 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -194,6 +194,7 @@ extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp) extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getlastsoftcheckpoint(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dhtput(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dhtget(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1be126e2..9bb74944 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -5,6 +5,7 @@ #include "main.h" #include "bitcoinrpc.h" +#include "softcheckpoint.h" using namespace json_spirit; using namespace std; @@ -203,3 +204,29 @@ Value verifychain(const Array& params, bool fHelp) return VerifyDB(nCheckLevel, nCheckDepth); } + +Value getlastsoftcheckpoint(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getlastsoftcheckpoint" + "Returns votes of last soft checkpoint."); + + Object result; + + int height; + uint256 hash; + std::set usernamesSet; + if( SoftCheckpoints::GetLastCPVotes(height, hash, usernamesSet) ) { + result.push_back(Pair("height", height)); + result.push_back(Pair("hash", hash.GetHex())); + + Array usernames; + BOOST_FOREACH(const std::string &user, usernamesSet) { + usernames.push_back(user); + } + result.push_back(Pair("usernames", usernames)); + } + + return result; +} diff --git a/src/softcheckpoint.cpp b/src/softcheckpoint.cpp index 1a63c9bf..7cc5d35f 100644 --- a/src/softcheckpoint.cpp +++ b/src/softcheckpoint.cpp @@ -16,8 +16,8 @@ #include "init.h" #include "twister.h" -#define dbgprintf OutputDebugStringF -//#define dbgprintf(...) // no debug printf +//#define dbgprintf OutputDebugStringF +#define dbgprintf(...) // no debug printf namespace SoftCheckpoints { @@ -266,4 +266,19 @@ namespace SoftCheckpoints } } } + + bool GetLastCPVotes(int &height, uint256 &hash, std::set &usernames) { + LOCK(cs_softCP); + if (!lastSoftCP.first) + return false; + + height = lastSoftCP.first; + hash = lastSoftCP.second; + + usernames.clear(); + BOOST_FOREACH(const CPSigMap::value_type& i, lastSoftCPSigs) { + usernames.insert(i.first); + } + return true; + } } diff --git a/src/softcheckpoint.h b/src/softcheckpoint.h index 2cb5934d..86f900c8 100644 --- a/src/softcheckpoint.h +++ b/src/softcheckpoint.h @@ -31,6 +31,8 @@ namespace SoftCheckpoints void RelayCP(const CSoftCheckpoint& cp, CNode* pfrom); void RelayLastCPToNode(CNode* pnode); + + bool GetLastCPVotes(int &height, uint256 &hash, std::set &usernames); } class CSoftCheckpoint