You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2098 lines
90 KiB
2098 lines
90 KiB
12 years ago
|
// Copyright (c) 2010 Satoshi Nakamoto
|
||
10 years ago
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||
10 years ago
|
// Distributed under the MIT software license, see the accompanying
|
||
12 years ago
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
|
|
||
10 years ago
|
#include "amount.h"
|
||
12 years ago
|
#include "base58.h"
|
||
11 years ago
|
#include "core_io.h"
|
||
11 years ago
|
#include "rpcserver.h"
|
||
12 years ago
|
#include "init.h"
|
||
12 years ago
|
#include "net.h"
|
||
|
#include "netbase.h"
|
||
11 years ago
|
#include "timedata.h"
|
||
12 years ago
|
#include "util.h"
|
||
10 years ago
|
#include "utilmoneystr.h"
|
||
12 years ago
|
#include "wallet.h"
|
||
|
#include "walletdb.h"
|
||
|
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#include <boost/assign/list_of.hpp>
|
||
10 years ago
|
|
||
12 years ago
|
#include "json/json_spirit_utils.h"
|
||
|
#include "json/json_spirit_value.h"
|
||
12 years ago
|
|
||
|
using namespace std;
|
||
12 years ago
|
using namespace json_spirit;
|
||
12 years ago
|
|
||
12 years ago
|
int64_t nWalletUnlockTime;
|
||
12 years ago
|
static CCriticalSection cs_nWalletUnlockTime;
|
||
|
|
||
12 years ago
|
std::string HelpRequiringPassphrase()
|
||
12 years ago
|
{
|
||
11 years ago
|
return pwalletMain && pwalletMain->IsCrypted()
|
||
11 years ago
|
? "\nRequires wallet passphrase to be set with walletpassphrase call."
|
||
12 years ago
|
: "";
|
||
|
}
|
||
|
|
||
12 years ago
|
void EnsureWalletIsUnlocked()
|
||
12 years ago
|
{
|
||
|
if (pwalletMain->IsLocked())
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
|
||
12 years ago
|
}
|
||
|
|
||
|
void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
|
||
|
{
|
||
|
int confirms = wtx.GetDepthInMainChain();
|
||
|
entry.push_back(Pair("confirmations", confirms));
|
||
13 years ago
|
if (wtx.IsCoinBase())
|
||
|
entry.push_back(Pair("generated", true));
|
||
11 years ago
|
if (confirms > 0)
|
||
12 years ago
|
{
|
||
|
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
|
||
|
entry.push_back(Pair("blockindex", wtx.nIndex));
|
||
11 years ago
|
entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
|
||
12 years ago
|
}
|
||
11 years ago
|
uint256 hash = wtx.GetHash();
|
||
|
entry.push_back(Pair("txid", hash.GetHex()));
|
||
|
Array conflicts;
|
||
|
BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())
|
||
|
conflicts.push_back(conflict.GetHex());
|
||
|
entry.push_back(Pair("walletconflicts", conflicts));
|
||
11 years ago
|
entry.push_back(Pair("time", wtx.GetTxTime()));
|
||
11 years ago
|
entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
|
||
12 years ago
|
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 == "*")
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name");
|
||
12 years ago
|
return strAccount;
|
||
|
}
|
||
|
|
||
|
Value getnewaddress(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() > 1)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"getnewaddress ( \"account\" )\n"
|
||
|
"\nReturns a new Bitcoin address for receiving payments.\n"
|
||
10 years ago
|
"If 'account' is specified (DEPRECATED), it is added to the address book \n"
|
||
11 years ago
|
"so payments received with the address will be credited to 'account'.\n"
|
||
|
"\nArguments:\n"
|
||
10 years ago
|
"1. \"account\" (string, optional) DEPRECATED. The account name for the address to be linked to. If not provided, the default account \"\" is used. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created if there is no account by the given name.\n"
|
||
11 years ago
|
"\nResult:\n"
|
||
|
"\"bitcoinaddress\" (string) The new bitcoin address\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("getnewaddress", "")
|
||
10 years ago
|
+ HelpExampleRpc("getnewaddress", "")
|
||
11 years ago
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
// 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;
|
||
11 years ago
|
if (!pwalletMain->GetKeyFromPool(newKey))
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
|
||
12 years ago
|
CKeyID keyID = newKey.GetID();
|
||
|
|
||
11 years ago
|
pwalletMain->SetAddressBook(keyID, strAccount, "receive");
|
||
12 years ago
|
|
||
|
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())
|
||
|
{
|
||
10 years ago
|
CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
|
||
12 years ago
|
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)
|
||
|
{
|
||
11 years ago
|
if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
|
||
12 years ago
|
|
||
11 years ago
|
pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
|
||
12 years ago
|
walletdb.WriteAccount(strAccount, account);
|
||
|
}
|
||
|
|
||
|
return CBitcoinAddress(account.vchPubKey.GetID());
|
||
|
}
|
||
|
|
||
|
Value getaccountaddress(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() != 1)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"getaccountaddress \"account\"\n"
|
||
10 years ago
|
"\nDEPRECATED. Returns the current Bitcoin address for receiving payments to this account.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
|
"1. \"account\" (string, required) The account name for the address. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created and a new address created if there is no account by the given name.\n"
|
||
|
"\nResult:\n"
|
||
|
"\"bitcoinaddress\" (string) The account bitcoin address\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("getaccountaddress", "")
|
||
|
+ HelpExampleCli("getaccountaddress", "\"\"")
|
||
|
+ HelpExampleCli("getaccountaddress", "\"myaccount\"")
|
||
|
+ HelpExampleRpc("getaccountaddress", "\"myaccount\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
// 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;
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
Value getrawchangeaddress(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() > 1)
|
||
|
throw runtime_error(
|
||
|
"getrawchangeaddress\n"
|
||
11 years ago
|
"\nReturns a new Bitcoin address, for receiving change.\n"
|
||
|
"This is for use with raw transactions, NOT normal use.\n"
|
||
|
"\nResult:\n"
|
||
|
"\"address\" (string) The address\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("getrawchangeaddress", "")
|
||
|
+ HelpExampleRpc("getrawchangeaddress", "")
|
||
|
);
|
||
11 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
11 years ago
|
if (!pwalletMain->IsLocked())
|
||
|
pwalletMain->TopUpKeyPool();
|
||
|
|
||
|
CReserveKey reservekey(pwalletMain);
|
||
|
CPubKey vchPubKey;
|
||
|
if (!reservekey.GetReservedKey(vchPubKey))
|
||
11 years ago
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
|
||
11 years ago
|
|
||
|
reservekey.KeepKey();
|
||
|
|
||
|
CKeyID keyID = vchPubKey.GetID();
|
||
|
|
||
|
return CBitcoinAddress(keyID).ToString();
|
||
|
}
|
||
|
|
||
12 years ago
|
|
||
|
Value setaccount(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"setaccount \"bitcoinaddress\" \"account\"\n"
|
||
10 years ago
|
"\nDEPRECATED. Sets the account associated with the given address.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
|
"1. \"bitcoinaddress\" (string, required) The bitcoin address to be associated with an account.\n"
|
||
|
"2. \"account\" (string, required) The account to assign the address to.\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"tabby\"")
|
||
|
+ HelpExampleRpc("setaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"tabby\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
CBitcoinAddress address(params[0].get_str());
|
||
|
if (!address.IsValid())
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||
12 years ago
|
|
||
|
string strAccount;
|
||
|
if (params.size() > 1)
|
||
|
strAccount = AccountFromValue(params[1]);
|
||
|
|
||
10 years ago
|
// Only add the account if the address is yours.
|
||
|
if (IsMine(*pwalletMain, address.Get()))
|
||
12 years ago
|
{
|
||
10 years ago
|
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
||
|
if (pwalletMain->mapAddressBook.count(address.Get()))
|
||
|
{
|
||
|
string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
|
||
|
if (address == GetAccountAddress(strOldAccount))
|
||
|
GetAccountAddress(strOldAccount, true);
|
||
|
}
|
||
|
pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
|
||
12 years ago
|
}
|
||
10 years ago
|
else
|
||
|
throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
|
||
12 years ago
|
|
||
|
return Value::null;
|
||
|
}
|
||
|
|
||
|
|
||
|
Value getaccount(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() != 1)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"getaccount \"bitcoinaddress\"\n"
|
||
10 years ago
|
"\nDEPRECATED. Returns the account associated with the given address.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
|
"1. \"bitcoinaddress\" (string, required) The bitcoin address for account lookup.\n"
|
||
|
"\nResult:\n"
|
||
|
"\"accountname\" (string) the account address\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\"")
|
||
|
+ HelpExampleRpc("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
CBitcoinAddress address(params[0].get_str());
|
||
|
if (!address.IsValid())
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||
12 years ago
|
|
||
|
string strAccount;
|
||
12 years ago
|
map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
|
||
|
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
|
||
|
strAccount = (*mi).second.name;
|
||
12 years ago
|
return strAccount;
|
||
|
}
|
||
|
|
||
|
|
||
|
Value getaddressesbyaccount(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() != 1)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"getaddressesbyaccount \"account\"\n"
|
||
10 years ago
|
"\nDEPRECATED. Returns the list of addresses for the given account.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
|
"1. \"account\" (string, required) The account name.\n"
|
||
|
"\nResult:\n"
|
||
|
"[ (json array of string)\n"
|
||
|
" \"bitcoinaddress\" (string) a bitcoin address associated with the given account\n"
|
||
|
" ,...\n"
|
||
|
"]\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("getaddressesbyaccount", "\"tabby\"")
|
||
|
+ HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
string strAccount = AccountFromValue(params[0]);
|
||
|
|
||
|
// Find all addresses that have the given account
|
||
|
Array ret;
|
||
12 years ago
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
|
||
12 years ago
|
{
|
||
|
const CBitcoinAddress& address = item.first;
|
||
12 years ago
|
const string& strName = item.second.name;
|
||
12 years ago
|
if (strName == strAccount)
|
||
|
ret.push_back(address.ToString());
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
10 years ago
|
static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew)
|
||
10 years ago
|
{
|
||
10 years ago
|
CAmount curBalance = pwalletMain->GetBalance();
|
||
|
|
||
10 years ago
|
// Check amount
|
||
|
if (nValue <= 0)
|
||
10 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
|
||
10 years ago
|
|
||
10 years ago
|
if (nValue > curBalance)
|
||
10 years ago
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
|
||
|
|
||
|
// Parse Bitcoin address
|
||
|
CScript scriptPubKey = GetScriptForDestination(address);
|
||
|
|
||
|
// Create and send the transaction
|
||
|
CReserveKey reservekey(pwalletMain);
|
||
|
CAmount nFeeRequired;
|
||
10 years ago
|
std::string strError;
|
||
10 years ago
|
vector<CRecipient> vecSend;
|
||
|
int nChangePosRet = -1;
|
||
|
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
|
||
|
vecSend.push_back(recipient);
|
||
|
if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError)) {
|
||
|
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > pwalletMain->GetBalance())
|
||
|
strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
|
||
|
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
||
10 years ago
|
}
|
||
|
if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
|
||
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
|
||
|
}
|
||
|
|
||
12 years ago
|
Value sendtoaddress(const Array& params, bool fHelp)
|
||
|
{
|
||
10 years ago
|
if (fHelp || params.size() < 2 || params.size() > 5)
|
||
12 years ago
|
throw runtime_error(
|
||
10 years ago
|
"sendtoaddress \"bitcoinaddress\" amount ( \"comment\" \"comment-to\" subtractfeefromamount )\n"
|
||
10 years ago
|
"\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n"
|
||
11 years ago
|
+ HelpRequiringPassphrase() +
|
||
|
"\nArguments:\n"
|
||
|
"1. \"bitcoinaddress\" (string, required) The bitcoin address to send to.\n"
|
||
|
"2. \"amount\" (numeric, required) The amount in btc to send. eg 0.1\n"
|
||
|
"3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
|
||
|
" This is not part of the transaction, just kept in your wallet.\n"
|
||
|
"4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n"
|
||
|
" to which you're sending the transaction. This is not part of the \n"
|
||
|
" transaction, just kept in your wallet.\n"
|
||
10 years ago
|
"5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
|
||
|
" The recipient will receive less bitcoins than you enter in the amount field.\n"
|
||
11 years ago
|
"\nResult:\n"
|
||
11 years ago
|
"\"transactionid\" (string) The transaction id.\n"
|
||
11 years ago
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1")
|
||
|
+ HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"")
|
||
10 years ago
|
+ HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" true")
|
||
11 years ago
|
+ HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.1, \"donation\", \"seans outpost\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
CBitcoinAddress address(params[0].get_str());
|
||
|
if (!address.IsValid())
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||
12 years ago
|
|
||
|
// Amount
|
||
11 years ago
|
CAmount nAmount = AmountFromValue(params[1]);
|
||
12 years ago
|
|
||
|
// 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();
|
||
|
|
||
10 years ago
|
bool fSubtractFeeFromAmount = false;
|
||
|
if (params.size() > 4)
|
||
|
fSubtractFeeFromAmount = params[4].get_bool();
|
||
|
|
||
11 years ago
|
EnsureWalletIsUnlocked();
|
||
12 years ago
|
|
||
10 years ago
|
SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx);
|
||
12 years ago
|
|
||
|
return wtx.GetHash().GetHex();
|
||
|
}
|
||
|
|
||
12 years ago
|
Value listaddressgroupings(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp)
|
||
12 years ago
|
throw runtime_error(
|
||
|
"listaddressgroupings\n"
|
||
11 years ago
|
"\nLists groups of addresses which have had their common ownership\n"
|
||
12 years ago
|
"made public by common use as inputs or as the resulting change\n"
|
||
11 years ago
|
"in past transactions\n"
|
||
|
"\nResult:\n"
|
||
|
"[\n"
|
||
|
" [\n"
|
||
|
" [\n"
|
||
|
" \"bitcoinaddress\", (string) The bitcoin address\n"
|
||
|
" amount, (numeric) The amount in btc\n"
|
||
10 years ago
|
" \"account\" (string, optional) The account (DEPRECATED)\n"
|
||
11 years ago
|
" ]\n"
|
||
|
" ,...\n"
|
||
|
" ]\n"
|
||
|
" ,...\n"
|
||
|
"]\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("listaddressgroupings", "")
|
||
|
+ HelpExampleRpc("listaddressgroupings", "")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
Array jsonGroupings;
|
||
11 years ago
|
map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
|
||
12 years ago
|
BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
|
||
12 years ago
|
{
|
||
|
Array jsonGrouping;
|
||
12 years ago
|
BOOST_FOREACH(CTxDestination address, grouping)
|
||
12 years ago
|
{
|
||
|
Array addressInfo;
|
||
12 years ago
|
addressInfo.push_back(CBitcoinAddress(address).ToString());
|
||
12 years ago
|
addressInfo.push_back(ValueFromAmount(balances[address]));
|
||
|
{
|
||
|
LOCK(pwalletMain->cs_wallet);
|
||
|
if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
|
||
12 years ago
|
addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
|
||
12 years ago
|
}
|
||
|
jsonGrouping.push_back(addressInfo);
|
||
|
}
|
||
|
jsonGroupings.push_back(jsonGrouping);
|
||
|
}
|
||
|
return jsonGroupings;
|
||
|
}
|
||
|
|
||
12 years ago
|
Value signmessage(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() != 2)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"signmessage \"bitcoinaddress\" \"message\"\n"
|
||
|
"\nSign a message with the private key of an address"
|
||
|
+ HelpRequiringPassphrase() + "\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"bitcoinaddress\" (string, required) The bitcoin address to use for the private key.\n"
|
||
|
"2. \"message\" (string, required) The message to create a signature of.\n"
|
||
|
"\nResult:\n"
|
||
|
"\"signature\" (string) The signature of the message encoded in base 64\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nUnlock the wallet for 30 seconds\n"
|
||
|
+ HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
|
||
|
"\nCreate the signature\n"
|
||
|
+ HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
|
||
|
"\nVerify the signature\n"
|
||
|
+ HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
|
||
|
"\nAs json rpc\n"
|
||
|
+ HelpExampleRpc("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"my message\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
EnsureWalletIsUnlocked();
|
||
|
|
||
|
string strAddress = params[0].get_str();
|
||
|
string strMessage = params[1].get_str();
|
||
|
|
||
|
CBitcoinAddress addr(strAddress);
|
||
|
if (!addr.IsValid())
|
||
12 years ago
|
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
|
||
12 years ago
|
|
||
|
CKeyID keyID;
|
||
|
if (!addr.GetKeyID(keyID))
|
||
12 years ago
|
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
|
||
12 years ago
|
|
||
|
CKey key;
|
||
|
if (!pwalletMain->GetKey(keyID, key))
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
|
||
12 years ago
|
|
||
12 years ago
|
CHashWriter ss(SER_GETHASH, 0);
|
||
12 years ago
|
ss << strMessageMagic;
|
||
|
ss << strMessage;
|
||
|
|
||
|
vector<unsigned char> vchSig;
|
||
12 years ago
|
if (!key.SignCompact(ss.GetHash(), vchSig))
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
|
||
12 years ago
|
|
||
|
return EncodeBase64(&vchSig[0], vchSig.size());
|
||
|
}
|
||
|
|
||
|
Value getreceivedbyaddress(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"getreceivedbyaddress \"bitcoinaddress\" ( minconf )\n"
|
||
|
"\nReturns the total amount received by the given bitcoinaddress in transactions with at least minconf confirmations.\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"bitcoinaddress\" (string, required) The bitcoin address for transactions.\n"
|
||
|
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
|
||
|
"\nResult:\n"
|
||
|
"amount (numeric) The total amount in btc received at this address.\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nThe amount from transactions with at least 1 confirmation\n"
|
||
|
+ HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\"") +
|
||
|
"\nThe amount including unconfirmed transactions, zero confirmations\n"
|
||
|
+ HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" 0") +
|
||
|
"\nThe amount with at least 6 confirmation, very safe\n"
|
||
|
+ HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" 6") +
|
||
|
"\nAs a json rpc call\n"
|
||
|
+ HelpExampleRpc("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", 6")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
// Bitcoin address
|
||
|
CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
|
||
|
if (!address.IsValid())
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||
10 years ago
|
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
||
12 years ago
|
if (!IsMine(*pwalletMain,scriptPubKey))
|
||
|
return (double)0.0;
|
||
|
|
||
|
// Minimum confirmations
|
||
|
int nMinDepth = 1;
|
||
|
if (params.size() > 1)
|
||
|
nMinDepth = params[1].get_int();
|
||
|
|
||
|
// Tally
|
||
11 years ago
|
CAmount nAmount = 0;
|
||
12 years ago
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||
|
{
|
||
|
const CWalletTx& wtx = (*it).second;
|
||
12 years ago
|
if (wtx.IsCoinBase() || !IsFinalTx(wtx))
|
||
12 years ago
|
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(
|
||
11 years ago
|
"getreceivedbyaccount \"account\" ( minconf )\n"
|
||
10 years ago
|
"\nDEPRECATED. Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
|
"1. \"account\" (string, required) The selected account, may be the default account using \"\".\n"
|
||
|
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
|
||
|
"\nResult:\n"
|
||
|
"amount (numeric) The total amount in btc received for this account.\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nAmount received by the default account with at least 1 confirmation\n"
|
||
|
+ HelpExampleCli("getreceivedbyaccount", "\"\"") +
|
||
|
"\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n"
|
||
|
+ HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") +
|
||
|
"\nThe amount with at least 6 confirmation, very safe\n"
|
||
|
+ HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") +
|
||
|
"\nAs a json rpc call\n"
|
||
|
+ HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
// 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]);
|
||
12 years ago
|
set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
|
||
12 years ago
|
|
||
|
// Tally
|
||
11 years ago
|
CAmount nAmount = 0;
|
||
12 years ago
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||
|
{
|
||
|
const CWalletTx& wtx = (*it).second;
|
||
12 years ago
|
if (wtx.IsCoinBase() || !IsFinalTx(wtx))
|
||
12 years ago
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
|
||
12 years ago
|
{
|
||
11 years ago
|
CAmount nBalance = 0;
|
||
12 years ago
|
|
||
|
// Tally wallet transactions
|
||
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||
|
{
|
||
|
const CWalletTx& wtx = (*it).second;
|
||
11 years ago
|
if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
|
||
12 years ago
|
continue;
|
||
|
|
||
11 years ago
|
CAmount nReceived, nSent, nFee;
|
||
11 years ago
|
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
|
||
12 years ago
|
|
||
|
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
||
|
nBalance += nReceived;
|
||
13 years ago
|
nBalance -= nSent + nFee;
|
||
12 years ago
|
}
|
||
|
|
||
|
// Tally internal accounting entries
|
||
|
nBalance += walletdb.GetAccountCreditDebit(strAccount);
|
||
|
|
||
|
return nBalance;
|
||
|
}
|
||
|
|
||
11 years ago
|
CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
|
||
12 years ago
|
{
|
||
|
CWalletDB walletdb(pwalletMain->strWalletFile);
|
||
11 years ago
|
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
|
||
12 years ago
|
}
|
||
|
|
||
|
|
||
|
Value getbalance(const Array& params, bool fHelp)
|
||
|
{
|
||
11 years ago
|
if (fHelp || params.size() > 3)
|
||
12 years ago
|
throw runtime_error(
|
||
11 years ago
|
"getbalance ( \"account\" minconf includeWatchonly )\n"
|
||
11 years ago
|
"\nIf account is not specified, returns the server's total available balance.\n"
|
||
10 years ago
|
"If account is specified (DEPRECATED), returns the balance in the account.\n"
|
||
11 years ago
|
"Note that the account \"\" is not the same as leaving the parameter out.\n"
|
||
|
"The server total may be different to the balance in the default \"\" account.\n"
|
||
|
"\nArguments:\n"
|
||
10 years ago
|
"1. \"account\" (string, optional) DEPRECATED. The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n"
|
||
11 years ago
|
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
|
||
11 years ago
|
"3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n"
|
||
11 years ago
|
"\nResult:\n"
|
||
|
"amount (numeric) The total amount in btc received for this account.\n"
|
||
|
"\nExamples:\n"
|
||
10 years ago
|
"\nThe total amount in the wallet\n"
|
||
11 years ago
|
+ HelpExampleCli("getbalance", "") +
|
||
10 years ago
|
"\nThe total amount in the wallet at least 5 blocks confirmed\n"
|
||
11 years ago
|
+ HelpExampleCli("getbalance", "\"*\" 6") +
|
||
11 years ago
|
"\nAs a json rpc call\n"
|
||
10 years ago
|
+ HelpExampleRpc("getbalance", "\"*\", 6")
|
||
11 years ago
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
if (params.size() == 0)
|
||
|
return ValueFromAmount(pwalletMain->GetBalance());
|
||
|
|
||
|
int nMinDepth = 1;
|
||
|
if (params.size() > 1)
|
||
|
nMinDepth = params[1].get_int();
|
||
11 years ago
|
isminefilter filter = ISMINE_SPENDABLE;
|
||
11 years ago
|
if(params.size() > 2)
|
||
|
if(params[2].get_bool())
|
||
11 years ago
|
filter = filter | ISMINE_WATCH_ONLY;
|
||
12 years ago
|
|
||
|
if (params[0].get_str() == "*") {
|
||
|
// Calculate total balance a different way from GetBalance()
|
||
|
// (GetBalance() sums up all unspent TxOuts)
|
||
12 years ago
|
// getbalance and getbalance '*' 0 should return the same number
|
||
11 years ago
|
CAmount nBalance = 0;
|
||
12 years ago
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||
|
{
|
||
|
const CWalletTx& wtx = (*it).second;
|
||
11 years ago
|
if (!wtx.IsTrusted() || wtx.GetBlocksToMaturity() > 0)
|
||
12 years ago
|
continue;
|
||
|
|
||
11 years ago
|
CAmount allFee;
|
||
12 years ago
|
string strSentAccount;
|
||
11 years ago
|
list<COutputEntry> listReceived;
|
||
|
list<COutputEntry> listSent;
|
||
11 years ago
|
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
|
||
12 years ago
|
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
||
|
{
|
||
11 years ago
|
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||
|
nBalance += r.amount;
|
||
12 years ago
|
}
|
||
11 years ago
|
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||
|
nBalance -= s.amount;
|
||
12 years ago
|
nBalance -= allFee;
|
||
|
}
|
||
|
return ValueFromAmount(nBalance);
|
||
|
}
|
||
|
|
||
|
string strAccount = AccountFromValue(params[0]);
|
||
|
|
||
11 years ago
|
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
|
||
12 years ago
|
|
||
|
return ValueFromAmount(nBalance);
|
||
|
}
|
||
|
|
||
11 years ago
|
Value getunconfirmedbalance(const Array ¶ms, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() > 0)
|
||
|
throw runtime_error(
|
||
|
"getunconfirmedbalance\n"
|
||
|
"Returns the server's total unconfirmed balance\n");
|
||
10 years ago
|
|
||
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
11 years ago
|
return ValueFromAmount(pwalletMain->GetUnconfirmedBalance());
|
||
|
}
|
||
|
|
||
12 years ago
|
|
||
|
Value movecmd(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() < 3 || params.size() > 5)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
|
||
10 years ago
|
"\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
|
"1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
|
||
|
"2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
|
||
|
"3. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
|
||
|
"4. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
|
||
|
"\nResult:\n"
|
||
|
"true|false (boolean) true if successfull.\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nMove 0.01 btc from the default account to the account named tabby\n"
|
||
|
+ HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
|
||
|
"\nMove 0.01 btc timotei to akiko with a comment and funds have 6 confirmations\n"
|
||
|
+ HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
|
||
|
"\nAs a json rpc call\n"
|
||
|
+ HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
string strFrom = AccountFromValue(params[0]);
|
||
|
string strTo = AccountFromValue(params[1]);
|
||
11 years ago
|
CAmount nAmount = AmountFromValue(params[2]);
|
||
12 years ago
|
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())
|
||
12 years ago
|
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
|
||
12 years ago
|
|
||
12 years ago
|
int64_t nNow = GetAdjustedTime();
|
||
12 years ago
|
|
||
|
// Debit
|
||
|
CAccountingEntry debit;
|
||
12 years ago
|
debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
|
||
12 years ago
|
debit.strAccount = strFrom;
|
||
|
debit.nCreditDebit = -nAmount;
|
||
|
debit.nTime = nNow;
|
||
|
debit.strOtherAccount = strTo;
|
||
|
debit.strComment = strComment;
|
||
|
walletdb.WriteAccountingEntry(debit);
|
||
|
|
||
|
// Credit
|
||
|
CAccountingEntry credit;
|
||
12 years ago
|
credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
|
||
12 years ago
|
credit.strAccount = strTo;
|
||
|
credit.nCreditDebit = nAmount;
|
||
|
credit.nTime = nNow;
|
||
|
credit.strOtherAccount = strFrom;
|
||
|
credit.strComment = strComment;
|
||
|
walletdb.WriteAccountingEntry(credit);
|
||
|
|
||
|
if (!walletdb.TxnCommit())
|
||
12 years ago
|
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
|
||
12 years ago
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
Value sendfrom(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() < 3 || params.size() > 6)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"sendfrom \"fromaccount\" \"tobitcoinaddress\" amount ( minconf \"comment\" \"comment-to\" )\n"
|
||
10 years ago
|
"\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a bitcoin address.\n"
|
||
11 years ago
|
"The amount is a real and is rounded to the nearest 0.00000001."
|
||
|
+ HelpRequiringPassphrase() + "\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
|
||
|
"2. \"tobitcoinaddress\" (string, required) The bitcoin address to send funds to.\n"
|
||
|
"3. amount (numeric, required) The amount in btc. (transaction fee is added on top).\n"
|
||
|
"4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
|
||
|
"5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
|
||
|
" This is not part of the transaction, just kept in your wallet.\n"
|
||
|
"6. \"comment-to\" (string, optional) An optional comment to store the name of the person or organization \n"
|
||
|
" to which you're sending the transaction. This is not part of the transaction, \n"
|
||
|
" it is just kept in your wallet.\n"
|
||
|
"\nResult:\n"
|
||
11 years ago
|
"\"transactionid\" (string) The transaction id.\n"
|
||
11 years ago
|
"\nExamples:\n"
|
||
|
"\nSend 0.01 btc from the default account to the address, must have at least 1 confirmation\n"
|
||
|
+ HelpExampleCli("sendfrom", "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") +
|
||
|
"\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n"
|
||
|
+ HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") +
|
||
|
"\nAs a json rpc call\n"
|
||
|
+ HelpExampleRpc("sendfrom", "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 6, \"donation\", \"seans outpost\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
string strAccount = AccountFromValue(params[0]);
|
||
|
CBitcoinAddress address(params[1].get_str());
|
||
|
if (!address.IsValid())
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||
11 years ago
|
CAmount nAmount = AmountFromValue(params[2]);
|
||
12 years ago
|
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
|
||
11 years ago
|
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
||
12 years ago
|
if (nAmount > nBalance)
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
||
12 years ago
|
|
||
10 years ago
|
SendMoney(address.Get(), nAmount, false, wtx);
|
||
12 years ago
|
|
||
|
return wtx.GetHash().GetHex();
|
||
|
}
|
||
|
|
||
|
|
||
|
Value sendmany(const Array& params, bool fHelp)
|
||
|
{
|
||
10 years ago
|
if (fHelp || params.size() < 2 || params.size() > 5)
|
||
12 years ago
|
throw runtime_error(
|
||
10 years ago
|
"sendmany \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] )\n"
|
||
11 years ago
|
"\nSend multiple times. Amounts are double-precision floating point numbers."
|
||
|
+ HelpRequiringPassphrase() + "\n"
|
||
|
"\nArguments:\n"
|
||
10 years ago
|
"1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n"
|
||
11 years ago
|
"2. \"amounts\" (string, required) A json object with addresses and amounts\n"
|
||
|
" {\n"
|
||
|
" \"address\":amount (numeric) The bitcoin address is the key, the numeric amount in btc is the value\n"
|
||
|
" ,...\n"
|
||
|
" }\n"
|
||
|
"3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
|
||
|
"4. \"comment\" (string, optional) A comment\n"
|
||
10 years ago
|
"5. subtractfeefromamount (string, optional) A json array with addresses.\n"
|
||
10 years ago
|
" The fee will be equally deducted from the amount of each selected address.\n"
|
||
|
" Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
|
||
10 years ago
|
" If no addresses are specified here, the sender pays the fee.\n"
|
||
|
" [\n"
|
||
|
" \"address\" (string) Subtract fee from this address\n"
|
||
10 years ago
|
" ,...\n"
|
||
10 years ago
|
" ]\n"
|
||
11 years ago
|
"\nResult:\n"
|
||
|
"\"transactionid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
|
||
11 years ago
|
" the number of addresses.\n"
|
||
11 years ago
|
"\nExamples:\n"
|
||
|
"\nSend two amounts to two different addresses:\n"
|
||
10 years ago
|
+ HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"") +
|
||
11 years ago
|
"\nSend two amounts to two different addresses setting the confirmation and comment:\n"
|
||
10 years ago
|
+ HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 6 \"testing\"") +
|
||
10 years ago
|
"\nSend two amounts to two different addresses, subtract fee from amount:\n"
|
||
10 years ago
|
+ HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 1 \"\" \"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\",\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") +
|
||
11 years ago
|
"\nAs a json rpc call\n"
|
||
10 years ago
|
+ HelpExampleRpc("sendmany", "\"\", \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\", 6, \"testing\"")
|
||
11 years ago
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
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();
|
||
|
|
||
10 years ago
|
Array subtractFeeFromAmount;
|
||
10 years ago
|
if (params.size() > 4)
|
||
10 years ago
|
subtractFeeFromAmount = params[4].get_array();
|
||
10 years ago
|
|
||
12 years ago
|
set<CBitcoinAddress> setAddress;
|
||
10 years ago
|
vector<CRecipient> vecSend;
|
||
12 years ago
|
|
||
11 years ago
|
CAmount totalAmount = 0;
|
||
12 years ago
|
BOOST_FOREACH(const Pair& s, sendTo)
|
||
|
{
|
||
|
CBitcoinAddress address(s.name_);
|
||
|
if (!address.IsValid())
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+s.name_);
|
||
12 years ago
|
|
||
|
if (setAddress.count(address))
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
|
||
12 years ago
|
setAddress.insert(address);
|
||
|
|
||
10 years ago
|
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
||
11 years ago
|
CAmount nAmount = AmountFromValue(s.value_);
|
||
12 years ago
|
totalAmount += nAmount;
|
||
|
|
||
10 years ago
|
bool fSubtractFeeFromAmount = false;
|
||
10 years ago
|
BOOST_FOREACH(const Value& addr, subtractFeeFromAmount)
|
||
|
if (addr.get_str() == s.name_)
|
||
10 years ago
|
fSubtractFeeFromAmount = true;
|
||
|
|
||
|
CRecipient recipient = {scriptPubKey, nAmount, fSubtractFeeFromAmount};
|
||
|
vecSend.push_back(recipient);
|
||
12 years ago
|
}
|
||
|
|
||
|
EnsureWalletIsUnlocked();
|
||
|
|
||
|
// Check funds
|
||
11 years ago
|
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
||
12 years ago
|
if (totalAmount > nBalance)
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
||
12 years ago
|
|
||
|
// Send
|
||
|
CReserveKey keyChange(pwalletMain);
|
||
11 years ago
|
CAmount nFeeRequired = 0;
|
||
10 years ago
|
int nChangePosRet = -1;
|
||
12 years ago
|
string strFailReason;
|
||
10 years ago
|
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason);
|
||
12 years ago
|
if (!fCreated)
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
|
||
12 years ago
|
if (!pwalletMain->CommitTransaction(wtx, keyChange))
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
|
||
12 years ago
|
|
||
|
return wtx.GetHash().GetHex();
|
||
|
}
|
||
|
|
||
11 years ago
|
// Defined in rpcmisc.cpp
|
||
11 years ago
|
extern CScript _createmultisig_redeemScript(const Array& params);
|
||
12 years ago
|
|
||
|
Value addmultisigaddress(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() < 2 || params.size() > 3)
|
||
|
{
|
||
11 years ago
|
string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
|
||
|
"\nAdd a nrequired-to-sign multisignature address to the wallet.\n"
|
||
|
"Each key is a Bitcoin address or hex-encoded public key.\n"
|
||
10 years ago
|
"If 'account' is specified (DEPRECATED), assign address to that account.\n"
|
||
11 years ago
|
|
||
|
"\nArguments:\n"
|
||
|
"1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
|
||
|
"2. \"keysobject\" (string, required) A json array of bitcoin addresses or hex-encoded public keys\n"
|
||
|
" [\n"
|
||
|
" \"address\" (string) bitcoin address or hex-encoded public key\n"
|
||
|
" ...,\n"
|
||
|
" ]\n"
|
||
10 years ago
|
"3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n"
|
||
11 years ago
|
|
||
|
"\nResult:\n"
|
||
|
"\"bitcoinaddress\" (string) A bitcoin address associated with the keys.\n"
|
||
|
|
||
|
"\nExamples:\n"
|
||
|
"\nAdd a multisig address from 2 addresses\n"
|
||
|
+ HelpExampleCli("addmultisigaddress", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
|
||
|
"\nAs json rpc call\n"
|
||
|
+ HelpExampleRpc("addmultisigaddress", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
|
||
|
;
|
||
12 years ago
|
throw runtime_error(msg);
|
||
|
}
|
||
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
string strAccount;
|
||
|
if (params.size() > 2)
|
||
|
strAccount = AccountFromValue(params[2]);
|
||
12 years ago
|
|
||
|
// Construct using pay-to-script-hash:
|
||
11 years ago
|
CScript inner = _createmultisig_redeemScript(params);
|
||
10 years ago
|
CScriptID innerID(inner);
|
||
12 years ago
|
pwalletMain->AddCScript(inner);
|
||
|
|
||
11 years ago
|
pwalletMain->SetAddressBook(innerID, strAccount, "send");
|
||
12 years ago
|
return CBitcoinAddress(innerID).ToString();
|
||
|
}
|
||
|
|
||
|
|
||
|
struct tallyitem
|
||
|
{
|
||
11 years ago
|
CAmount nAmount;
|
||
12 years ago
|
int nConf;
|
||
12 years ago
|
vector<uint256> txids;
|
||
11 years ago
|
bool fIsWatchonly;
|
||
12 years ago
|
tallyitem()
|
||
|
{
|
||
|
nAmount = 0;
|
||
|
nConf = std::numeric_limits<int>::max();
|
||
11 years ago
|
fIsWatchonly = false;
|
||
12 years ago
|
}
|
||
|
};
|
||
|
|
||
|
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();
|
||
|
|
||
11 years ago
|
isminefilter filter = ISMINE_SPENDABLE;
|
||
11 years ago
|
if(params.size() > 2)
|
||
|
if(params[2].get_bool())
|
||
11 years ago
|
filter = filter | ISMINE_WATCH_ONLY;
|
||
11 years ago
|
|
||
12 years ago
|
// Tally
|
||
|
map<CBitcoinAddress, tallyitem> mapTally;
|
||
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||
|
{
|
||
|
const CWalletTx& wtx = (*it).second;
|
||
|
|
||
12 years ago
|
if (wtx.IsCoinBase() || !IsFinalTx(wtx))
|
||
12 years ago
|
continue;
|
||
|
|
||
|
int nDepth = wtx.GetDepthInMainChain();
|
||
|
if (nDepth < nMinDepth)
|
||
|
continue;
|
||
|
|
||
|
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
|
||
|
{
|
||
|
CTxDestination address;
|
||
11 years ago
|
if (!ExtractDestination(txout.scriptPubKey, address))
|
||
|
continue;
|
||
|
|
||
|
isminefilter mine = IsMine(*pwalletMain, address);
|
||
11 years ago
|
if(!(mine & filter))
|
||
12 years ago
|
continue;
|
||
|
|
||
|
tallyitem& item = mapTally[address];
|
||
|
item.nAmount += txout.nValue;
|
||
|
item.nConf = min(item.nConf, nDepth);
|
||
12 years ago
|
item.txids.push_back(wtx.GetHash());
|
||
11 years ago
|
if (mine & ISMINE_WATCH_ONLY)
|
||
11 years ago
|
item.fIsWatchonly = true;
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// Reply
|
||
|
Array ret;
|
||
|
map<string, tallyitem> mapAccountTally;
|
||
12 years ago
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
|
||
12 years ago
|
{
|
||
|
const CBitcoinAddress& address = item.first;
|
||
12 years ago
|
const string& strAccount = item.second.name;
|
||
12 years ago
|
map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address);
|
||
|
if (it == mapTally.end() && !fIncludeEmpty)
|
||
|
continue;
|
||
|
|
||
11 years ago
|
CAmount nAmount = 0;
|
||
12 years ago
|
int nConf = std::numeric_limits<int>::max();
|
||
11 years ago
|
bool fIsWatchonly = false;
|
||
12 years ago
|
if (it != mapTally.end())
|
||
|
{
|
||
|
nAmount = (*it).second.nAmount;
|
||
|
nConf = (*it).second.nConf;
|
||
11 years ago
|
fIsWatchonly = (*it).second.fIsWatchonly;
|
||
12 years ago
|
}
|
||
|
|
||
|
if (fByAccounts)
|
||
|
{
|
||
|
tallyitem& item = mapAccountTally[strAccount];
|
||
|
item.nAmount += nAmount;
|
||
|
item.nConf = min(item.nConf, nConf);
|
||
11 years ago
|
item.fIsWatchonly = fIsWatchonly;
|
||
12 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
Object obj;
|
||
11 years ago
|
if(fIsWatchonly)
|
||
|
obj.push_back(Pair("involvesWatchonly", true));
|
||
12 years ago
|
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)));
|
||
12 years ago
|
Array transactions;
|
||
12 years ago
|
if (it != mapTally.end())
|
||
12 years ago
|
{
|
||
12 years ago
|
BOOST_FOREACH(const uint256& item, (*it).second.txids)
|
||
|
{
|
||
|
transactions.push_back(item.GetHex());
|
||
|
}
|
||
12 years ago
|
}
|
||
|
obj.push_back(Pair("txids", transactions));
|
||
12 years ago
|
ret.push_back(obj);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (fByAccounts)
|
||
|
{
|
||
|
for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
|
||
|
{
|
||
11 years ago
|
CAmount nAmount = (*it).second.nAmount;
|
||
12 years ago
|
int nConf = (*it).second.nConf;
|
||
|
Object obj;
|
||
11 years ago
|
if((*it).second.fIsWatchonly)
|
||
|
obj.push_back(Pair("involvesWatchonly", true));
|
||
12 years ago
|
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)
|
||
|
{
|
||
11 years ago
|
if (fHelp || params.size() > 3)
|
||
12 years ago
|
throw runtime_error(
|
||
11 years ago
|
"listreceivedbyaddress ( minconf includeempty includeWatchonly)\n"
|
||
11 years ago
|
"\nList balances by receiving address.\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
|
||
10 years ago
|
"2. includeempty (numeric, optional, default=false) Whether to include addresses that haven't received any payments.\n"
|
||
11 years ago
|
"3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
|
||
11 years ago
|
|
||
|
"\nResult:\n"
|
||
|
"[\n"
|
||
|
" {\n"
|
||
10 years ago
|
" \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
|
||
11 years ago
|
" \"address\" : \"receivingaddress\", (string) The receiving address\n"
|
||
10 years ago
|
" \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n"
|
||
11 years ago
|
" \"amount\" : x.xxx, (numeric) The total amount in btc received by the address\n"
|
||
|
" \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
|
||
|
" }\n"
|
||
|
" ,...\n"
|
||
|
"]\n"
|
||
|
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("listreceivedbyaddress", "")
|
||
|
+ HelpExampleCli("listreceivedbyaddress", "6 true")
|
||
11 years ago
|
+ HelpExampleRpc("listreceivedbyaddress", "6, true, true")
|
||
11 years ago
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
return ListReceived(params, false);
|
||
|
}
|
||
|
|
||
|
Value listreceivedbyaccount(const Array& params, bool fHelp)
|
||
|
{
|
||
11 years ago
|
if (fHelp || params.size() > 3)
|
||
12 years ago
|
throw runtime_error(
|
||
11 years ago
|
"listreceivedbyaccount ( minconf includeempty includeWatchonly)\n"
|
||
10 years ago
|
"\nDEPRECATED. List balances by account.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
|
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
|
||
|
"2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n"
|
||
11 years ago
|
"3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"
|
||
11 years ago
|
|
||
|
"\nResult:\n"
|
||
|
"[\n"
|
||
|
" {\n"
|
||
10 years ago
|
" \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
|
||
11 years ago
|
" \"account\" : \"accountname\", (string) The account name of the receiving account\n"
|
||
|
" \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
|
||
|
" \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
|
||
|
" }\n"
|
||
|
" ,...\n"
|
||
|
"]\n"
|
||
|
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("listreceivedbyaccount", "")
|
||
|
+ HelpExampleCli("listreceivedbyaccount", "6 true")
|
||
11 years ago
|
+ HelpExampleRpc("listreceivedbyaccount", "6, true, true")
|
||
11 years ago
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
return ListReceived(params, true);
|
||
|
}
|
||
|
|
||
12 years ago
|
static void MaybePushAddress(Object & entry, const CTxDestination &dest)
|
||
|
{
|
||
|
CBitcoinAddress addr;
|
||
|
if (addr.Set(dest))
|
||
|
entry.push_back(Pair("address", addr.ToString()));
|
||
|
}
|
||
|
|
||
11 years ago
|
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter)
|
||
12 years ago
|
{
|
||
11 years ago
|
CAmount nFee;
|
||
12 years ago
|
string strSentAccount;
|
||
11 years ago
|
list<COutputEntry> listReceived;
|
||
|
list<COutputEntry> listSent;
|
||
12 years ago
|
|
||
11 years ago
|
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
|
||
12 years ago
|
|
||
|
bool fAllAccounts = (strAccount == string("*"));
|
||
11 years ago
|
bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
|
||
12 years ago
|
|
||
|
// Sent
|
||
|
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
|
||
|
{
|
||
11 years ago
|
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||
12 years ago
|
{
|
||
|
Object entry;
|
||
11 years ago
|
if(involvesWatchonly || (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY))
|
||
11 years ago
|
entry.push_back(Pair("involvesWatchonly", true));
|
||
12 years ago
|
entry.push_back(Pair("account", strSentAccount));
|
||
11 years ago
|
MaybePushAddress(entry, s.destination);
|
||
11 years ago
|
entry.push_back(Pair("category", "send"));
|
||
11 years ago
|
entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
|
||
|
entry.push_back(Pair("vout", s.vout));
|
||
12 years ago
|
entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
|
||
|
if (fLong)
|
||
|
WalletTxToJSON(wtx, entry);
|
||
|
ret.push_back(entry);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Received
|
||
|
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
|
||
|
{
|
||
11 years ago
|
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||
12 years ago
|
{
|
||
|
string account;
|
||
11 years ago
|
if (pwalletMain->mapAddressBook.count(r.destination))
|
||
|
account = pwalletMain->mapAddressBook[r.destination].name;
|
||
12 years ago
|
if (fAllAccounts || (account == strAccount))
|
||
|
{
|
||
|
Object entry;
|
||
11 years ago
|
if(involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY))
|
||
11 years ago
|
entry.push_back(Pair("involvesWatchonly", true));
|
||
12 years ago
|
entry.push_back(Pair("account", account));
|
||
11 years ago
|
MaybePushAddress(entry, r.destination);
|
||
13 years ago
|
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
|
||
11 years ago
|
{
|
||
11 years ago
|
entry.push_back(Pair("category", "receive"));
|
||
11 years ago
|
}
|
||
11 years ago
|
entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
|
||
|
entry.push_back(Pair("vout", r.vout));
|
||
12 years ago
|
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"));
|
||
11 years ago
|
entry.push_back(Pair("time", acentry.nTime));
|
||
12 years ago
|
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)
|
||
|
{
|
||
11 years ago
|
if (fHelp || params.size() > 4)
|
||
12 years ago
|
throw runtime_error(
|
||
11 years ago
|
"listtransactions ( \"account\" count from includeWatchonly)\n"
|
||
11 years ago
|
"\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
|
||
|
"\nArguments:\n"
|
||
10 years ago
|
"1. \"account\" (string, optional) DEPRECATED. The account name. Should be \"*\".\n"
|
||
11 years ago
|
"2. count (numeric, optional, default=10) The number of transactions to return\n"
|
||
|
"3. from (numeric, optional, default=0) The number of transactions to skip\n"
|
||
11 years ago
|
"4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n"
|
||
11 years ago
|
"\nResult:\n"
|
||
|
"[\n"
|
||
|
" {\n"
|
||
10 years ago
|
" \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n"
|
||
11 years ago
|
" It will be \"\" for the default account.\n"
|
||
|
" \"address\":\"bitcoinaddress\", (string) The bitcoin address of the transaction. Not present for \n"
|
||
|
" move transactions (category = move).\n"
|
||
|
" \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
|
||
|
" transaction between accounts, and not associated with an address,\n"
|
||
|
" transaction id or block. 'send' and 'receive' transactions are \n"
|
||
|
" associated with an address, transaction id and block details\n"
|
||
|
" \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the\n"
|
||
|
" 'move' category for moves outbound. It is positive for the 'receive' category,\n"
|
||
|
" and for the 'move' category for inbound funds.\n"
|
||
11 years ago
|
" \"vout\" : n, (numeric) the vout value\n"
|
||
11 years ago
|
" \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the \n"
|
||
|
" 'send' category of transactions.\n"
|
||
|
" \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
|
||
|
" 'receive' category of transactions.\n"
|
||
|
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
|
||
|
" category of transactions.\n"
|
||
|
" \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n"
|
||
|
" category of transactions.\n"
|
||
11 years ago
|
" \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
|
||
11 years ago
|
" \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
|
||
|
" \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
|
||
|
" for 'send' and 'receive' category of transactions.\n"
|
||
|
" \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
|
||
|
" \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n"
|
||
|
" from (for receiving funds, positive amounts), or went to (for sending funds,\n"
|
||
|
" negative amounts).\n"
|
||
|
" }\n"
|
||
|
"]\n"
|
||
|
|
||
|
"\nExamples:\n"
|
||
|
"\nList the most recent 10 transactions in the systems\n"
|
||
|
+ HelpExampleCli("listtransactions", "") +
|
||
10 years ago
|
"\nList transactions 100 to 120\n"
|
||
|
+ HelpExampleCli("listtransactions", "\"*\" 20 100") +
|
||
11 years ago
|
"\nAs a json rpc call\n"
|
||
10 years ago
|
+ HelpExampleRpc("listtransactions", "\"*\", 20, 100")
|
||
11 years ago
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
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();
|
||
11 years ago
|
isminefilter filter = ISMINE_SPENDABLE;
|
||
11 years ago
|
if(params.size() > 3)
|
||
|
if(params[3].get_bool())
|
||
11 years ago
|
filter = filter | ISMINE_WATCH_ONLY;
|
||
12 years ago
|
|
||
|
if (nCount < 0)
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
|
||
12 years ago
|
if (nFrom < 0)
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
|
||
12 years ago
|
|
||
|
Array ret;
|
||
|
|
||
12 years ago
|
std::list<CAccountingEntry> acentries;
|
||
|
CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, strAccount);
|
||
12 years ago
|
|
||
|
// iterate backwards until we have nCount items to return:
|
||
13 years ago
|
for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
|
||
12 years ago
|
{
|
||
|
CWalletTx *const pwtx = (*it).second.first;
|
||
|
if (pwtx != 0)
|
||
11 years ago
|
ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
|
||
12 years ago
|
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)
|
||
|
{
|
||
11 years ago
|
if (fHelp || params.size() > 2)
|
||
12 years ago
|
throw runtime_error(
|
||
11 years ago
|
"listaccounts ( minconf includeWatchonly)\n"
|
||
10 years ago
|
"\nDEPRECATED. Returns Object that has account names as keys, account balances as values.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
10 years ago
|
"1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n"
|
||
11 years ago
|
"2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n"
|
||
11 years ago
|
"\nResult:\n"
|
||
|
"{ (json object where keys are account names, and values are numeric balances\n"
|
||
|
" \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
|
||
|
" ...\n"
|
||
|
"}\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nList account balances where there at least 1 confirmation\n"
|
||
|
+ HelpExampleCli("listaccounts", "") +
|
||
|
"\nList account balances including zero confirmation transactions\n"
|
||
|
+ HelpExampleCli("listaccounts", "0") +
|
||
|
"\nList account balances for 6 or more confirmations\n"
|
||
|
+ HelpExampleCli("listaccounts", "6") +
|
||
|
"\nAs json rpc call\n"
|
||
|
+ HelpExampleRpc("listaccounts", "6")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
int nMinDepth = 1;
|
||
|
if (params.size() > 0)
|
||
|
nMinDepth = params[0].get_int();
|
||
11 years ago
|
isminefilter includeWatchonly = ISMINE_SPENDABLE;
|
||
11 years ago
|
if(params.size() > 1)
|
||
|
if(params[1].get_bool())
|
||
11 years ago
|
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
|
||
12 years ago
|
|
||
11 years ago
|
map<string, CAmount> mapAccountBalances;
|
||
12 years ago
|
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
|
||
11 years ago
|
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
|
||
12 years ago
|
mapAccountBalances[entry.second.name] = 0;
|
||
12 years ago
|
}
|
||
|
|
||
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||
|
{
|
||
|
const CWalletTx& wtx = (*it).second;
|
||
11 years ago
|
CAmount nFee;
|
||
12 years ago
|
string strSentAccount;
|
||
11 years ago
|
list<COutputEntry> listReceived;
|
||
|
list<COutputEntry> listSent;
|
||
11 years ago
|
int nDepth = wtx.GetDepthInMainChain();
|
||
|
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
|
||
11 years ago
|
continue;
|
||
11 years ago
|
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
|
||
12 years ago
|
mapAccountBalances[strSentAccount] -= nFee;
|
||
11 years ago
|
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||
|
mapAccountBalances[strSentAccount] -= s.amount;
|
||
11 years ago
|
if (nDepth >= nMinDepth)
|
||
12 years ago
|
{
|
||
11 years ago
|
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||
|
if (pwalletMain->mapAddressBook.count(r.destination))
|
||
|
mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
|
||
12 years ago
|
else
|
||
11 years ago
|
mapAccountBalances[""] += r.amount;
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
|
list<CAccountingEntry> acentries;
|
||
|
CWalletDB(pwalletMain->strWalletFile).ListAccountCreditDebit("*", acentries);
|
||
|
BOOST_FOREACH(const CAccountingEntry& entry, acentries)
|
||
|
mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
|
||
|
|
||
|
Object ret;
|
||
11 years ago
|
BOOST_FOREACH(const PAIRTYPE(string, CAmount)& accountBalance, mapAccountBalances) {
|
||
12 years ago
|
ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
Value listsinceblock(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n"
|
||
11 years ago
|
"\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
|
||
|
"2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n"
|
||
11 years ago
|
"3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')"
|
||
11 years ago
|
"\nResult:\n"
|
||
|
"{\n"
|
||
|
" \"transactions\": [\n"
|
||
10 years ago
|
" \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n"
|
||
11 years ago
|
" \"address\":\"bitcoinaddress\", (string) The bitcoin address of the transaction. Not present for move transactions (category = move).\n"
|
||
|
" \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
|
||
|
" \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the 'move' category for moves \n"
|
||
|
" outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
|
||
11 years ago
|
" \"vout\" : n, (numeric) the vout value\n"
|
||
11 years ago
|
" \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the 'send' category of transactions.\n"
|
||
|
" \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
|
||
|
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
|
||
|
" \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
|
||
|
" \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
|
||
11 years ago
|
" \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
|
||
11 years ago
|
" \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
|
||
|
" \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
|
||
|
" \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
|
||
|
" \"to\": \"...\", (string) If a comment to is associated with the transaction.\n"
|
||
|
" ],\n"
|
||
|
" \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n"
|
||
|
"}\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("listsinceblock", "")
|
||
|
+ HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6")
|
||
|
+ HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
CBlockIndex *pindex = NULL;
|
||
|
int target_confirms = 1;
|
||
11 years ago
|
isminefilter filter = ISMINE_SPENDABLE;
|
||
12 years ago
|
|
||
|
if (params.size() > 0)
|
||
|
{
|
||
10 years ago
|
uint256 blockId;
|
||
12 years ago
|
|
||
|
blockId.SetHex(params[0].get_str());
|
||
10 years ago
|
BlockMap::iterator it = mapBlockIndex.find(blockId);
|
||
11 years ago
|
if (it != mapBlockIndex.end())
|
||
|
pindex = it->second;
|
||
12 years ago
|
}
|
||
|
|
||
|
if (params.size() > 1)
|
||
|
{
|
||
|
target_confirms = params[1].get_int();
|
||
|
|
||
|
if (target_confirms < 1)
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
if(params.size() > 2)
|
||
|
if(params[2].get_bool())
|
||
11 years ago
|
filter = filter | ISMINE_WATCH_ONLY;
|
||
11 years ago
|
|
||
11 years ago
|
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
|
||
12 years ago
|
|
||
|
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)
|
||
11 years ago
|
ListTransactions(tx, "*", 0, true, transactions, filter);
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
|
||
10 years ago
|
uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256();
|
||
12 years ago
|
|
||
|
Object ret;
|
||
|
ret.push_back(Pair("transactions", transactions));
|
||
|
ret.push_back(Pair("lastblock", lastblock.GetHex()));
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
Value gettransaction(const Array& params, bool fHelp)
|
||
|
{
|
||
11 years ago
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||
12 years ago
|
throw runtime_error(
|
||
10 years ago
|
"gettransaction \"txid\" ( includeWatchonly )\n"
|
||
11 years ago
|
"\nGet detailed information about in-wallet transaction <txid>\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"txid\" (string, required) The transaction id\n"
|
||
11 years ago
|
"2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n"
|
||
11 years ago
|
"\nResult:\n"
|
||
|
"{\n"
|
||
|
" \"amount\" : x.xxx, (numeric) The transaction amount in btc\n"
|
||
|
" \"confirmations\" : n, (numeric) The number of confirmations\n"
|
||
|
" \"blockhash\" : \"hash\", (string) The block hash\n"
|
||
|
" \"blockindex\" : xx, (numeric) The block index\n"
|
||
|
" \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
|
||
11 years ago
|
" \"txid\" : \"transactionid\", (string) The transaction id.\n"
|
||
11 years ago
|
" \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
|
||
|
" \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
|
||
|
" \"details\" : [\n"
|
||
|
" {\n"
|
||
10 years ago
|
" \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n"
|
||
11 years ago
|
" \"address\" : \"bitcoinaddress\", (string) The bitcoin address involved in the transaction\n"
|
||
|
" \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
|
||
|
" \"amount\" : x.xxx (numeric) The amount in btc\n"
|
||
11 years ago
|
" \"vout\" : n, (numeric) the vout value\n"
|
||
11 years ago
|
" }\n"
|
||
|
" ,...\n"
|
||
11 years ago
|
" ],\n"
|
||
|
" \"hex\" : \"data\" (string) Raw data for transaction\n"
|
||
11 years ago
|
"}\n"
|
||
|
|
||
10 years ago
|
"\nExamples:\n"
|
||
11 years ago
|
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
|
||
10 years ago
|
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
|
||
11 years ago
|
+ HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
uint256 hash;
|
||
|
hash.SetHex(params[0].get_str());
|
||
|
|
||
11 years ago
|
isminefilter filter = ISMINE_SPENDABLE;
|
||
11 years ago
|
if(params.size() > 1)
|
||
|
if(params[1].get_bool())
|
||
11 years ago
|
filter = filter | ISMINE_WATCH_ONLY;
|
||
11 years ago
|
|
||
12 years ago
|
Object entry;
|
||
|
if (!pwalletMain->mapWallet.count(hash))
|
||
12 years ago
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
|
||
12 years ago
|
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
|
||
|
|
||
10 years ago
|
CAmount nCredit = wtx.GetCredit(filter);
|
||
11 years ago
|
CAmount nDebit = wtx.GetDebit(filter);
|
||
|
CAmount nNet = nCredit - nDebit;
|
||
|
CAmount nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
|
||
12 years ago
|
|
||
|
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
|
||
11 years ago
|
if (wtx.IsFromMe(filter))
|
||
12 years ago
|
entry.push_back(Pair("fee", ValueFromAmount(nFee)));
|
||
|
|
||
|
WalletTxToJSON(wtx, entry);
|
||
|
|
||
|
Array details;
|
||
11 years ago
|
ListTransactions(wtx, "*", 0, false, details, filter);
|
||
12 years ago
|
entry.push_back(Pair("details", details));
|
||
|
|
||
11 years ago
|
string strHex = EncodeHexTx(static_cast<CTransaction>(wtx));
|
||
11 years ago
|
entry.push_back(Pair("hex", strHex));
|
||
|
|
||
12 years ago
|
return entry;
|
||
|
}
|
||
|
|
||
|
|
||
|
Value backupwallet(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() != 1)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"backupwallet \"destination\"\n"
|
||
|
"\nSafely copies wallet.dat to destination, which can be a directory or a path with filename.\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"destination\" (string) The destination directory or file\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("backupwallet", "\"backup.dat\"")
|
||
|
+ HelpExampleRpc("backupwallet", "\"backup.dat\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
string strDest = params[0].get_str();
|
||
12 years ago
|
if (!BackupWallet(*pwalletMain, strDest))
|
||
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
|
||
12 years ago
|
|
||
|
return Value::null;
|
||
|
}
|
||
|
|
||
|
|
||
|
Value keypoolrefill(const Array& params, bool fHelp)
|
||
|
{
|
||
12 years ago
|
if (fHelp || params.size() > 1)
|
||
12 years ago
|
throw runtime_error(
|
||
11 years ago
|
"keypoolrefill ( newsize )\n"
|
||
|
"\nFills the keypool."
|
||
|
+ HelpRequiringPassphrase() + "\n"
|
||
|
"\nArguments\n"
|
||
|
"1. newsize (numeric, optional, default=100) The new keypool size\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("keypoolrefill", "")
|
||
|
+ HelpExampleRpc("keypoolrefill", "")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
11 years ago
|
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
|
||
|
unsigned int kpSize = 0;
|
||
12 years ago
|
if (params.size() > 0) {
|
||
|
if (params[0].get_int() < 0)
|
||
11 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
|
||
|
kpSize = (unsigned int)params[0].get_int();
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
EnsureWalletIsUnlocked();
|
||
12 years ago
|
pwalletMain->TopUpKeyPool(kpSize);
|
||
12 years ago
|
|
||
12 years ago
|
if (pwalletMain->GetKeyPoolSize() < kpSize)
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
|
||
12 years ago
|
|
||
|
return Value::null;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
static void LockWallet(CWallet* pWallet)
|
||
12 years ago
|
{
|
||
12 years ago
|
LOCK(cs_nWalletUnlockTime);
|
||
|
nWalletUnlockTime = 0;
|
||
|
pWallet->Lock();
|
||
12 years ago
|
}
|
||
|
|
||
|
Value walletpassphrase(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
|
||
|
throw runtime_error(
|
||
11 years ago
|
"walletpassphrase \"passphrase\" timeout\n"
|
||
|
"\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
|
||
|
"This is needed prior to performing transactions related to private keys such as sending bitcoins\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"passphrase\" (string, required) The wallet passphrase\n"
|
||
|
"2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
|
||
11 years ago
|
"\nNote:\n"
|
||
|
"Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
|
||
|
"time that overrides the old one.\n"
|
||
11 years ago
|
"\nExamples:\n"
|
||
|
"\nunlock the wallet for 60 seconds\n"
|
||
|
+ HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") +
|
||
|
"\nLock the wallet again (before 60 seconds)\n"
|
||
|
+ HelpExampleCli("walletlock", "") +
|
||
|
"\nAs json rpc call\n"
|
||
|
+ HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")
|
||
|
);
|
||
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
if (fHelp)
|
||
|
return true;
|
||
|
if (!pwalletMain->IsCrypted())
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
|
||
12 years ago
|
|
||
|
// 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))
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
||
12 years ago
|
}
|
||
|
else
|
||
|
throw runtime_error(
|
||
|
"walletpassphrase <passphrase> <timeout>\n"
|
||
|
"Stores the wallet decryption key in memory for <timeout> seconds.");
|
||
|
|
||
12 years ago
|
pwalletMain->TopUpKeyPool();
|
||
|
|
||
12 years ago
|
int64_t nSleepTime = params[1].get_int64();
|
||
12 years ago
|
LOCK(cs_nWalletUnlockTime);
|
||
|
nWalletUnlockTime = GetTime() + nSleepTime;
|
||
|
RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime);
|
||
12 years ago
|
|
||
|
return Value::null;
|
||
|
}
|
||
|
|
||
|
|
||
|
Value walletpassphrasechange(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2))
|
||
|
throw runtime_error(
|
||
11 years ago
|
"walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n"
|
||
|
"\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"oldpassphrase\" (string) The current passphrase\n"
|
||
|
"2. \"newpassphrase\" (string) The new passphrase\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
|
||
|
+ HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
|
||
|
);
|
||
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
if (fHelp)
|
||
|
return true;
|
||
|
if (!pwalletMain->IsCrypted())
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
|
||
12 years ago
|
|
||
|
// 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))
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
|
||
12 years ago
|
|
||
|
return Value::null;
|
||
|
}
|
||
|
|
||
|
|
||
|
Value walletlock(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0))
|
||
|
throw runtime_error(
|
||
|
"walletlock\n"
|
||
11 years ago
|
"\nRemoves the wallet encryption key from memory, locking the wallet.\n"
|
||
12 years ago
|
"After calling this method, you will need to call walletpassphrase again\n"
|
||
11 years ago
|
"before being able to call any methods which require the wallet to be unlocked.\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nSet the passphrase for 2 minutes to perform a transaction\n"
|
||
|
+ HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") +
|
||
|
"\nPerform a send (requires passphrase set)\n"
|
||
|
+ HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") +
|
||
|
"\nClear the passphrase since we are done before 2 minutes is up\n"
|
||
|
+ HelpExampleCli("walletlock", "") +
|
||
|
"\nAs json rpc call\n"
|
||
|
+ HelpExampleRpc("walletlock", "")
|
||
|
);
|
||
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
if (fHelp)
|
||
|
return true;
|
||
|
if (!pwalletMain->IsCrypted())
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
|
||
12 years ago
|
|
||
|
{
|
||
|
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(
|
||
11 years ago
|
"encryptwallet \"passphrase\"\n"
|
||
|
"\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
|
||
|
"After this, any calls that interact with private keys such as sending or signing \n"
|
||
|
"will require the passphrase to be set prior the making these calls.\n"
|
||
|
"Use the walletpassphrase call for this, and then walletlock call.\n"
|
||
|
"If the wallet is already encrypted, use the walletpassphrasechange call.\n"
|
||
|
"Note that this will shutdown the server.\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nEncrypt you wallet\n"
|
||
|
+ HelpExampleCli("encryptwallet", "\"my pass phrase\"") +
|
||
|
"\nNow set the passphrase to use the wallet, such as for signing or sending bitcoin\n"
|
||
|
+ HelpExampleCli("walletpassphrase", "\"my pass phrase\"") +
|
||
|
"\nNow we can so something like sign\n"
|
||
|
+ HelpExampleCli("signmessage", "\"bitcoinaddress\" \"test message\"") +
|
||
|
"\nNow lock the wallet again by removing the passphrase\n"
|
||
|
+ HelpExampleCli("walletlock", "") +
|
||
|
"\nAs a json rpc call\n"
|
||
|
+ HelpExampleRpc("encryptwallet", "\"my pass phrase\"")
|
||
|
);
|
||
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
if (fHelp)
|
||
|
return true;
|
||
|
if (pwalletMain->IsCrypted())
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
|
||
12 years ago
|
|
||
|
// 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))
|
||
12 years ago
|
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
|
||
12 years ago
|
|
||
|
// 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
|
||
12 years ago
|
// unencrypted private keys. So:
|
||
12 years ago
|
StartShutdown();
|
||
12 years ago
|
return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
Value lockunspent(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||
|
throw runtime_error(
|
||
11 years ago
|
"lockunspent unlock [{\"txid\":\"txid\",\"vout\":n},...]\n"
|
||
|
"\nUpdates list of temporarily unspendable outputs.\n"
|
||
11 years ago
|
"Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
|
||
11 years ago
|
"A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n"
|
||
|
"Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
|
||
|
"is always cleared (by virtue of process exit) when a node stops or fails.\n"
|
||
|
"Also see the listunspent call\n"
|
||
|
"\nArguments:\n"
|
||
|
"1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions\n"
|
||
|
"2. \"transactions\" (string, required) A json array of objects. Each object the txid (string) vout (numeric)\n"
|
||
|
" [ (json array of json objects)\n"
|
||
|
" {\n"
|
||
|
" \"txid\":\"id\", (string) The transaction id\n"
|
||
|
" \"vout\": n (numeric) The output number\n"
|
||
|
" }\n"
|
||
|
" ,...\n"
|
||
|
" ]\n"
|
||
|
|
||
|
"\nResult:\n"
|
||
|
"true|false (boolean) Whether the command was successful or not\n"
|
||
|
|
||
|
"\nExamples:\n"
|
||
|
"\nList the unspent transactions\n"
|
||
|
+ HelpExampleCli("listunspent", "") +
|
||
|
"\nLock an unspent transaction\n"
|
||
|
+ HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
|
||
|
"\nList the locked transactions\n"
|
||
|
+ HelpExampleCli("listlockunspent", "") +
|
||
|
"\nUnlock the transaction again\n"
|
||
|
+ HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
|
||
|
"\nAs a json rpc call\n"
|
||
|
+ HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
if (params.size() == 1)
|
||
10 years ago
|
RPCTypeCheck(params, boost::assign::list_of(bool_type));
|
||
12 years ago
|
else
|
||
10 years ago
|
RPCTypeCheck(params, boost::assign::list_of(bool_type)(array_type));
|
||
12 years ago
|
|
||
|
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)
|
||
11 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
|
||
12 years ago
|
const Object& o = output.get_obj();
|
||
|
|
||
10 years ago
|
RPCTypeCheck(o, boost::assign::map_list_of("txid", str_type)("vout", int_type));
|
||
12 years ago
|
|
||
|
string txid = find_value(o, "txid").get_str();
|
||
|
if (!IsHex(txid))
|
||
11 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
|
||
12 years ago
|
|
||
|
int nOutput = find_value(o, "vout").get_int();
|
||
|
if (nOutput < 0)
|
||
11 years ago
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
|
||
12 years ago
|
|
||
10 years ago
|
COutPoint outpt(uint256S(txid), nOutput);
|
||
12 years ago
|
|
||
|
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"
|
||
11 years ago
|
"\nReturns list of temporarily unspendable outputs.\n"
|
||
|
"See the lockunspent call to lock and unlock transactions for spending.\n"
|
||
|
"\nResult:\n"
|
||
|
"[\n"
|
||
|
" {\n"
|
||
|
" \"txid\" : \"transactionid\", (string) The transaction id locked\n"
|
||
|
" \"vout\" : n (numeric) The vout value\n"
|
||
|
" }\n"
|
||
|
" ,...\n"
|
||
|
"]\n"
|
||
|
"\nExamples:\n"
|
||
|
"\nList the unspent transactions\n"
|
||
|
+ HelpExampleCli("listunspent", "") +
|
||
|
"\nLock an unspent transaction\n"
|
||
|
+ HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
|
||
|
"\nList the locked transactions\n"
|
||
|
+ HelpExampleCli("listlockunspent", "") +
|
||
|
"\nUnlock the transaction again\n"
|
||
|
+ HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
|
||
|
"\nAs a json rpc call\n"
|
||
|
+ HelpExampleRpc("listlockunspent", "")
|
||
|
);
|
||
12 years ago
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
12 years ago
|
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;
|
||
|
}
|
||
|
|
||
11 years ago
|
Value settxfee(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() < 1 || params.size() > 1)
|
||
|
throw runtime_error(
|
||
|
"settxfee amount\n"
|
||
11 years ago
|
"\nSet the transaction fee per kB.\n"
|
||
11 years ago
|
"\nArguments:\n"
|
||
11 years ago
|
"1. amount (numeric, required) The transaction fee in BTC/kB rounded to the nearest 0.00000001\n"
|
||
11 years ago
|
"\nResult\n"
|
||
|
"true|false (boolean) Returns true if successful\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("settxfee", "0.00001")
|
||
|
+ HelpExampleRpc("settxfee", "0.00001")
|
||
|
);
|
||
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
11 years ago
|
// Amount
|
||
11 years ago
|
CAmount nAmount = 0;
|
||
11 years ago
|
if (params[0].get_real() != 0.0)
|
||
|
nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts
|
||
|
|
||
11 years ago
|
payTxFee = CFeeRate(nAmount, 1000);
|
||
11 years ago
|
return true;
|
||
|
}
|
||
|
|
||
11 years ago
|
Value getwalletinfo(const Array& params, bool fHelp)
|
||
|
{
|
||
|
if (fHelp || params.size() != 0)
|
||
|
throw runtime_error(
|
||
|
"getwalletinfo\n"
|
||
|
"Returns an object containing various wallet state info.\n"
|
||
|
"\nResult:\n"
|
||
|
"{\n"
|
||
|
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
|
||
10 years ago
|
" \"balance\": xxxxxxx, (numeric) the total confirmed bitcoin balance of the wallet\n"
|
||
10 years ago
|
" \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed bitcoin balance of the wallet\n"
|
||
|
" \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet\n"
|
||
11 years ago
|
" \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
|
||
|
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
|
||
|
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
|
||
|
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
|
||
|
"}\n"
|
||
|
"\nExamples:\n"
|
||
|
+ HelpExampleCli("getwalletinfo", "")
|
||
|
+ HelpExampleRpc("getwalletinfo", "")
|
||
|
);
|
||
|
|
||
10 years ago
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||
|
|
||
11 years ago
|
Object obj;
|
||
|
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
|
||
|
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
|
||
10 years ago
|
obj.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwalletMain->GetUnconfirmedBalance())));
|
||
|
obj.push_back(Pair("immature_balance", ValueFromAmount(pwalletMain->GetImmatureBalance())));
|
||
11 years ago
|
obj.push_back(Pair("txcount", (int)pwalletMain->mapWallet.size()));
|
||
11 years ago
|
obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
|
||
11 years ago
|
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
|
||
|
if (pwalletMain->IsCrypted())
|
||
11 years ago
|
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
|
||
11 years ago
|
return obj;
|
||
|
}
|