If you set the flag, I don't see any reason to prepend 'sent' to the transaction ID; better to just return the transaction ID on successful send.
Patches:
Code:
diff --git a/rpc.cpp b/rpc.cpp
index 920fe90..8714b7e 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -342,10 +342,11 @@ Value getaddressesbylabel(const Array& params, bool fHelp)
Value sendtoaddress(const Array& params, bool fHelp)
{
- if (fHelp || params.size() < 2 || params.size() > 4)
+ if (fHelp || params.size() < 2 || params.size() > 5)
throw runtime_error(
- "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n"
- "<amount> is a real and is rounded to the nearest 0.01");
+ "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] [return-tx-id-flag]\n"
+ "<amount> is a real and is rounded to the nearest 0.01\n"
+ "returns string 'sent' if return-tx-id-flag is false (default), otherwise returns transaction id.");
string strAddress = params[0].get_str();
@@ -361,9 +362,15 @@ Value sendtoaddress(const Array& params, bool fHelp)
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
wtx.mapValue["to"] = params[3].get_str();
+ bool fReturnTxID = false;
+ if (params.size() > 4)
+ fReturnTxID = params[4].get_bool();
+
string strError = SendMoneyToBitcoinAddress(strAddress, nAmount, wtx);
if (strError != "")
throw runtime_error(strError);
+ if (fReturnTxID)
+ return wtx.GetHash().ToString();
return "sent";
}
@@ -1103,6 +1110,7 @@ int CommandLineRPC(int argc, char *argv[])
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 == "sendtoaddress" && n > 4) ConvertTo<bool>(params[4]);
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
index 920fe90..8714b7e 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -342,10 +342,11 @@ Value getaddressesbylabel(const Array& params, bool fHelp)
Value sendtoaddress(const Array& params, bool fHelp)
{
- if (fHelp || params.size() < 2 || params.size() > 4)
+ if (fHelp || params.size() < 2 || params.size() > 5)
throw runtime_error(
- "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n"
- "<amount> is a real and is rounded to the nearest 0.01");
+ "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] [return-tx-id-flag]\n"
+ "<amount> is a real and is rounded to the nearest 0.01\n"
+ "returns string 'sent' if return-tx-id-flag is false (default), otherwise returns transaction id.");
string strAddress = params[0].get_str();
@@ -361,9 +362,15 @@ Value sendtoaddress(const Array& params, bool fHelp)
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
wtx.mapValue["to"] = params[3].get_str();
+ bool fReturnTxID = false;
+ if (params.size() > 4)
+ fReturnTxID = params[4].get_bool();
+
string strError = SendMoneyToBitcoinAddress(strAddress, nAmount, wtx);
if (strError != "")
throw runtime_error(strError);
+ if (fReturnTxID)
+ return wtx.GetHash().ToString();
return "sent";
}
@@ -1103,6 +1110,7 @@ int CommandLineRPC(int argc, char *argv[])
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 == "sendtoaddress" && n > 4) ConvertTo<bool>(params[4]);
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