rpc changes:

- support ix and ds from cmd-line for sendtoaddress and sendmany
 - darksend cmd only controls process of mixing now (can't send funds anymore)

Closes #692
This commit is contained in:
UdjinM6 2016-02-01 20:22:00 +03:00 committed by Holger Schinzel
parent bbbbdd8100
commit eb76f789f5
3 changed files with 59 additions and 74 deletions

View File

@ -33,6 +33,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "getnetworkhashps", 0 }, { "getnetworkhashps", 0 },
{ "getnetworkhashps", 1 }, { "getnetworkhashps", 1 },
{ "sendtoaddress", 1 }, { "sendtoaddress", 1 },
{ "sendtoaddress", 4 },
{ "sendtoaddress", 5 },
{ "sendtoaddressix", 1 }, { "sendtoaddressix", 1 },
{ "settxfee", 0 }, { "settxfee", 0 },
{ "getreceivedbyaddress", 1 }, { "getreceivedbyaddress", 1 },
@ -62,6 +64,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listsinceblock", 2 }, { "listsinceblock", 2 },
{ "sendmany", 1 }, { "sendmany", 1 },
{ "sendmany", 2 }, { "sendmany", 2 },
{ "sendmany", 4 },
{ "sendmany", 5 },
{ "addmultisigaddress", 0 }, { "addmultisigaddress", 0 },
{ "addmultisigaddress", 1 }, { "addmultisigaddress", 1 },
{ "createmultisig", 0 }, { "createmultisig", 0 },

View File

@ -18,89 +18,50 @@
#include <fstream> #include <fstream>
using namespace json_spirit; using namespace json_spirit;
void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew, AvailableCoinsType coin_type=ALL_COINS)
{
// Check amount
if (nValue <= 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
if (nValue > pwalletMain->GetBalance())
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
string strError;
if (pwalletMain->IsLocked())
{
strError = "Error: Wallet locked, unable to create transaction!";
LogPrintf("SendMoney() : %s", strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
// Parse Dash address
CScript scriptPubKey = GetScriptForDestination(address);
// Create and send the transaction
CReserveKey reservekey(pwalletMain);
CAmount nFeeRequired;
if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError, NULL, coin_type))
{
if (nValue + nFeeRequired > pwalletMain->GetBalance())
strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
LogPrintf("SendMoney() : %s\n", strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
}
Value darksend(const Array& params, bool fHelp) Value darksend(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() == 0) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
"darksend <dashaddress> <amount>\n" "darksend \"command\"\n"
"dashaddress, reset, or auto (AutoDenominate)" "\nArguments:\n"
"<amount> is a real and will be rounded to the next 0.1" "1. \"command\" (string or set of strings, required) The command to execute\n"
"\nAvailable commands:\n"
" start - Start mixing\n"
" stop - Stop mixing\n"
" reset - Reset mixing\n"
" status - Print mixing status\n"
+ HelpRequiringPassphrase()); + HelpRequiringPassphrase());
if (pwalletMain->IsLocked()) if(params[0].get_str() == "start"){
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
if(params[0].get_str() == "auto"){
if(fMasterNode) if(fMasterNode)
return "DarkSend is not supported from masternodes"; return "Mixing is not supported from masternodes";
return "DoAutomaticDenominating " + (darkSendPool.DoAutomaticDenominating() ? "successful" : ("failed: " + darkSendPool.GetStatus())); fEnableDarksend = true;
bool result = darkSendPool.DoAutomaticDenominating();
// fEnableDarksend = result;
return "Mixing " + (result ? "started successfully" : ("start failed: " + darkSendPool.GetStatus() + ", will retry"));
}
if(params[0].get_str() == "stop"){
fEnableDarksend = false;
return "Mixing was stopped";
} }
if(params[0].get_str() == "reset"){ if(params[0].get_str() == "reset"){
darkSendPool.Reset(); darkSendPool.Reset();
return "successfully reset darksend"; return "Mixing was reset";
} }
if (params.size() != 2) if(params[0].get_str() == "status"){
throw runtime_error( return "Mixing status: " + darkSendPool.GetStatus();
"darksend <dashaddress> <amount>\n" }
"dashaddress, denominate, or auto (AutoDenominate)"
"<amount> is a real and will be rounded to the next 0.1"
+ HelpRequiringPassphrase());
CBitcoinAddress address(params[0].get_str()); return "Unknown command, please see \"help darksend\"";
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address");
// Amount
CAmount nAmount = AmountFromValue(params[1]);
// Wallet comments
CWalletTx wtx;
// string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx, ONLY_DENOMINATED);
SendMoney(address.Get(), nAmount, wtx, ONLY_DENOMINATED);
// if (strError != "")
// throw JSONRPCError(RPC_WALLET_ERROR, strError);
return wtx.GetHash().GetHex();
} }
Value getpoolinfo(const Array& params, bool fHelp) Value getpoolinfo(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)

View File

@ -314,7 +314,7 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
return ret; return ret;
} }
void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew, bool fUseIX=false) void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew, bool fUseIX=false, bool fUseDS=false)
{ {
// Check amount // Check amount
if (nValue <= 0) if (nValue <= 0)
@ -337,7 +337,8 @@ void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew,
// Create and send the transaction // Create and send the transaction
CReserveKey reservekey(pwalletMain); CReserveKey reservekey(pwalletMain);
CAmount nFeeRequired; CAmount nFeeRequired;
if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError, NULL, ALL_COINS, fUseIX, (CAmount)0)) if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired,
strError, NULL, fUseDS ? ONLY_DENOMINATED : ALL_COINS, fUseIX, (CAmount)0))
{ {
if (nValue + nFeeRequired > pwalletMain->GetBalance()) if (nValue + nFeeRequired > pwalletMain->GetBalance())
strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired)); strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
@ -350,9 +351,9 @@ void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew,
Value sendtoaddress(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() > 6)
throw runtime_error( throw runtime_error(
"sendtoaddress \"dashaddress\" amount ( \"comment\" \"comment-to\" )\n" "sendtoaddress \"dashaddress\" amount ( \"comment\" \"comment-to\" use_ix use_ds)\n"
"\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n" "\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n"
+ HelpRequiringPassphrase() + + HelpRequiringPassphrase() +
"\nArguments:\n" "\nArguments:\n"
@ -363,6 +364,8 @@ Value sendtoaddress(const Array& params, bool fHelp)
"4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n" "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n"
" to which you're sending the transaction. This is not part of the \n" " to which you're sending the transaction. This is not part of the \n"
" transaction, just kept in your wallet.\n" " transaction, just kept in your wallet.\n"
"5. \"use_ix\" (bool, optional) Send this transaction as IX (default: false)\n"
"6. \"use_ds\" (bool, optional) Use anonymized funds only (default: false)\n"
"\nResult:\n" "\nResult:\n"
"\"transactionid\" (string) The transaction id.\n" "\"transactionid\" (string) The transaction id.\n"
"\nExamples:\n" "\nExamples:\n"
@ -384,10 +387,16 @@ Value sendtoaddress(const Array& params, bool fHelp)
wtx.mapValue["comment"] = params[2].get_str(); wtx.mapValue["comment"] = params[2].get_str();
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
wtx.mapValue["to"] = params[3].get_str(); wtx.mapValue["to"] = params[3].get_str();
bool fUseIX = false;
bool fUseDS = false;
if (params.size() > 4 && params[4].type() != null_type)
fUseIX = params[4].get_bool();
if (params.size() > 5 && params[5].type() != null_type)
fUseDS = params[5].get_bool();
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
SendMoney(address.Get(), nAmount, wtx); SendMoney(address.Get(), nAmount, wtx, fUseIX, fUseDS);
return wtx.GetHash().GetHex(); return wtx.GetHash().GetHex();
} }
@ -435,6 +444,7 @@ Value sendtoaddressix(const Array& params, bool fHelp)
return wtx.GetHash().GetHex(); return wtx.GetHash().GetHex();
} }
Value listaddressgroupings(const Array& params, bool fHelp) Value listaddressgroupings(const Array& params, bool fHelp)
{ {
if (fHelp) if (fHelp)
@ -879,9 +889,9 @@ Value sendfrom(const Array& params, bool fHelp)
Value sendmany(const Array& params, bool fHelp) Value sendmany(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() < 2 || params.size() > 4) if (fHelp || params.size() < 2 || params.size() > 6)
throw runtime_error( throw runtime_error(
"sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" )\n" "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" use_ix use_ds)\n"
"\nSend multiple times. Amounts are double-precision floating point numbers." "\nSend multiple times. Amounts are double-precision floating point numbers."
+ HelpRequiringPassphrase() + "\n" + HelpRequiringPassphrase() + "\n"
"\nArguments:\n" "\nArguments:\n"
@ -893,6 +903,8 @@ Value sendmany(const Array& params, bool fHelp)
" }\n" " }\n"
"3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n" "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
"4. \"comment\" (string, optional) A comment\n" "4. \"comment\" (string, optional) A comment\n"
"5. \"use_ix\" (bool, optional) Send this transaction as IX (default: false)\n"
"6. \"use_ds\" (bool, optional) Use anonymized funds only (default: false)\n"
"\nResult:\n" "\nResult:\n"
"\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n" "\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
" the number of addresses.\n" " the number of addresses.\n"
@ -948,7 +960,15 @@ Value sendmany(const Array& params, bool fHelp)
CReserveKey keyChange(pwalletMain); CReserveKey keyChange(pwalletMain);
CAmount nFeeRequired = 0; CAmount nFeeRequired = 0;
string strFailReason; string strFailReason;
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason); bool fUseIX = false;
bool fUseDS = false;
if (params.size() > 4 && params[4].type() != null_type)
fUseIX = params[4].get_bool();
if (params.size() > 5 && params[5].type() != null_type)
fUseDS = params[5].get_bool();
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason,
NULL, fUseDS ? ONLY_DENOMINATED : ALL_COINS, fUseIX);
if (!fCreated) if (!fCreated)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
if (!pwalletMain->CommitTransaction(wtx, keyChange)) if (!pwalletMain->CommitTransaction(wtx, keyChange))