|
|
|
@ -32,16 +32,16 @@ using namespace std;
@@ -32,16 +32,16 @@ using namespace std;
|
|
|
|
|
int64_t nWalletUnlockTime; |
|
|
|
|
static CCriticalSection cs_nWalletUnlockTime; |
|
|
|
|
|
|
|
|
|
std::string HelpRequiringPassphrase() |
|
|
|
|
std::string HelpRequiringPassphrase(CWallet * const pwallet) |
|
|
|
|
{ |
|
|
|
|
return pwalletMain && pwalletMain->IsCrypted() |
|
|
|
|
return pwallet && pwallet->IsCrypted() |
|
|
|
|
? "\nRequires wallet passphrase to be set with walletpassphrase call." |
|
|
|
|
: ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool EnsureWalletIsAvailable(bool avoidException) |
|
|
|
|
bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException) |
|
|
|
|
{ |
|
|
|
|
if (!pwalletMain) |
|
|
|
|
if (!pwallet) |
|
|
|
|
{ |
|
|
|
|
if (!avoidException) |
|
|
|
|
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); |
|
|
|
@ -51,9 +51,9 @@ bool EnsureWalletIsAvailable(bool avoidException)
@@ -51,9 +51,9 @@ bool EnsureWalletIsAvailable(bool avoidException)
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void EnsureWalletIsUnlocked() |
|
|
|
|
void EnsureWalletIsUnlocked(CWallet * const pwallet) |
|
|
|
|
{ |
|
|
|
|
if (pwalletMain->IsLocked()) |
|
|
|
|
if (pwallet->IsLocked()) |
|
|
|
|
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -106,7 +106,7 @@ string AccountFromValue(const UniValue& value)
@@ -106,7 +106,7 @@ string AccountFromValue(const UniValue& value)
|
|
|
|
|
|
|
|
|
|
UniValue getnewaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
@ -146,10 +146,10 @@ UniValue getnewaddress(const JSONRPCRequest& request)
@@ -146,10 +146,10 @@ UniValue getnewaddress(const JSONRPCRequest& request)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) |
|
|
|
|
CBitcoinAddress GetAccountAddress(CWallet * const pwallet, string strAccount, bool bForceNew=false) |
|
|
|
|
{ |
|
|
|
|
CPubKey pubKey; |
|
|
|
|
if (!pwalletMain->GetAccountPubkey(pubKey, strAccount, bForceNew)) { |
|
|
|
|
if (!pwallet->GetAccountPubkey(pubKey, strAccount, bForceNew)) { |
|
|
|
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -158,7 +158,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
@@ -158,7 +158,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
|
|
|
|
|
|
|
|
|
|
UniValue getaccountaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
@ -183,14 +183,14 @@ UniValue getaccountaddress(const JSONRPCRequest& request)
@@ -183,14 +183,14 @@ UniValue getaccountaddress(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue ret(UniValue::VSTR); |
|
|
|
|
|
|
|
|
|
ret = GetAccountAddress(strAccount).ToString(); |
|
|
|
|
ret = GetAccountAddress(pwalletMain, strAccount).ToString(); |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UniValue getrawchangeaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
@ -225,7 +225,7 @@ UniValue getrawchangeaddress(const JSONRPCRequest& request)
@@ -225,7 +225,7 @@ UniValue getrawchangeaddress(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue setaccount(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
@ -257,8 +257,8 @@ UniValue setaccount(const JSONRPCRequest& request)
@@ -257,8 +257,8 @@ UniValue setaccount(const JSONRPCRequest& request)
|
|
|
|
|
if (pwalletMain->mapAddressBook.count(address.Get())) |
|
|
|
|
{ |
|
|
|
|
string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name; |
|
|
|
|
if (address == GetAccountAddress(strOldAccount)) |
|
|
|
|
GetAccountAddress(strOldAccount, true); |
|
|
|
|
if (address == GetAccountAddress(pwalletMain, strOldAccount)) |
|
|
|
|
GetAccountAddress(pwalletMain, strOldAccount, true); |
|
|
|
|
} |
|
|
|
|
pwalletMain->SetAddressBook(address.Get(), strAccount, "receive"); |
|
|
|
|
} |
|
|
|
@ -271,7 +271,7 @@ UniValue setaccount(const JSONRPCRequest& request)
@@ -271,7 +271,7 @@ UniValue setaccount(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue getaccount(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
@ -303,7 +303,7 @@ UniValue getaccount(const JSONRPCRequest& request)
@@ -303,7 +303,7 @@ UniValue getaccount(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue getaddressesbyaccount(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
@ -338,9 +338,9 @@ UniValue getaddressesbyaccount(const JSONRPCRequest& request)
@@ -338,9 +338,9 @@ UniValue getaddressesbyaccount(const JSONRPCRequest& request)
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew) |
|
|
|
|
static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew) |
|
|
|
|
{ |
|
|
|
|
CAmount curBalance = pwalletMain->GetBalance(); |
|
|
|
|
CAmount curBalance = pwallet->GetBalance(); |
|
|
|
|
|
|
|
|
|
// Check amount
|
|
|
|
|
if (nValue <= 0) |
|
|
|
@ -349,27 +349,27 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
@@ -349,27 +349,27 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
|
|
|
|
|
if (nValue > curBalance) |
|
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); |
|
|
|
|
|
|
|
|
|
if (pwalletMain->GetBroadcastTransactions() && !g_connman) |
|
|
|
|
if (pwallet->GetBroadcastTransactions() && !g_connman) |
|
|
|
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
|
|
|
|
|
|
|
|
|
// Parse Bitcoin address
|
|
|
|
|
CScript scriptPubKey = GetScriptForDestination(address); |
|
|
|
|
|
|
|
|
|
// Create and send the transaction
|
|
|
|
|
CReserveKey reservekey(pwalletMain); |
|
|
|
|
CReserveKey reservekey(pwallet); |
|
|
|
|
CAmount nFeeRequired; |
|
|
|
|
std::string strError; |
|
|
|
|
vector<CRecipient> vecSend; |
|
|
|
|
int nChangePosRet = -1; |
|
|
|
|
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; |
|
|
|
|
vecSend.push_back(recipient); |
|
|
|
|
if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError)) { |
|
|
|
|
if (!pwallet->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError)) { |
|
|
|
|
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) |
|
|
|
|
strError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired)); |
|
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, strError); |
|
|
|
|
} |
|
|
|
|
CValidationState state; |
|
|
|
|
if (!pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get(), state)) { |
|
|
|
|
if (!pwallet->CommitTransaction(wtxNew, reservekey, g_connman.get(), state)) { |
|
|
|
|
strError = strprintf("Error: The transaction was rejected! Reason given: %s", state.GetRejectReason()); |
|
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, strError); |
|
|
|
|
} |
|
|
|
@ -377,14 +377,14 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
@@ -377,14 +377,14 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
|
|
|
|
|
|
|
|
|
|
UniValue sendtoaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) |
|
|
|
|
throw runtime_error( |
|
|
|
|
"sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" subtractfeefromamount )\n" |
|
|
|
|
"\nSend an amount to a given address.\n" |
|
|
|
|
+ HelpRequiringPassphrase() + |
|
|
|
|
+ HelpRequiringPassphrase(pwalletMain) + |
|
|
|
|
"\nArguments:\n" |
|
|
|
|
"1. \"address\" (string, required) The bitcoin address to send to.\n" |
|
|
|
|
"2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" |
|
|
|
@ -426,16 +426,16 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
@@ -426,16 +426,16 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
|
|
|
|
|
if (request.params.size() > 4) |
|
|
|
|
fSubtractFeeFromAmount = request.params[4].get_bool(); |
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(); |
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
|
|
|
|
|
|
SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx); |
|
|
|
|
SendMoney(pwalletMain, address.Get(), nAmount, fSubtractFeeFromAmount, wtx); |
|
|
|
|
|
|
|
|
|
return wtx.GetHash().GetHex(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UniValue listaddressgroupings(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
@ -486,14 +486,14 @@ UniValue listaddressgroupings(const JSONRPCRequest& request)
@@ -486,14 +486,14 @@ UniValue listaddressgroupings(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue signmessage(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 2) |
|
|
|
|
throw runtime_error( |
|
|
|
|
"signmessage \"address\" \"message\"\n" |
|
|
|
|
"\nSign a message with the private key of an address" |
|
|
|
|
+ HelpRequiringPassphrase() + "\n" |
|
|
|
|
+ HelpRequiringPassphrase(pwalletMain) + "\n" |
|
|
|
|
"\nArguments:\n" |
|
|
|
|
"1. \"address\" (string, required) The bitcoin address to use for the private key.\n" |
|
|
|
|
"2. \"message\" (string, required) The message to create a signature of.\n" |
|
|
|
@ -512,7 +512,7 @@ UniValue signmessage(const JSONRPCRequest& request)
@@ -512,7 +512,7 @@ UniValue signmessage(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(); |
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
|
|
|
|
|
|
string strAddress = request.params[0].get_str(); |
|
|
|
|
string strMessage = request.params[1].get_str(); |
|
|
|
@ -542,7 +542,7 @@ UniValue signmessage(const JSONRPCRequest& request)
@@ -542,7 +542,7 @@ UniValue signmessage(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue getreceivedbyaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
@ -600,7 +600,7 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request)
@@ -600,7 +600,7 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue getreceivedbyaccount(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
@ -657,7 +657,7 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request)
@@ -657,7 +657,7 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue getbalance(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
@ -746,7 +746,7 @@ UniValue getbalance(const JSONRPCRequest& request)
@@ -746,7 +746,7 @@ UniValue getbalance(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue getunconfirmedbalance(const JSONRPCRequest &request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 0) |
|
|
|
@ -762,7 +762,7 @@ UniValue getunconfirmedbalance(const JSONRPCRequest &request)
@@ -762,7 +762,7 @@ UniValue getunconfirmedbalance(const JSONRPCRequest &request)
|
|
|
|
|
|
|
|
|
|
UniValue movecmd(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 3 || request.params.size() > 5) |
|
|
|
@ -809,14 +809,14 @@ UniValue movecmd(const JSONRPCRequest& request)
@@ -809,14 +809,14 @@ UniValue movecmd(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue sendfrom(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 3 || request.params.size() > 6) |
|
|
|
|
throw runtime_error( |
|
|
|
|
"sendfrom \"fromaccount\" \"toaddress\" amount ( minconf \"comment\" \"comment_to\" )\n" |
|
|
|
|
"\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a bitcoin address." |
|
|
|
|
+ HelpRequiringPassphrase() + "\n" |
|
|
|
|
+ HelpRequiringPassphrase(pwalletMain) + "\n" |
|
|
|
|
"\nArguments:\n" |
|
|
|
|
"1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n" |
|
|
|
|
" Specifying an account does not influence coin selection, but it does associate the newly created\n" |
|
|
|
@ -861,14 +861,14 @@ UniValue sendfrom(const JSONRPCRequest& request)
@@ -861,14 +861,14 @@ UniValue sendfrom(const JSONRPCRequest& request)
|
|
|
|
|
if (request.params.size() > 5 && !request.params[5].isNull() && !request.params[5].get_str().empty()) |
|
|
|
|
wtx.mapValue["to"] = request.params[5].get_str(); |
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(); |
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
|
|
|
|
|
|
// Check funds
|
|
|
|
|
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); |
|
|
|
|
if (nAmount > nBalance) |
|
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); |
|
|
|
|
|
|
|
|
|
SendMoney(address.Get(), nAmount, false, wtx); |
|
|
|
|
SendMoney(pwalletMain, address.Get(), nAmount, false, wtx); |
|
|
|
|
|
|
|
|
|
return wtx.GetHash().GetHex(); |
|
|
|
|
} |
|
|
|
@ -876,14 +876,14 @@ UniValue sendfrom(const JSONRPCRequest& request)
@@ -876,14 +876,14 @@ UniValue sendfrom(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue sendmany(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) |
|
|
|
|
throw runtime_error( |
|
|
|
|
"sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] )\n" |
|
|
|
|
"\nSend multiple times. Amounts are double-precision floating point numbers." |
|
|
|
|
+ HelpRequiringPassphrase() + "\n" |
|
|
|
|
+ HelpRequiringPassphrase(pwalletMain) + "\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" |
|
|
|
@ -967,7 +967,7 @@ UniValue sendmany(const JSONRPCRequest& request)
@@ -967,7 +967,7 @@ UniValue sendmany(const JSONRPCRequest& request)
|
|
|
|
|
vecSend.push_back(recipient); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(); |
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
|
|
|
|
|
|
// Check funds
|
|
|
|
|
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); |
|
|
|
@ -992,11 +992,11 @@ UniValue sendmany(const JSONRPCRequest& request)
@@ -992,11 +992,11 @@ UniValue sendmany(const JSONRPCRequest& request)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Defined in rpc/misc.cpp
|
|
|
|
|
extern CScript _createmultisig_redeemScript(const UniValue& params); |
|
|
|
|
extern CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& params); |
|
|
|
|
|
|
|
|
|
UniValue addmultisigaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) |
|
|
|
@ -1034,7 +1034,7 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
@@ -1034,7 +1034,7 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
|
|
|
|
|
strAccount = AccountFromValue(request.params[2]); |
|
|
|
|
|
|
|
|
|
// Construct using pay-to-script-hash:
|
|
|
|
|
CScript inner = _createmultisig_redeemScript(request.params); |
|
|
|
|
CScript inner = _createmultisig_redeemScript(pwalletMain, request.params); |
|
|
|
|
CScriptID innerID(inner); |
|
|
|
|
pwalletMain->AddCScript(inner); |
|
|
|
|
|
|
|
|
@ -1045,20 +1045,23 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
@@ -1045,20 +1045,23 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
|
|
|
|
|
class Witnessifier : public boost::static_visitor<bool> |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
CWallet * const pwallet; |
|
|
|
|
CScriptID result; |
|
|
|
|
|
|
|
|
|
Witnessifier(CWallet *_pwallet) : pwallet(_pwallet) {} |
|
|
|
|
|
|
|
|
|
bool operator()(const CNoDestination &dest) const { return false; } |
|
|
|
|
|
|
|
|
|
bool operator()(const CKeyID &keyID) { |
|
|
|
|
CPubKey pubkey; |
|
|
|
|
if (pwalletMain) { |
|
|
|
|
if (pwallet) { |
|
|
|
|
CScript basescript = GetScriptForDestination(keyID); |
|
|
|
|
isminetype typ; |
|
|
|
|
typ = IsMine(*pwalletMain, basescript, SIGVERSION_WITNESS_V0); |
|
|
|
|
typ = IsMine(*pwallet, basescript, SIGVERSION_WITNESS_V0); |
|
|
|
|
if (typ != ISMINE_SPENDABLE && typ != ISMINE_WATCH_SOLVABLE) |
|
|
|
|
return false; |
|
|
|
|
CScript witscript = GetScriptForWitness(basescript); |
|
|
|
|
pwalletMain->AddCScript(witscript); |
|
|
|
|
pwallet->AddCScript(witscript); |
|
|
|
|
result = CScriptID(witscript); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -1067,7 +1070,7 @@ public:
@@ -1067,7 +1070,7 @@ public:
|
|
|
|
|
|
|
|
|
|
bool operator()(const CScriptID &scriptID) { |
|
|
|
|
CScript subscript; |
|
|
|
|
if (pwalletMain && pwalletMain->GetCScript(scriptID, subscript)) { |
|
|
|
|
if (pwallet && pwallet->GetCScript(scriptID, subscript)) { |
|
|
|
|
int witnessversion; |
|
|
|
|
std::vector<unsigned char> witprog; |
|
|
|
|
if (subscript.IsWitnessProgram(witnessversion, witprog)) { |
|
|
|
@ -1075,11 +1078,11 @@ public:
@@ -1075,11 +1078,11 @@ public:
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
isminetype typ; |
|
|
|
|
typ = IsMine(*pwalletMain, subscript, SIGVERSION_WITNESS_V0); |
|
|
|
|
typ = IsMine(*pwallet, subscript, SIGVERSION_WITNESS_V0); |
|
|
|
|
if (typ != ISMINE_SPENDABLE && typ != ISMINE_WATCH_SOLVABLE) |
|
|
|
|
return false; |
|
|
|
|
CScript witscript = GetScriptForWitness(subscript); |
|
|
|
|
pwalletMain->AddCScript(witscript); |
|
|
|
|
pwallet->AddCScript(witscript); |
|
|
|
|
result = CScriptID(witscript); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -1089,7 +1092,7 @@ public:
@@ -1089,7 +1092,7 @@ public:
|
|
|
|
|
|
|
|
|
|
UniValue addwitnessaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) |
|
|
|
@ -1119,7 +1122,7 @@ UniValue addwitnessaddress(const JSONRPCRequest& request)
@@ -1119,7 +1122,7 @@ UniValue addwitnessaddress(const JSONRPCRequest& request)
|
|
|
|
|
if (!address.IsValid()) |
|
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); |
|
|
|
|
|
|
|
|
|
Witnessifier w; |
|
|
|
|
Witnessifier w(pwalletMain); |
|
|
|
|
CTxDestination dest = address.Get(); |
|
|
|
|
bool ret = boost::apply_visitor(w, dest); |
|
|
|
|
if (!ret) { |
|
|
|
@ -1145,7 +1148,7 @@ struct tallyitem
@@ -1145,7 +1148,7 @@ struct tallyitem
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
UniValue ListReceived(const UniValue& params, bool fByAccounts) |
|
|
|
|
UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bool fByAccounts) |
|
|
|
|
{ |
|
|
|
|
// Minimum confirmations
|
|
|
|
|
int nMinDepth = 1; |
|
|
|
@ -1164,7 +1167,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
@@ -1164,7 +1167,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
|
|
|
|
|
|
|
|
|
// Tally
|
|
|
|
|
map<CBitcoinAddress, tallyitem> mapTally; |
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) |
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) |
|
|
|
|
{ |
|
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
|
|
|
|
@ -1181,7 +1184,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
@@ -1181,7 +1184,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
|
|
|
|
if (!ExtractDestination(txout.scriptPubKey, address)) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
isminefilter mine = IsMine(*pwalletMain, address); |
|
|
|
|
isminefilter mine = IsMine(*pwallet, address); |
|
|
|
|
if(!(mine & filter)) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
@ -1197,7 +1200,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
@@ -1197,7 +1200,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
|
|
|
|
// Reply
|
|
|
|
|
UniValue ret(UniValue::VARR); |
|
|
|
|
map<string, tallyitem> mapAccountTally; |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook) |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwallet->mapAddressBook) |
|
|
|
|
{ |
|
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
|
const string& strAccount = item.second.name; |
|
|
|
@ -1267,7 +1270,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
@@ -1267,7 +1270,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
|
|
|
|
|
|
|
|
|
UniValue listreceivedbyaddress(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
@ -1304,12 +1307,12 @@ UniValue listreceivedbyaddress(const JSONRPCRequest& request)
@@ -1304,12 +1307,12 @@ UniValue listreceivedbyaddress(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
|
|
|
|
|
|
return ListReceived(request.params, false); |
|
|
|
|
return ListReceived(pwalletMain, request.params, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UniValue listreceivedbyaccount(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
@ -1341,7 +1344,7 @@ UniValue listreceivedbyaccount(const JSONRPCRequest& request)
@@ -1341,7 +1344,7 @@ UniValue listreceivedbyaccount(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
|
|
|
|
|
|
return ListReceived(request.params, true); |
|
|
|
|
return ListReceived(pwalletMain, request.params, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void MaybePushAddress(UniValue & entry, const CTxDestination &dest) |
|
|
|
@ -1351,7 +1354,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
@@ -1351,7 +1354,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
|
|
|
|
|
entry.push_back(Pair("address", addr.ToString())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter) |
|
|
|
|
void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter) |
|
|
|
|
{ |
|
|
|
|
CAmount nFee; |
|
|
|
|
string strSentAccount; |
|
|
|
@ -1369,14 +1372,14 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
@@ -1369,14 +1372,14 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
|
|
|
|
BOOST_FOREACH(const COutputEntry& s, listSent) |
|
|
|
|
{ |
|
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
|
if(involvesWatchonly || (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY)) |
|
|
|
|
if(involvesWatchonly || (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) |
|
|
|
|
entry.push_back(Pair("involvesWatchonly", true)); |
|
|
|
|
entry.push_back(Pair("account", strSentAccount)); |
|
|
|
|
MaybePushAddress(entry, s.destination); |
|
|
|
|
entry.push_back(Pair("category", "send")); |
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); |
|
|
|
|
if (pwalletMain->mapAddressBook.count(s.destination)) |
|
|
|
|
entry.push_back(Pair("label", pwalletMain->mapAddressBook[s.destination].name)); |
|
|
|
|
if (pwallet->mapAddressBook.count(s.destination)) |
|
|
|
|
entry.push_back(Pair("label", pwallet->mapAddressBook[s.destination].name)); |
|
|
|
|
entry.push_back(Pair("vout", s.vout)); |
|
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); |
|
|
|
|
if (fLong) |
|
|
|
@ -1392,12 +1395,12 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
@@ -1392,12 +1395,12 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
|
|
|
|
BOOST_FOREACH(const COutputEntry& r, listReceived) |
|
|
|
|
{ |
|
|
|
|
string account; |
|
|
|
|
if (pwalletMain->mapAddressBook.count(r.destination)) |
|
|
|
|
account = pwalletMain->mapAddressBook[r.destination].name; |
|
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) |
|
|
|
|
account = pwallet->mapAddressBook[r.destination].name; |
|
|
|
|
if (fAllAccounts || (account == strAccount)) |
|
|
|
|
{ |
|
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
|
if(involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY)) |
|
|
|
|
if(involvesWatchonly || (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) |
|
|
|
|
entry.push_back(Pair("involvesWatchonly", true)); |
|
|
|
|
entry.push_back(Pair("account", account)); |
|
|
|
|
MaybePushAddress(entry, r.destination); |
|
|
|
@ -1415,7 +1418,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
@@ -1415,7 +1418,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
|
|
|
|
entry.push_back(Pair("category", "receive")); |
|
|
|
|
} |
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(r.amount))); |
|
|
|
|
if (pwalletMain->mapAddressBook.count(r.destination)) |
|
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) |
|
|
|
|
entry.push_back(Pair("label", account)); |
|
|
|
|
entry.push_back(Pair("vout", r.vout)); |
|
|
|
|
if (fLong) |
|
|
|
@ -1445,7 +1448,7 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Un
@@ -1445,7 +1448,7 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Un
|
|
|
|
|
|
|
|
|
|
UniValue listtransactions(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 4) |
|
|
|
@ -1538,7 +1541,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
@@ -1538,7 +1541,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
|
|
|
|
|
{ |
|
|
|
|
CWalletTx *const pwtx = (*it).second.first; |
|
|
|
|
if (pwtx != 0) |
|
|
|
|
ListTransactions(*pwtx, strAccount, 0, true, ret, filter); |
|
|
|
|
ListTransactions(pwalletMain, *pwtx, strAccount, 0, true, ret, filter); |
|
|
|
|
CAccountingEntry *const pacentry = (*it).second.second; |
|
|
|
|
if (pacentry != 0) |
|
|
|
|
AcentryToJSON(*pacentry, strAccount, ret); |
|
|
|
@ -1573,7 +1576,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
@@ -1573,7 +1576,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue listaccounts(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 2) |
|
|
|
@ -1652,7 +1655,7 @@ UniValue listaccounts(const JSONRPCRequest& request)
@@ -1652,7 +1655,7 @@ UniValue listaccounts(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue listsinceblock(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
@ -1743,7 +1746,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
@@ -1743,7 +1746,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
|
|
|
|
|
CWalletTx tx = (*it).second; |
|
|
|
|
|
|
|
|
|
if (depth == -1 || tx.GetDepthInMainChain() < depth) |
|
|
|
|
ListTransactions(tx, "*", 0, true, transactions, filter); |
|
|
|
|
ListTransactions(pwalletMain, tx, "*", 0, true, transactions, filter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms]; |
|
|
|
@ -1758,7 +1761,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
@@ -1758,7 +1761,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue gettransaction(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
@ -1833,7 +1836,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
@@ -1833,7 +1836,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
|
|
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
|
|
|
|
|
|
UniValue details(UniValue::VARR); |
|
|
|
|
ListTransactions(wtx, "*", 0, false, details, filter); |
|
|
|
|
ListTransactions(pwalletMain, wtx, "*", 0, false, details, filter); |
|
|
|
|
entry.push_back(Pair("details", details)); |
|
|
|
|
|
|
|
|
|
string strHex = EncodeHexTx(static_cast<CTransaction>(wtx), RPCSerializationFlags()); |
|
|
|
@ -1844,7 +1847,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
@@ -1844,7 +1847,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue abandontransaction(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
@ -1879,7 +1882,7 @@ UniValue abandontransaction(const JSONRPCRequest& request)
@@ -1879,7 +1882,7 @@ UniValue abandontransaction(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue backupwallet(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
@ -1905,14 +1908,14 @@ UniValue backupwallet(const JSONRPCRequest& request)
@@ -1905,14 +1908,14 @@ UniValue backupwallet(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue keypoolrefill(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
|
throw runtime_error( |
|
|
|
|
"keypoolrefill ( newsize )\n" |
|
|
|
|
"\nFills the keypool." |
|
|
|
|
+ HelpRequiringPassphrase() + "\n" |
|
|
|
|
+ HelpRequiringPassphrase(pwalletMain) + "\n" |
|
|
|
|
"\nArguments\n" |
|
|
|
|
"1. newsize (numeric, optional, default=100) The new keypool size\n" |
|
|
|
|
"\nExamples:\n" |
|
|
|
@ -1930,7 +1933,7 @@ UniValue keypoolrefill(const JSONRPCRequest& request)
@@ -1930,7 +1933,7 @@ UniValue keypoolrefill(const JSONRPCRequest& request)
|
|
|
|
|
kpSize = (unsigned int)request.params[0].get_int(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked(); |
|
|
|
|
EnsureWalletIsUnlocked(pwalletMain); |
|
|
|
|
pwalletMain->TopUpKeyPool(kpSize); |
|
|
|
|
|
|
|
|
|
if (pwalletMain->GetKeyPoolSize() < kpSize) |
|
|
|
@ -1949,7 +1952,7 @@ static void LockWallet(CWallet* pWallet)
@@ -1949,7 +1952,7 @@ static void LockWallet(CWallet* pWallet)
|
|
|
|
|
|
|
|
|
|
UniValue walletpassphrase(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 2)) |
|
|
|
@ -2009,7 +2012,7 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
@@ -2009,7 +2012,7 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue walletpassphrasechange(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 2)) |
|
|
|
@ -2055,7 +2058,7 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request)
@@ -2055,7 +2058,7 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue walletlock(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 0)) |
|
|
|
@ -2094,7 +2097,7 @@ UniValue walletlock(const JSONRPCRequest& request)
@@ -2094,7 +2097,7 @@ UniValue walletlock(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue encryptwallet(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (!pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 1)) |
|
|
|
@ -2151,7 +2154,7 @@ UniValue encryptwallet(const JSONRPCRequest& request)
@@ -2151,7 +2154,7 @@ UniValue encryptwallet(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue lockunspent(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
@ -2240,7 +2243,7 @@ UniValue lockunspent(const JSONRPCRequest& request)
@@ -2240,7 +2243,7 @@ UniValue lockunspent(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue listlockunspent(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 0) |
|
|
|
@ -2289,7 +2292,7 @@ UniValue listlockunspent(const JSONRPCRequest& request)
@@ -2289,7 +2292,7 @@ UniValue listlockunspent(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue settxfee(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) |
|
|
|
@ -2316,7 +2319,7 @@ UniValue settxfee(const JSONRPCRequest& request)
@@ -2316,7 +2319,7 @@ UniValue settxfee(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue getwalletinfo(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 0) |
|
|
|
@ -2362,7 +2365,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
@@ -2362,7 +2365,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue resendwallettransactions(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 0) |
|
|
|
@ -2390,7 +2393,7 @@ UniValue resendwallettransactions(const JSONRPCRequest& request)
@@ -2390,7 +2393,7 @@ UniValue resendwallettransactions(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue listunspent(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 4) |
|
|
|
@ -2514,7 +2517,7 @@ UniValue listunspent(const JSONRPCRequest& request)
@@ -2514,7 +2517,7 @@ UniValue listunspent(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
UniValue fundrawtransaction(const JSONRPCRequest& request) |
|
|
|
|
{ |
|
|
|
|
if (!EnsureWalletIsAvailable(request.fHelp)) |
|
|
|
|
if (!EnsureWalletIsAvailable(pwalletMain, request.fHelp)) |
|
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
@ -2674,7 +2677,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
@@ -2674,7 +2677,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
|
|
|
|
|
// calculation, but we should be able to refactor after priority is removed).
|
|
|
|
|
// NOTE: this requires that all inputs must be in mapWallet (eg the tx should
|
|
|
|
|
// be IsAllFromMe).
|
|
|
|
|
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx) |
|
|
|
|
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, CWallet &wallet) |
|
|
|
|
{ |
|
|
|
|
CMutableTransaction txNew(tx); |
|
|
|
|
std::vector<pair<CWalletTx *, unsigned int>> vCoins; |
|
|
|
@ -2682,11 +2685,11 @@ int64_t CalculateMaximumSignedTxSize(const CTransaction &tx)
@@ -2682,11 +2685,11 @@ int64_t CalculateMaximumSignedTxSize(const CTransaction &tx)
|
|
|
|
|
// IsAllFromMe(ISMINE_SPENDABLE), so every input should already be in our
|
|
|
|
|
// wallet, with a valid index into the vout array.
|
|
|
|
|
for (auto& input : tx.vin) { |
|
|
|
|
const auto mi = pwalletMain->mapWallet.find(input.prevout.hash); |
|
|
|
|
assert(mi != pwalletMain->mapWallet.end() && input.prevout.n < mi->second.tx->vout.size()); |
|
|
|
|
const auto mi = wallet.mapWallet.find(input.prevout.hash); |
|
|
|
|
assert(mi != wallet.mapWallet.end() && input.prevout.n < mi->second.tx->vout.size()); |
|
|
|
|
vCoins.emplace_back(make_pair(&(mi->second), input.prevout.n)); |
|
|
|
|
} |
|
|
|
|
if (!pwalletMain->DummySignTx(txNew, vCoins)) { |
|
|
|
|
if (!wallet.DummySignTx(txNew, vCoins)) { |
|
|
|
|
// This should never happen, because IsAllFromMe(ISMINE_SPENDABLE)
|
|
|
|
|
// implies that we can sign for every input.
|
|
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction contains inputs that cannot be signed"); |
|
|
|
@ -2802,7 +2805,7 @@ UniValue bumpfee(const JSONRPCRequest& request)
@@ -2802,7 +2805,7 @@ UniValue bumpfee(const JSONRPCRequest& request)
|
|
|
|
|
|
|
|
|
|
// Calculate the expected size of the new transaction.
|
|
|
|
|
int64_t txSize = GetVirtualTransactionSize(*(wtx.tx)); |
|
|
|
|
const int64_t maxNewTxSize = CalculateMaximumSignedTxSize(*wtx.tx); |
|
|
|
|
const int64_t maxNewTxSize = CalculateMaximumSignedTxSize(*wtx.tx, *pwallet); |
|
|
|
|
|
|
|
|
|
// optional parameters
|
|
|
|
|
bool specifiedConfirmTarget = false; |
|
|
|
|