From 5024b7d3f66faa819f8aeeb2dc6971a899d8c433 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Thu, 30 Jul 2015 11:33:37 -0700 Subject: [PATCH] Added sendtoaddressix for api IX support --- src/masternode-budget.cpp | 2 +- src/rpcclient.cpp | 1 + src/rpcmasternode-budget.cpp | 4 +++ src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/rpcwallet.cpp | 47 ++++++++++++++++++++++++++++++++++-- 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 44c1882da5..352d2b4038 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -75,7 +75,7 @@ bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, s } //if we're syncing we won't have instantX information, so accept 1 confirmation - if(conf >= BUDGET_FEE_CONFIRMATIONS || (!masternodeSync.IsSynced() && conf >= 1)){ + if(conf >= BUDGET_FEE_CONFIRMATIONS){ return true; } else { strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", BUDGET_FEE_CONFIRMATIONS, conf); diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 2e056b2e0e..6bf0973d3b 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -33,6 +33,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getnetworkhashps", 0 }, { "getnetworkhashps", 1 }, { "sendtoaddress", 1 }, + { "sendtoaddressix", 1 }, { "settxfee", 0 }, { "getreceivedbyaddress", 1 }, { "getreceivedbyaccount", 1 }, diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index d0da9c5869..f67ac27d53 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -176,6 +176,10 @@ Value mnbudget(const Array& params, bool fHelp) return "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError; } + if(!masternodeSync.IsSynced()){ + return "Must wait for client to sync with masternode network. Try again in a minute or so."; + } + if(!budgetProposalBroadcast.IsValid(strError)){ return "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError; } diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index b3b23750d7..1602a8df8e 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -352,6 +352,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "sendfrom", &sendfrom, false, false, true }, { "wallet", "sendmany", &sendmany, false, false, true }, { "wallet", "sendtoaddress", &sendtoaddress, false, false, true }, + { "wallet", "sendtoaddressix", &sendtoaddressix, false, false, true }, { "wallet", "setaccount", &setaccount, true, false, true }, { "wallet", "settxfee", &settxfee, true, false, true }, { "wallet", "signmessage", &signmessage, true, false, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index bf37f65fa9..9182b63c12 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -169,6 +169,7 @@ extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHel extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendtoaddressix(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 2658b66b24..5118504d89 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -312,7 +312,7 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) return ret; } -void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew) +void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew, bool fUseIX=false) { // Check amount if (nValue <= 0) @@ -335,7 +335,7 @@ void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew) // Create and send the transaction CReserveKey reservekey(pwalletMain); CAmount nFeeRequired; - if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError)) + if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError, NULL, ALL_COINS, fUseIX, (CAmount)0)) { 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)); @@ -390,6 +390,49 @@ Value sendtoaddress(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } +Value sendtoaddressix(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 2 || params.size() > 4) + throw runtime_error( + "sendtoaddressix \"dashaddress\" amount ( \"comment\" \"comment-to\" )\n" + "\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n" + + HelpRequiringPassphrase() + + "\nArguments:\n" + "1. \"dashaddress\" (string, required) The dash address to send to.\n" + "2. \"amount\" (numeric, required) The amount in btc to send. eg 0.1\n" + "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" + " This is not part of the transaction, just kept in your wallet.\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" + " transaction, just kept in your wallet.\n" + "\nResult:\n" + "\"transactionid\" (string) The transaction id.\n" + "\nExamples:\n" + + HelpExampleCli("sendtoaddressix", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1") + + HelpExampleCli("sendtoaddressix", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.1 \"donation\" \"seans outpost\"") + + HelpExampleRpc("sendtoaddressix", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\", 0.1, \"donation\", \"seans outpost\"") + ); + + CBitcoinAddress address(params[0].get_str()); + if (!address.IsValid()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); + + // Amount + CAmount nAmount = AmountFromValue(params[1]); + + // Wallet comments + CWalletTx wtx; + if (params.size() > 2 && params[2].type() != null_type && !params[2].get_str().empty()) + wtx.mapValue["comment"] = params[2].get_str(); + if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) + wtx.mapValue["to"] = params[3].get_str(); + + EnsureWalletIsUnlocked(); + + SendMoney(address.Get(), nAmount, wtx, true); + + return wtx.GetHash().GetHex(); +} Value listaddressgroupings(const Array& params, bool fHelp) { if (fHelp)