diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index 7d8231f5e47cf..4f74a284dd1e4 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -61,7 +61,7 @@ def run_test(self): #Empty Tx addr = self.nodes[1].getnewaddress() - assert_array_result(self.nodes[1].listreceivedbyaddress(0,True), + assert_array_result(self.nodes[1].listreceivedbyaddress(0, False, True), {"address":addr}, {"address":addr, "account":"", "amount":0, "confirmations":0, "txids":[]}) @@ -128,7 +128,7 @@ def run_test(self): #Create a new account named "mynewaccount" that has a 0 balance self.nodes[1].getaccountaddress("mynewaccount") - received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(0,True),{"account":"mynewaccount"}) + received_by_account_json = get_sub_array_from_array(self.nodes[1].listreceivedbyaccount(0, False, True),{"account":"mynewaccount"}) if len(received_by_account_json) == 0: raise AssertionError("No accounts found in node") diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 69515843b9c54..bd0ad89059577 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -138,7 +138,7 @@ def run_test (self): node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('200'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid))) # Sendmany 100 DASH - txid = self.nodes[2].sendmany('from1', {address: 100}, 0, "", []) + txid = self.nodes[2].sendmany('from1', {address: 100}, 0, False, "", []) self.nodes[2].generate(1) self.sync_all() node_0_bal += Decimal('100') @@ -146,7 +146,7 @@ def run_test (self): assert_equal(self.nodes[0].getbalance(), node_0_bal) # Sendmany 100 DASH with subtract fee from amount - txid = self.nodes[2].sendmany('from1', {address: 100}, 0, "", [address]) + txid = self.nodes[2].sendmany('from1', {address: 100}, 0, False, "", [address]) self.nodes[2].generate(1) self.sync_all() node_2_bal -= Decimal('100') diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 162045e644707..1b52f684fdc8a 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -40,15 +40,20 @@ static const CRPCConvertParam vRPCConvertParams[] = { "instantsendtoaddress", 4 }, { "settxfee", 0 }, { "getreceivedbyaddress", 1 }, + { "getreceivedbyaddress", 2 }, { "getreceivedbyaccount", 1 }, + { "getreceivedbyaccount", 2 }, { "listreceivedbyaddress", 0 }, { "listreceivedbyaddress", 1 }, { "listreceivedbyaddress", 2 }, + { "listreceivedbyaddress", 3 }, { "listreceivedbyaccount", 0 }, { "listreceivedbyaccount", 1 }, { "listreceivedbyaccount", 2 }, + { "listreceivedbyaccount", 3 }, { "getbalance", 1 }, { "getbalance", 2 }, + { "getbalance", 3 }, { "getchaintips", 0 }, { "getchaintips", 1 }, { "getblockhash", 0 }, @@ -57,11 +62,13 @@ static const CRPCConvertParam vRPCConvertParams[] = { "move", 3 }, { "sendfrom", 2 }, { "sendfrom", 3 }, + { "sendfrom", 4 }, { "listtransactions", 1 }, { "listtransactions", 2 }, { "listtransactions", 3 }, { "listaccounts", 0 }, { "listaccounts", 1 }, + { "listaccounts", 2 }, { "walletpassphrase", 1 }, { "walletpassphrase", 2 }, { "getblocktemplate", 0 }, @@ -69,9 +76,10 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listsinceblock", 2 }, { "sendmany", 1 }, { "sendmany", 2 }, - { "sendmany", 4 }, + { "sendmany", 3 }, { "sendmany", 5 }, { "sendmany", 6 }, + { "sendmany", 7 }, { "addmultisigaddress", 0 }, { "addmultisigaddress", 1 }, { "createmultisig", 0 }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6258234c5b80b..f2700c287e27d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -60,9 +60,9 @@ void EnsureWalletIsUnlocked() void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) { int confirms = wtx.GetDepthInMainChain(false); - int confirmsTotal = instantsend.GetConfirmations(wtx.GetHash()) + confirms; - entry.push_back(Pair("confirmations", confirmsTotal)); - entry.push_back(Pair("bcconfirmations", confirms)); + bool fLocked = instantsend.IsLockedInstantSendTransaction(wtx.GetHash()); + entry.push_back(Pair("confirmations", confirms)); + entry.push_back(Pair("instantlock", fLocked)); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); if (confirms > 0) @@ -417,7 +417,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) "\nSend an amount to a given address.\n" + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"dashaddress\" (string, required) The dash address to send to.\n" + "1. \"dashaddress\" (string, required) The dash address to send to.\n" "2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " 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" @@ -643,15 +643,16 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() < 1 || params.size() > 2) + if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( - "getreceivedbyaddress \"dashaddress\" ( minconf )\n" - "\nReturns the total amount received by the given dashaddress in transactions with at least minconf confirmations.\n" + "getreceivedbyaddress \"dashaddress\" ( minconf addlockconf )\n" + "\nReturns the total amount received by the given dashaddress in transactions with specified minimum number of confirmations.\n" "\nArguments:\n" "1. \"dashaddress\" (string, required) The dash address for transactions.\n" - "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" + "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" + "3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" "\nResult:\n" - "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n" + "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n" "\nExamples:\n" "\nThe amount from transactions with at least 1 confirmation\n" + HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") + @@ -677,6 +678,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) int nMinDepth = 1; if (params.size() > 1) nMinDepth = params[1].get_int(); + bool fAddLockConf = (params.size() > 2 && params[2].get_bool()); // Tally CAmount nAmount = 0; @@ -688,7 +690,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (txout.scriptPubKey == scriptPubKey) - if (wtx.GetDepthInMainChain() >= nMinDepth) + if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth) nAmount += txout.nValue; } @@ -701,15 +703,16 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() < 1 || params.size() > 2) + if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( - "getreceivedbyaccount \"account\" ( minconf )\n" - "\nDEPRECATED. Returns the total amount received by addresses with in transactions with at least [minconf] confirmations.\n" + "getreceivedbyaccount \"account\" ( minconf addlockconf )\n" + "\nDEPRECATED. Returns the total amount received by addresses with in transactions with specified minimum number of confirmations.\n" "\nArguments:\n" "1. \"account\" (string, required) The selected account, may be the default account using \"\".\n" - "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" + "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" + "3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" "\nResult:\n" - "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" + "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" "\nExamples:\n" "\nAmount received by the default account with at least 1 confirmation\n" + HelpExampleCli("getreceivedbyaccount", "\"\"") + @@ -727,6 +730,7 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) int nMinDepth = 1; if (params.size() > 1) nMinDepth = params[1].get_int(); + bool fAddLockConf = (params.size() > 2 && params[2].get_bool()); // Get the set of pub keys assigned to account string strAccount = AccountFromValue(params[0]); @@ -744,7 +748,7 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) { CTxDestination address; if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address)) - if (wtx.GetDepthInMainChain() >= nMinDepth) + if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth) nAmount += txout.nValue; } } @@ -753,7 +757,7 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) } -CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter) +CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter, bool fAddLockConf) { CAmount nBalance = 0; @@ -761,13 +765,13 @@ CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; - if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0) + if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain(fAddLockConf) < 0) continue; CAmount nReceived, nSent, nFee; wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter); - if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) + if (nReceived != 0 && wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth) nBalance += nReceived; nBalance -= nSent + nFee; } @@ -778,10 +782,10 @@ CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi return nBalance; } -CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter) +CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter, bool fAddLockConf) { CWalletDB walletdb(pwalletMain->strWalletFile); - return GetAccountBalance(walletdb, strAccount, nMinDepth, filter); + return GetAccountBalance(walletdb, strAccount, nMinDepth, filter, fAddLockConf); } @@ -790,17 +794,18 @@ UniValue getbalance(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() > 3) + if (fHelp || params.size() > 4) throw runtime_error( - "getbalance ( \"account\" minconf includeWatchonly )\n" + "getbalance ( \"account\" minconf addlockconf includeWatchonly )\n" "\nIf account is not specified, returns the server's total available balance.\n" "If account is specified (DEPRECATED), returns the balance in the account.\n" "Note that the account \"\" is not the same as leaving the parameter out.\n" "The server total may be different to the balance in the default \"\" account.\n" "\nArguments:\n" - "1. \"account\" (string, optional) DEPRECATED. The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n" + "1. \"account\" (string, optional) DEPRECATED. The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n" "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" - "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n" + "3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" + "4. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" "\nExamples:\n" @@ -820,9 +825,10 @@ UniValue getbalance(const UniValue& params, bool fHelp) int nMinDepth = 1; if (params.size() > 1) nMinDepth = params[1].get_int(); + bool fAddLockConf = (params.size() > 2 && params[2].get_bool()); isminefilter filter = ISMINE_SPENDABLE; - if(params.size() > 2) - if(params[2].get_bool()) + if(params.size() > 3) + if(params[3].get_bool()) filter = filter | ISMINE_WATCH_ONLY; if (params[0].get_str() == "*") { @@ -841,7 +847,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) list listReceived; list listSent; wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); - if (wtx.GetDepthInMainChain() >= nMinDepth) + if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth) { BOOST_FOREACH(const COutputEntry& r, listReceived) nBalance += r.amount; @@ -855,7 +861,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) string strAccount = AccountFromValue(params[0]); - CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter); + CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter, fAddLockConf); return ValueFromAmount(nBalance); } @@ -886,13 +892,13 @@ UniValue movecmd(const UniValue& params, bool fHelp) "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n" "\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n" "\nArguments:\n" - "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n" - "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n" - "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n" - "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" - "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n" + "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n" + "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n" + "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n" + "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" + "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n" "\nResult:\n" - "true|false (boolean) true if successful.\n" + "true|false (boolean) true if successful.\n" "\nExamples:\n" "\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n" + HelpExampleCli("move", "\"\" \"tabby\" 0.01") + @@ -954,23 +960,24 @@ UniValue sendfrom(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() < 3 || params.size() > 6) + if (fHelp || params.size() < 3 || params.size() > 7) throw runtime_error( - "sendfrom \"fromaccount\" \"todashaddress\" amount ( minconf \"comment\" \"comment-to\" )\n" + "sendfrom \"fromaccount\" \"todashaddress\" amount ( minconf addlockconf \"comment\" \"comment-to\" )\n" "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a dash address." + HelpRequiringPassphrase() + "\n" "\nArguments:\n" - "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n" + "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n" "2. \"todashaddress\" (string, required) The dash address to send funds to.\n" - "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n" - "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" - "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" + "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n" + "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" + "5. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" + "6. \"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" - "6. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n" + "7. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n" " to which you're sending the transaction. This is not part of the transaction, \n" " it is just kept in your wallet.\n" "\nResult:\n" - "\"transactionid\" (string) The transaction id.\n" + "\"transactionid\" (string) The transaction id.\n" "\nExamples:\n" "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n" + HelpExampleCli("sendfrom", "\"\" \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" 0.01") + @@ -992,18 +999,19 @@ UniValue sendfrom(const UniValue& params, bool fHelp) int nMinDepth = 1; if (params.size() > 3) nMinDepth = params[3].get_int(); + bool fAddLockConf = (params.size() > 4 && params[4].get_bool()); CWalletTx wtx; wtx.strFromAccount = strAccount; - if (params.size() > 4 && !params[4].isNull() && !params[4].get_str().empty()) - wtx.mapValue["comment"] = params[4].get_str(); if (params.size() > 5 && !params[5].isNull() && !params[5].get_str().empty()) - wtx.mapValue["to"] = params[5].get_str(); + wtx.mapValue["comment"] = params[5].get_str(); + if (params.size() > 6 && !params[6].isNull() && !params[6].get_str().empty()) + wtx.mapValue["to"] = params[6].get_str(); EnsureWalletIsUnlocked(); // Check funds - CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); + CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf); if (nAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); @@ -1018,21 +1026,22 @@ UniValue sendmany(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() < 2 || params.size() > 7) + if (fHelp || params.size() < 2 || params.size() > 8) throw runtime_error( - "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] subtractfeefromamount use_is use_ps )\n" + "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf addlockconf \"comment\" [\"address\",...] subtractfeefromamount use_is use_ps )\n" "\nSend multiple times. Amounts are double-precision floating point numbers." + HelpRequiringPassphrase() + "\n" "\nArguments:\n" - "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n" - "2. \"amounts\" (string, required) A json object with addresses and amounts\n" + "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n" + "2. \"amounts\" (string, required) A json object with addresses and amounts\n" " {\n" - " \"address\":amount (numeric or string) The dash address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n" + " \"address\":amount (numeric or string) The dash address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n" " ,...\n" " }\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" - "5. subtractfeefromamount (string, optional) A json array with addresses.\n" + "4. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" + "5. \"comment\" (string, optional) A comment\n" + "6. subtractfeefromamount (string, optional) A json array with addresses.\n" " The fee will be equally deducted from the amount of each selected address.\n" " Those recipients will receive less dashs than you enter in their corresponding amount field.\n" " If no addresses are specified here, the sender pays the fee.\n" @@ -1040,10 +1049,10 @@ UniValue sendmany(const UniValue& params, bool fHelp) " \"address\" (string) Subtract fee from this address\n" " ,...\n" " ]\n" - "6. \"use_is\" (bool, optional) Send this transaction as InstantSend (default: false)\n" - "7. \"use_ps\" (bool, optional) Use anonymized funds only (default: false)\n" + "7. \"use_is\" (bool, optional) Send this transaction as InstantSend (default: false)\n" + "8. \"use_ps\" (bool, optional) Use anonymized funds only (default: false)\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" "\nExamples:\n" "\nSend two amounts to two different addresses:\n" @@ -1064,15 +1073,16 @@ UniValue sendmany(const UniValue& params, bool fHelp) int nMinDepth = 1; if (params.size() > 2) nMinDepth = params[2].get_int(); + bool fAddLockConf = (params.size() > 3 && params[3].get_bool()); CWalletTx wtx; wtx.strFromAccount = strAccount; - if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty()) - wtx.mapValue["comment"] = params[3].get_str(); + if (params.size() > 4 && !params[4].isNull() && !params[4].get_str().empty()) + wtx.mapValue["comment"] = params[4].get_str(); UniValue subtractFeeFromAmount(UniValue::VARR); - if (params.size() > 4) - subtractFeeFromAmount = params[4].get_array(); + if (params.size() > 5) + subtractFeeFromAmount = params[5].get_array(); set setAddress; vector vecSend; @@ -1109,7 +1119,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) EnsureWalletIsUnlocked(); // Check funds - CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); + CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf); if (totalAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); @@ -1120,10 +1130,10 @@ UniValue sendmany(const UniValue& params, bool fHelp) string strFailReason; bool fUseInstantSend = false; bool fUsePrivateSend = false; - if (params.size() > 5) - fUseInstantSend = params[5].get_bool(); if (params.size() > 6) - fUsePrivateSend = params[6].get_bool(); + fUseInstantSend = params[6].get_bool(); + if (params.size() > 7) + fUsePrivateSend = params[7].get_bool(); bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason, NULL, true, fUsePrivateSend ? ONLY_DENOMINATED : ALL_COINS, fUseInstantSend); @@ -1191,14 +1201,12 @@ struct tallyitem { CAmount nAmount; int nConf; - int nBCConf; vector txids; bool fIsWatchonly; tallyitem() { nAmount = 0; nConf = std::numeric_limits::max(); - nBCConf = std::numeric_limits::max(); fIsWatchonly = false; } }; @@ -1209,15 +1217,16 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) int nMinDepth = 1; if (params.size() > 0) nMinDepth = params[0].get_int(); + bool fAddLockConf = (params.size() > 1 && params[1].get_bool()); // Whether to include empty accounts bool fIncludeEmpty = false; - if (params.size() > 1) - fIncludeEmpty = params[1].get_bool(); + if (params.size() > 2) + fIncludeEmpty = params[2].get_bool(); isminefilter filter = ISMINE_SPENDABLE; - if(params.size() > 2) - if(params[2].get_bool()) + if(params.size() > 3) + if(params[3].get_bool()) filter = filter | ISMINE_WATCH_ONLY; // Tally @@ -1229,8 +1238,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) if (wtx.IsCoinBase() || !CheckFinalTx(wtx)) continue; - int nDepth = wtx.GetDepthInMainChain(); - int nBCDepth = wtx.GetDepthInMainChain(false); + int nDepth = wtx.GetDepthInMainChain(fAddLockConf); if (nDepth < nMinDepth) continue; @@ -1247,7 +1255,6 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) tallyitem& item = mapTally[address]; item.nAmount += txout.nValue; item.nConf = min(item.nConf, nDepth); - item.nBCConf = min(item.nBCConf, nBCDepth); item.txids.push_back(wtx.GetHash()); if (mine & ISMINE_WATCH_ONLY) item.fIsWatchonly = true; @@ -1267,13 +1274,11 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) CAmount nAmount = 0; int nConf = std::numeric_limits::max(); - int nBCConf = std::numeric_limits::max(); bool fIsWatchonly = false; if (it != mapTally.end()) { nAmount = (*it).second.nAmount; nConf = (*it).second.nConf; - nBCConf = (*it).second.nBCConf; fIsWatchonly = (*it).second.fIsWatchonly; } @@ -1282,7 +1287,6 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) tallyitem& item = mapAccountTally[strAccount]; item.nAmount += nAmount; item.nConf = min(item.nConf, nConf); - item.nBCConf = min(item.nBCConf, nBCConf); item.fIsWatchonly = fIsWatchonly; } else @@ -1294,7 +1298,6 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) obj.push_back(Pair("account", strAccount)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); - obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits::max() ? 0 : nBCConf))); if (!fByAccounts) obj.push_back(Pair("label", strAccount)); UniValue transactions(UniValue::VARR); @@ -1316,14 +1319,12 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) { CAmount nAmount = (*it).second.nAmount; int nConf = (*it).second.nConf; - int nBCConf = (*it).second.nBCConf; UniValue obj(UniValue::VOBJ); if((*it).second.fIsWatchonly) obj.push_back(Pair("involvesWatchonly", true)); obj.push_back(Pair("account", (*it).first)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); - obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits::max() ? 0 : nBCConf))); ret.push_back(obj); } } @@ -1336,25 +1337,27 @@ UniValue listreceivedbyaddress(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() > 3) + if (fHelp || params.size() > 4) throw runtime_error( - "listreceivedbyaddress ( minconf includeempty includeWatchonly)\n" + "listreceivedbyaddress ( minconf addlockconf includeempty includeWatchonly)\n" "\nList balances by receiving address.\n" "\nArguments:\n" - "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" - "2. includeempty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n" - "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" + "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" + "2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" + "3. includeempty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n" + "4. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" "\nResult:\n" "[\n" " {\n" " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n" - " \"address\" : \"receivingaddress\", (string) The receiving address\n" - " \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n" + " \"address\" : \"receivingaddress\", (string) The receiving address\n" + " \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n" " \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n" - " \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n" - " \"bcconfirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n" - " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" + " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included.\n" + " If 'addlockconf' is true, the minimum number of confirmations is calculated\n" + " including additional " + std::to_string(nInstantSendDepth) + " confirmations for transactions locked via InstantSend\n" + " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" " }\n" " ,...\n" "]\n" @@ -1375,24 +1378,24 @@ UniValue listreceivedbyaccount(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() > 3) + if (fHelp || params.size() > 4) throw runtime_error( - "listreceivedbyaccount ( minconf includeempty includeWatchonly)\n" + "listreceivedbyaccount ( minconf addlockconf includeempty includeWatchonly)\n" "\nDEPRECATED. List balances by account.\n" "\nArguments:\n" - "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" - "2. includeempty (bool, optional, default=false) Whether to include accounts that haven't received any payments.\n" - "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" + "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" + "2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" + "3. includeempty (bool, optional, default=false) Whether to include accounts that haven't received any payments.\n" + "4. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" "\nResult:\n" "[\n" " {\n" " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n" - " \"account\" : \"accountname\", (string) The account name of the receiving account\n" + " \"account\" : \"accountname\", (string) The account name of the receiving account\n" " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n" - " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" - " \"bcconfirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n" - " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" + " \"confirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n" + " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" " }\n" " ,...\n" "]\n" @@ -1515,19 +1518,19 @@ UniValue listtransactions(const UniValue& params, bool fHelp) if (fHelp || params.size() > 4) throw runtime_error( - "listtransactions ( \"account\" count from includeWatchonly)\n" + "listtransactions ( \"account\" count from includeWatchonly)\n" "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n" "\nArguments:\n" - "1. \"account\" (string, optional) DEPRECATED. The account name. Should be \"*\".\n" - "2. count (numeric, optional, default=10) The number of transactions to return\n" - "3. from (numeric, optional, default=0) The number of transactions to skip\n" + "1. \"account\" (string, optional) DEPRECATED. The account name. Should be \"*\".\n" + "2. count (numeric, optional, default=10) The number of transactions to return\n" + "3. from (numeric, optional, default=0) The number of transactions to skip\n" "4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n" "\nResult:\n" "[\n" " {\n" - " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n" + " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n" " It will be \"\" for the default account.\n" - " \"address\":\"dashaddress\", (string) The dash address of the transaction. Not present for \n" + " \"address\":\"dashaddress\", (string) The dash address of the transaction. Not present for \n" " move transactions (category = move).\n" " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n" " transaction between accounts, and not associated with an address,\n" @@ -1539,10 +1542,8 @@ UniValue listtransactions(const UniValue& params, bool fHelp) " \"vout\": n, (numeric) the vout value\n" " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n" " 'send' category of transactions.\n" - " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" - " 'receive' category of transactions. Negative confirmations indicate the\n" - " transaction conflicts with the block chain\n" - " \"bcconfirmations\": n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and \n" + " \"instantlock\" : true|false, (bool) Current transaction lock state. Available for 'send' and 'receive' category of transactions.\n" + " \"confirmations\": n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and \n" " 'receive' category of transactions. Negative confirmations indicate the\n" " transation conflicts with the block chain\n" " \"trusted\": xxx (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n" @@ -1551,12 +1552,12 @@ UniValue listtransactions(const UniValue& params, bool fHelp) " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n" " category of transactions.\n" " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" - " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" + " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n" " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n" " for 'send' and 'receive' category of transactions.\n" - " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" - " \"label\": \"label\" (string) A comment for the address/transaction, if any\n" + " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" + " \"label\": \"label\" (string) A comment for the address/transaction, if any\n" " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n" " from (for receiving funds, positive amounts), or went to (for sending funds,\n" " negative amounts).\n" @@ -1642,15 +1643,16 @@ UniValue listaccounts(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() > 2) + if (fHelp || params.size() > 3) throw runtime_error( - "listaccounts ( minconf includeWatchonly)\n" + "listaccounts ( minconf addlockconf includeWatchonly)\n" "\nDEPRECATED. Returns Object that has account names as keys, account balances as values.\n" "\nArguments:\n" - "1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n" - "2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n" + "1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n" + "2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n" + "3. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n" "\nResult:\n" - "{ (json object where keys are account names, and values are numeric balances\n" + "{ (json object where keys are account names, and values are numeric balances\n" " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n" " ...\n" "}\n" @@ -1670,9 +1672,10 @@ UniValue listaccounts(const UniValue& params, bool fHelp) int nMinDepth = 1; if (params.size() > 0) nMinDepth = params[0].get_int(); + bool fAddLockConf = (params.size() > 1 && params[1].get_bool()); isminefilter includeWatchonly = ISMINE_SPENDABLE; - if(params.size() > 1) - if(params[1].get_bool()) + if(params.size() > 2) + if(params[2].get_bool()) includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY; map mapAccountBalances; @@ -1688,7 +1691,7 @@ UniValue listaccounts(const UniValue& params, bool fHelp) string strSentAccount; list listReceived; list listSent; - int nDepth = wtx.GetDepthInMainChain(); + int nDepth = wtx.GetDepthInMainChain(fAddLockConf); if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) continue; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly); @@ -1726,32 +1729,32 @@ UniValue listsinceblock(const UniValue& params, bool fHelp) "listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n" "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n" "\nArguments:\n" - "1. \"blockhash\" (string, optional) The block hash to list transactions since\n" + "1. \"blockhash\" (string, optional) The block hash to list transactions since\n" "2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n" "3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')" "\nResult:\n" "{\n" " \"transactions\": [\n" - " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n" - " \"address\":\"dashaddress\", (string) The dash address of the transaction. Not present for move transactions (category = move).\n" - " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n" + " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n" + " \"address\":\"dashaddress\", (string) The dash address of the transaction. Not present for move transactions (category = move).\n" + " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n" " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n" " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n" " \"vout\" : n, (numeric) the vout value\n" " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n" - " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" - " \"bcconfirmations\" : n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" - " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" + " \"instantlock\" : true|false, (bool) Current transaction lock state. Available for 'send' and 'receive' category of transactions.\n" + " \"confirmations\" : n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" + " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n" " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n" " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n" - " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" - " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" - " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n" + " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" + " \"label\" : \"label\" (string) A comment for the address/transaction, if any\n" + " \"to\": \"...\", (string) If a comment to is associated with the transaction.\n" " ],\n" - " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n" + " \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n" "}\n" "\nExamples:\n" + HelpExampleCli("listsinceblock", "") @@ -1821,14 +1824,14 @@ UniValue gettransaction(const UniValue& params, bool fHelp) "gettransaction \"txid\" ( includeWatchonly )\n" "\nGet detailed information about in-wallet transaction \n" "\nArguments:\n" - "1. \"txid\" (string, required) The transaction id\n" + "1. \"txid\" (string, required) The transaction id\n" "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n" "\nResult:\n" "{\n" " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n" - " \"confirmations\" : n, (numeric) The number of confirmations\n" - " \"bcconfirmations\" : n, (numeric) The number of blockchain confirmations\n" - " \"blockhash\" : \"hash\", (string) The block hash\n" + " \"instantlock\" : true|false, (bool) Current transaction lock state\n" + " \"confirmations\" : n, (numeric) The number of blockchain confirmations\n" + " \"blockhash\" : \"hash\", (string) The block hash\n" " \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n" " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n" " \"txid\" : \"transactionid\", (string) The transaction id.\n" @@ -1838,16 +1841,16 @@ UniValue gettransaction(const UniValue& params, bool fHelp) " may be unknown for unconfirmed transactions not in the mempool\n" " \"details\" : [\n" " {\n" - " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n" - " \"address\" : \"dashaddress\", (string) The dash address involved in the transaction\n" + " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n" + " \"address\" : \"dashaddress\", (string) The dash address involved in the transaction\n" " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n" - " \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n" + " \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n" " \"label\" : \"label\", (string) A comment for the address/transaction, if any\n" - " \"vout\" : n, (numeric) the vout value\n" + " \"vout\" : n, (numeric) the vout value\n" " }\n" " ,...\n" " ],\n" - " \"hex\" : \"data\" (string) Raw data for transaction\n" + " \"hex\" : \"data\" (string) Raw data for transaction\n" "}\n" "\nExamples:\n" @@ -2530,7 +2533,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) if (fHelp || params.size() > 3) throw runtime_error( - "listunspent ( minconf maxconf [\"address\",...] )\n" + "listunspent ( minconf maxconf [\"address\",...] )\n" "\nReturns array of unspent transaction outputs\n" "with between minconf and maxconf (inclusive) confirmations.\n" "Optionally filter to only include txouts paid to specified addresses.\n" @@ -2539,19 +2542,19 @@ UniValue listunspent(const UniValue& params, bool fHelp) "\nArguments:\n" "1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n" "2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n" - "3. \"addresses\" (string) A json array of dash addresses to filter\n" + "3. \"addresses\" (string) A json array of dash addresses to filter\n" " [\n" - " \"address\" (string) dash address\n" + " \"address\" (string) dash address\n" " ,...\n" " ]\n" "\nResult\n" - "[ (array of json object)\n" + "[ (array of json object)\n" " {\n" - " \"txid\" : \"txid\", (string) the transaction id \n" + " \"txid\" : \"txid\", (string) the transaction id \n" " \"vout\" : n, (numeric) the vout value\n" - " \"address\" : \"address\", (string) the dash address\n" - " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n" - " \"scriptPubKey\" : \"key\", (string) the script key\n" + " \"address\" : \"address\", (string) the dash address\n" + " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n" + " \"scriptPubKey\" : \"key\", (string) the script key\n" " \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n" " \"confirmations\" : n (numeric) The number of confirmations\n" " \"ps_rounds\" : n (numeric) The number of PS round\n"