19 #include <boost/bind.hpp> 20 #include <boost/filesystem.hpp> 21 #include <boost/foreach.hpp> 22 #include <boost/iostreams/concepts.hpp> 23 #include <boost/iostreams/stream.hpp> 24 #include <boost/shared_ptr.hpp> 25 #include <boost/signals2/signal.hpp> 26 #include <boost/thread.hpp> 27 #include <boost/algorithm/string/case_conv.hpp> 40 static std::map<std::string, boost::shared_ptr<RPCTimerBase> >
deadlineTimers;
46 boost::signals2::signal<void (const CRPCCommand&)>
PreCommand;
47 boost::signals2::signal<void (const CRPCCommand&)>
PostCommand;
71 const list<UniValue::VType>& typesExpected,
77 if (params.
size() <= i)
81 if (!((v.
type() == t) || (fAllowNull && (v.
isNull()))))
92 const map<string, UniValue::VType>& typesExpected,
98 if (!fAllowNull && v.
isNull())
101 if (!((v.
type() == t.second) || (fAllowNull && (v.
isNull()))))
103 string err =
strprintf(
"Expected type %s for %s, got %s",
124 bool sign = amount < 0;
125 int64_t n_abs = (sign ? -amount : amount);
126 int64_t quotient = n_abs /
COIN;
127 int64_t remainder = n_abs %
COIN;
129 strprintf(
"%s%d.%08d", sign ?
"-" :
"", quotient, remainder));
169 set<rpcfn_type> setDone;
170 vector<pair<string, const CRPCCommand*> > vCommands;
172 for (map<string, const CRPCCommand*>::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi)
173 vCommands.push_back(make_pair(mi->second->category + mi->first, mi->second));
174 sort(vCommands.begin(), vCommands.end());
179 string strMethod = pcmd->
name;
181 if (strMethod.find(
"label") != string::npos)
183 if ((strCommand !=
"" || pcmd->
category ==
"hidden") && strMethod != strCommand)
189 if (setDone.insert(pfn).second)
190 (*pfn)(params,
true);
192 catch (
const std::exception& e)
195 string strHelp = string(e.what());
196 if (strCommand ==
"")
198 if (strHelp.find(
'\n') != string::npos)
199 strHelp = strHelp.substr(0, strHelp.find(
'\n'));
203 if (!category.empty())
206 string firstLetter = category.substr(0,1);
207 boost::to_upper(firstLetter);
208 strRet +=
"== " + firstLetter + category.substr(1) +
" ==\n";
211 strRet += strHelp +
"\n";
215 strRet =
strprintf(
"help: unknown command: %s\n", strCommand);
216 strRet = strRet.substr(0,strRet.size()-1);
222 if (fHelp || params.
size() > 1)
224 "help ( \"command\" )\n" 225 "\nList all commands, or get help for a specified command.\n" 227 "1. \"command\" (string, optional) The command to get help on\n" 229 "\"text\" (string) The help text\n" 233 if (params.
size() > 0)
234 strCommand = params[0].get_str();
243 if (fHelp || params.
size() > 1)
246 "\nStop Dash Core server.");
250 return "Dash Core server stopping";
260 {
"control",
"getinfo", &
getinfo,
true },
261 {
"control",
"debug", &
debug,
true },
262 {
"control",
"help", &
help,
true },
263 {
"control",
"stop", &
stop,
true },
267 {
"network",
"addnode", &
addnode,
true },
273 {
"network",
"ping", &
ping,
true },
274 {
"network",
"setban", &
setban,
true },
275 {
"network",
"listbanned", &
listbanned,
true },
283 {
"blockchain",
"getblock", &
getblock,
true },
292 {
"blockchain",
"gettxout", &
gettxout,
true },
296 {
"blockchain",
"verifychain", &
verifychain,
true },
307 {
"generating",
"getgenerate", &
getgenerate,
true },
308 {
"generating",
"setgenerate", &
setgenerate,
true },
309 {
"generating",
"generate", &
generate,
true },
314 {
"rawtransactions",
"decodescript", &
decodescript,
true },
350 {
"dash",
"gobject", &
gobject,
true },
353 {
"dash",
"voteraw", &
voteraw,
true },
354 {
"dash",
"mnsync", &
mnsync,
true },
355 {
"dash",
"spork", &
spork,
true },
362 {
"wallet",
"keepass", &
keepass,
true },
367 {
"wallet",
"dumphdinfo", &
dumphdinfo,
true },
368 {
"wallet",
"dumpwallet", &
dumpwallet,
true },
371 {
"wallet",
"getaccount", &
getaccount,
true },
373 {
"wallet",
"getbalance", &
getbalance,
false },
397 {
"wallet",
"move", &
movecmd,
false },
398 {
"wallet",
"sendfrom", &
sendfrom,
false },
399 {
"wallet",
"sendmany", &
sendmany,
false },
401 {
"wallet",
"setaccount", &
setaccount,
true },
402 {
"wallet",
"settxfee", &
settxfee,
true },
404 {
"wallet",
"walletlock", &
walletlock,
true },
407 #endif // ENABLE_WALLET 418 mapCommands[pcmd->
name] = pcmd;
424 map<string, const CRPCCommand*>::const_iterator it = mapCommands.find(
name);
425 if (it == mapCommands.end())
440 LogPrint(
"rpc",
"Interrupting RPC\n");
492 if (!valMethod.
isStr())
494 strMethod = valMethod.
get_str();
495 if (strMethod !=
"getblocktemplate")
502 else if (valParams.
isNull())
523 catch (
const std::exception& e)
535 for (
unsigned int reqIdx = 0; reqIdx < vReq.
size(); reqIdx++)
538 return ret.
write() +
"\n";
560 return pcmd->
actor(params,
false);
562 catch (
const std::exception& e)
572 std::vector<std::string> commandList;
573 typedef std::map<std::string, const CRPCCommand*> commandMap;
575 std::transform( mapCommands.begin(), mapCommands.end(),
576 std::back_inserter(commandList),
577 boost::bind(&commandMap::value_type::first,_1) );
581 std::string
HelpExampleCli(
const std::string& methodname,
const std::string& args)
583 return "> dash-cli " + methodname +
" " + args +
"\n";
586 std::string
HelpExampleRpc(
const std::string& methodname,
const std::string& args)
588 return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", " 589 "\"method\": \"" + methodname +
"\", \"params\": [" + args +
"] }' -H 'content-type: text/plain;' http://127.0.0.1:9998/\n";
604 void RPCRunLater(
const std::string&
name, boost::function<
void(
void)> func, int64_t nSeconds)
610 LogPrint(
"rpc",
"queue run of timer %s in %i seconds (using %s)\n",
name, nSeconds, timerInterface->
Name());
UniValue importprivkey(const UniValue ¶ms, bool fHelp)
UniValue abandontransaction(const UniValue ¶ms, bool fHelp)
UniValue getrawchangeaddress(const UniValue ¶ms, bool fHelp)
UniValue addmultisigaddress(const UniValue ¶ms, bool fHelp)
UniValue gettxoutproof(const UniValue ¶ms, bool fHelp)
UniValue prioritisetransaction(const UniValue ¶ms, bool fHelp)
vector< unsigned char > ParseHexV(const UniValue &v, string strName)
UniValue getnetworkhashps(const UniValue ¶ms, bool fHelp)
UniValue listreceivedbyaccount(const UniValue ¶ms, bool fHelp)
UniValue spork(const UniValue ¶ms, bool fHelp)
UniValue resendwallettransactions(const UniValue ¶ms, bool fHelp)
UniValue walletpassphrase(const UniValue ¶ms, bool fHelp)
const CRPCCommand * operator[](const std::string &name) const
UniValue getaddressbalance(const UniValue ¶ms, bool fHelp)
UniValue dumpwallet(const UniValue ¶ms, bool fHelp)
UniValue getaddressesbyaccount(const UniValue ¶ms, bool fHelp)
boost::signals2::signal< void()> Started
UniValue getunconfirmedbalance(const UniValue ¶ms, bool fHelp)
UniValue getaddresstxids(const UniValue ¶ms, bool fHelp)
UniValue getgovernanceinfo(const UniValue ¶ms, bool fHelp)
UniValue importelectrumwallet(const UniValue ¶ms, bool fHelp)
UniValue importpubkey(const UniValue ¶ms, bool fHelp)
UniValue getblockheader(const UniValue ¶ms, bool fHelp)
UniValue keypoolrefill(const UniValue ¶ms, bool fHelp)
UniValue privatesend(const UniValue ¶ms, bool fHelp)
void SetRPCWarmupStatus(const std::string &newStatus)
virtual const char * Name()=0
UniValue getdifficulty(const UniValue ¶ms, bool fHelp)
void OnPreCommand(boost::function< void(const CRPCCommand &)> slot)
std::string JSONRPCExecBatch(const UniValue &vReq)
static const CAmount COIN
UniValue getblocktemplate(const UniValue ¶ms, bool fHelp)
UniValue getaddressdeltas(const UniValue ¶ms, bool fHelp)
UniValue validateaddress(const UniValue ¶ms, bool fHelp)
UniValue gobject(const UniValue ¶ms, bool fHelp)
bool MoneyRange(const CAmount &nValue)
uint256 ParseHashO(const UniValue &o, string strKey)
UniValue settxfee(const UniValue ¶ms, bool fHelp)
UniValue reconsiderblock(const UniValue ¶ms, bool fHelp)
const std::string & getValStr() const
UniValue getreceivedbyaccount(const UniValue ¶ms, bool fHelp)
virtual RPCTimerBase * NewTimer(boost::function< void(void)> &func, int64_t millis)=0
UniValue dumpprivkey(const UniValue ¶ms, bool fHelp)
UniValue getbalance(const UniValue ¶ms, bool fHelp)
UniValue clearbanned(const UniValue ¶ms, bool fHelp)
UniValue getspentinfo(const UniValue ¶ms, bool fHelp)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
UniValue getrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue listaccounts(const UniValue ¶ms, bool fHelp)
UniValue getblockheaders(const UniValue ¶ms, bool fHelp)
UniValue getreceivedbyaddress(const UniValue ¶ms, bool fHelp)
UniValue getsuperblockbudget(const UniValue ¶ms, bool fHelp)
UniValue sentinelping(const UniValue ¶ms, bool fHelp)
bool IsHex(const string &str)
UniValue listtransactions(const UniValue ¶ms, bool fHelp)
UniValue estimatepriority(const UniValue ¶ms, bool fHelp)
UniValue getaccount(const UniValue ¶ms, bool fHelp)
UniValue gettxout(const UniValue ¶ms, bool fHelp)
UniValue sendmany(const UniValue ¶ms, bool fHelp)
boost::signals2::signal< void(const CRPCCommand &)> PostCommand
static const CRPCCommand vRPCCommands[]
UniValue getblock(const UniValue ¶ms, bool fHelp)
Transaction already in chain.
UniValue sendfrom(const UniValue ¶ms, bool fHelp)
UniValue backupwallet(const UniValue ¶ms, bool fHelp)
UniValue listunspent(const UniValue ¶ms, bool fHelp)
bool push_back(const UniValue &val)
UniValue signmessage(const UniValue ¶ms, bool fHelp)
UniValue getaccountaddress(const UniValue ¶ms, bool fHelp)
UniValue ValueFromAmount(const CAmount &amount)
UniValue sendtoaddress(const UniValue ¶ms, bool fHelp)
Ran out of memory during operation.
UniValue getblockhashes(const UniValue ¶ms, bool fHelp)
UniValue listbanned(const UniValue ¶ms, bool fHelp)
const UniValue & find_value(const UniValue &obj, const std::string &name)
UniValue getaddressutxos(const UniValue ¶ms, bool fHelp)
UniValue fundrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue submitblock(const UniValue ¶ms, bool fHelp)
void SetRPCWarmupFinished()
UniValue getaddednodeinfo(const UniValue ¶ms, bool fHelp)
UniValue disconnectnode(const UniValue ¶ms, bool fHelp)
UniValue verifychain(const UniValue ¶ms, bool fHelp)
boost::signals2::signal< void(const CRPCCommand &)> PreCommand
const char * uvTypeName(UniValue::VType t)
UniValue getnewaddress(const UniValue ¶ms, bool fHelp)
UniValue setban(const UniValue ¶ms, bool fHelp)
const UniValue & get_obj() const
UniValue setaccount(const UniValue ¶ms, bool fHelp)
UniValue getmempoolinfo(const UniValue ¶ms, bool fHelp)
void RPCRunLater(const std::string &name, boost::function< void(void)> func, int64_t nSeconds)
static int LogPrint(const char *category, const char *format)
UniValue getblockhash(const UniValue ¶ms, bool fHelp)
static std::vector< RPCTimerInterface * > timerInterfaces
UniValue keepass(const UniValue ¶ms, bool fHelp)
UniValue getblockcount(const UniValue ¶ms, bool fHelp)
void OnStarted(boost::function< void()> slot)
UniValue masternode(const UniValue ¶ms, bool fHelp)
UniValue getwalletinfo(const UniValue ¶ms, bool fHelp)
UniValue listlockunspent(const UniValue ¶ms, bool fHelp)
static UniValue JSONRPCExecOne(const UniValue &req)
UniValue setgenerate(const UniValue ¶ms, bool fHelp)
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
UniValue signrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue createrawtransaction(const UniValue ¶ms, bool fHelp)
Server is in safe mode, and command is not allowed in safe mode.
UniValue listsinceblock(const UniValue ¶ms, bool fHelp)
UniValue getconnectioncount(const UniValue ¶ms, bool fHelp)
UniValue decoderawtransaction(const UniValue ¶ms, bool fHelp)
vector< unsigned char > ParseHex(const char *psz)
UniValue createmultisig(const UniValue ¶ms, bool fHelp)
UniValue encryptwallet(const UniValue ¶ms, bool fHelp)
General application defined errors.
UniValue getinfo(const UniValue ¶ms, bool fHelp)
UniValue walletpassphrasechange(const UniValue ¶ms, bool fHelp)
UniValue listaddressgroupings(const UniValue ¶ms, bool fHelp)
UniValue importaddress(const UniValue ¶ms, bool fHelp)
UniValue lockunspent(const UniValue ¶ms, bool fHelp)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
CAmount AmountFromValue(const UniValue &value)
UniValue voteraw(const UniValue ¶ms, bool fHelp)
UniValue getnettotals(const UniValue ¶ms, bool fHelp)
uint256 ParseHashV(const UniValue &v, string strName)
static struct CRPCSignals g_rpcSignals
UniValue dumphdinfo(const UniValue ¶ms, bool fHelp)
UniValue masternodebroadcast(const UniValue ¶ms, bool fHelp)
void RPCTypeCheckObj(const UniValue &o, const map< string, UniValue::VType > &typesExpected, bool fAllowNull)
UniValue(* rpcfn_type)(const UniValue ¶ms, bool fHelp)
UniValue instantsendtoaddress(const UniValue ¶ms, bool fHelp)
UniValue importwallet(const UniValue ¶ms, bool fHelp)
UniValue generate(const UniValue ¶ms, bool fHelp)
UniValue masternodelist(const UniValue ¶ms, bool fHelp)
UniValue sendrawtransaction(const UniValue ¶ms, bool fHelp)
void RPCTypeCheck(const UniValue ¶ms, const list< UniValue::VType > &typesExpected, bool fAllowNull)
void RPCRegisterTimerInterface(RPCTimerInterface *iface)
UniValue getaddressmempool(const UniValue ¶ms, bool fHelp)
UniValue gettxoutsetinfo(const UniValue ¶ms, bool fHelp)
UniValue getrawmempool(const UniValue ¶ms, bool fHelp)
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
UniValue movecmd(const UniValue ¶ms, bool fHelp)
UniValue setnetworkactive(const UniValue ¶ms, bool fHelp)
UniValue ping(const UniValue ¶ms, bool fHelp)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)
UniValue invalidateblock(const UniValue ¶ms, bool fHelp)
bool RPCIsInWarmup(std::string *outStatus)
const UniValue NullUniValue
UniValue getpeerinfo(const UniValue ¶ms, bool fHelp)
UniValue getnetworkinfo(const UniValue ¶ms, bool fHelp)
UniValue mnsync(const UniValue ¶ms, bool fHelp)
void parse(const UniValue &valRequest)
Standard JSON-RPC 2.0 errors.
std::string help(const std::string &name) const
UniValue verifytxoutproof(const UniValue ¶ms, bool fHelp)
vector< unsigned char > ParseHexO(const UniValue &o, string strKey)
UniValue verifymessage(const UniValue ¶ms, bool fHelp)
UniValue listreceivedbyaddress(const UniValue ¶ms, bool fHelp)
boost::signals2::signal< void()> Stopped
UniValue estimatesmartfee(const UniValue ¶ms, bool fHelp)
UniValue stop(const UniValue ¶ms, bool fHelp)
static std::string rpcWarmupStatus("RPC server started")
void OnStopped(boost::function< void()> slot)
UniValue setmocktime(const UniValue ¶ms, bool fHelp)
UniValue addnode(const UniValue ¶ms, bool fHelp)
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
UniValue getpoolinfo(const UniValue ¶ms, bool fHelp)
static CCriticalSection cs_rpcWarmup
UniValue estimatefee(const UniValue ¶ms, bool fHelp)
UniValue execute(const std::string &method, const UniValue ¶ms) const
UniValue debug(const UniValue ¶ms, bool fHelp)
void OnPostCommand(boost::function< void(const CRPCCommand &)> slot)
std::vector< std::string > listCommands() const
UniValue estimatesmartpriority(const UniValue ¶ms, bool fHelp)
UniValue decodescript(const UniValue ¶ms, bool fHelp)
UniValue JSONRPCError(int code, const string &message)
UniValue gettransaction(const UniValue ¶ms, bool fHelp)
static std::map< std::string, boost::shared_ptr< RPCTimerBase > > deadlineTimers
UniValue getchaintips(const UniValue ¶ms, bool fHelp)
UniValue getblockchaininfo(const UniValue ¶ms, bool fHelp)
string SanitizeString(const string &str, int rule)
const UniValue & get_array() const
std::string get_str() const
UniValue help(const UniValue ¶ms, bool fHelp)
UniValue getmininginfo(const UniValue ¶ms, bool fHelp)
UniValue walletlock(const UniValue ¶ms, bool fHelp)
void RPCUnregisterTimerInterface(RPCTimerInterface *iface)
UniValue getgenerate(const UniValue ¶ms, bool fHelp)