[move] move listunspent to wallet/rpcwallet.cpp
This commit is contained in:
parent
c8a1350119
commit
0b9dc9c8f5
@ -193,117 +193,6 @@ Value getrawtransaction(const Array& params, bool fHelp)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
Value listunspent(const Array& params, bool fHelp)
|
|
||||||
{
|
|
||||||
if (fHelp || params.size() > 3)
|
|
||||||
throw runtime_error(
|
|
||||||
"listunspent ( minconf maxconf [\"address\",...] )\n"
|
|
||||||
"\nReturns array of unspent transaction outputs\n"
|
|
||||||
"with between minconf and maxconf (inclusive) confirmations.\n"
|
|
||||||
"Optionally filter to only include txouts paid to specified addresses.\n"
|
|
||||||
"Results are an array of Objects, each of which has:\n"
|
|
||||||
"{txid, vout, scriptPubKey, amount, confirmations}\n"
|
|
||||||
"\nArguments:\n"
|
|
||||||
"1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n"
|
|
||||||
"2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
|
|
||||||
"3. \"addresses\" (string) A json array of bitcoin addresses to filter\n"
|
|
||||||
" [\n"
|
|
||||||
" \"address\" (string) bitcoin address\n"
|
|
||||||
" ,...\n"
|
|
||||||
" ]\n"
|
|
||||||
"\nResult\n"
|
|
||||||
"[ (array of json object)\n"
|
|
||||||
" {\n"
|
|
||||||
" \"txid\" : \"txid\", (string) the transaction id \n"
|
|
||||||
" \"vout\" : n, (numeric) the vout value\n"
|
|
||||||
" \"address\" : \"address\", (string) the bitcoin address\n"
|
|
||||||
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
|
|
||||||
" \"scriptPubKey\" : \"key\", (string) the script key\n"
|
|
||||||
" \"amount\" : x.xxx, (numeric) the transaction amount in btc\n"
|
|
||||||
" \"confirmations\" : n (numeric) The number of confirmations\n"
|
|
||||||
" }\n"
|
|
||||||
" ,...\n"
|
|
||||||
"]\n"
|
|
||||||
|
|
||||||
"\nExamples\n"
|
|
||||||
+ HelpExampleCli("listunspent", "")
|
|
||||||
+ HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
|
|
||||||
+ HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
|
|
||||||
);
|
|
||||||
|
|
||||||
RPCTypeCheck(params, boost::assign::list_of(int_type)(int_type)(array_type));
|
|
||||||
|
|
||||||
int nMinDepth = 1;
|
|
||||||
if (params.size() > 0)
|
|
||||||
nMinDepth = params[0].get_int();
|
|
||||||
|
|
||||||
int nMaxDepth = 9999999;
|
|
||||||
if (params.size() > 1)
|
|
||||||
nMaxDepth = params[1].get_int();
|
|
||||||
|
|
||||||
set<CBitcoinAddress> setAddress;
|
|
||||||
if (params.size() > 2) {
|
|
||||||
Array inputs = params[2].get_array();
|
|
||||||
BOOST_FOREACH(Value& input, inputs) {
|
|
||||||
CBitcoinAddress address(input.get_str());
|
|
||||||
if (!address.IsValid())
|
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+input.get_str());
|
|
||||||
if (setAddress.count(address))
|
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+input.get_str());
|
|
||||||
setAddress.insert(address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Array results;
|
|
||||||
vector<COutput> vecOutputs;
|
|
||||||
assert(pwalletMain != NULL);
|
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
|
||||||
pwalletMain->AvailableCoins(vecOutputs, false);
|
|
||||||
BOOST_FOREACH(const COutput& out, vecOutputs) {
|
|
||||||
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (setAddress.size()) {
|
|
||||||
CTxDestination address;
|
|
||||||
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!setAddress.count(address))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
|
||||||
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
|
||||||
Object entry;
|
|
||||||
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
|
|
||||||
entry.push_back(Pair("vout", out.i));
|
|
||||||
CTxDestination address;
|
|
||||||
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
|
|
||||||
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
|
||||||
if (pwalletMain->mapAddressBook.count(address))
|
|
||||||
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
|
|
||||||
}
|
|
||||||
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
|
|
||||||
if (pk.IsPayToScriptHash()) {
|
|
||||||
CTxDestination address;
|
|
||||||
if (ExtractDestination(pk, address)) {
|
|
||||||
const CScriptID& hash = boost::get<const CScriptID&>(address);
|
|
||||||
CScript redeemScript;
|
|
||||||
if (pwalletMain->GetCScript(hash, redeemScript))
|
|
||||||
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entry.push_back(Pair("amount",ValueFromAmount(nValue)));
|
|
||||||
entry.push_back(Pair("confirmations",out.nDepth));
|
|
||||||
entry.push_back(Pair("spendable", out.fSpendable));
|
|
||||||
results.push_back(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Value createrawtransaction(const Array& params, bool fHelp)
|
Value createrawtransaction(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 2)
|
if (fHelp || params.size() != 2)
|
||||||
|
@ -2118,3 +2118,115 @@ Value resendwallettransactions(const Array& params, bool fHelp)
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value listunspent(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
|
return Value::null;
|
||||||
|
|
||||||
|
if (fHelp || params.size() > 3)
|
||||||
|
throw runtime_error(
|
||||||
|
"listunspent ( minconf maxconf [\"address\",...] )\n"
|
||||||
|
"\nReturns array of unspent transaction outputs\n"
|
||||||
|
"with between minconf and maxconf (inclusive) confirmations.\n"
|
||||||
|
"Optionally filter to only include txouts paid to specified addresses.\n"
|
||||||
|
"Results are an array of Objects, each of which has:\n"
|
||||||
|
"{txid, vout, scriptPubKey, amount, confirmations}\n"
|
||||||
|
"\nArguments:\n"
|
||||||
|
"1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n"
|
||||||
|
"2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
|
||||||
|
"3. \"addresses\" (string) A json array of bitcoin addresses to filter\n"
|
||||||
|
" [\n"
|
||||||
|
" \"address\" (string) bitcoin address\n"
|
||||||
|
" ,...\n"
|
||||||
|
" ]\n"
|
||||||
|
"\nResult\n"
|
||||||
|
"[ (array of json object)\n"
|
||||||
|
" {\n"
|
||||||
|
" \"txid\" : \"txid\", (string) the transaction id \n"
|
||||||
|
" \"vout\" : n, (numeric) the vout value\n"
|
||||||
|
" \"address\" : \"address\", (string) the bitcoin address\n"
|
||||||
|
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
|
||||||
|
" \"scriptPubKey\" : \"key\", (string) the script key\n"
|
||||||
|
" \"amount\" : x.xxx, (numeric) the transaction amount in btc\n"
|
||||||
|
" \"confirmations\" : n (numeric) The number of confirmations\n"
|
||||||
|
" }\n"
|
||||||
|
" ,...\n"
|
||||||
|
"]\n"
|
||||||
|
|
||||||
|
"\nExamples\n"
|
||||||
|
+ HelpExampleCli("listunspent", "")
|
||||||
|
+ HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
|
||||||
|
+ HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
|
||||||
|
);
|
||||||
|
|
||||||
|
RPCTypeCheck(params, boost::assign::list_of(int_type)(int_type)(array_type));
|
||||||
|
|
||||||
|
int nMinDepth = 1;
|
||||||
|
if (params.size() > 0)
|
||||||
|
nMinDepth = params[0].get_int();
|
||||||
|
|
||||||
|
int nMaxDepth = 9999999;
|
||||||
|
if (params.size() > 1)
|
||||||
|
nMaxDepth = params[1].get_int();
|
||||||
|
|
||||||
|
set<CBitcoinAddress> setAddress;
|
||||||
|
if (params.size() > 2) {
|
||||||
|
Array inputs = params[2].get_array();
|
||||||
|
BOOST_FOREACH(Value& input, inputs) {
|
||||||
|
CBitcoinAddress address(input.get_str());
|
||||||
|
if (!address.IsValid())
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+input.get_str());
|
||||||
|
if (setAddress.count(address))
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+input.get_str());
|
||||||
|
setAddress.insert(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Array results;
|
||||||
|
vector<COutput> vecOutputs;
|
||||||
|
assert(pwalletMain != NULL);
|
||||||
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
pwalletMain->AvailableCoins(vecOutputs, false);
|
||||||
|
BOOST_FOREACH(const COutput& out, vecOutputs) {
|
||||||
|
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (setAddress.size()) {
|
||||||
|
CTxDestination address;
|
||||||
|
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!setAddress.count(address))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||||
|
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
||||||
|
Object entry;
|
||||||
|
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
|
||||||
|
entry.push_back(Pair("vout", out.i));
|
||||||
|
CTxDestination address;
|
||||||
|
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
|
||||||
|
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
||||||
|
if (pwalletMain->mapAddressBook.count(address))
|
||||||
|
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
|
||||||
|
}
|
||||||
|
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
|
||||||
|
if (pk.IsPayToScriptHash()) {
|
||||||
|
CTxDestination address;
|
||||||
|
if (ExtractDestination(pk, address)) {
|
||||||
|
const CScriptID& hash = boost::get<const CScriptID&>(address);
|
||||||
|
CScript redeemScript;
|
||||||
|
if (pwalletMain->GetCScript(hash, redeemScript))
|
||||||
|
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry.push_back(Pair("amount",ValueFromAmount(nValue)));
|
||||||
|
entry.push_back(Pair("confirmations",out.nDepth));
|
||||||
|
entry.push_back(Pair("spendable", out.fSpendable));
|
||||||
|
results.push_back(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user