|
|
@ -43,8 +43,7 @@ std::string HelpRequiringPassphrase(CWallet * const pwallet) |
|
|
|
|
|
|
|
|
|
|
|
bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException) |
|
|
|
bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!pwallet) |
|
|
|
if (!pwallet) { |
|
|
|
{ |
|
|
|
|
|
|
|
if (!avoidException) |
|
|
|
if (!avoidException) |
|
|
|
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); |
|
|
|
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); |
|
|
|
else |
|
|
|
else |
|
|
@ -55,9 +54,10 @@ bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException) |
|
|
|
|
|
|
|
|
|
|
|
void EnsureWalletIsUnlocked(CWallet * const pwallet) |
|
|
|
void EnsureWalletIsUnlocked(CWallet * const pwallet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pwallet->IsLocked()) |
|
|
|
if (pwallet->IsLocked()) { |
|
|
|
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); |
|
|
|
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) |
|
|
|
void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -110,8 +110,9 @@ UniValue getnewaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -135,13 +136,15 @@ UniValue getnewaddress(const JSONRPCRequest& request) |
|
|
|
if (request.params.size() > 0) |
|
|
|
if (request.params.size() > 0) |
|
|
|
strAccount = AccountFromValue(request.params[0]); |
|
|
|
strAccount = AccountFromValue(request.params[0]); |
|
|
|
|
|
|
|
|
|
|
|
if (!pwallet->IsLocked()) |
|
|
|
if (!pwallet->IsLocked()) { |
|
|
|
pwallet->TopUpKeyPool(); |
|
|
|
pwallet->TopUpKeyPool(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Generate a new key that is added to wallet
|
|
|
|
// Generate a new key that is added to wallet
|
|
|
|
CPubKey newKey; |
|
|
|
CPubKey newKey; |
|
|
|
if (!pwallet->GetKeyFromPool(newKey)) |
|
|
|
if (!pwallet->GetKeyFromPool(newKey)) { |
|
|
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); |
|
|
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); |
|
|
|
|
|
|
|
} |
|
|
|
CKeyID keyID = newKey.GetID(); |
|
|
|
CKeyID keyID = newKey.GetID(); |
|
|
|
|
|
|
|
|
|
|
|
pwallet->SetAddressBook(keyID, strAccount, "receive"); |
|
|
|
pwallet->SetAddressBook(keyID, strAccount, "receive"); |
|
|
@ -164,8 +167,9 @@ UniValue getaccountaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -198,8 +202,9 @@ UniValue getrawchangeaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -215,8 +220,9 @@ UniValue getrawchangeaddress(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
if (!pwallet->IsLocked()) |
|
|
|
if (!pwallet->IsLocked()) { |
|
|
|
pwallet->TopUpKeyPool(); |
|
|
|
pwallet->TopUpKeyPool(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CReserveKey reservekey(pwallet); |
|
|
|
CReserveKey reservekey(pwallet); |
|
|
|
CPubKey vchPubKey; |
|
|
|
CPubKey vchPubKey; |
|
|
@ -235,8 +241,9 @@ UniValue setaccount(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -261,15 +268,14 @@ UniValue setaccount(const JSONRPCRequest& request) |
|
|
|
strAccount = AccountFromValue(request.params[1]); |
|
|
|
strAccount = AccountFromValue(request.params[1]); |
|
|
|
|
|
|
|
|
|
|
|
// Only add the account if the address is yours.
|
|
|
|
// Only add the account if the address is yours.
|
|
|
|
if (IsMine(*pwallet, address.Get())) |
|
|
|
if (IsMine(*pwallet, address.Get())) { |
|
|
|
{ |
|
|
|
|
|
|
|
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
|
|
|
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
|
|
|
if (pwallet->mapAddressBook.count(address.Get())) |
|
|
|
if (pwallet->mapAddressBook.count(address.Get())) { |
|
|
|
{ |
|
|
|
|
|
|
|
string strOldAccount = pwallet->mapAddressBook[address.Get()].name; |
|
|
|
string strOldAccount = pwallet->mapAddressBook[address.Get()].name; |
|
|
|
if (address == GetAccountAddress(pwallet, strOldAccount)) |
|
|
|
if (address == GetAccountAddress(pwallet, strOldAccount)) { |
|
|
|
GetAccountAddress(pwallet, strOldAccount, true); |
|
|
|
GetAccountAddress(pwallet, strOldAccount, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
pwallet->SetAddressBook(address.Get(), strAccount, "receive"); |
|
|
|
pwallet->SetAddressBook(address.Get(), strAccount, "receive"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -283,8 +289,9 @@ UniValue getaccount(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -307,8 +314,9 @@ UniValue getaccount(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
string strAccount; |
|
|
|
string strAccount; |
|
|
|
map<CTxDestination, CAddressBookData>::iterator mi = pwallet->mapAddressBook.find(address.Get()); |
|
|
|
map<CTxDestination, CAddressBookData>::iterator mi = pwallet->mapAddressBook.find(address.Get()); |
|
|
|
if (mi != pwallet->mapAddressBook.end() && !(*mi).second.name.empty()) |
|
|
|
if (mi != pwallet->mapAddressBook.end() && !(*mi).second.name.empty()) { |
|
|
|
strAccount = (*mi).second.name; |
|
|
|
strAccount = (*mi).second.name; |
|
|
|
|
|
|
|
} |
|
|
|
return strAccount; |
|
|
|
return strAccount; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -317,8 +325,9 @@ UniValue getaddressesbyaccount(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -342,8 +351,7 @@ UniValue getaddressesbyaccount(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
// Find all addresses that have the given account
|
|
|
|
// Find all addresses that have the given account
|
|
|
|
UniValue ret(UniValue::VARR); |
|
|
|
UniValue ret(UniValue::VARR); |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwallet->mapAddressBook) |
|
|
|
for (const std::pair<CBitcoinAddress, CAddressBookData>& item : pwallet->mapAddressBook) { |
|
|
|
{ |
|
|
|
|
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
const string& strName = item.second.name; |
|
|
|
const string& strName = item.second.name; |
|
|
|
if (strName == strAccount) |
|
|
|
if (strName == strAccount) |
|
|
@ -363,8 +371,9 @@ static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CA |
|
|
|
if (nValue > curBalance) |
|
|
|
if (nValue > curBalance) |
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); |
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); |
|
|
|
|
|
|
|
|
|
|
|
if (pwallet->GetBroadcastTransactions() && !g_connman) |
|
|
|
if (pwallet->GetBroadcastTransactions() && !g_connman) { |
|
|
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
|
|
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Parse Bitcoin address
|
|
|
|
// Parse Bitcoin address
|
|
|
|
CScript scriptPubKey = GetScriptForDestination(address); |
|
|
|
CScript scriptPubKey = GetScriptForDestination(address); |
|
|
@ -393,8 +402,9 @@ UniValue sendtoaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) |
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -453,8 +463,9 @@ UniValue listaddressgroupings(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
if (request.fHelp) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -483,8 +494,7 @@ UniValue listaddressgroupings(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue jsonGroupings(UniValue::VARR); |
|
|
|
UniValue jsonGroupings(UniValue::VARR); |
|
|
|
map<CTxDestination, CAmount> balances = pwallet->GetAddressBalances(); |
|
|
|
map<CTxDestination, CAmount> balances = pwallet->GetAddressBalances(); |
|
|
|
BOOST_FOREACH(set<CTxDestination> grouping, pwallet->GetAddressGroupings()) |
|
|
|
for (set<CTxDestination> grouping : pwallet->GetAddressGroupings()) { |
|
|
|
{ |
|
|
|
|
|
|
|
UniValue jsonGrouping(UniValue::VARR); |
|
|
|
UniValue jsonGrouping(UniValue::VARR); |
|
|
|
BOOST_FOREACH(CTxDestination address, grouping) |
|
|
|
BOOST_FOREACH(CTxDestination address, grouping) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -492,9 +502,10 @@ UniValue listaddressgroupings(const JSONRPCRequest& request) |
|
|
|
addressInfo.push_back(CBitcoinAddress(address).ToString()); |
|
|
|
addressInfo.push_back(CBitcoinAddress(address).ToString()); |
|
|
|
addressInfo.push_back(ValueFromAmount(balances[address])); |
|
|
|
addressInfo.push_back(ValueFromAmount(balances[address])); |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pwallet->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwallet->mapAddressBook.end()) |
|
|
|
if (pwallet->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwallet->mapAddressBook.end()) { |
|
|
|
addressInfo.push_back(pwallet->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name); |
|
|
|
addressInfo.push_back(pwallet->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
jsonGrouping.push_back(addressInfo); |
|
|
|
jsonGrouping.push_back(addressInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
jsonGroupings.push_back(jsonGrouping); |
|
|
|
jsonGroupings.push_back(jsonGrouping); |
|
|
@ -506,8 +517,9 @@ UniValue signmessage(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 2) |
|
|
|
if (request.fHelp || request.params.size() != 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -546,8 +558,9 @@ UniValue signmessage(const JSONRPCRequest& request) |
|
|
|
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); |
|
|
|
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); |
|
|
|
|
|
|
|
|
|
|
|
CKey key; |
|
|
|
CKey key; |
|
|
|
if (!pwallet->GetKey(keyID, key)) |
|
|
|
if (!pwallet->GetKey(keyID, key)) { |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available"); |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CHashWriter ss(SER_GETHASH, 0); |
|
|
|
CHashWriter ss(SER_GETHASH, 0); |
|
|
|
ss << strMessageMagic; |
|
|
|
ss << strMessageMagic; |
|
|
@ -564,8 +577,9 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -594,8 +608,9 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request) |
|
|
|
if (!address.IsValid()) |
|
|
|
if (!address.IsValid()) |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); |
|
|
|
CScript scriptPubKey = GetScriptForDestination(address.Get()); |
|
|
|
CScript scriptPubKey = GetScriptForDestination(address.Get()); |
|
|
|
if (!IsMine(*pwallet, scriptPubKey)) |
|
|
|
if (!IsMine(*pwallet, scriptPubKey)) { |
|
|
|
return ValueFromAmount(0); |
|
|
|
return ValueFromAmount(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Minimum confirmations
|
|
|
|
// Minimum confirmations
|
|
|
|
int nMinDepth = 1; |
|
|
|
int nMinDepth = 1; |
|
|
@ -604,9 +619,8 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
// Tally
|
|
|
|
// Tally
|
|
|
|
CAmount nAmount = 0; |
|
|
|
CAmount nAmount = 0; |
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) |
|
|
|
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { |
|
|
|
{ |
|
|
|
const CWalletTx& wtx = pairWtx.second; |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
|
|
|
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) |
|
|
|
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
@ -624,8 +638,9 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -660,20 +675,20 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
// Tally
|
|
|
|
// Tally
|
|
|
|
CAmount nAmount = 0; |
|
|
|
CAmount nAmount = 0; |
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) |
|
|
|
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { |
|
|
|
{ |
|
|
|
const CWalletTx& wtx = pairWtx.second; |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
|
|
|
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) |
|
|
|
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.tx->vout) |
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.tx->vout) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CTxDestination address; |
|
|
|
CTxDestination address; |
|
|
|
if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwallet, address) && setAddress.count(address)) |
|
|
|
if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwallet, address) && setAddress.count(address)) { |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
nAmount += txout.nValue; |
|
|
|
nAmount += txout.nValue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ValueFromAmount(nAmount); |
|
|
|
return ValueFromAmount(nAmount); |
|
|
|
} |
|
|
|
} |
|
|
@ -683,8 +698,9 @@ UniValue getbalance(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -740,9 +756,8 @@ UniValue getbalance(const JSONRPCRequest& request) |
|
|
|
// TxIns spending from the wallet. This also has fewer restrictions on
|
|
|
|
// TxIns spending from the wallet. This also has fewer restrictions on
|
|
|
|
// which unconfirmed transactions are considered trusted.
|
|
|
|
// which unconfirmed transactions are considered trusted.
|
|
|
|
CAmount nBalance = 0; |
|
|
|
CAmount nBalance = 0; |
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) |
|
|
|
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { |
|
|
|
{ |
|
|
|
const CWalletTx& wtx = pairWtx.second; |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
|
|
|
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0) |
|
|
|
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
@ -774,8 +789,9 @@ UniValue getunconfirmedbalance(const JSONRPCRequest &request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 0) |
|
|
|
if (request.fHelp || request.params.size() > 0) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -792,8 +808,9 @@ UniValue movecmd(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 3 || request.params.size() > 5) |
|
|
|
if (request.fHelp || request.params.size() < 3 || request.params.size() > 5) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -830,8 +847,9 @@ UniValue movecmd(const JSONRPCRequest& request) |
|
|
|
if (request.params.size() > 4) |
|
|
|
if (request.params.size() > 4) |
|
|
|
strComment = request.params[4].get_str(); |
|
|
|
strComment = request.params[4].get_str(); |
|
|
|
|
|
|
|
|
|
|
|
if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) |
|
|
|
if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) { |
|
|
|
throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); |
|
|
|
throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -841,8 +859,9 @@ UniValue sendfrom(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 3 || request.params.size() > 6) |
|
|
|
if (request.fHelp || request.params.size() < 3 || request.params.size() > 6) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -910,8 +929,9 @@ UniValue sendmany(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) |
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -951,8 +971,9 @@ UniValue sendmany(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
if (pwallet->GetBroadcastTransactions() && !g_connman) |
|
|
|
if (pwallet->GetBroadcastTransactions() && !g_connman) { |
|
|
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
|
|
|
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string strAccount = AccountFromValue(request.params[0]); |
|
|
|
string strAccount = AccountFromValue(request.params[0]); |
|
|
|
UniValue sendTo = request.params[1].get_obj(); |
|
|
|
UniValue sendTo = request.params[1].get_obj(); |
|
|
@ -1032,8 +1053,9 @@ UniValue addmultisigaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) |
|
|
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1130,8 +1152,9 @@ UniValue addwitnessaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1205,9 +1228,8 @@ UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bool fByA |
|
|
|
|
|
|
|
|
|
|
|
// Tally
|
|
|
|
// Tally
|
|
|
|
map<CBitcoinAddress, tallyitem> mapTally; |
|
|
|
map<CBitcoinAddress, tallyitem> mapTally; |
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) |
|
|
|
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { |
|
|
|
{ |
|
|
|
const CWalletTx& wtx = pairWtx.second; |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) |
|
|
|
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -1238,8 +1260,7 @@ UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bool fByA |
|
|
|
// Reply
|
|
|
|
// Reply
|
|
|
|
UniValue ret(UniValue::VARR); |
|
|
|
UniValue ret(UniValue::VARR); |
|
|
|
map<string, tallyitem> mapAccountTally; |
|
|
|
map<string, tallyitem> mapAccountTally; |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwallet->mapAddressBook) |
|
|
|
for (const std::pair<CBitcoinAddress, CAddressBookData>& item : pwallet->mapAddressBook) { |
|
|
|
{ |
|
|
|
|
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
const string& strAccount = item.second.name; |
|
|
|
const string& strAccount = item.second.name; |
|
|
|
map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address); |
|
|
|
map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address); |
|
|
@ -1310,8 +1331,9 @@ UniValue listreceivedbyaddress(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1354,8 +1376,9 @@ UniValue listreceivedbyaccount(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
if (request.fHelp || request.params.size() > 3) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1414,14 +1437,16 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const strin |
|
|
|
BOOST_FOREACH(const COutputEntry& s, listSent) |
|
|
|
BOOST_FOREACH(const COutputEntry& s, listSent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
if(involvesWatchonly || (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) |
|
|
|
if (involvesWatchonly || (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) { |
|
|
|
entry.push_back(Pair("involvesWatchonly", true)); |
|
|
|
entry.push_back(Pair("involvesWatchonly", true)); |
|
|
|
|
|
|
|
} |
|
|
|
entry.push_back(Pair("account", strSentAccount)); |
|
|
|
entry.push_back(Pair("account", strSentAccount)); |
|
|
|
MaybePushAddress(entry, s.destination); |
|
|
|
MaybePushAddress(entry, s.destination); |
|
|
|
entry.push_back(Pair("category", "send")); |
|
|
|
entry.push_back(Pair("category", "send")); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); |
|
|
|
if (pwallet->mapAddressBook.count(s.destination)) |
|
|
|
if (pwallet->mapAddressBook.count(s.destination)) { |
|
|
|
entry.push_back(Pair("label", pwallet->mapAddressBook[s.destination].name)); |
|
|
|
entry.push_back(Pair("label", pwallet->mapAddressBook[s.destination].name)); |
|
|
|
|
|
|
|
} |
|
|
|
entry.push_back(Pair("vout", s.vout)); |
|
|
|
entry.push_back(Pair("vout", s.vout)); |
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); |
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); |
|
|
|
if (fLong) |
|
|
|
if (fLong) |
|
|
@ -1437,13 +1462,15 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const strin |
|
|
|
BOOST_FOREACH(const COutputEntry& r, listReceived) |
|
|
|
BOOST_FOREACH(const COutputEntry& r, listReceived) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string account; |
|
|
|
string account; |
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) |
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) { |
|
|
|
account = pwallet->mapAddressBook[r.destination].name; |
|
|
|
account = pwallet->mapAddressBook[r.destination].name; |
|
|
|
|
|
|
|
} |
|
|
|
if (fAllAccounts || (account == strAccount)) |
|
|
|
if (fAllAccounts || (account == strAccount)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
if(involvesWatchonly || (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) |
|
|
|
if (involvesWatchonly || (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) { |
|
|
|
entry.push_back(Pair("involvesWatchonly", true)); |
|
|
|
entry.push_back(Pair("involvesWatchonly", true)); |
|
|
|
|
|
|
|
} |
|
|
|
entry.push_back(Pair("account", account)); |
|
|
|
entry.push_back(Pair("account", account)); |
|
|
|
MaybePushAddress(entry, r.destination); |
|
|
|
MaybePushAddress(entry, r.destination); |
|
|
|
if (wtx.IsCoinBase()) |
|
|
|
if (wtx.IsCoinBase()) |
|
|
@ -1460,8 +1487,9 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const strin |
|
|
|
entry.push_back(Pair("category", "receive")); |
|
|
|
entry.push_back(Pair("category", "receive")); |
|
|
|
} |
|
|
|
} |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(r.amount))); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(r.amount))); |
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) |
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) { |
|
|
|
entry.push_back(Pair("label", account)); |
|
|
|
entry.push_back(Pair("label", account)); |
|
|
|
|
|
|
|
} |
|
|
|
entry.push_back(Pair("vout", r.vout)); |
|
|
|
entry.push_back(Pair("vout", r.vout)); |
|
|
|
if (fLong) |
|
|
|
if (fLong) |
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
|
WalletTxToJSON(wtx, entry); |
|
|
@ -1492,8 +1520,9 @@ UniValue listtransactions(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 4) |
|
|
|
if (request.fHelp || request.params.size() > 4) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1622,8 +1651,9 @@ UniValue listaccounts(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1659,14 +1689,14 @@ UniValue listaccounts(const JSONRPCRequest& request) |
|
|
|
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY; |
|
|
|
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY; |
|
|
|
|
|
|
|
|
|
|
|
map<string, CAmount> mapAccountBalances; |
|
|
|
map<string, CAmount> mapAccountBalances; |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwallet->mapAddressBook) { |
|
|
|
for (const std::pair<CTxDestination, CAddressBookData>& entry : pwallet->mapAddressBook) { |
|
|
|
if (IsMine(*pwallet, entry.first) & includeWatchonly) // This address belongs to me
|
|
|
|
if (IsMine(*pwallet, entry.first) & includeWatchonly) { // This address belongs to me
|
|
|
|
mapAccountBalances[entry.second.name] = 0; |
|
|
|
mapAccountBalances[entry.second.name] = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) |
|
|
|
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { |
|
|
|
{ |
|
|
|
const CWalletTx& wtx = pairWtx.second; |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
|
|
|
|
CAmount nFee; |
|
|
|
CAmount nFee; |
|
|
|
string strSentAccount; |
|
|
|
string strSentAccount; |
|
|
|
list<COutputEntry> listReceived; |
|
|
|
list<COutputEntry> listReceived; |
|
|
@ -1681,8 +1711,9 @@ UniValue listaccounts(const JSONRPCRequest& request) |
|
|
|
if (nDepth >= nMinDepth) |
|
|
|
if (nDepth >= nMinDepth) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const COutputEntry& r, listReceived) |
|
|
|
BOOST_FOREACH(const COutputEntry& r, listReceived) |
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) |
|
|
|
if (pwallet->mapAddressBook.count(r.destination)) { |
|
|
|
mapAccountBalances[pwallet->mapAddressBook[r.destination].name] += r.amount; |
|
|
|
mapAccountBalances[pwallet->mapAddressBook[r.destination].name] += r.amount; |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
mapAccountBalances[""] += r.amount; |
|
|
|
mapAccountBalances[""] += r.amount; |
|
|
|
} |
|
|
|
} |
|
|
@ -1703,8 +1734,9 @@ UniValue listsinceblock(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
if (request.fHelp) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1789,9 +1821,8 @@ UniValue listsinceblock(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
UniValue transactions(UniValue::VARR); |
|
|
|
UniValue transactions(UniValue::VARR); |
|
|
|
|
|
|
|
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); it++) |
|
|
|
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { |
|
|
|
{ |
|
|
|
CWalletTx tx = pairWtx.second; |
|
|
|
CWalletTx tx = (*it).second; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (depth == -1 || tx.GetDepthInMainChain() < depth) |
|
|
|
if (depth == -1 || tx.GetDepthInMainChain() < depth) |
|
|
|
ListTransactions(pwallet, tx, "*", 0, true, transactions, filter); |
|
|
|
ListTransactions(pwallet, tx, "*", 0, true, transactions, filter); |
|
|
@ -1811,8 +1842,9 @@ UniValue gettransaction(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1870,8 +1902,9 @@ UniValue gettransaction(const JSONRPCRequest& request) |
|
|
|
filter = filter | ISMINE_WATCH_ONLY; |
|
|
|
filter = filter | ISMINE_WATCH_ONLY; |
|
|
|
|
|
|
|
|
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
UniValue entry(UniValue::VOBJ); |
|
|
|
if (!pwallet->mapWallet.count(hash)) |
|
|
|
if (!pwallet->mapWallet.count(hash)) { |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); |
|
|
|
|
|
|
|
} |
|
|
|
const CWalletTx& wtx = pwallet->mapWallet[hash]; |
|
|
|
const CWalletTx& wtx = pwallet->mapWallet[hash]; |
|
|
|
|
|
|
|
|
|
|
|
CAmount nCredit = wtx.GetCredit(filter); |
|
|
|
CAmount nCredit = wtx.GetCredit(filter); |
|
|
@ -1899,8 +1932,9 @@ UniValue abandontransaction(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1923,10 +1957,12 @@ UniValue abandontransaction(const JSONRPCRequest& request) |
|
|
|
uint256 hash; |
|
|
|
uint256 hash; |
|
|
|
hash.SetHex(request.params[0].get_str()); |
|
|
|
hash.SetHex(request.params[0].get_str()); |
|
|
|
|
|
|
|
|
|
|
|
if (!pwallet->mapWallet.count(hash)) |
|
|
|
if (!pwallet->mapWallet.count(hash)) { |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); |
|
|
|
if (!pwallet->AbandonTransaction(hash)) |
|
|
|
} |
|
|
|
|
|
|
|
if (!pwallet->AbandonTransaction(hash)) { |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
} |
|
|
|
} |
|
|
@ -1936,8 +1972,9 @@ UniValue backupwallet(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
if (request.fHelp || request.params.size() != 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1953,8 +1990,9 @@ UniValue backupwallet(const JSONRPCRequest& request) |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
string strDest = request.params[0].get_str(); |
|
|
|
string strDest = request.params[0].get_str(); |
|
|
|
if (!pwallet->BackupWallet(strDest)) |
|
|
|
if (!pwallet->BackupWallet(strDest)) { |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
} |
|
|
|
} |
|
|
@ -1964,8 +2002,9 @@ UniValue keypoolrefill(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
if (request.fHelp || request.params.size() > 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -1992,8 +2031,9 @@ UniValue keypoolrefill(const JSONRPCRequest& request) |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
pwallet->TopUpKeyPool(kpSize); |
|
|
|
pwallet->TopUpKeyPool(kpSize); |
|
|
|
|
|
|
|
|
|
|
|
if (pwallet->GetKeyPoolSize() < kpSize) |
|
|
|
if (pwallet->GetKeyPoolSize() < kpSize) { |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); |
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
} |
|
|
|
} |
|
|
@ -2010,10 +2050,11 @@ UniValue walletpassphrase(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) |
|
|
|
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"walletpassphrase \"passphrase\" timeout\n" |
|
|
|
"walletpassphrase \"passphrase\" timeout\n" |
|
|
|
"\nStores the wallet decryption key in memory for 'timeout' seconds.\n" |
|
|
|
"\nStores the wallet decryption key in memory for 'timeout' seconds.\n" |
|
|
@ -2032,13 +2073,15 @@ UniValue walletpassphrase(const JSONRPCRequest& request) |
|
|
|
"\nAs json rpc call\n" |
|
|
|
"\nAs json rpc call\n" |
|
|
|
+ HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60") |
|
|
|
+ HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
if (request.fHelp) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
if (!pwallet->IsCrypted()) |
|
|
|
if (!pwallet->IsCrypted()) { |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called."); |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Note that the walletpassphrase is stored in request.params[0] which is not mlock()ed
|
|
|
|
// Note that the walletpassphrase is stored in request.params[0] which is not mlock()ed
|
|
|
|
SecureString strWalletPass; |
|
|
|
SecureString strWalletPass; |
|
|
@ -2049,9 +2092,10 @@ UniValue walletpassphrase(const JSONRPCRequest& request) |
|
|
|
|
|
|
|
|
|
|
|
if (strWalletPass.length() > 0) |
|
|
|
if (strWalletPass.length() > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!pwallet->Unlock(strWalletPass)) |
|
|
|
if (!pwallet->Unlock(strWalletPass)) { |
|
|
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); |
|
|
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"walletpassphrase <passphrase> <timeout>\n" |
|
|
|
"walletpassphrase <passphrase> <timeout>\n" |
|
|
@ -2071,10 +2115,11 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) |
|
|
|
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n" |
|
|
|
"walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n" |
|
|
|
"\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n" |
|
|
|
"\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n" |
|
|
@ -2085,13 +2130,15 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request) |
|
|
|
+ HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"") |
|
|
|
+ HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"") |
|
|
|
+ HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"") |
|
|
|
+ HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
if (request.fHelp) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
if (!pwallet->IsCrypted()) |
|
|
|
if (!pwallet->IsCrypted()) { |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
|
|
|
|
// TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
|
|
|
|
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
|
|
|
|
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
|
|
|
@ -2108,8 +2155,9 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request) |
|
|
|
"walletpassphrasechange <oldpassphrase> <newpassphrase>\n" |
|
|
|
"walletpassphrasechange <oldpassphrase> <newpassphrase>\n" |
|
|
|
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>."); |
|
|
|
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>."); |
|
|
|
|
|
|
|
|
|
|
|
if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) |
|
|
|
if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) { |
|
|
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); |
|
|
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
} |
|
|
|
} |
|
|
@ -2119,10 +2167,11 @@ UniValue walletlock(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) |
|
|
|
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) { |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"walletlock\n" |
|
|
|
"walletlock\n" |
|
|
|
"\nRemoves the wallet encryption key from memory, locking the wallet.\n" |
|
|
|
"\nRemoves the wallet encryption key from memory, locking the wallet.\n" |
|
|
@ -2138,13 +2187,15 @@ UniValue walletlock(const JSONRPCRequest& request) |
|
|
|
"\nAs json rpc call\n" |
|
|
|
"\nAs json rpc call\n" |
|
|
|
+ HelpExampleRpc("walletlock", "") |
|
|
|
+ HelpExampleRpc("walletlock", "") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
if (request.fHelp) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
if (!pwallet->IsCrypted()) |
|
|
|
if (!pwallet->IsCrypted()) { |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called."); |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pwallet->Lock(); |
|
|
|
pwallet->Lock(); |
|
|
|
pwallet->nRelockTime = 0; |
|
|
|
pwallet->nRelockTime = 0; |
|
|
@ -2157,10 +2208,11 @@ UniValue encryptwallet(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!pwallet->IsCrypted() && (request.fHelp || request.params.size() != 1)) |
|
|
|
if (!pwallet->IsCrypted() && (request.fHelp || request.params.size() != 1)) { |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"encryptwallet \"passphrase\"\n" |
|
|
|
"encryptwallet \"passphrase\"\n" |
|
|
|
"\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n" |
|
|
|
"\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n" |
|
|
@ -2183,13 +2235,15 @@ UniValue encryptwallet(const JSONRPCRequest& request) |
|
|
|
"\nAs a json rpc call\n" |
|
|
|
"\nAs a json rpc call\n" |
|
|
|
+ HelpExampleRpc("encryptwallet", "\"my pass phrase\"") |
|
|
|
+ HelpExampleRpc("encryptwallet", "\"my pass phrase\"") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
LOCK2(cs_main, pwallet->cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp) |
|
|
|
if (request.fHelp) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
if (pwallet->IsCrypted()) |
|
|
|
if (pwallet->IsCrypted()) { |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called."); |
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
|
|
|
|
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
|
|
|
|
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
|
|
|
|
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
|
|
|
@ -2202,8 +2256,9 @@ UniValue encryptwallet(const JSONRPCRequest& request) |
|
|
|
"encryptwallet <passphrase>\n" |
|
|
|
"encryptwallet <passphrase>\n" |
|
|
|
"Encrypts the wallet with <passphrase>."); |
|
|
|
"Encrypts the wallet with <passphrase>."); |
|
|
|
|
|
|
|
|
|
|
|
if (!pwallet->EncryptWallet(strWalletPass)) |
|
|
|
if (!pwallet->EncryptWallet(strWalletPass)) { |
|
|
|
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet."); |
|
|
|
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// BDB seems to have a bad habit of writing old data into
|
|
|
|
// BDB seems to have a bad habit of writing old data into
|
|
|
|
// slack space in .dat files; that is bad if the old data is
|
|
|
|
// slack space in .dat files; that is bad if the old data is
|
|
|
@ -2216,8 +2271,9 @@ UniValue lockunspent(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -2307,8 +2363,9 @@ UniValue listlockunspent(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 0) |
|
|
|
if (request.fHelp || request.params.size() > 0) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -2358,8 +2415,9 @@ UniValue settxfee(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -2387,8 +2445,9 @@ UniValue getwalletinfo(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 0) |
|
|
|
if (request.fHelp || request.params.size() != 0) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -2422,8 +2481,9 @@ UniValue getwalletinfo(const JSONRPCRequest& request) |
|
|
|
obj.push_back(Pair("txcount", (int)pwallet->mapWallet.size())); |
|
|
|
obj.push_back(Pair("txcount", (int)pwallet->mapWallet.size())); |
|
|
|
obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime())); |
|
|
|
obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime())); |
|
|
|
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize())); |
|
|
|
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize())); |
|
|
|
if (pwallet->IsCrypted()) |
|
|
|
if (pwallet->IsCrypted()) { |
|
|
|
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime)); |
|
|
|
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime)); |
|
|
|
|
|
|
|
} |
|
|
|
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()))); |
|
|
|
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()))); |
|
|
|
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; |
|
|
|
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; |
|
|
|
if (!masterKeyID.IsNull()) |
|
|
|
if (!masterKeyID.IsNull()) |
|
|
@ -2435,8 +2495,9 @@ UniValue resendwallettransactions(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() != 0) |
|
|
|
if (request.fHelp || request.params.size() != 0) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -2465,8 +2526,9 @@ UniValue listunspent(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() > 4) |
|
|
|
if (request.fHelp || request.params.size() > 4) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -2565,16 +2627,18 @@ UniValue listunspent(const JSONRPCRequest& request) |
|
|
|
if (fValidAddress) { |
|
|
|
if (fValidAddress) { |
|
|
|
entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); |
|
|
|
entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); |
|
|
|
|
|
|
|
|
|
|
|
if (pwallet->mapAddressBook.count(address)) |
|
|
|
if (pwallet->mapAddressBook.count(address)) { |
|
|
|
entry.push_back(Pair("account", pwallet->mapAddressBook[address].name)); |
|
|
|
entry.push_back(Pair("account", pwallet->mapAddressBook[address].name)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (scriptPubKey.IsPayToScriptHash()) { |
|
|
|
if (scriptPubKey.IsPayToScriptHash()) { |
|
|
|
const CScriptID& hash = boost::get<CScriptID>(address); |
|
|
|
const CScriptID& hash = boost::get<CScriptID>(address); |
|
|
|
CScript redeemScript; |
|
|
|
CScript redeemScript; |
|
|
|
if (pwallet->GetCScript(hash, redeemScript)) |
|
|
|
if (pwallet->GetCScript(hash, redeemScript)) { |
|
|
|
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); |
|
|
|
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); |
|
|
|
entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue))); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue))); |
|
|
@ -2591,8 +2655,9 @@ UniValue fundrawtransaction(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
CWallet * const pwallet = GetWalletForJSONRPCRequest(request); |
|
|
|
|
|
|
|
|
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) |
|
|
|
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
|
|
|
return NullUniValue; |
|
|
|
return NullUniValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
@ -2733,8 +2798,9 @@ UniValue fundrawtransaction(const JSONRPCRequest& request) |
|
|
|
CAmount nFeeOut; |
|
|
|
CAmount nFeeOut; |
|
|
|
string strFailReason; |
|
|
|
string strFailReason; |
|
|
|
|
|
|
|
|
|
|
|
if(!pwallet->FundTransaction(tx, nFeeOut, overrideEstimatedFeerate, feeRate, changePosition, strFailReason, includeWatching, lockUnspents, setSubtractFeeFromOutputs, reserveChangeKey, changeAddress)) |
|
|
|
if (!pwallet->FundTransaction(tx, nFeeOut, overrideEstimatedFeerate, feeRate, changePosition, strFailReason, includeWatching, lockUnspents, setSubtractFeeFromOutputs, reserveChangeKey, changeAddress)) { |
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason); |
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UniValue result(UniValue::VOBJ); |
|
|
|
UniValue result(UniValue::VOBJ); |
|
|
|
result.push_back(Pair("hex", EncodeHexTx(tx))); |
|
|
|
result.push_back(Pair("hex", EncodeHexTx(tx))); |
|
|
|