aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-10 19:21:17 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-10 19:21:17 +0000
commit342e1b73385cac5a5b2fc7316d82a2b55b3a85d4 (patch)
tree779fde91134f080040a38214ce53fc75c01f1360
parent94cfec07fd302c9ff9b6a80c47418d4fe56596ae (diff)
downloadbitcoin-342e1b73385cac5a5b2fc7316d82a2b55b3a85d4.tar.xz
json-spirit print reals with 8 decimal places,
bitcoind help <command> instead of bitcoind <command> -? git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@126 1a98c847-1fd6-4fd8-948a-caf3550aa51b
-rw-r--r--init.cpp4
-rw-r--r--json/json_spirit_value.h2
-rw-r--r--json/json_spirit_writer_template.h5
-rw-r--r--rpc.cpp93
4 files changed, 48 insertions, 56 deletions
diff --git a/init.cpp b/init.cpp
index b8df26c828..0eacebc305 100644
--- a/init.cpp
+++ b/init.cpp
@@ -147,8 +147,8 @@ bool AppInit2(int argc, char* argv[])
_("Usage:") + "\t\t\t\t\t\t\t\t\t\t\n" +
" bitcoin [options] \t " + "\n" +
" bitcoin [options] <command> [params]\t " + _("Send command to -server or bitcoind\n") +
- " bitcoin [options] <command> -? \t\t " + _("Get help for a command\n") +
- " bitcoin help \t\t\t " + _("List commands\n") +
+ " bitcoin [options] help \t\t " + _("List commands\n") +
+ " bitcoin [options] help <command> \t\t " + _("Get help for a command\n") +
_("Options:\n") +
" -conf=<file> \t " + _("Specify configuration file (default: bitcoin.conf)\n") +
" -gen \t " + _("Generate coins\n") +
diff --git a/json/json_spirit_value.h b/json/json_spirit_value.h
index e9bcd36b80..05747faac3 100644
--- a/json/json_spirit_value.h
+++ b/json/json_spirit_value.h
@@ -342,7 +342,7 @@ namespace json_spirit
{
std::ostringstream os;
- /// satoshi: tell the types by name instead of by number
+ ///// Bitcoin: Tell the types by name instead of by number
os << "value is type " << Value_type_name[type()] << ", expected " << Value_type_name[vtype];
throw std::runtime_error( os.str() );
diff --git a/json/json_spirit_writer_template.h b/json/json_spirit_writer_template.h
index c993756555..90d2ae69d2 100644
--- a/json/json_spirit_writer_template.h
+++ b/json/json_spirit_writer_template.h
@@ -124,8 +124,11 @@ namespace json_spirit
case str_type: output( value.get_str() ); break;
case bool_type: output( value.get_bool() ); break;
case int_type: output_int( value ); break;
- case real_type: os_ << std::showpoint << std::setprecision( 16 )
+
+ /// Bitcoin: Added std::fixed and changed precision from 16 to 8
+ case real_type: os_ << std::showpoint << std::fixed << std::setprecision(8)
<< value.get_real(); break;
+
case null_type: os_ << "null"; break;
default: assert( false );
}
diff --git a/rpc.cpp b/rpc.cpp
index f63e6b8355..d058981b35 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -56,10 +56,14 @@ void PrintConsole(const char* format, ...)
Value help(const Array& params, bool fHelp)
{
- if (fHelp || params.size() != 0)
+ if (fHelp || params.size() > 1)
throw runtime_error(
- "help\n"
- "List commands.");
+ "help [command]\n"
+ "List commands, or get help for a command.");
+
+ string strCommand;
+ if (params.size() > 0)
+ strCommand = params[0].get_str();
string strRet;
set<rpcfn_type> setDone;
@@ -70,6 +74,8 @@ Value help(const Array& params, bool fHelp)
if (strMethod == "getamountreceived" ||
strMethod == "getallreceived")
continue;
+ if (strCommand != "" && strMethod != strCommand)
+ continue;
try
{
Array params;
@@ -81,11 +87,14 @@ Value help(const Array& params, bool fHelp)
{
// Help text is returned in an exception
string strHelp = string(e.what());
- if (strHelp.find('\n') != -1)
- strHelp = strHelp.substr(0, strHelp.find('\n'));
+ if (strCommand == "")
+ if (strHelp.find('\n') != -1)
+ strHelp = strHelp.substr(0, strHelp.find('\n'));
strRet += strHelp + "\n";
}
}
+ if (strRet == "")
+ strRet = strprintf("help: unknown command: %s\n", strCommand.c_str());
strRet = strRet.substr(0,strRet.size()-1);
return strRet;
}
@@ -1059,57 +1068,37 @@ int CommandLineRPC(int argc, char *argv[])
argv++;
}
- // Check that the method exists
+ // Method
if (argc < 2)
throw runtime_error("too few parameters");
string strMethod = argv[1];
- if (!mapCallTable.count(strMethod))
- throw runtime_error(strprintf("unknown command: %s", strMethod.c_str()));
- Value result;
- if (argc == 3 && strcmp(argv[2], "-?") == 0)
- {
- // Call help locally, help text is returned in an exception
- try
- {
- map<string, rpcfn_type>::iterator mi = mapCallTable.find(strMethod);
- Array params;
- (*(*mi).second)(params, true);
- }
- catch (std::exception& e)
- {
- result = e.what();
- }
- }
- else
- {
- // Parameters default to strings
- Array params;
- for (int i = 2; i < argc; i++)
- params.push_back(argv[i]);
- int n = params.size();
-
- //
- // Special case non-string parameter types
- //
- 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);
- }
+ // Parameters default to strings
+ Array params;
+ for (int i = 2; i < argc; i++)
+ params.push_back(argv[i]);
+ int n = params.size();
+
+ //
+ // Special case non-string parameter types
+ //
+ 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
+ Value result = CallRPC(strMethod, params);
// Print result
string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true));