X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Frpcnet.cpp;h=d0f4516ea9e51dd0dbc96ca66d85cbee9dbef9d8;hp=e67c5f1ebe0f9b29b826586f224704e9128c3327;hb=5a73a5bcab66ec1012ac88b4d61bdc1e0213286c;hpb=0a7d6c34393639170a541b9d8acf89f158489b8c diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index e67c5f1..d0f4516 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -8,6 +8,7 @@ #include "db.h" #include "walletdb.h" #include "net.h" +#include "ntp.h" using namespace json_spirit; using namespace std; @@ -344,4 +345,29 @@ Value getnettotals(const Array& params, bool fHelp) obj.push_back(Pair("totalbytessent", static_cast(CNode::GetTotalBytesSent()))); obj.push_back(Pair("timemillis", static_cast(GetTimeMillis()))); return obj; -} \ No newline at end of file +} + +Value ntptime(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "ntptime [ntpserver]\n" + "Returns current time from specific or random NTP server."); + + int64_t nTime; + if (params.size() > 0) + { + string strHostName = params[0].get_str(); + nTime = NtpGetTime(strHostName); + } + else + nTime = NtpGetTime(); + + if (nTime < 0) + throw runtime_error("Request error"); + + Object obj; + obj.push_back(Pair("epoch", nTime)); + obj.push_back(Pair("time", DateTimeStrFormat(nTime))); + return obj; +}