2012-08-21 16:38:57 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2013-10-20 21:25:06 +02:00
|
|
|
// Copyright (c) 2009-2013 The Bitcoin developers
|
2012-08-21 16:38:57 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2012-09-27 19:52:09 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
|
|
|
|
#include "base58.h"
|
2012-08-21 16:38:57 +02:00
|
|
|
#include "bitcoinrpc.h"
|
|
|
|
#include "init.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "net.h"
|
|
|
|
#include "netbase.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "wallet.h"
|
|
|
|
#include "walletdb.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <boost/assign/list_of.hpp>
|
|
|
|
#include "json/json_spirit_utils.h"
|
|
|
|
#include "json/json_spirit_value.h"
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
using namespace std;
|
2012-09-27 19:52:09 +02:00
|
|
|
using namespace boost;
|
|
|
|
using namespace boost::assign;
|
|
|
|
using namespace json_spirit;
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nWalletUnlockTime;
|
2012-08-21 16:38:57 +02:00
|
|
|
static CCriticalSection cs_nWalletUnlockTime;
|
|
|
|
|
2012-08-24 08:44:51 +02:00
|
|
|
std::string HelpRequiringPassphrase()
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
2013-08-25 06:00:02 +02:00
|
|
|
return pwalletMain && pwalletMain->IsCrypted()
|
2012-08-21 16:38:57 +02:00
|
|
|
? "\nrequires wallet passphrase to be set with walletpassphrase first"
|
|
|
|
: "";
|
|
|
|
}
|
|
|
|
|
2012-08-24 08:44:51 +02:00
|
|
|
void EnsureWalletIsUnlocked()
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
if (pwalletMain->IsLocked())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
|
|
|
|
{
|
|
|
|
int confirms = wtx.GetDepthInMainChain();
|
|
|
|
entry.push_back(Pair("confirmations", confirms));
|
2012-06-02 04:33:28 +02:00
|
|
|
if (wtx.IsCoinBase())
|
|
|
|
entry.push_back(Pair("generated", true));
|
2012-08-21 16:38:57 +02:00
|
|
|
if (confirms)
|
|
|
|
{
|
|
|
|
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
|
|
|
|
entry.push_back(Pair("blockindex", wtx.nIndex));
|
2012-05-28 18:56:50 +02:00
|
|
|
entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime)));
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
entry.push_back(Pair("txid", wtx.GetHash().GetHex()));
|
|
|
|
entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime()));
|
2012-05-28 18:56:50 +02:00
|
|
|
entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived));
|
2012-08-21 16:38:57 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue)
|
|
|
|
entry.push_back(Pair(item.first, item.second));
|
|
|
|
}
|
|
|
|
|
|
|
|
string AccountFromValue(const Value& value)
|
|
|
|
{
|
|
|
|
string strAccount = value.get_str();
|
|
|
|
if (strAccount == "*")
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name");
|
2012-08-21 16:38:57 +02:00
|
|
|
return strAccount;
|
|
|
|
}
|
|
|
|
|
2012-08-21 17:03:38 +02:00
|
|
|
Value getinfo(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 0)
|
|
|
|
throw runtime_error(
|
|
|
|
"getinfo\n"
|
|
|
|
"Returns an object containing various state info.");
|
|
|
|
|
2012-09-23 12:55:05 +02:00
|
|
|
proxyType proxy;
|
|
|
|
GetProxy(NET_IPV4, proxy);
|
2012-08-21 17:03:38 +02:00
|
|
|
|
|
|
|
Object obj;
|
|
|
|
obj.push_back(Pair("version", (int)CLIENT_VERSION));
|
|
|
|
obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
|
2013-08-25 06:00:02 +02:00
|
|
|
if (pwalletMain) {
|
|
|
|
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
|
|
|
|
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
|
|
|
|
}
|
2013-10-10 23:07:44 +02:00
|
|
|
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
2013-01-11 12:11:34 +01:00
|
|
|
obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
|
2012-08-21 17:03:38 +02:00
|
|
|
obj.push_back(Pair("connections", (int)vNodes.size()));
|
2012-09-23 12:55:05 +02:00
|
|
|
obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
|
2012-08-21 17:03:38 +02:00
|
|
|
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
2013-05-07 15:16:25 +02:00
|
|
|
obj.push_back(Pair("testnet", TestNet()));
|
2013-08-25 06:00:02 +02:00
|
|
|
if (pwalletMain) {
|
|
|
|
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
|
|
|
|
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
|
|
|
|
}
|
2012-08-21 17:03:38 +02:00
|
|
|
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
|
2013-08-25 06:00:02 +02:00
|
|
|
if (pwalletMain && pwalletMain->IsCrypted())
|
2013-05-07 16:47:00 +02:00
|
|
|
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
|
2012-08-21 17:03:38 +02:00
|
|
|
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-21 16:38:57 +02:00
|
|
|
Value getnewaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"getnewaddress [account]\n"
|
|
|
|
"Returns a new Bitcoin address for receiving payments. "
|
|
|
|
"If [account] is specified (recommended), it is added to the address book "
|
|
|
|
"so payments received with the address will be credited to [account].");
|
|
|
|
|
|
|
|
// Parse the account first so we don't generate a key if there's an error
|
|
|
|
string strAccount;
|
|
|
|
if (params.size() > 0)
|
|
|
|
strAccount = AccountFromValue(params[0]);
|
|
|
|
|
|
|
|
if (!pwalletMain->IsLocked())
|
|
|
|
pwalletMain->TopUpKeyPool();
|
|
|
|
|
|
|
|
// Generate a new key that is added to wallet
|
|
|
|
CPubKey newKey;
|
2013-08-23 21:54:50 +02:00
|
|
|
if (!pwalletMain->GetKeyFromPool(newKey))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
|
2012-08-21 16:38:57 +02:00
|
|
|
CKeyID keyID = newKey.GetID();
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
pwalletMain->SetAddressBook(keyID, strAccount, "receive");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return CBitcoinAddress(keyID).ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
|
|
|
|
{
|
|
|
|
CWalletDB walletdb(pwalletMain->strWalletFile);
|
|
|
|
|
|
|
|
CAccount account;
|
|
|
|
walletdb.ReadAccount(strAccount, account);
|
|
|
|
|
|
|
|
bool bKeyUsed = false;
|
|
|
|
|
|
|
|
// Check if the current key has been used
|
|
|
|
if (account.vchPubKey.IsValid())
|
|
|
|
{
|
|
|
|
CScript scriptPubKey;
|
|
|
|
scriptPubKey.SetDestination(account.vchPubKey.GetID());
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
|
|
|
|
it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
|
|
|
|
++it)
|
|
|
|
{
|
|
|
|
const CWalletTx& wtx = (*it).second;
|
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
|
|
|
|
if (txout.scriptPubKey == scriptPubKey)
|
|
|
|
bKeyUsed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a new key
|
|
|
|
if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed)
|
|
|
|
{
|
2013-08-23 21:54:50 +02:00
|
|
|
if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
|
2012-08-21 16:38:57 +02:00
|
|
|
walletdb.WriteAccount(strAccount, account);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CBitcoinAddress(account.vchPubKey.GetID());
|
|
|
|
}
|
|
|
|
|
|
|
|
Value getaccountaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"getaccountaddress <account>\n"
|
|
|
|
"Returns the current Bitcoin address for receiving payments to this account.");
|
|
|
|
|
|
|
|
// Parse the account first so we don't generate a key if there's an error
|
|
|
|
string strAccount = AccountFromValue(params[0]);
|
|
|
|
|
|
|
|
Value ret;
|
|
|
|
|
|
|
|
ret = GetAccountAddress(strAccount).ToString();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-28 22:29:52 +02:00
|
|
|
Value getrawchangeaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"getrawchangeaddress\n"
|
|
|
|
"Returns a new Bitcoin address, for receiving change. "
|
|
|
|
"This is for use with raw transactions, NOT normal use.");
|
|
|
|
|
|
|
|
if (!pwalletMain->IsLocked())
|
|
|
|
pwalletMain->TopUpKeyPool();
|
|
|
|
|
|
|
|
CReserveKey reservekey(pwalletMain);
|
|
|
|
CPubKey vchPubKey;
|
|
|
|
if (!reservekey.GetReservedKey(vchPubKey))
|
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Unable to obtain key for change");
|
|
|
|
|
|
|
|
reservekey.KeepKey();
|
|
|
|
|
|
|
|
CKeyID keyID = vchPubKey.GetID();
|
|
|
|
|
|
|
|
return CBitcoinAddress(keyID).ToString();
|
|
|
|
}
|
|
|
|
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
Value setaccount(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"setaccount <bitcoinaddress> <account>\n"
|
|
|
|
"Sets the account associated with the given address.");
|
|
|
|
|
|
|
|
CBitcoinAddress address(params[0].get_str());
|
|
|
|
if (!address.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
string strAccount;
|
|
|
|
if (params.size() > 1)
|
|
|
|
strAccount = AccountFromValue(params[1]);
|
|
|
|
|
|
|
|
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
|
|
|
if (pwalletMain->mapAddressBook.count(address.Get()))
|
|
|
|
{
|
2013-07-15 07:20:50 +02:00
|
|
|
string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
|
2012-08-21 16:38:57 +02:00
|
|
|
if (address == GetAccountAddress(strOldAccount))
|
|
|
|
GetAccountAddress(strOldAccount, true);
|
|
|
|
}
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return Value::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value getaccount(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"getaccount <bitcoinaddress>\n"
|
|
|
|
"Returns the account associated with the given address.");
|
|
|
|
|
|
|
|
CBitcoinAddress address(params[0].get_str());
|
|
|
|
if (!address.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
string strAccount;
|
2013-07-15 07:20:50 +02:00
|
|
|
map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
|
|
|
|
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
|
|
|
|
strAccount = (*mi).second.name;
|
2012-08-21 16:38:57 +02:00
|
|
|
return strAccount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value getaddressesbyaccount(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"getaddressesbyaccount <account>\n"
|
|
|
|
"Returns the list of addresses for the given account.");
|
|
|
|
|
|
|
|
string strAccount = AccountFromValue(params[0]);
|
|
|
|
|
|
|
|
// Find all addresses that have the given account
|
|
|
|
Array ret;
|
2013-07-15 07:20:50 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
const CBitcoinAddress& address = item.first;
|
2013-07-15 07:20:50 +02:00
|
|
|
const string& strName = item.second.name;
|
2012-08-21 16:38:57 +02:00
|
|
|
if (strName == strAccount)
|
|
|
|
ret.push_back(address.ToString());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value sendtoaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 2 || params.size() > 4)
|
|
|
|
throw runtime_error(
|
|
|
|
"sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n"
|
|
|
|
"<amount> is a real and is rounded to the nearest 0.00000001"
|
|
|
|
+ HelpRequiringPassphrase());
|
|
|
|
|
|
|
|
CBitcoinAddress address(params[0].get_str());
|
|
|
|
if (!address.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Amount
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = AmountFromValue(params[1]);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Wallet comments
|
|
|
|
CWalletTx wtx;
|
|
|
|
if (params.size() > 2 && params[2].type() != null_type && !params[2].get_str().empty())
|
|
|
|
wtx.mapValue["comment"] = params[2].get_str();
|
|
|
|
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
|
|
|
|
wtx.mapValue["to"] = params[3].get_str();
|
|
|
|
|
|
|
|
if (pwalletMain->IsLocked())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
|
|
|
|
if (strError != "")
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return wtx.GetHash().GetHex();
|
|
|
|
}
|
|
|
|
|
2012-08-01 18:48:42 +02:00
|
|
|
Value listaddressgroupings(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp)
|
2012-08-20 19:43:33 +02:00
|
|
|
throw runtime_error(
|
|
|
|
"listaddressgroupings\n"
|
|
|
|
"Lists groups of addresses which have had their common ownership\n"
|
|
|
|
"made public by common use as inputs or as the resulting change\n"
|
|
|
|
"in past transactions");
|
2012-08-01 18:48:42 +02:00
|
|
|
|
|
|
|
Array jsonGroupings;
|
2013-04-13 07:13:08 +02:00
|
|
|
map<CTxDestination, int64_t> balances = pwalletMain->GetAddressBalances();
|
2012-08-20 19:43:33 +02:00
|
|
|
BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
|
2012-08-01 18:48:42 +02:00
|
|
|
{
|
|
|
|
Array jsonGrouping;
|
2012-08-20 19:43:33 +02:00
|
|
|
BOOST_FOREACH(CTxDestination address, grouping)
|
2012-08-01 18:48:42 +02:00
|
|
|
{
|
|
|
|
Array addressInfo;
|
2012-08-20 19:43:33 +02:00
|
|
|
addressInfo.push_back(CBitcoinAddress(address).ToString());
|
2012-08-01 18:48:42 +02:00
|
|
|
addressInfo.push_back(ValueFromAmount(balances[address]));
|
|
|
|
{
|
|
|
|
LOCK(pwalletMain->cs_wallet);
|
|
|
|
if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
|
2013-07-15 07:20:50 +02:00
|
|
|
addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
|
2012-08-01 18:48:42 +02:00
|
|
|
}
|
|
|
|
jsonGrouping.push_back(addressInfo);
|
|
|
|
}
|
|
|
|
jsonGroupings.push_back(jsonGrouping);
|
|
|
|
}
|
|
|
|
return jsonGroupings;
|
|
|
|
}
|
|
|
|
|
2012-08-21 16:38:57 +02:00
|
|
|
Value signmessage(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"signmessage <bitcoinaddress> <message>\n"
|
|
|
|
"Sign a message with the private key of an address");
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked();
|
|
|
|
|
|
|
|
string strAddress = params[0].get_str();
|
|
|
|
string strMessage = params[1].get_str();
|
|
|
|
|
|
|
|
CBitcoinAddress addr(strAddress);
|
|
|
|
if (!addr.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
CKeyID keyID;
|
|
|
|
if (!addr.GetKeyID(keyID))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
CKey key;
|
|
|
|
if (!pwalletMain->GetKey(keyID, key))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2012-10-19 23:13:44 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, 0);
|
2012-08-21 16:38:57 +02:00
|
|
|
ss << strMessageMagic;
|
|
|
|
ss << strMessage;
|
|
|
|
|
|
|
|
vector<unsigned char> vchSig;
|
2012-10-19 23:13:44 +02:00
|
|
|
if (!key.SignCompact(ss.GetHash(), vchSig))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return EncodeBase64(&vchSig[0], vchSig.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
Value verifymessage(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 3)
|
|
|
|
throw runtime_error(
|
|
|
|
"verifymessage <bitcoinaddress> <signature> <message>\n"
|
|
|
|
"Verify a signed message");
|
|
|
|
|
|
|
|
string strAddress = params[0].get_str();
|
|
|
|
string strSign = params[1].get_str();
|
|
|
|
string strMessage = params[2].get_str();
|
|
|
|
|
|
|
|
CBitcoinAddress addr(strAddress);
|
|
|
|
if (!addr.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
CKeyID keyID;
|
|
|
|
if (!addr.GetKeyID(keyID))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
bool fInvalid = false;
|
|
|
|
vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
|
|
|
|
|
|
|
|
if (fInvalid)
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2012-10-19 23:13:44 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, 0);
|
2012-08-21 16:38:57 +02:00
|
|
|
ss << strMessageMagic;
|
|
|
|
ss << strMessage;
|
|
|
|
|
2013-05-01 06:52:05 +02:00
|
|
|
CPubKey pubkey;
|
|
|
|
if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
|
2012-08-21 16:38:57 +02:00
|
|
|
return false;
|
|
|
|
|
2013-05-01 06:52:05 +02:00
|
|
|
return (pubkey.GetID() == keyID);
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value getreceivedbyaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"getreceivedbyaddress <bitcoinaddress> [minconf=1]\n"
|
|
|
|
"Returns the total amount received by <bitcoinaddress> in transactions with at least [minconf] confirmations.");
|
|
|
|
|
|
|
|
// Bitcoin address
|
|
|
|
CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
|
|
|
|
CScript scriptPubKey;
|
|
|
|
if (!address.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
2012-08-21 16:38:57 +02:00
|
|
|
scriptPubKey.SetDestination(address.Get());
|
|
|
|
if (!IsMine(*pwalletMain,scriptPubKey))
|
|
|
|
return (double)0.0;
|
|
|
|
|
|
|
|
// Minimum confirmations
|
|
|
|
int nMinDepth = 1;
|
|
|
|
if (params.size() > 1)
|
|
|
|
nMinDepth = params[1].get_int();
|
|
|
|
|
|
|
|
// Tally
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
|
|
|
{
|
|
|
|
const CWalletTx& wtx = (*it).second;
|
2013-01-08 13:17:15 +01:00
|
|
|
if (wtx.IsCoinBase() || !IsFinalTx(wtx))
|
2012-08-21 16:38:57 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
|
|
|
|
if (txout.scriptPubKey == scriptPubKey)
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
nAmount += txout.nValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ValueFromAmount(nAmount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value getreceivedbyaccount(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"getreceivedbyaccount <account> [minconf=1]\n"
|
|
|
|
"Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.");
|
|
|
|
|
|
|
|
// Minimum confirmations
|
|
|
|
int nMinDepth = 1;
|
|
|
|
if (params.size() > 1)
|
|
|
|
nMinDepth = params[1].get_int();
|
|
|
|
|
|
|
|
// Get the set of pub keys assigned to account
|
|
|
|
string strAccount = AccountFromValue(params[0]);
|
2013-07-16 01:01:09 +02:00
|
|
|
set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Tally
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
|
|
|
{
|
|
|
|
const CWalletTx& wtx = (*it).second;
|
2013-01-08 13:17:15 +01:00
|
|
|
if (wtx.IsCoinBase() || !IsFinalTx(wtx))
|
2012-08-21 16:38:57 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
|
|
|
|
{
|
|
|
|
CTxDestination address;
|
|
|
|
if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address))
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
nAmount += txout.nValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (double)nAmount / (double)COIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nBalance = 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Tally wallet transactions
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
|
|
|
{
|
|
|
|
const CWalletTx& wtx = (*it).second;
|
2013-01-08 13:17:15 +01:00
|
|
|
if (!IsFinalTx(wtx))
|
2012-08-21 16:38:57 +02:00
|
|
|
continue;
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nReceived, nSent, nFee;
|
2012-06-02 04:33:28 +02:00
|
|
|
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
nBalance += nReceived;
|
2012-06-02 04:33:28 +02:00
|
|
|
nBalance -= nSent + nFee;
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tally internal accounting entries
|
|
|
|
nBalance += walletdb.GetAccountCreditDebit(strAccount);
|
|
|
|
|
|
|
|
return nBalance;
|
|
|
|
}
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t GetAccountBalance(const string& strAccount, int nMinDepth)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
CWalletDB walletdb(pwalletMain->strWalletFile);
|
|
|
|
return GetAccountBalance(walletdb, strAccount, nMinDepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value getbalance(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"getbalance [account] [minconf=1]\n"
|
|
|
|
"If [account] is not specified, returns the server's total available balance.\n"
|
|
|
|
"If [account] is specified, returns the balance in the account.");
|
|
|
|
|
|
|
|
if (params.size() == 0)
|
|
|
|
return ValueFromAmount(pwalletMain->GetBalance());
|
|
|
|
|
|
|
|
int nMinDepth = 1;
|
|
|
|
if (params.size() > 1)
|
|
|
|
nMinDepth = params[1].get_int();
|
|
|
|
|
|
|
|
if (params[0].get_str() == "*") {
|
|
|
|
// Calculate total balance a different way from GetBalance()
|
|
|
|
// (GetBalance() sums up all unspent TxOuts)
|
2013-02-04 20:04:26 +01:00
|
|
|
// getbalance and getbalance '*' 0 should return the same number
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nBalance = 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
|
|
|
{
|
|
|
|
const CWalletTx& wtx = (*it).second;
|
2013-02-04 20:04:26 +01:00
|
|
|
if (!wtx.IsConfirmed())
|
2012-08-21 16:38:57 +02:00
|
|
|
continue;
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t allFee;
|
2012-08-21 16:38:57 +02:00
|
|
|
string strSentAccount;
|
2013-04-13 07:13:08 +02:00
|
|
|
list<pair<CTxDestination, int64_t> > listReceived;
|
|
|
|
list<pair<CTxDestination, int64_t> > listSent;
|
2012-06-02 04:33:28 +02:00
|
|
|
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount);
|
2012-08-21 16:38:57 +02:00
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
|
2012-08-21 16:38:57 +02:00
|
|
|
nBalance += r.second;
|
|
|
|
}
|
2013-04-13 07:13:08 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listSent)
|
2012-08-21 16:38:57 +02:00
|
|
|
nBalance -= r.second;
|
|
|
|
nBalance -= allFee;
|
|
|
|
}
|
|
|
|
return ValueFromAmount(nBalance);
|
|
|
|
}
|
|
|
|
|
|
|
|
string strAccount = AccountFromValue(params[0]);
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return ValueFromAmount(nBalance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value movecmd(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 3 || params.size() > 5)
|
|
|
|
throw runtime_error(
|
|
|
|
"move <fromaccount> <toaccount> <amount> [minconf=1] [comment]\n"
|
|
|
|
"Move from one account in your wallet to another.");
|
|
|
|
|
|
|
|
string strFrom = AccountFromValue(params[0]);
|
|
|
|
string strTo = AccountFromValue(params[1]);
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = AmountFromValue(params[2]);
|
2012-08-21 16:38:57 +02:00
|
|
|
if (params.size() > 3)
|
|
|
|
// unused parameter, used to be nMinDepth, keep type-checking it though
|
|
|
|
(void)params[3].get_int();
|
|
|
|
string strComment;
|
|
|
|
if (params.size() > 4)
|
|
|
|
strComment = params[4].get_str();
|
|
|
|
|
|
|
|
CWalletDB walletdb(pwalletMain->strWalletFile);
|
|
|
|
if (!walletdb.TxnBegin())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nNow = GetAdjustedTime();
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Debit
|
|
|
|
CAccountingEntry debit;
|
2012-11-13 23:52:37 +01:00
|
|
|
debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
|
2012-08-21 16:38:57 +02:00
|
|
|
debit.strAccount = strFrom;
|
|
|
|
debit.nCreditDebit = -nAmount;
|
|
|
|
debit.nTime = nNow;
|
|
|
|
debit.strOtherAccount = strTo;
|
|
|
|
debit.strComment = strComment;
|
|
|
|
walletdb.WriteAccountingEntry(debit);
|
|
|
|
|
|
|
|
// Credit
|
|
|
|
CAccountingEntry credit;
|
2012-11-13 23:52:37 +01:00
|
|
|
credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
|
2012-08-21 16:38:57 +02:00
|
|
|
credit.strAccount = strTo;
|
|
|
|
credit.nCreditDebit = nAmount;
|
|
|
|
credit.nTime = nNow;
|
|
|
|
credit.strOtherAccount = strFrom;
|
|
|
|
credit.strComment = strComment;
|
|
|
|
walletdb.WriteAccountingEntry(credit);
|
|
|
|
|
|
|
|
if (!walletdb.TxnCommit())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value sendfrom(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 3 || params.size() > 6)
|
|
|
|
throw runtime_error(
|
|
|
|
"sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n"
|
|
|
|
"<amount> is a real and is rounded to the nearest 0.00000001"
|
|
|
|
+ HelpRequiringPassphrase());
|
|
|
|
|
|
|
|
string strAccount = AccountFromValue(params[0]);
|
|
|
|
CBitcoinAddress address(params[1].get_str());
|
|
|
|
if (!address.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = AmountFromValue(params[2]);
|
2012-08-21 16:38:57 +02:00
|
|
|
int nMinDepth = 1;
|
|
|
|
if (params.size() > 3)
|
|
|
|
nMinDepth = params[3].get_int();
|
|
|
|
|
|
|
|
CWalletTx wtx;
|
|
|
|
wtx.strFromAccount = strAccount;
|
|
|
|
if (params.size() > 4 && params[4].type() != null_type && !params[4].get_str().empty())
|
|
|
|
wtx.mapValue["comment"] = params[4].get_str();
|
|
|
|
if (params.size() > 5 && params[5].type() != null_type && !params[5].get_str().empty())
|
|
|
|
wtx.mapValue["to"] = params[5].get_str();
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked();
|
|
|
|
|
|
|
|
// Check funds
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
|
2012-08-21 16:38:57 +02:00
|
|
|
if (nAmount > nBalance)
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Send
|
|
|
|
string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
|
|
|
|
if (strError != "")
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return wtx.GetHash().GetHex();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value sendmany(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 2 || params.size() > 4)
|
|
|
|
throw runtime_error(
|
|
|
|
"sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n"
|
|
|
|
"amounts are double-precision floating point numbers"
|
|
|
|
+ HelpRequiringPassphrase());
|
|
|
|
|
|
|
|
string strAccount = AccountFromValue(params[0]);
|
|
|
|
Object sendTo = params[1].get_obj();
|
|
|
|
int nMinDepth = 1;
|
|
|
|
if (params.size() > 2)
|
|
|
|
nMinDepth = params[2].get_int();
|
|
|
|
|
|
|
|
CWalletTx wtx;
|
|
|
|
wtx.strFromAccount = strAccount;
|
|
|
|
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
|
|
|
|
wtx.mapValue["comment"] = params[3].get_str();
|
|
|
|
|
|
|
|
set<CBitcoinAddress> setAddress;
|
2013-04-13 07:13:08 +02:00
|
|
|
vector<pair<CScript, int64_t> > vecSend;
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t totalAmount = 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
BOOST_FOREACH(const Pair& s, sendTo)
|
|
|
|
{
|
|
|
|
CBitcoinAddress address(s.name_);
|
|
|
|
if (!address.IsValid())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+s.name_);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
if (setAddress.count(address))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
|
2012-08-21 16:38:57 +02:00
|
|
|
setAddress.insert(address);
|
|
|
|
|
|
|
|
CScript scriptPubKey;
|
|
|
|
scriptPubKey.SetDestination(address.Get());
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = AmountFromValue(s.value_);
|
2012-08-21 16:38:57 +02:00
|
|
|
totalAmount += nAmount;
|
|
|
|
|
|
|
|
vecSend.push_back(make_pair(scriptPubKey, nAmount));
|
|
|
|
}
|
|
|
|
|
|
|
|
EnsureWalletIsUnlocked();
|
|
|
|
|
|
|
|
// Check funds
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth);
|
2012-08-21 16:38:57 +02:00
|
|
|
if (totalAmount > nBalance)
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Send
|
|
|
|
CReserveKey keyChange(pwalletMain);
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nFeeRequired = 0;
|
2013-04-25 23:31:22 +02:00
|
|
|
string strFailReason;
|
|
|
|
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason);
|
2012-08-21 16:38:57 +02:00
|
|
|
if (!fCreated)
|
2013-04-25 23:31:22 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
|
2012-08-21 16:38:57 +02:00
|
|
|
if (!pwalletMain->CommitTransaction(wtx, keyChange))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return wtx.GetHash().GetHex();
|
|
|
|
}
|
|
|
|
|
2012-09-10 15:32:40 +02:00
|
|
|
//
|
|
|
|
// Used by addmultisigaddress / createmultisig:
|
|
|
|
//
|
|
|
|
static CScript _createmultisig(const Array& params)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
int nRequired = params[0].get_int();
|
|
|
|
const Array& keys = params[1].get_array();
|
|
|
|
|
|
|
|
// Gather public keys
|
|
|
|
if (nRequired < 1)
|
|
|
|
throw runtime_error("a multisignature address must require at least one key to redeem");
|
|
|
|
if ((int)keys.size() < nRequired)
|
|
|
|
throw runtime_error(
|
|
|
|
strprintf("not enough keys supplied "
|
2012-09-29 11:57:44 +02:00
|
|
|
"(got %"PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired));
|
2013-05-01 06:52:05 +02:00
|
|
|
std::vector<CPubKey> pubkeys;
|
2012-08-21 16:38:57 +02:00
|
|
|
pubkeys.resize(keys.size());
|
|
|
|
for (unsigned int i = 0; i < keys.size(); i++)
|
|
|
|
{
|
|
|
|
const std::string& ks = keys[i].get_str();
|
|
|
|
|
|
|
|
// Case 1: Bitcoin address and we have full public key:
|
|
|
|
CBitcoinAddress address(ks);
|
2013-08-25 06:00:02 +02:00
|
|
|
if (pwalletMain && address.IsValid())
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
CKeyID keyID;
|
|
|
|
if (!address.GetKeyID(keyID))
|
|
|
|
throw runtime_error(
|
|
|
|
strprintf("%s does not refer to a key",ks.c_str()));
|
|
|
|
CPubKey vchPubKey;
|
|
|
|
if (!pwalletMain->GetPubKey(keyID, vchPubKey))
|
|
|
|
throw runtime_error(
|
|
|
|
strprintf("no full public key for address %s",ks.c_str()));
|
2013-05-01 06:52:05 +02:00
|
|
|
if (!vchPubKey.IsFullyValid())
|
2012-08-21 16:38:57 +02:00
|
|
|
throw runtime_error(" Invalid public key: "+ks);
|
2013-05-01 06:52:05 +02:00
|
|
|
pubkeys[i] = vchPubKey;
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Case 2: hex public key
|
|
|
|
else if (IsHex(ks))
|
|
|
|
{
|
|
|
|
CPubKey vchPubKey(ParseHex(ks));
|
2013-05-01 06:52:05 +02:00
|
|
|
if (!vchPubKey.IsFullyValid())
|
2012-08-21 16:38:57 +02:00
|
|
|
throw runtime_error(" Invalid public key: "+ks);
|
2013-05-01 06:52:05 +02:00
|
|
|
pubkeys[i] = vchPubKey;
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw runtime_error(" Invalid public key: "+ks);
|
|
|
|
}
|
|
|
|
}
|
2012-09-10 15:32:40 +02:00
|
|
|
CScript result;
|
|
|
|
result.SetMultisig(nRequired, pubkeys);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value addmultisigaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 2 || params.size() > 3)
|
|
|
|
{
|
|
|
|
string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n"
|
|
|
|
"Add a nrequired-to-sign multisignature address to the wallet\"\n"
|
|
|
|
"each key is a Bitcoin address or hex-encoded public key\n"
|
|
|
|
"If [account] is specified, assign address to [account].";
|
|
|
|
throw runtime_error(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
string strAccount;
|
|
|
|
if (params.size() > 2)
|
|
|
|
strAccount = AccountFromValue(params[2]);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Construct using pay-to-script-hash:
|
2012-09-10 15:32:40 +02:00
|
|
|
CScript inner = _createmultisig(params);
|
2012-08-21 16:38:57 +02:00
|
|
|
CScriptID innerID = inner.GetID();
|
|
|
|
pwalletMain->AddCScript(inner);
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
pwalletMain->SetAddressBook(innerID, strAccount, "send");
|
2012-08-21 16:38:57 +02:00
|
|
|
return CBitcoinAddress(innerID).ToString();
|
|
|
|
}
|
|
|
|
|
2012-09-10 15:32:40 +02:00
|
|
|
Value createmultisig(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 2 || params.size() > 2)
|
|
|
|
{
|
|
|
|
string msg = "createmultisig <nrequired> <'[\"key\",\"key\"]'>\n"
|
|
|
|
"Creates a multi-signature address and returns a json object\n"
|
|
|
|
"with keys:\n"
|
|
|
|
"address : bitcoin address\n"
|
|
|
|
"redeemScript : hex-encoded redemption script";
|
|
|
|
throw runtime_error(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct using pay-to-script-hash:
|
|
|
|
CScript inner = _createmultisig(params);
|
|
|
|
CScriptID innerID = inner.GetID();
|
|
|
|
CBitcoinAddress address(innerID);
|
|
|
|
|
|
|
|
Object result;
|
|
|
|
result.push_back(Pair("address", address.ToString()));
|
|
|
|
result.push_back(Pair("redeemScript", HexStr(inner.begin(), inner.end())));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
struct tallyitem
|
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount;
|
2012-08-21 16:38:57 +02:00
|
|
|
int nConf;
|
2012-12-13 15:59:10 +01:00
|
|
|
vector<uint256> txids;
|
2012-08-21 16:38:57 +02:00
|
|
|
tallyitem()
|
|
|
|
{
|
|
|
|
nAmount = 0;
|
|
|
|
nConf = std::numeric_limits<int>::max();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Value ListReceived(const Array& params, bool fByAccounts)
|
|
|
|
{
|
|
|
|
// Minimum confirmations
|
|
|
|
int nMinDepth = 1;
|
|
|
|
if (params.size() > 0)
|
|
|
|
nMinDepth = params[0].get_int();
|
|
|
|
|
|
|
|
// Whether to include empty accounts
|
|
|
|
bool fIncludeEmpty = false;
|
|
|
|
if (params.size() > 1)
|
|
|
|
fIncludeEmpty = params[1].get_bool();
|
|
|
|
|
|
|
|
// Tally
|
|
|
|
map<CBitcoinAddress, tallyitem> mapTally;
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
|
|
|
{
|
|
|
|
const CWalletTx& wtx = (*it).second;
|
|
|
|
|
2013-01-08 13:17:15 +01:00
|
|
|
if (wtx.IsCoinBase() || !IsFinalTx(wtx))
|
2012-08-21 16:38:57 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int nDepth = wtx.GetDepthInMainChain();
|
|
|
|
if (nDepth < nMinDepth)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
|
|
|
|
{
|
|
|
|
CTxDestination address;
|
|
|
|
if (!ExtractDestination(txout.scriptPubKey, address) || !IsMine(*pwalletMain, address))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tallyitem& item = mapTally[address];
|
|
|
|
item.nAmount += txout.nValue;
|
|
|
|
item.nConf = min(item.nConf, nDepth);
|
2012-12-13 15:59:10 +01:00
|
|
|
item.txids.push_back(wtx.GetHash());
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reply
|
|
|
|
Array ret;
|
|
|
|
map<string, tallyitem> mapAccountTally;
|
2013-07-15 07:20:50 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
const CBitcoinAddress& address = item.first;
|
2013-07-15 07:20:50 +02:00
|
|
|
const string& strAccount = item.second.name;
|
2012-08-21 16:38:57 +02:00
|
|
|
map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address);
|
|
|
|
if (it == mapTally.end() && !fIncludeEmpty)
|
|
|
|
continue;
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
int nConf = std::numeric_limits<int>::max();
|
|
|
|
if (it != mapTally.end())
|
|
|
|
{
|
|
|
|
nAmount = (*it).second.nAmount;
|
|
|
|
nConf = (*it).second.nConf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fByAccounts)
|
|
|
|
{
|
|
|
|
tallyitem& item = mapAccountTally[strAccount];
|
|
|
|
item.nAmount += nAmount;
|
|
|
|
item.nConf = min(item.nConf, nConf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Object obj;
|
|
|
|
obj.push_back(Pair("address", address.ToString()));
|
|
|
|
obj.push_back(Pair("account", strAccount));
|
|
|
|
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
|
|
|
|
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
2012-12-13 15:59:10 +01:00
|
|
|
Array transactions;
|
2012-12-16 20:10:32 +01:00
|
|
|
if (it != mapTally.end())
|
2012-12-13 15:59:10 +01:00
|
|
|
{
|
2012-12-16 20:10:32 +01:00
|
|
|
BOOST_FOREACH(const uint256& item, (*it).second.txids)
|
|
|
|
{
|
|
|
|
transactions.push_back(item.GetHex());
|
|
|
|
}
|
2012-12-13 15:59:10 +01:00
|
|
|
}
|
|
|
|
obj.push_back(Pair("txids", transactions));
|
2012-08-21 16:38:57 +02:00
|
|
|
ret.push_back(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fByAccounts)
|
|
|
|
{
|
|
|
|
for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
|
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nAmount = (*it).second.nAmount;
|
2012-08-21 16:38:57 +02:00
|
|
|
int nConf = (*it).second.nConf;
|
|
|
|
Object obj;
|
|
|
|
obj.push_back(Pair("account", (*it).first));
|
|
|
|
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
|
|
|
|
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
|
|
|
ret.push_back(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value listreceivedbyaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"listreceivedbyaddress [minconf=1] [includeempty=false]\n"
|
|
|
|
"[minconf] is the minimum number of confirmations before payments are included.\n"
|
|
|
|
"[includeempty] whether to include addresses that haven't received any payments.\n"
|
|
|
|
"Returns an array of objects containing:\n"
|
|
|
|
" \"address\" : receiving address\n"
|
|
|
|
" \"account\" : the account of the receiving address\n"
|
|
|
|
" \"amount\" : total amount received by the address\n"
|
2012-12-16 20:10:32 +01:00
|
|
|
" \"confirmations\" : number of confirmations of the most recent transaction included\n"
|
|
|
|
" \"txids\" : list of transactions with outputs to the address\n");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return ListReceived(params, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value listreceivedbyaccount(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"listreceivedbyaccount [minconf=1] [includeempty=false]\n"
|
|
|
|
"[minconf] is the minimum number of confirmations before payments are included.\n"
|
|
|
|
"[includeempty] whether to include accounts that haven't received any payments.\n"
|
|
|
|
"Returns an array of objects containing:\n"
|
|
|
|
" \"account\" : the account of the receiving addresses\n"
|
|
|
|
" \"amount\" : total amount received by addresses with this account\n"
|
|
|
|
" \"confirmations\" : number of confirmations of the most recent transaction included");
|
|
|
|
|
|
|
|
return ListReceived(params, true);
|
|
|
|
}
|
|
|
|
|
2012-09-22 05:22:34 +02:00
|
|
|
static void MaybePushAddress(Object & entry, const CTxDestination &dest)
|
|
|
|
{
|
|
|
|
CBitcoinAddress addr;
|
|
|
|
if (addr.Set(dest))
|
|
|
|
entry.push_back(Pair("address", addr.ToString()));
|
|
|
|
}
|
|
|
|
|
2012-08-21 16:38:57 +02:00
|
|
|
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret)
|
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nFee;
|
2012-08-21 16:38:57 +02:00
|
|
|
string strSentAccount;
|
2013-04-13 07:13:08 +02:00
|
|
|
list<pair<CTxDestination, int64_t> > listReceived;
|
|
|
|
list<pair<CTxDestination, int64_t> > listSent;
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2012-06-02 04:33:28 +02:00
|
|
|
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
bool fAllAccounts = (strAccount == string("*"));
|
|
|
|
|
|
|
|
// Sent
|
|
|
|
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
|
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
Object entry;
|
|
|
|
entry.push_back(Pair("account", strSentAccount));
|
2012-09-22 05:22:34 +02:00
|
|
|
MaybePushAddress(entry, s.first);
|
2012-08-21 16:38:57 +02:00
|
|
|
entry.push_back(Pair("category", "send"));
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(-s.second)));
|
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
|
|
|
|
if (fLong)
|
|
|
|
WalletTxToJSON(wtx, entry);
|
|
|
|
ret.push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Received
|
|
|
|
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
string account;
|
|
|
|
if (pwalletMain->mapAddressBook.count(r.first))
|
2013-07-15 07:20:50 +02:00
|
|
|
account = pwalletMain->mapAddressBook[r.first].name;
|
2012-08-21 16:38:57 +02:00
|
|
|
if (fAllAccounts || (account == strAccount))
|
|
|
|
{
|
|
|
|
Object entry;
|
|
|
|
entry.push_back(Pair("account", account));
|
2012-09-22 05:22:34 +02:00
|
|
|
MaybePushAddress(entry, r.first);
|
2012-06-02 04:33:28 +02:00
|
|
|
if (wtx.IsCoinBase())
|
|
|
|
{
|
|
|
|
if (wtx.GetDepthInMainChain() < 1)
|
|
|
|
entry.push_back(Pair("category", "orphan"));
|
|
|
|
else if (wtx.GetBlocksToMaturity() > 0)
|
|
|
|
entry.push_back(Pair("category", "immature"));
|
|
|
|
else
|
|
|
|
entry.push_back(Pair("category", "generate"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
entry.push_back(Pair("category", "receive"));
|
2012-08-21 16:38:57 +02:00
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(r.second)));
|
|
|
|
if (fLong)
|
|
|
|
WalletTxToJSON(wtx, entry);
|
|
|
|
ret.push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret)
|
|
|
|
{
|
|
|
|
bool fAllAccounts = (strAccount == string("*"));
|
|
|
|
|
|
|
|
if (fAllAccounts || acentry.strAccount == strAccount)
|
|
|
|
{
|
|
|
|
Object entry;
|
|
|
|
entry.push_back(Pair("account", acentry.strAccount));
|
|
|
|
entry.push_back(Pair("category", "move"));
|
|
|
|
entry.push_back(Pair("time", (boost::int64_t)acentry.nTime));
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit)));
|
|
|
|
entry.push_back(Pair("otheraccount", acentry.strOtherAccount));
|
|
|
|
entry.push_back(Pair("comment", acentry.strComment));
|
|
|
|
ret.push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Value listtransactions(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 3)
|
|
|
|
throw runtime_error(
|
|
|
|
"listtransactions [account] [count=10] [from=0]\n"
|
|
|
|
"Returns up to [count] most recent transactions skipping the first [from] transactions for account [account].");
|
|
|
|
|
|
|
|
string strAccount = "*";
|
|
|
|
if (params.size() > 0)
|
|
|
|
strAccount = params[0].get_str();
|
|
|
|
int nCount = 10;
|
|
|
|
if (params.size() > 1)
|
|
|
|
nCount = params[1].get_int();
|
|
|
|
int nFrom = 0;
|
|
|
|
if (params.size() > 2)
|
|
|
|
nFrom = params[2].get_int();
|
|
|
|
|
|
|
|
if (nCount < 0)
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
|
2012-08-21 16:38:57 +02:00
|
|
|
if (nFrom < 0)
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
Array ret;
|
|
|
|
|
2012-09-02 00:07:47 +02:00
|
|
|
std::list<CAccountingEntry> acentries;
|
|
|
|
CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, strAccount);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// iterate backwards until we have nCount items to return:
|
2012-05-28 20:45:12 +02:00
|
|
|
for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
|
|
|
CWalletTx *const pwtx = (*it).second.first;
|
|
|
|
if (pwtx != 0)
|
|
|
|
ListTransactions(*pwtx, strAccount, 0, true, ret);
|
|
|
|
CAccountingEntry *const pacentry = (*it).second.second;
|
|
|
|
if (pacentry != 0)
|
|
|
|
AcentryToJSON(*pacentry, strAccount, ret);
|
|
|
|
|
|
|
|
if ((int)ret.size() >= (nCount+nFrom)) break;
|
|
|
|
}
|
|
|
|
// ret is newest to oldest
|
|
|
|
|
|
|
|
if (nFrom > (int)ret.size())
|
|
|
|
nFrom = ret.size();
|
|
|
|
if ((nFrom + nCount) > (int)ret.size())
|
|
|
|
nCount = ret.size() - nFrom;
|
|
|
|
Array::iterator first = ret.begin();
|
|
|
|
std::advance(first, nFrom);
|
|
|
|
Array::iterator last = ret.begin();
|
|
|
|
std::advance(last, nFrom+nCount);
|
|
|
|
|
|
|
|
if (last != ret.end()) ret.erase(last, ret.end());
|
|
|
|
if (first != ret.begin()) ret.erase(ret.begin(), first);
|
|
|
|
|
|
|
|
std::reverse(ret.begin(), ret.end()); // Return oldest to newest
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value listaccounts(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"listaccounts [minconf=1]\n"
|
|
|
|
"Returns Object that has account names as keys, account balances as values.");
|
|
|
|
|
|
|
|
int nMinDepth = 1;
|
|
|
|
if (params.size() > 0)
|
|
|
|
nMinDepth = params[0].get_int();
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
map<string, int64_t> mapAccountBalances;
|
2013-07-15 07:20:50 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
|
2012-08-21 16:38:57 +02:00
|
|
|
if (IsMine(*pwalletMain, entry.first)) // This address belongs to me
|
2013-07-15 07:20:50 +02:00
|
|
|
mapAccountBalances[entry.second.name] = 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
|
|
|
{
|
|
|
|
const CWalletTx& wtx = (*it).second;
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nFee;
|
2012-08-21 16:38:57 +02:00
|
|
|
string strSentAccount;
|
2013-04-13 07:13:08 +02:00
|
|
|
list<pair<CTxDestination, int64_t> > listReceived;
|
|
|
|
list<pair<CTxDestination, int64_t> > listSent;
|
2012-06-02 04:33:28 +02:00
|
|
|
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount);
|
2012-08-21 16:38:57 +02:00
|
|
|
mapAccountBalances[strSentAccount] -= nFee;
|
2013-04-13 07:13:08 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent)
|
2012-08-21 16:38:57 +02:00
|
|
|
mapAccountBalances[strSentAccount] -= s.second;
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
|
|
|
{
|
2013-04-13 07:13:08 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& r, listReceived)
|
2012-08-21 16:38:57 +02:00
|
|
|
if (pwalletMain->mapAddressBook.count(r.first))
|
2013-07-15 07:20:50 +02:00
|
|
|
mapAccountBalances[pwalletMain->mapAddressBook[r.first].name] += r.second;
|
2012-08-21 16:38:57 +02:00
|
|
|
else
|
|
|
|
mapAccountBalances[""] += r.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list<CAccountingEntry> acentries;
|
|
|
|
CWalletDB(pwalletMain->strWalletFile).ListAccountCreditDebit("*", acentries);
|
|
|
|
BOOST_FOREACH(const CAccountingEntry& entry, acentries)
|
|
|
|
mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
|
|
|
|
|
|
|
|
Object ret;
|
2013-04-13 07:13:08 +02:00
|
|
|
BOOST_FOREACH(const PAIRTYPE(string, int64_t)& accountBalance, mapAccountBalances) {
|
2012-08-21 16:38:57 +02:00
|
|
|
ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value listsinceblock(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp)
|
|
|
|
throw runtime_error(
|
|
|
|
"listsinceblock [blockhash] [target-confirmations]\n"
|
2013-08-15 23:15:39 +02:00
|
|
|
"Get all wallet transactions in blocks since block [blockhash], or all wallet transactions if omitted");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
CBlockIndex *pindex = NULL;
|
|
|
|
int target_confirms = 1;
|
|
|
|
|
|
|
|
if (params.size() > 0)
|
|
|
|
{
|
|
|
|
uint256 blockId = 0;
|
|
|
|
|
|
|
|
blockId.SetHex(params[0].get_str());
|
2013-10-12 15:18:08 +02:00
|
|
|
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(blockId);
|
|
|
|
if (it != mapBlockIndex.end())
|
|
|
|
pindex = it->second;
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (params.size() > 1)
|
|
|
|
{
|
|
|
|
target_confirms = params[1].get_int();
|
|
|
|
|
|
|
|
if (target_confirms < 1)
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
2013-10-10 23:07:44 +02:00
|
|
|
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
Array transactions;
|
|
|
|
|
|
|
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++)
|
|
|
|
{
|
|
|
|
CWalletTx tx = (*it).second;
|
|
|
|
|
|
|
|
if (depth == -1 || tx.GetDepthInMainChain() < depth)
|
|
|
|
ListTransactions(tx, "*", 0, true, transactions);
|
|
|
|
}
|
|
|
|
|
2013-10-10 23:07:44 +02:00
|
|
|
CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
|
|
|
|
uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : 0;
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
Object ret;
|
|
|
|
ret.push_back(Pair("transactions", transactions));
|
|
|
|
ret.push_back(Pair("lastblock", lastblock.GetHex()));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value gettransaction(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"gettransaction <txid>\n"
|
|
|
|
"Get detailed information about in-wallet transaction <txid>");
|
|
|
|
|
|
|
|
uint256 hash;
|
|
|
|
hash.SetHex(params[0].get_str());
|
|
|
|
|
|
|
|
Object entry;
|
|
|
|
if (!pwalletMain->mapWallet.count(hash))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
|
2012-08-21 16:38:57 +02:00
|
|
|
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nCredit = wtx.GetCredit();
|
|
|
|
int64_t nDebit = wtx.GetDebit();
|
|
|
|
int64_t nNet = nCredit - nDebit;
|
|
|
|
int64_t nFee = (wtx.IsFromMe() ? GetValueOut(wtx) - nDebit : 0);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
|
|
|
|
if (wtx.IsFromMe())
|
|
|
|
entry.push_back(Pair("fee", ValueFromAmount(nFee)));
|
|
|
|
|
|
|
|
WalletTxToJSON(wtx, entry);
|
|
|
|
|
|
|
|
Array details;
|
|
|
|
ListTransactions(wtx, "*", 0, false, details);
|
|
|
|
entry.push_back(Pair("details", details));
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value backupwallet(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"backupwallet <destination>\n"
|
|
|
|
"Safely copies wallet.dat to destination, which can be a directory or a path with filename.");
|
|
|
|
|
|
|
|
string strDest = params[0].get_str();
|
2012-11-27 16:27:54 +01:00
|
|
|
if (!BackupWallet(*pwalletMain, strDest))
|
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return Value::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value keypoolrefill(const Array& params, bool fHelp)
|
|
|
|
{
|
2013-06-25 22:21:42 +02:00
|
|
|
if (fHelp || params.size() > 1)
|
2012-08-21 16:38:57 +02:00
|
|
|
throw runtime_error(
|
2013-06-25 22:21:42 +02:00
|
|
|
"keypoolrefill [new-size]\n"
|
2012-08-21 16:38:57 +02:00
|
|
|
"Fills the keypool."
|
|
|
|
+ HelpRequiringPassphrase());
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
unsigned int kpSize = max(GetArg("-keypool", 100), (int64_t) 0);
|
2013-06-25 22:21:42 +02:00
|
|
|
if (params.size() > 0) {
|
|
|
|
if (params[0].get_int() < 0)
|
2013-10-23 16:19:49 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size");
|
2013-06-25 22:21:42 +02:00
|
|
|
kpSize = (unsigned int) params[0].get_int();
|
|
|
|
}
|
|
|
|
|
2012-08-21 16:38:57 +02:00
|
|
|
EnsureWalletIsUnlocked();
|
|
|
|
|
2013-06-25 22:21:42 +02:00
|
|
|
pwalletMain->TopUpKeyPool(kpSize);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2013-06-25 22:21:42 +02:00
|
|
|
if (pwalletMain->GetKeyPoolSize() < kpSize)
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return Value::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-07 16:47:00 +02:00
|
|
|
static void LockWallet(CWallet* pWallet)
|
2012-08-21 16:38:57 +02:00
|
|
|
{
|
2013-05-07 16:47:00 +02:00
|
|
|
LOCK(cs_nWalletUnlockTime);
|
|
|
|
nWalletUnlockTime = 0;
|
|
|
|
pWallet->Lock();
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value walletpassphrase(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
|
|
|
|
throw runtime_error(
|
|
|
|
"walletpassphrase <passphrase> <timeout>\n"
|
|
|
|
"Stores the wallet decryption key in memory for <timeout> seconds.");
|
|
|
|
if (fHelp)
|
|
|
|
return true;
|
2013-10-23 16:19:49 +02:00
|
|
|
if (!fServer)
|
|
|
|
throw JSONRPCError(RPC_SERVER_NOT_STARTED, "Error: RPC server was not started, use server=1 to change this.");
|
2012-08-21 16:38:57 +02:00
|
|
|
if (!pwalletMain->IsCrypted())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// Note that the walletpassphrase is stored in params[0] which is not mlock()ed
|
|
|
|
SecureString strWalletPass;
|
|
|
|
strWalletPass.reserve(100);
|
|
|
|
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
|
|
|
|
// Alternately, find a way to make params[0] mlock()'d to begin with.
|
|
|
|
strWalletPass = params[0].get_str().c_str();
|
|
|
|
|
|
|
|
if (strWalletPass.length() > 0)
|
|
|
|
{
|
|
|
|
if (!pwalletMain->Unlock(strWalletPass))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
throw runtime_error(
|
|
|
|
"walletpassphrase <passphrase> <timeout>\n"
|
|
|
|
"Stores the wallet decryption key in memory for <timeout> seconds.");
|
|
|
|
|
2013-05-07 16:47:00 +02:00
|
|
|
pwalletMain->TopUpKeyPool();
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t nSleepTime = params[1].get_int64();
|
2013-05-07 16:47:00 +02:00
|
|
|
LOCK(cs_nWalletUnlockTime);
|
|
|
|
nWalletUnlockTime = GetTime() + nSleepTime;
|
|
|
|
RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return Value::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value walletpassphrasechange(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
|
|
|
|
throw runtime_error(
|
|
|
|
"walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
|
|
|
|
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
|
|
|
|
if (fHelp)
|
|
|
|
return true;
|
|
|
|
if (!pwalletMain->IsCrypted())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
|
|
|
|
// Alternately, find a way to make params[0] mlock()'d to begin with.
|
|
|
|
SecureString strOldWalletPass;
|
|
|
|
strOldWalletPass.reserve(100);
|
|
|
|
strOldWalletPass = params[0].get_str().c_str();
|
|
|
|
|
|
|
|
SecureString strNewWalletPass;
|
|
|
|
strNewWalletPass.reserve(100);
|
|
|
|
strNewWalletPass = params[1].get_str().c_str();
|
|
|
|
|
|
|
|
if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
|
|
|
|
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
|
|
|
|
|
|
|
|
if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
return Value::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value walletlock(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0))
|
|
|
|
throw runtime_error(
|
|
|
|
"walletlock\n"
|
|
|
|
"Removes the wallet encryption key from memory, locking the wallet.\n"
|
|
|
|
"After calling this method, you will need to call walletpassphrase again\n"
|
|
|
|
"before being able to call any methods which require the wallet to be unlocked.");
|
|
|
|
if (fHelp)
|
|
|
|
return true;
|
|
|
|
if (!pwalletMain->IsCrypted())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
LOCK(cs_nWalletUnlockTime);
|
|
|
|
pwalletMain->Lock();
|
|
|
|
nWalletUnlockTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Value::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value encryptwallet(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1))
|
|
|
|
throw runtime_error(
|
|
|
|
"encryptwallet <passphrase>\n"
|
|
|
|
"Encrypts the wallet with <passphrase>.");
|
|
|
|
if (fHelp)
|
|
|
|
return true;
|
|
|
|
if (pwalletMain->IsCrypted())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
|
|
|
|
// Alternately, find a way to make params[0] mlock()'d to begin with.
|
|
|
|
SecureString strWalletPass;
|
|
|
|
strWalletPass.reserve(100);
|
|
|
|
strWalletPass = params[0].get_str().c_str();
|
|
|
|
|
|
|
|
if (strWalletPass.length() < 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"encryptwallet <passphrase>\n"
|
|
|
|
"Encrypts the wallet with <passphrase>.");
|
|
|
|
|
|
|
|
if (!pwalletMain->EncryptWallet(strWalletPass))
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
// 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
|
2012-08-23 14:19:13 +02:00
|
|
|
// unencrypted private keys. So:
|
2012-08-21 16:38:57 +02:00
|
|
|
StartShutdown();
|
2012-09-18 18:26:02 +02:00
|
|
|
return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class DescribeAddressVisitor : public boost::static_visitor<Object>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Object operator()(const CNoDestination &dest) const { return Object(); }
|
|
|
|
|
|
|
|
Object operator()(const CKeyID &keyID) const {
|
|
|
|
Object obj;
|
|
|
|
CPubKey vchPubKey;
|
|
|
|
pwalletMain->GetPubKey(keyID, vchPubKey);
|
|
|
|
obj.push_back(Pair("isscript", false));
|
2013-04-30 21:56:04 +02:00
|
|
|
obj.push_back(Pair("pubkey", HexStr(vchPubKey)));
|
2012-08-21 16:38:57 +02:00
|
|
|
obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object operator()(const CScriptID &scriptID) const {
|
|
|
|
Object obj;
|
|
|
|
obj.push_back(Pair("isscript", true));
|
|
|
|
CScript subscript;
|
|
|
|
pwalletMain->GetCScript(scriptID, subscript);
|
|
|
|
std::vector<CTxDestination> addresses;
|
|
|
|
txnouttype whichType;
|
|
|
|
int nRequired;
|
|
|
|
ExtractDestinations(subscript, whichType, addresses, nRequired);
|
|
|
|
obj.push_back(Pair("script", GetTxnOutputType(whichType)));
|
2013-07-15 09:07:38 +02:00
|
|
|
obj.push_back(Pair("hex", HexStr(subscript.begin(), subscript.end())));
|
2012-08-21 16:38:57 +02:00
|
|
|
Array a;
|
|
|
|
BOOST_FOREACH(const CTxDestination& addr, addresses)
|
|
|
|
a.push_back(CBitcoinAddress(addr).ToString());
|
|
|
|
obj.push_back(Pair("addresses", a));
|
|
|
|
if (whichType == TX_MULTISIG)
|
|
|
|
obj.push_back(Pair("sigsrequired", nRequired));
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Value validateaddress(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() != 1)
|
|
|
|
throw runtime_error(
|
|
|
|
"validateaddress <bitcoinaddress>\n"
|
|
|
|
"Return information about <bitcoinaddress>.");
|
|
|
|
|
|
|
|
CBitcoinAddress address(params[0].get_str());
|
|
|
|
bool isValid = address.IsValid();
|
|
|
|
|
|
|
|
Object ret;
|
|
|
|
ret.push_back(Pair("isvalid", isValid));
|
|
|
|
if (isValid)
|
|
|
|
{
|
|
|
|
CTxDestination dest = address.Get();
|
|
|
|
string currentAddress = address.ToString();
|
|
|
|
ret.push_back(Pair("address", currentAddress));
|
2013-08-26 04:02:57 +02:00
|
|
|
bool fMine = pwalletMain ? IsMine(*pwalletMain, dest) : false;
|
2012-08-21 16:38:57 +02:00
|
|
|
ret.push_back(Pair("ismine", fMine));
|
|
|
|
if (fMine) {
|
|
|
|
Object detail = boost::apply_visitor(DescribeAddressVisitor(), dest);
|
|
|
|
ret.insert(ret.end(), detail.begin(), detail.end());
|
|
|
|
}
|
2013-08-26 04:02:57 +02:00
|
|
|
if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
|
2013-07-15 07:20:50 +02:00
|
|
|
ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
|
2012-08-21 16:38:57 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-27 19:52:09 +02:00
|
|
|
Value lockunspent(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
|
|
|
throw runtime_error(
|
|
|
|
"lockunspent unlock? [array-of-Objects]\n"
|
|
|
|
"Updates list of temporarily unspendable outputs.");
|
|
|
|
|
|
|
|
if (params.size() == 1)
|
|
|
|
RPCTypeCheck(params, list_of(bool_type));
|
|
|
|
else
|
|
|
|
RPCTypeCheck(params, list_of(bool_type)(array_type));
|
|
|
|
|
|
|
|
bool fUnlock = params[0].get_bool();
|
|
|
|
|
|
|
|
if (params.size() == 1) {
|
|
|
|
if (fUnlock)
|
|
|
|
pwalletMain->UnlockAllCoins();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Array outputs = params[1].get_array();
|
|
|
|
BOOST_FOREACH(Value& output, outputs)
|
|
|
|
{
|
|
|
|
if (output.type() != obj_type)
|
2013-08-06 13:52:38 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
|
2012-09-27 19:52:09 +02:00
|
|
|
const Object& o = output.get_obj();
|
|
|
|
|
|
|
|
RPCTypeCheck(o, map_list_of("txid", str_type)("vout", int_type));
|
|
|
|
|
|
|
|
string txid = find_value(o, "txid").get_str();
|
|
|
|
if (!IsHex(txid))
|
2013-08-06 13:52:38 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
|
2012-09-27 19:52:09 +02:00
|
|
|
|
|
|
|
int nOutput = find_value(o, "vout").get_int();
|
|
|
|
if (nOutput < 0)
|
2013-08-06 13:52:38 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
|
2012-09-27 19:52:09 +02:00
|
|
|
|
|
|
|
COutPoint outpt(uint256(txid), nOutput);
|
|
|
|
|
|
|
|
if (fUnlock)
|
|
|
|
pwalletMain->UnlockCoin(outpt);
|
|
|
|
else
|
|
|
|
pwalletMain->LockCoin(outpt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value listlockunspent(const Array& params, bool fHelp)
|
|
|
|
{
|
|
|
|
if (fHelp || params.size() > 0)
|
|
|
|
throw runtime_error(
|
|
|
|
"listlockunspent\n"
|
|
|
|
"Returns list of temporarily unspendable outputs.");
|
|
|
|
|
|
|
|
vector<COutPoint> vOutpts;
|
|
|
|
pwalletMain->ListLockedCoins(vOutpts);
|
|
|
|
|
|
|
|
Array ret;
|
|
|
|
|
|
|
|
BOOST_FOREACH(COutPoint &outpt, vOutpts) {
|
|
|
|
Object o;
|
|
|
|
|
|
|
|
o.push_back(Pair("txid", outpt.hash.GetHex()));
|
|
|
|
o.push_back(Pair("vout", (int)outpt.n));
|
|
|
|
ret.push_back(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|