|
|
@ -13,7 +13,7 @@ |
|
|
|
#include <boost/iostreams/stream.hpp> |
|
|
|
#include <boost/iostreams/stream.hpp> |
|
|
|
#include <boost/algorithm/string.hpp> |
|
|
|
#include <boost/algorithm/string.hpp> |
|
|
|
#ifdef USE_SSL |
|
|
|
#ifdef USE_SSL |
|
|
|
#include <boost/asio/ssl.hpp> |
|
|
|
#include <boost/asio/ssl.hpp> |
|
|
|
#include <boost/filesystem.hpp> |
|
|
|
#include <boost/filesystem.hpp> |
|
|
|
#include <boost/filesystem/fstream.hpp> |
|
|
|
#include <boost/filesystem/fstream.hpp> |
|
|
|
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream; |
|
|
|
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream; |
|
|
@ -342,7 +342,7 @@ Value getnewaddress(const Array& params, bool fHelp) |
|
|
|
strAccount = AccountFromValue(params[0]); |
|
|
|
strAccount = AccountFromValue(params[0]); |
|
|
|
|
|
|
|
|
|
|
|
// Generate a new key that is added to wallet
|
|
|
|
// Generate a new key that is added to wallet
|
|
|
|
string strAddress = PubKeyToAddress(pwalletMain->GetOrReuseKeyFromPool()); |
|
|
|
string strAddress = CBitcoinAddress(pwalletMain->GetOrReuseKeyFromPool()).ToString(); |
|
|
|
|
|
|
|
|
|
|
|
// This could be done in the same main CS as GetKeyFromKeyPool.
|
|
|
|
// This could be done in the same main CS as GetKeyFromKeyPool.
|
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
@ -353,7 +353,7 @@ Value getnewaddress(const Array& params, bool fHelp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// requires cs_main, cs_mapWallet, cs_mapAddressBook locks
|
|
|
|
// requires cs_main, cs_mapWallet, cs_mapAddressBook locks
|
|
|
|
string GetAccountAddress(string strAccount, bool bForceNew=false) |
|
|
|
CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string strAddress; |
|
|
|
string strAddress; |
|
|
|
|
|
|
|
|
|
|
@ -393,16 +393,14 @@ string GetAccountAddress(string strAccount, bool bForceNew=false) |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
account.vchPubKey = pwalletMain->GetOrReuseKeyFromPool(); |
|
|
|
account.vchPubKey = pwalletMain->GetOrReuseKeyFromPool(); |
|
|
|
string strAddress = PubKeyToAddress(account.vchPubKey); |
|
|
|
string strAddress = CBitcoinAddress(account.vchPubKey).ToString(); |
|
|
|
pwalletMain->SetAddressBookName(strAddress, strAccount); |
|
|
|
pwalletMain->SetAddressBookName(strAddress, strAccount); |
|
|
|
walletdb.WriteAccount(strAccount, account); |
|
|
|
walletdb.WriteAccount(strAccount, account); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
strAddress = PubKeyToAddress(account.vchPubKey); |
|
|
|
return CBitcoinAddress(account.vchPubKey); |
|
|
|
|
|
|
|
|
|
|
|
return strAddress; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value getaccountaddress(const Array& params, bool fHelp) |
|
|
|
Value getaccountaddress(const Array& params, bool fHelp) |
|
|
@ -421,7 +419,7 @@ Value getaccountaddress(const Array& params, bool fHelp) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ret = GetAccountAddress(strAccount); |
|
|
|
ret = GetAccountAddress(strAccount).ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
@ -437,9 +435,8 @@ Value setaccount(const Array& params, bool fHelp) |
|
|
|
"Sets the account associated with the given address."); |
|
|
|
"Sets the account associated with the given address."); |
|
|
|
|
|
|
|
|
|
|
|
string strAddress = params[0].get_str(); |
|
|
|
string strAddress = params[0].get_str(); |
|
|
|
uint160 hash160; |
|
|
|
CBitcoinAddress address(strAddress); |
|
|
|
bool isValid = AddressToHash160(strAddress, hash160); |
|
|
|
if (!address.IsValid()) |
|
|
|
if (!isValid) |
|
|
|
|
|
|
|
throw JSONRPCError(-5, "Invalid bitcoin address"); |
|
|
|
throw JSONRPCError(-5, "Invalid bitcoin address"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -452,10 +449,10 @@ Value setaccount(const Array& params, bool fHelp) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pwalletMain->mapAddressBook.count(strAddress)) |
|
|
|
if (pwalletMain->mapAddressBook.count(address)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string strOldAccount = pwalletMain->mapAddressBook[strAddress]; |
|
|
|
string strOldAccount = pwalletMain->mapAddressBook[address]; |
|
|
|
if (strAddress == GetAccountAddress(strOldAccount)) |
|
|
|
if (address == GetAccountAddress(strOldAccount)) |
|
|
|
GetAccountAddress(strOldAccount, true); |
|
|
|
GetAccountAddress(strOldAccount, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -474,11 +471,12 @@ Value getaccount(const Array& params, bool fHelp) |
|
|
|
"Returns the account associated with the given address."); |
|
|
|
"Returns the account associated with the given address."); |
|
|
|
|
|
|
|
|
|
|
|
string strAddress = params[0].get_str(); |
|
|
|
string strAddress = params[0].get_str(); |
|
|
|
|
|
|
|
CBitcoinAddress address(strAddress); |
|
|
|
|
|
|
|
|
|
|
|
string strAccount; |
|
|
|
string strAccount; |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
map<string, string>::iterator mi = pwalletMain->mapAddressBook.find(strAddress); |
|
|
|
map<CBitcoinAddress, string>::iterator mi = pwalletMain->mapAddressBook.find(address); |
|
|
|
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) |
|
|
|
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) |
|
|
|
strAccount = (*mi).second; |
|
|
|
strAccount = (*mi).second; |
|
|
|
} |
|
|
|
} |
|
|
@ -499,17 +497,12 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) |
|
|
|
Array ret; |
|
|
|
Array ret; |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, string)& item, pwalletMain->mapAddressBook) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const string& strAddress = item.first; |
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
const string& strName = item.second; |
|
|
|
const string& strName = item.second; |
|
|
|
if (strName == strAccount) |
|
|
|
if (strName == strAccount) |
|
|
|
{ |
|
|
|
ret.push_back(address.ToString()); |
|
|
|
// We're only adding valid bitcoin addresses and not ip addresses
|
|
|
|
|
|
|
|
CScript scriptPubKey; |
|
|
|
|
|
|
|
if (scriptPubKey.SetBitcoinAddress(strAddress)) |
|
|
|
|
|
|
|
ret.push_back(strAddress); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
@ -578,10 +571,11 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) |
|
|
|
"Returns the total amount received by <bitcoinaddress> in transactions with at least [minconf] confirmations."); |
|
|
|
"Returns the total amount received by <bitcoinaddress> in transactions with at least [minconf] confirmations."); |
|
|
|
|
|
|
|
|
|
|
|
// Bitcoin address
|
|
|
|
// Bitcoin address
|
|
|
|
string strAddress = params[0].get_str(); |
|
|
|
CBitcoinAddress address = CBitcoinAddress(params[0].get_str()); |
|
|
|
CScript scriptPubKey; |
|
|
|
CScript scriptPubKey; |
|
|
|
if (!scriptPubKey.SetBitcoinAddress(strAddress)) |
|
|
|
if (!address.IsValid()) |
|
|
|
throw JSONRPCError(-5, "Invalid bitcoin address"); |
|
|
|
throw JSONRPCError(-5, "Invalid bitcoin address"); |
|
|
|
|
|
|
|
scriptPubKey.SetBitcoinAddress(address); |
|
|
|
if (!IsMine(*pwalletMain,scriptPubKey)) |
|
|
|
if (!IsMine(*pwalletMain,scriptPubKey)) |
|
|
|
return (double)0.0; |
|
|
|
return (double)0.0; |
|
|
|
|
|
|
|
|
|
|
@ -611,22 +605,16 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GetAccountPubKeys(string strAccount, set<CScript>& setPubKey) |
|
|
|
void GetAccountAddresses(string strAccount, set<CBitcoinAddress>& setAddress) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, string)& item, pwalletMain->mapAddressBook) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const string& strAddress = item.first; |
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
const string& strName = item.second; |
|
|
|
const string& strName = item.second; |
|
|
|
if (strName == strAccount) |
|
|
|
if (strName == strAccount) |
|
|
|
{ |
|
|
|
setAddress.insert(address); |
|
|
|
// We're only counting our own valid bitcoin addresses and not ip addresses
|
|
|
|
|
|
|
|
CScript scriptPubKey; |
|
|
|
|
|
|
|
if (scriptPubKey.SetBitcoinAddress(strAddress)) |
|
|
|
|
|
|
|
if (IsMine(*pwalletMain,scriptPubKey)) |
|
|
|
|
|
|
|
setPubKey.insert(scriptPubKey); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -646,8 +634,8 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) |
|
|
|
|
|
|
|
|
|
|
|
// Get the set of pub keys that have the label
|
|
|
|
// Get the set of pub keys that have the label
|
|
|
|
string strAccount = AccountFromValue(params[0]); |
|
|
|
string strAccount = AccountFromValue(params[0]); |
|
|
|
set<CScript> setPubKey; |
|
|
|
set<CBitcoinAddress> setAddress; |
|
|
|
GetAccountPubKeys(strAccount, setPubKey); |
|
|
|
GetAccountAddresses(strAccount, setAddress); |
|
|
|
|
|
|
|
|
|
|
|
// Tally
|
|
|
|
// Tally
|
|
|
|
int64 nAmount = 0; |
|
|
|
int64 nAmount = 0; |
|
|
@ -660,9 +648,12 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout) |
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout) |
|
|
|
if (setPubKey.count(txout.scriptPubKey)) |
|
|
|
{ |
|
|
|
|
|
|
|
CBitcoinAddress address; |
|
|
|
|
|
|
|
if (ExtractAddress(txout.scriptPubKey, pwalletMain, address) && setAddress.count(address)) |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
nAmount += txout.nValue; |
|
|
|
nAmount += txout.nValue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -733,13 +724,13 @@ Value getbalance(const Array& params, bool fHelp) |
|
|
|
int64 allGeneratedImmature, allGeneratedMature, allFee; |
|
|
|
int64 allGeneratedImmature, allGeneratedMature, allFee; |
|
|
|
allGeneratedImmature = allGeneratedMature = allFee = 0; |
|
|
|
allGeneratedImmature = allGeneratedMature = allFee = 0; |
|
|
|
string strSentAccount; |
|
|
|
string strSentAccount; |
|
|
|
list<pair<string, int64> > listReceived; |
|
|
|
list<pair<CBitcoinAddress, int64> > listReceived; |
|
|
|
list<pair<string, int64> > listSent; |
|
|
|
list<pair<CBitcoinAddress, int64> > listSent; |
|
|
|
wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount); |
|
|
|
wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount); |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string,int64)& r, listReceived) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listReceived) |
|
|
|
nBalance += r.second; |
|
|
|
nBalance += r.second; |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string,int64)& r, listSent) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listSent) |
|
|
|
nBalance -= r.second; |
|
|
|
nBalance -= r.second; |
|
|
|
nBalance -= allFee; |
|
|
|
nBalance -= allFee; |
|
|
|
nBalance += allGeneratedMature; |
|
|
|
nBalance += allGeneratedMature; |
|
|
@ -874,23 +865,23 @@ Value sendmany(const Array& params, bool fHelp) |
|
|
|
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) |
|
|
|
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) |
|
|
|
wtx.mapValue["comment"] = params[3].get_str(); |
|
|
|
wtx.mapValue["comment"] = params[3].get_str(); |
|
|
|
|
|
|
|
|
|
|
|
set<string> setAddress; |
|
|
|
set<CBitcoinAddress> setAddress; |
|
|
|
vector<pair<CScript, int64> > vecSend; |
|
|
|
vector<pair<CScript, int64> > vecSend; |
|
|
|
|
|
|
|
|
|
|
|
int64 totalAmount = 0; |
|
|
|
int64 totalAmount = 0; |
|
|
|
BOOST_FOREACH(const Pair& s, sendTo) |
|
|
|
BOOST_FOREACH(const Pair& s, sendTo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint160 hash160; |
|
|
|
CBitcoinAddress address(s.name_); |
|
|
|
string strAddress = s.name_; |
|
|
|
if (!address.IsValid()) |
|
|
|
|
|
|
|
throw JSONRPCError(-5, string("Invalid bitcoin address:")+s.name_); |
|
|
|
|
|
|
|
|
|
|
|
if (setAddress.count(strAddress)) |
|
|
|
if (setAddress.count(address)) |
|
|
|
throw JSONRPCError(-8, string("Invalid parameter, duplicated address: ")+strAddress); |
|
|
|
throw JSONRPCError(-8, string("Invalid parameter, duplicated address: ")+s.name_); |
|
|
|
setAddress.insert(strAddress); |
|
|
|
setAddress.insert(address); |
|
|
|
|
|
|
|
|
|
|
|
CScript scriptPubKey; |
|
|
|
CScript scriptPubKey; |
|
|
|
if (!scriptPubKey.SetBitcoinAddress(strAddress)) |
|
|
|
scriptPubKey.SetBitcoinAddress(address); |
|
|
|
throw JSONRPCError(-5, string("Invalid bitcoin address:")+strAddress); |
|
|
|
int64 nAmount = AmountFromValue(s.value_); |
|
|
|
int64 nAmount = AmountFromValue(s.value_); |
|
|
|
|
|
|
|
totalAmount += nAmount; |
|
|
|
totalAmount += nAmount; |
|
|
|
|
|
|
|
|
|
|
|
vecSend.push_back(make_pair(scriptPubKey, nAmount)); |
|
|
|
vecSend.push_back(make_pair(scriptPubKey, nAmount)); |
|
|
@ -950,7 +941,7 @@ Value ListReceived(const Array& params, bool fByAccounts) |
|
|
|
fIncludeEmpty = params[1].get_bool(); |
|
|
|
fIncludeEmpty = params[1].get_bool(); |
|
|
|
|
|
|
|
|
|
|
|
// Tally
|
|
|
|
// Tally
|
|
|
|
map<uint160, tallyitem> mapTally; |
|
|
|
map<CBitcoinAddress, tallyitem> mapTally; |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) |
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) |
|
|
@ -965,12 +956,11 @@ Value ListReceived(const Array& params, bool fByAccounts) |
|
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout) |
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Only counting our own bitcoin addresses and not ip addresses
|
|
|
|
CBitcoinAddress address; |
|
|
|
uint160 hash160 = txout.scriptPubKey.GetBitcoinAddressHash160(); |
|
|
|
if (!ExtractAddress(txout.scriptPubKey, pwalletMain, address) || !address.IsValid()) |
|
|
|
if (hash160 == 0 || !mapPubKeys.count(hash160)) // IsMine
|
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
tallyitem& item = mapTally[hash160]; |
|
|
|
tallyitem& item = mapTally[address]; |
|
|
|
item.nAmount += txout.nValue; |
|
|
|
item.nAmount += txout.nValue; |
|
|
|
item.nConf = min(item.nConf, nDepth); |
|
|
|
item.nConf = min(item.nConf, nDepth); |
|
|
|
} |
|
|
|
} |
|
|
@ -982,14 +972,11 @@ Value ListReceived(const Array& params, bool fByAccounts) |
|
|
|
map<string, tallyitem> mapAccountTally; |
|
|
|
map<string, tallyitem> mapAccountTally; |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, string)& item, pwalletMain->mapAddressBook) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const string& strAddress = item.first; |
|
|
|
const CBitcoinAddress& address = item.first; |
|
|
|
const string& strAccount = item.second; |
|
|
|
const string& strAccount = item.second; |
|
|
|
uint160 hash160; |
|
|
|
map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address); |
|
|
|
if (!AddressToHash160(strAddress, hash160)) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
map<uint160, tallyitem>::iterator it = mapTally.find(hash160); |
|
|
|
|
|
|
|
if (it == mapTally.end() && !fIncludeEmpty) |
|
|
|
if (it == mapTally.end() && !fIncludeEmpty) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
@ -1010,7 +997,7 @@ Value ListReceived(const Array& params, bool fByAccounts) |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
Object obj; |
|
|
|
Object obj; |
|
|
|
obj.push_back(Pair("address", strAddress)); |
|
|
|
obj.push_back(Pair("address", address.ToString())); |
|
|
|
obj.push_back(Pair("account", strAccount)); |
|
|
|
obj.push_back(Pair("account", strAccount)); |
|
|
|
obj.push_back(Pair("label", strAccount)); // deprecated
|
|
|
|
obj.push_back(Pair("label", strAccount)); // deprecated
|
|
|
|
obj.push_back(Pair("amount", ValueFromAmount(nAmount))); |
|
|
|
obj.push_back(Pair("amount", ValueFromAmount(nAmount))); |
|
|
@ -1073,8 +1060,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe |
|
|
|
{ |
|
|
|
{ |
|
|
|
int64 nGeneratedImmature, nGeneratedMature, nFee; |
|
|
|
int64 nGeneratedImmature, nGeneratedMature, nFee; |
|
|
|
string strSentAccount; |
|
|
|
string strSentAccount; |
|
|
|
list<pair<string, int64> > listReceived; |
|
|
|
list<pair<CBitcoinAddress, int64> > listReceived; |
|
|
|
list<pair<string, int64> > listSent; |
|
|
|
list<pair<CBitcoinAddress, int64> > listSent; |
|
|
|
wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); |
|
|
|
wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); |
|
|
|
|
|
|
|
|
|
|
|
bool fAllAccounts = (strAccount == string("*")); |
|
|
|
bool fAllAccounts = (strAccount == string("*")); |
|
|
@ -1102,11 +1089,11 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe |
|
|
|
// Sent
|
|
|
|
// Sent
|
|
|
|
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) |
|
|
|
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, int64)& s, listSent) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& s, listSent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Object entry; |
|
|
|
Object entry; |
|
|
|
entry.push_back(Pair("account", strSentAccount)); |
|
|
|
entry.push_back(Pair("account", strSentAccount)); |
|
|
|
entry.push_back(Pair("address", s.first)); |
|
|
|
entry.push_back(Pair("address", s.first.ToString())); |
|
|
|
entry.push_back(Pair("category", "send")); |
|
|
|
entry.push_back(Pair("category", "send")); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.second))); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.second))); |
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); |
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee))); |
|
|
@ -1120,7 +1107,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe |
|
|
|
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, int64)& r, listReceived) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& r, listReceived) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string account; |
|
|
|
string account; |
|
|
|
if (pwalletMain->mapAddressBook.count(r.first)) |
|
|
|
if (pwalletMain->mapAddressBook.count(r.first)) |
|
|
@ -1129,7 +1116,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe |
|
|
|
{ |
|
|
|
{ |
|
|
|
Object entry; |
|
|
|
Object entry; |
|
|
|
entry.push_back(Pair("account", account)); |
|
|
|
entry.push_back(Pair("account", account)); |
|
|
|
entry.push_back(Pair("address", r.first)); |
|
|
|
entry.push_back(Pair("address", r.first.ToString())); |
|
|
|
entry.push_back(Pair("category", "receive")); |
|
|
|
entry.push_back(Pair("category", "receive")); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(r.second))); |
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(r.second))); |
|
|
|
if (fLong) |
|
|
|
if (fLong) |
|
|
@ -1212,7 +1199,7 @@ Value listtransactions(const Array& params, bool fHelp) |
|
|
|
} |
|
|
|
} |
|
|
|
// ret is now newest to oldest
|
|
|
|
// ret is now newest to oldest
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Make sure we return only last nCount items (sends-to-self might give us an extra):
|
|
|
|
// Make sure we return only last nCount items (sends-to-self might give us an extra):
|
|
|
|
if (ret.size() > nCount) |
|
|
|
if (ret.size() > nCount) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1240,9 +1227,8 @@ Value listaccounts(const Array& params, bool fHelp) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapWallet) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, string)& entry, pwalletMain->mapAddressBook) { |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& entry, pwalletMain->mapAddressBook) { |
|
|
|
uint160 hash160; |
|
|
|
if (pwalletMain->HaveKey(entry.first)) // This address belongs to me
|
|
|
|
if(AddressToHash160(entry.first, hash160) && mapPubKeys.count(hash160)) // This address belongs to me
|
|
|
|
|
|
|
|
mapAccountBalances[entry.second] = 0; |
|
|
|
mapAccountBalances[entry.second] = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1251,16 +1237,16 @@ Value listaccounts(const Array& params, bool fHelp) |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
const CWalletTx& wtx = (*it).second; |
|
|
|
int64 nGeneratedImmature, nGeneratedMature, nFee; |
|
|
|
int64 nGeneratedImmature, nGeneratedMature, nFee; |
|
|
|
string strSentAccount; |
|
|
|
string strSentAccount; |
|
|
|
list<pair<string, int64> > listReceived; |
|
|
|
list<pair<CBitcoinAddress, int64> > listReceived; |
|
|
|
list<pair<string, int64> > listSent; |
|
|
|
list<pair<CBitcoinAddress, int64> > listSent; |
|
|
|
wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); |
|
|
|
wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); |
|
|
|
mapAccountBalances[strSentAccount] -= nFee; |
|
|
|
mapAccountBalances[strSentAccount] -= nFee; |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, int64)& s, listSent) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& s, listSent) |
|
|
|
mapAccountBalances[strSentAccount] -= s.second; |
|
|
|
mapAccountBalances[strSentAccount] -= s.second; |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mapAccountBalances[""] += nGeneratedMature; |
|
|
|
mapAccountBalances[""] += nGeneratedMature; |
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, int64)& r, listReceived) |
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& r, listReceived) |
|
|
|
if (pwalletMain->mapAddressBook.count(r.first)) |
|
|
|
if (pwalletMain->mapAddressBook.count(r.first)) |
|
|
|
mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second; |
|
|
|
mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second; |
|
|
|
else |
|
|
|
else |
|
|
@ -1553,8 +1539,8 @@ Value validateaddress(const Array& params, bool fHelp) |
|
|
|
"Return information about <bitcoinaddress>."); |
|
|
|
"Return information about <bitcoinaddress>."); |
|
|
|
|
|
|
|
|
|
|
|
string strAddress = params[0].get_str(); |
|
|
|
string strAddress = params[0].get_str(); |
|
|
|
uint160 hash160; |
|
|
|
CBitcoinAddress address(strAddress); |
|
|
|
bool isValid = AddressToHash160(strAddress, hash160); |
|
|
|
bool isValid = address.IsValid(); |
|
|
|
|
|
|
|
|
|
|
|
Object ret; |
|
|
|
Object ret; |
|
|
|
ret.push_back(Pair("isvalid", isValid)); |
|
|
|
ret.push_back(Pair("isvalid", isValid)); |
|
|
@ -1562,13 +1548,13 @@ Value validateaddress(const Array& params, bool fHelp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Call Hash160ToAddress() so we always return current ADDRESSVERSION
|
|
|
|
// Call Hash160ToAddress() so we always return current ADDRESSVERSION
|
|
|
|
// version of the address:
|
|
|
|
// version of the address:
|
|
|
|
string currentAddress = Hash160ToAddress(hash160); |
|
|
|
string currentAddress = address.ToString(); |
|
|
|
ret.push_back(Pair("address", currentAddress)); |
|
|
|
ret.push_back(Pair("address", currentAddress)); |
|
|
|
ret.push_back(Pair("ismine", (mapPubKeys.count(hash160) > 0))); |
|
|
|
ret.push_back(Pair("ismine", (pwalletMain->HaveKey(address) > 0))); |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pwalletMain->mapAddressBook.count(currentAddress)) |
|
|
|
if (pwalletMain->mapAddressBook.count(address)) |
|
|
|
ret.push_back(Pair("account", pwalletMain->mapAddressBook[currentAddress])); |
|
|
|
ret.push_back(Pair("account", pwalletMain->mapAddressBook[address])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|