 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
25 #include <boost/bind.hpp>
26 #include <boost/iostreams/concepts.hpp>
27 #include <boost/iostreams/stream.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/signals2/signal.hpp>
30 #include <boost/thread.hpp>
31 #include <boost/algorithm/string/case_conv.hpp>
36 static bool fRPCRunning =
false;
37 static bool fRPCInWarmup =
true;
38 static std::string rpcWarmupStatus(
"RPC server started");
45 static std::map <std::string, boost::shared_ptr<RPCTimerBase>> deadlineTimers;
47 static struct CRPCSignals {
48 boost::signals2::signal<void()> Started;
49 boost::signals2::signal<void()> Stopped;
50 boost::signals2::signal<void(
const CRPCCommand &)> PreCommand;
51 boost::signals2::signal<void(
const CRPCCommand &)> PostCommand;
55 g_rpcSignals.Started.connect(slot);
59 g_rpcSignals.Stopped.connect(slot);
63 g_rpcSignals.PreCommand.connect(boost::bind(slot, _1));
67 g_rpcSignals.PostCommand.connect(boost::bind(slot, _1));
70 void RPCTypeCheck(
const UniValue ¶ms,
const std::list<UniValue::VType>& typesExpected,
bool fAllowNull) {
73 if (params.
size() <= i)
77 if (!((v.
type() == t) || (fAllowNull && (v.
isNull())))) {
78 std::string err =
strprintf(
"Expected type %s, got %s",
87 const std::map<std::string, UniValue::VType>& typesExpected,
92 if (!fAllowNull && v.
isNull())
95 if (!((v.
type() == t.second) || (fAllowNull && (v.
isNull())))) {
96 std::string err =
strprintf(
"Expected type %s for %s, got %s",
103 static inline int64_t roundint64(
double d) {
104 return (int64_t)(d > 0 ? d + 0.5 : d - 0.5);
112 if (dAmount <= 0.0 || dAmount > MAX_MONEY_OUT)
114 CAmount nAmount = roundint64(dAmount * COIN);
119 bool sign = amount < 0;
120 int64_t n_abs = (sign ? -amount : amount);
121 int64_t quotient = n_abs / COIN;
122 int64_t remainder = n_abs % COIN;
124 strprintf(
"%s%d.%08d", sign ?
"-" :
"", quotient, remainder));
133 if (64 != strHex.length())
180 std::string category;
181 std::set<rpcfn_type> setDone;
182 std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
184 for (std::map<std::string, const CRPCCommand*>::const_iterator mi =
mapCommands.begin(); mi !=
mapCommands.end(); ++mi)
185 vCommands.push_back(std::make_pair(mi->second->category + mi->first, mi->second));
186 std::sort(vCommands.begin(), vCommands.end());
190 std::string strMethod = pcmd->
name;
192 if (strMethod.find(
"label") != std::string::npos)
194 if ((strCommand !=
"" || pcmd->
category ==
"hidden") && strMethod != strCommand)
204 if (setDone.insert(pfn).second)
205 (*pfn)(params,
true);
206 }
catch (
const std::exception& e) {
208 std::string strHelp = std::string(e.what());
209 if (strCommand ==
"") {
210 if (strHelp.find(
'\n') != std::string::npos)
211 strHelp = strHelp.substr(0, strHelp.find(
'\n'));
214 if (!category.empty())
217 std::string firstLetter = category.substr(0, 1);
218 boost::to_upper(firstLetter);
219 strRet +=
"== " + firstLetter + category.substr(1) +
" ==\n";
222 strRet += strHelp +
"\n";
226 strRet =
strprintf(
"help: unknown command: %s\n", strCommand);
227 strRet = strRet.substr(0, strRet.size() - 1);
232 if (fHelp || params.
size() > 1)
233 throw std::runtime_error(
234 "help ( \"command\" )\n"
235 "\nList all commands, or get help for a specified command.\n"
237 "1. \"command\" (string, optional) The command to get help on\n"
239 "\"text\" (string) The help text\n");
241 std::string strCommand;
242 if (params.
size() > 0)
243 strCommand = params[0].
get_str();
251 if (fHelp || params.
size() > 1)
252 throw std::runtime_error(
254 "\nStop PRCY server.");
258 return "PRCY server stopping";
270 {
"control",
"getinfo", &
getinfo,
true,
false,
false},
271 {
"control",
"getversion", &
getversion,
true,
false,
false},
272 {
"control",
"help", &
help,
true,
true,
false},
273 {
"control",
"stop", &
stop,
true,
true,
false},
276 {
"network",
"getnetworkinfo", &
getnetworkinfo,
true,
false,
false},
277 {
"network",
"addnode", &
addnode,
true,
true,
false},
278 {
"network",
"disconnectnode", &
disconnectnode,
true,
true,
false},
281 {
"network",
"getnettotals", &
getnettotals,
true,
true,
false},
282 {
"network",
"getpeerinfo", &
getpeerinfo,
true,
false,
false},
283 {
"network",
"ping", &
ping,
true,
false,
false},
284 {
"network",
"setban", &
setban,
true,
false,
false},
285 {
"network",
"listbanned", &
listbanned,
true,
false,
false},
286 {
"network",
"clearbanned", &
clearbanned,
true,
false,
false},
289 {
"blockchain",
"getsupply", &
getsupply,
true,
false,
false},
290 {
"blockchain",
"getmaxsupply", &
getmaxsupply,
true,
false,
false},
293 {
"blockchain",
"getblockcount", &
getblockcount,
true,
false,
false},
294 {
"blockchain",
"getblock", &
getblock,
true,
false,
false},
295 {
"blockchain",
"getblockhash", &
getblockhash,
true,
false,
false},
297 {
"blockchain",
"getlastpoablock", &
getlastpoablock,
true,
false,
false},
303 {
"blockchain",
"resyncfrom", &
resyncfrom,
true,
false,
false},
304 {
"blockchain",
"getblockheader", &
getblockheader,
false,
false,
false},
305 {
"blockchain",
"getchaintips", &
getchaintips,
true,
false,
false},
306 {
"blockchain",
"getdifficulty", &
getdifficulty,
true,
false,
false},
307 {
"blockchain",
"getfeeinfo", &
getfeeinfo,
true,
false,
false},
308 {
"blockchain",
"getmempoolinfo", &
getmempoolinfo,
true,
true,
false},
309 {
"blockchain",
"getrawmempool", &
getrawmempool,
true,
false,
false},
310 {
"blockchain",
"gettxout", &
gettxout,
true,
false,
false},
311 {
"blockchain",
"gettxoutsetinfo", &
gettxoutsetinfo,
true,
false,
false},
312 {
"blockchain",
"verifychain", &
verifychain,
true,
false,
false},
313 {
"blockchain",
"invalidateblock", &
invalidateblock,
true,
true,
false},
314 {
"blockchain",
"reconsiderblock", &
reconsiderblock,
true,
true,
false},
315 {
"getinvalid",
"getinvalid", &
getinvalid,
true,
true,
false},
320 {
"mining",
"setminingnbits", &
setminingnbits,
true,
false,
false},
321 {
"mining",
"getmininginfo", &
getmininginfo,
true,
false,
false},
324 {
"mining",
"submitblock", &
submitblock,
true,
true,
false},
329 {
"generating",
"getgenerate", &
getgenerate,
true,
false,
false},
330 {
"generating",
"gethashespersec", &
gethashespersec,
true,
false,
false},
331 {
"generating",
"setgenerate", &
setgenerate,
true,
true,
false},
332 {
"generating",
"generate", &
generate,
true,
true,
false},
333 {
"generating",
"generatepoa", &
generatepoa,
true,
true,
false},
339 {
"rawtransactions",
"decodescript", &
decodescript,
true,
false,
false},
340 {
"rawtransactions",
"getrawtransaction", &
getrawtransaction,
true,
false,
false},
345 {
"util",
"logging", &
logging,
true,
false,
false},
357 {
"hidden",
"waitforblock", &
waitforblock,
true,
true,
false},
361 {
"prcycoin",
"masternode", &
masternode,
true,
true,
false},
375 {
"prcycoin",
"mnsync", &
mnsync,
true,
true,
false},
381 {
"wallet",
"backupwallet", &
backupwallet,
true,
false,
true},
386 {
"wallet",
"encryptwallet", &
encryptwallet,
true,
false,
true},
392 {
"wallet",
"importkeys", &
importkeys,
true,
false,
true},
396 {
"wallet",
"rescan", &
rescan,
true,
false,
true},
404 {
"wallet",
"getbalance", &
getbalance,
false,
false,
true},
405 {
"wallet",
"getbalances", &
getbalances,
false,
false,
true},
414 {
"wallet",
"gettransaction", &
gettransaction,
false,
false,
true},
416 {
"wallet",
"getwalletinfo", &
getwalletinfo,
false,
false,
true},
417 {
"wallet",
"gettxcount", &
gettxcount,
false,
false,
true},
427 {
"wallet",
"listsinceblock", &
listsinceblock,
false,
false,
true},
430 {
"wallet",
"listunspent", &
listunspent,
false,
false,
true},
441 {
"wallet",
"walletlock", &
walletlock,
true,
false,
true},
443 {
"wallet",
"unlockwallet", &
unlockwallet,
true,
false,
true},
448 #endif // ENABLE_WALLET
453 for (vcidx = 0; vcidx < (
sizeof(vRPCCommands) /
sizeof(vRPCCommands[0])); vcidx++) {
456 pcmd = &vRPCCommands[vcidx];
462 std::map<std::string, const CRPCCommand *>::const_iterator it =
mapCommands.find(
name);
472 g_rpcSignals.Started();
484 deadlineTimers.clear();
493 rpcWarmupStatus = newStatus;
498 assert(fRPCInWarmup);
499 fRPCInWarmup =
false;
505 *outStatus = rpcWarmupStatus;
523 if (!valMethod.
isStr())
533 else if (valParams.
isNull())
551 }
catch (
const UniValue& objError) {
553 }
catch (
const std::exception& e) {
563 for (
unsigned int reqIdx = 0; reqIdx < vReq.
size(); reqIdx++)
564 ret.
push_back(JSONRPCExecOne(vReq[reqIdx]));
566 return ret.
write() +
"\n";
571 std::string strWarmupStatus;
582 g_rpcSignals.PreCommand(*pcmd);
585 return pcmd->
actor(params,
false);
586 }
catch (
const std::exception& e) {
590 g_rpcSignals.PostCommand(*pcmd);
594 std::vector <std::string> commandList;
595 typedef std::map<std::string, const CRPCCommand *> commandMap;
598 std::back_inserter(commandList),
599 boost::bind(&commandMap::value_type::first, _1));
604 return "> prcycoin-cli " + methodname +
" " + args +
"\n";
608 return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", "
610 methodname +
"\", \"params\": [" + args +
"] }' -H 'content-type: text/plain;' http://127.0.0.1:59683/\n";
615 timerInterface = iface;
619 timerInterface = iface;
623 if (timerInterface == iface)
624 timerInterface = NULL;
627 void RPCRunLater(
const std::string &
name, boost::function<
void(
void)> func, int64_t nSeconds) {
630 deadlineTimers.erase(
name);
632 deadlineTimers.insert(
633 std::make_pair(
name, boost::shared_ptr<RPCTimerBase>(timerInterface->
NewTimer(func, nSeconds * 1000))));
@ RPC_INVALID_REQUEST
Standard JSON-RPC 2.0 errors.
@ RPC_MISC_ERROR
General application defined errors.
UniValue disconnectnode(const UniValue ¶ms, bool fHelp)
UniValue getblockindexstats(const UniValue ¶ms, bool fHelp)
UniValue setban(const UniValue ¶ms, bool fHelp)
UniValue invalidateblock(const UniValue ¶ms, bool fHelp)
UniValue getblockcount(const UniValue ¶ms, bool fHelp)
UniValue createmasternode(const UniValue ¶ms, bool fHelp)
int ParseInt(const UniValue &o, std::string strKey)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)
UniValue createrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue getlastpoaauditedpos(const UniValue ¶ms, bool fHelp)
UniValue getversion(const UniValue ¶ms, bool fHelp)
UniValue getlastpoablock(const UniValue ¶ms, bool fHelp)
UniValue getrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue rescanwallettransactions(const UniValue ¶ms, bool fHelp)
UniValue getblocktemplate(const UniValue ¶ms, bool fHelp)
UniValue getmaxsupply(const UniValue ¶ms, bool fHelp)
UniValue rescan(const UniValue ¶ms, bool fHelp)
UniValue masternodecurrent(const UniValue ¶ms, bool fHelp)
UniValue getrawmempool(const UniValue ¶ms, bool fHelp)
UniValue getpoablocktemplate(const UniValue ¶ms, bool fHelp)
UniValue getpeerinfo(const UniValue ¶ms, bool fHelp)
UniValue listtransactions(const UniValue ¶ms, bool fHelp)
UniValue getchaintips(const UniValue ¶ms, bool fHelp)
UniValue createprivacyaccount(const UniValue ¶ms, bool fHelp)
UniValue revealviewprivatekey(const UniValue ¶ms, bool fHelp)
UniValue gettransaction(const UniValue ¶ms, bool fHelp)
std::vector< unsigned char > ParseHex(const char *psz)
UniValue walletlock(const UniValue ¶ms, bool fHelp)
UniValue gettxout(const UniValue ¶ms, bool fHelp)
UniValue getmasternodewinners(const UniValue ¶ms, bool fHelp)
UniValue getnetworkinfo(const UniValue ¶ms, bool fHelp)
UniValue ValueFromAmount(const CAmount &amount)
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
UniValue getblock(const UniValue ¶ms, bool fHelp)
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
const UniValue NullUniValue
UniValue decodemasternodebroadcast(const UniValue ¶ms, bool fHelp)
UniValue getlastpoablocktime(const UniValue ¶ms, bool fHelp)
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
UniValue sendrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue generateintegratedaddress(const UniValue ¶ms, bool fHelp)
UniValue encryptwallet(const UniValue ¶ms, bool fHelp)
UniValue masternode(const UniValue ¶ms, bool fHelp)
UniValue getunconfirmedbalance(const UniValue ¶ms, bool fHelp)
UniValue getmininginfo(const UniValue ¶ms, bool fHelp)
UniValue sendalltostealthaddress(const UniValue ¶ms, bool fHelp)
UniValue createmasternodebroadcast(const UniValue ¶ms, bool fHelp)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
UniValue decodestealthaddress(const UniValue ¶ms, bool fHelp)
UniValue sendtostealthaddress(const UniValue ¶ms, bool fHelp)
UniValue getmempoolinfo(const UniValue ¶ms, bool fHelp)
UniValue getmasternodecount(const UniValue ¶ms, bool fHelp)
UniValue startmasternode(const UniValue ¶ms, bool fHelp)
UniValue prioritisetransaction(const UniValue ¶ms, bool fHelp)
bool ParseBool(const UniValue &o, std::string strKey)
UniValue getnetworkhashps(const UniValue ¶ms, bool fHelp)
UniValue getseesawrewardwithheight(const UniValue ¶ms, bool fHelp)
UniValue listmasternodeconf(const UniValue ¶ms, bool fHelp)
UniValue ping(const UniValue ¶ms, bool fHelp)
std::string JSONRPCExecBatch(const UniValue &vReq)
UniValue showtxprivatekeys(const UniValue ¶ms, bool fHelp)
UniValue erasefromwallet(const UniValue ¶ms, bool fHelp)
const std::string & get_str() const
void SetRPCWarmupFinished()
std::string help(std::string name) const
Note: This interface may still be subject to change.
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
UniValue getbalances(const UniValue ¶ms, bool fHelp)
UniValue readmasteraccount(const UniValue ¶ms, bool fHelp)
UniValue reconsiderblock(const UniValue ¶ms, bool fHelp)
UniValue getbalance(const UniValue ¶ms, bool fHelp)
UniValue getmasternodescores(const UniValue ¶ms, bool fHelp)
const UniValue & get_obj() const
UniValue gettxcount(const UniValue ¶ms, bool fHelp)
UniValue execute(const std::string &method, const UniValue ¶ms) const
Execute a method.
bool IsHex(const std::string &str)
UniValue listbanned(const UniValue ¶ms, bool fHelp)
UniValue walletpassphrasechange(const UniValue ¶ms, bool fHelp)
UniValue clearbanned(const UniValue ¶ms, bool fHelp)
UniValue getblockchaininfo(const UniValue ¶ms, bool fHelp)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValue::VType > &typesExpected, bool fAllowNull)
Check for expected keys/value types in an Object.
UniValue addnode(const UniValue ¶ms, bool fHelp)
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set factory function for timers, but only if unset.
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
UniValue decoderawtransaction(const UniValue ¶ms, bool fHelp)
UniValue revealmnemonicphrase(const UniValue ¶ms, bool fHelp)
UniValue revealspendprivatekey(const UniValue ¶ms, bool fHelp)
void OnStopped(boost::function< void()> slot)
UniValue resyncfrom(const UniValue ¶ms, bool fHelp)
void RPCRunLater(const std::string &name, boost::function< void(void)> func, int64_t nSeconds)
Run func nSeconds from now.
UniValue relaymasternodebroadcast(const UniValue ¶ms, bool fHelp)
UniValue reservebalance(const UniValue ¶ms, bool fHelp)
#define PAIRTYPE(t1, t2)
This is needed because the foreach macro can't get over the comma in pair<t1, t2>
UniValue JSONRPCError(int code, const std::string &message)
int64_t CAmount
Amount in PRCY (Can be negative)
std::vector< std::string > listCommands() const
Returns a list of registered commands.
UniValue waitfornewblock(const UniValue ¶ms, bool fHelp)
UniValue waitforblockheight(const UniValue ¶ms, bool fHelp)
@ RPC_IN_WARMUP
Transaction already in chain.
UniValue setdecoyconfirmation(const UniValue ¶ms, bool fHelp)
UniValue validatestealthaddress(const UniValue ¶ms, bool fHelp)
UniValue autocombinedust(const UniValue ¶ms, bool fHelp)
UniValue logging(const UniValue ¶ms, bool fHelp)
const char * uvTypeName(UniValue::VType t)
std::string HelpExampleRpc(std::string methodname, std::string args)
UniValue generatepoa(const UniValue ¶ms, bool fHelp)
UniValue getcurrentseesawreward(const UniValue ¶ms, bool fHelp)
256-bit unsigned big integer.
UniValue importkeys(const UniValue ¶ms, bool fHelp)
virtual RPCTimerBase * NewTimer(boost::function< void(void)> &func, int64_t millis)=0
Factory function for timers.
void SetHex(const char *psz)
UniValue erasewallettransactions(const UniValue ¶ms, bool fHelp)
CAmount AmountFromValue(const UniValue &value)
UniValue listmasternodes(const UniValue ¶ms, bool fHelp)
void parse(const UniValue &valRequest)
#define LogPrint(category,...)
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
UniValue setminingnbits(const UniValue ¶ms, bool fHelp)
UniValue unlockwallet(const UniValue ¶ms, bool fHelp)
UniValue getblockhash(const UniValue ¶ms, bool fHelp)
UniValue getlastpoablockhash(const UniValue ¶ms, bool fHelp)
virtual const char * Name()=0
Implementation name.
UniValue getinfo(const UniValue ¶ms, bool fHelp)
UniValue getgenerate(const UniValue ¶ms, bool fHelp)
PRCY RPC command dispatcher.
std::string HelpExampleCli(std::string methodname, std::string args)
void OnStarted(boost::function< void()> slot)
UniValue getnettotals(const UniValue ¶ms, bool fHelp)
UniValue getaddednodeinfo(const UniValue ¶ms, bool fHelp)
UniValue getwalletinfo(const UniValue ¶ms, bool fHelp)
UniValue getlastpoablockheight(const UniValue ¶ms, bool fHelp)
UniValue verifychain(const UniValue ¶ms, bool fHelp)
UniValue getseesawrewardratio(const UniValue ¶ms, bool fHelp)
UniValue showstealthaddress(const UniValue ¶ms, bool fHelp)
UniValue help(const UniValue ¶ms, bool fHelp)
UniValue setmaxreorgdepth(const UniValue ¶ms, bool fHelp)
UniValue gethashespersec(const UniValue ¶ms, bool fHelp)
UniValue listunspent(const UniValue ¶ms, bool fHelp)
bool push_back(const UniValue &val)
UniValue stop(const UniValue ¶ms, bool fHelp)
UniValue(* rpcfn_type)(const UniValue ¶ms, bool fHelp)
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
std::map< std::string, const CRPCCommand * > mapCommands
UniValue listtransactionsbypaymentid(const UniValue ¶ms, bool fHelp)
void OnPreCommand(boost::function< void(const CRPCCommand &)> slot)
UniValue getsupply(const UniValue ¶ms, bool fHelp)
const UniValue & find_value(const UniValue &obj, const std::string &name)
@ RPC_TYPE_ERROR
Server is in safe mode, and command is not allowed in safe mode.
UniValue getconnectioncount(const UniValue ¶ms, bool fHelp)
bool RPCIsInWarmup(std::string *outStatus)
UniValue gettxoutsetinfo(const UniValue ¶ms, bool fHelp)
UniValue mnsync(const UniValue ¶ms, bool fHelp)
UniValue waitforblock(const UniValue ¶ms, bool fHelp)
const UniValue & get_array() const
UniValue getunspentcount(const UniValue ¶ms, bool fHelp)
UniValue generate(const UniValue ¶ms, bool fHelp)
const CRPCCommand * operator[](const std::string &name) const
UniValue getstakingstatus(const UniValue ¶ms, bool fHelp)
UniValue getdecoyconfirmation(const UniValue ¶ms, bool fHelp)
UniValue getrawtransactionbyblockheight(const UniValue ¶ms, bool fHelp)
UniValue getblockheader(const UniValue ¶ms, bool fHelp)
void OnPostCommand(boost::function< void(const CRPCCommand &)> slot)
UniValue backupwallet(const UniValue ¶ms, bool fHelp)
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
UniValue getinvalid(const UniValue ¶ms, bool fHelp)
UniValue getdifficulty(const UniValue ¶ms, bool fHelp)
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set factory function for timers.
UniValue listsinceblock(const UniValue ¶ms, bool fHelp)
UniValue getfeeinfo(const UniValue ¶ms, bool fHelp)
UniValue decodescript(const UniValue ¶ms, bool fHelp)
uint256 ParseHashO(const UniValue &o, std::string strKey)
UniValue submitblock(const UniValue ¶ms, bool fHelp)
UniValue setgenerate(const UniValue ¶ms, bool fHelp)