|
|
@ -56,10 +56,14 @@ void PrintConsole(const char* format, ...) |
|
|
|
|
|
|
|
|
|
|
|
Value help(const Array& params, bool fHelp) |
|
|
|
Value help(const Array& params, bool fHelp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fHelp || params.size() != 0) |
|
|
|
if (fHelp || params.size() > 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"help\n" |
|
|
|
"help [command]\n" |
|
|
|
"List commands."); |
|
|
|
"List commands, or get help for a command."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string strCommand; |
|
|
|
|
|
|
|
if (params.size() > 0) |
|
|
|
|
|
|
|
strCommand = params[0].get_str(); |
|
|
|
|
|
|
|
|
|
|
|
string strRet; |
|
|
|
string strRet; |
|
|
|
set<rpcfn_type> setDone; |
|
|
|
set<rpcfn_type> setDone; |
|
|
@ -70,6 +74,8 @@ Value help(const Array& params, bool fHelp) |
|
|
|
if (strMethod == "getamountreceived" || |
|
|
|
if (strMethod == "getamountreceived" || |
|
|
|
strMethod == "getallreceived") |
|
|
|
strMethod == "getallreceived") |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
if (strCommand != "" && strMethod != strCommand) |
|
|
|
|
|
|
|
continue; |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
Array params; |
|
|
|
Array params; |
|
|
@ -81,11 +87,14 @@ Value help(const Array& params, bool fHelp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Help text is returned in an exception
|
|
|
|
// Help text is returned in an exception
|
|
|
|
string strHelp = string(e.what()); |
|
|
|
string strHelp = string(e.what()); |
|
|
|
if (strHelp.find('\n') != -1) |
|
|
|
if (strCommand == "") |
|
|
|
strHelp = strHelp.substr(0, strHelp.find('\n')); |
|
|
|
if (strHelp.find('\n') != -1) |
|
|
|
|
|
|
|
strHelp = strHelp.substr(0, strHelp.find('\n')); |
|
|
|
strRet += strHelp + "\n"; |
|
|
|
strRet += strHelp + "\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (strRet == "") |
|
|
|
|
|
|
|
strRet = strprintf("help: unknown command: %s\n", strCommand.c_str()); |
|
|
|
strRet = strRet.substr(0,strRet.size()-1); |
|
|
|
strRet = strRet.substr(0,strRet.size()-1); |
|
|
|
return strRet; |
|
|
|
return strRet; |
|
|
|
} |
|
|
|
} |
|
|
@ -1059,57 +1068,37 @@ int CommandLineRPC(int argc, char *argv[]) |
|
|
|
argv++; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check that the method exists
|
|
|
|
// Method
|
|
|
|
if (argc < 2) |
|
|
|
if (argc < 2) |
|
|
|
throw runtime_error("too few parameters"); |
|
|
|
throw runtime_error("too few parameters"); |
|
|
|
string strMethod = argv[1]; |
|
|
|
string strMethod = argv[1]; |
|
|
|
if (!mapCallTable.count(strMethod)) |
|
|
|
|
|
|
|
throw runtime_error(strprintf("unknown command: %s", strMethod.c_str())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value result; |
|
|
|
// Parameters default to strings
|
|
|
|
if (argc == 3 && strcmp(argv[2], "-?") == 0) |
|
|
|
Array params; |
|
|
|
{ |
|
|
|
for (int i = 2; i < argc; i++) |
|
|
|
// Call help locally, help text is returned in an exception
|
|
|
|
params.push_back(argv[i]); |
|
|
|
try |
|
|
|
int n = params.size(); |
|
|
|
{ |
|
|
|
|
|
|
|
map<string, rpcfn_type>::iterator mi = mapCallTable.find(strMethod); |
|
|
|
//
|
|
|
|
Array params; |
|
|
|
// Special case non-string parameter types
|
|
|
|
(*(*mi).second)(params, true); |
|
|
|
//
|
|
|
|
} |
|
|
|
if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]); |
|
|
|
catch (std::exception& e) |
|
|
|
if (strMethod == "setgenerate" && n > 1) ConvertTo<boost::int64_t>(params[1]); |
|
|
|
{ |
|
|
|
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]); |
|
|
|
result = e.what(); |
|
|
|
if (strMethod == "listtransactions" && n > 0) ConvertTo<boost::int64_t>(params[0]); |
|
|
|
} |
|
|
|
if (strMethod == "listtransactions" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
} |
|
|
|
if (strMethod == "getamountreceived" && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated
|
|
|
|
else |
|
|
|
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]); |
|
|
|
{ |
|
|
|
if (strMethod == "getreceivedbylabel" && n > 1) ConvertTo<boost::int64_t>(params[1]); |
|
|
|
// Parameters default to strings
|
|
|
|
if (strMethod == "getallreceived" && n > 0) ConvertTo<boost::int64_t>(params[0]); // deprecated
|
|
|
|
Array params; |
|
|
|
if (strMethod == "getallreceived" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
for (int i = 2; i < argc; i++) |
|
|
|
if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]); |
|
|
|
params.push_back(argv[i]); |
|
|
|
if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
int n = params.size(); |
|
|
|
if (strMethod == "listreceivedbylabel" && n > 0) ConvertTo<boost::int64_t>(params[0]); |
|
|
|
|
|
|
|
if (strMethod == "listreceivedbylabel" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
//
|
|
|
|
|
|
|
|
// Special case non-string parameter types
|
|
|
|
// Execute
|
|
|
|
//
|
|
|
|
Value result = CallRPC(strMethod, params); |
|
|
|
if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]); |
|
|
|
|
|
|
|
if (strMethod == "setgenerate" && n > 1) ConvertTo<boost::int64_t>(params[1]); |
|
|
|
|
|
|
|
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]); |
|
|
|
|
|
|
|
if (strMethod == "listtransactions" && n > 0) ConvertTo<boost::int64_t>(params[0]); |
|
|
|
|
|
|
|
if (strMethod == "listtransactions" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
|
|
|
|
if (strMethod == "getamountreceived" && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated
|
|
|
|
|
|
|
|
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]); |
|
|
|
|
|
|
|
if (strMethod == "getreceivedbylabel" && n > 1) ConvertTo<boost::int64_t>(params[1]); |
|
|
|
|
|
|
|
if (strMethod == "getallreceived" && n > 0) ConvertTo<boost::int64_t>(params[0]); // deprecated
|
|
|
|
|
|
|
|
if (strMethod == "getallreceived" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
|
|
|
|
if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]); |
|
|
|
|
|
|
|
if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
|
|
|
|
if (strMethod == "listreceivedbylabel" && n > 0) ConvertTo<boost::int64_t>(params[0]); |
|
|
|
|
|
|
|
if (strMethod == "listreceivedbylabel" && n > 1) ConvertTo<bool>(params[1]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
|
|
|
|
result = CallRPC(strMethod, params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Print result
|
|
|
|
// Print result
|
|
|
|
string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true)); |
|
|
|
string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true)); |
|
|
|