diff options
| author | Gregory Maxwell <[email protected]> | 2012-08-24 00:46:24 -0700 |
|---|---|---|
| committer | Gregory Maxwell <[email protected]> | 2012-08-24 00:46:24 -0700 |
| commit | c68c4bc7a45529735c868428632906d3c20a175a (patch) | |
| tree | 6edd9d67279c0c15729c752c12794cf34864c930 /src/rpcrawtransaction.cpp | |
| parent | Avoid leaving return types or function attributes on their own lines. (diff) | |
| parent | Change CWallet addressgrouping to use CTxDestination instead of strings. (diff) | |
| download | discoin-c68c4bc7a45529735c868428632906d3c20a175a.tar.xz discoin-c68c4bc7a45529735c868428632906d3c20a175a.zip | |
Merge pull request #1672 from gmaxwell/filter_listunspent
Listunspent txout address filtering and listaddressgroupings
Diffstat (limited to 'src/rpcrawtransaction.cpp')
| -rw-r--r-- | src/rpcrawtransaction.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 2430a0387..08b0049b0 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -136,24 +136,40 @@ Value getrawtransaction(const Array& params, bool fHelp) Value listunspent(const Array& params, bool fHelp) { - if (fHelp || params.size() > 2) + if (fHelp || params.size() > 3) throw runtime_error( - "listunspent [minconf=1] [maxconf=999999]\n" + "listunspent [minconf=1] [maxconf=9999999] [\"address\",...]\n" "Returns array of unspent transaction outputs\n" "with between minconf and maxconf (inclusive) confirmations.\n" + "Optionally filtered 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}"); - RPCTypeCheck(params, list_of(int_type)(int_type)); + RPCTypeCheck(params, list_of(int_type)(int_type)(array_type)); int nMinDepth = 1; if (params.size() > 0) nMinDepth = params[0].get_int(); - int nMaxDepth = 999999; + 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(-5, string("Invalid Bitcoin address: ")+input.get_str()); + if (setAddress.count(address)) + throw JSONRPCError(-8, string("Invalid parameter, duplicated address: ")+input.get_str()); + setAddress.insert(address); + } + } + Array results; vector<COutput> vecOutputs; pwalletMain->AvailableCoins(vecOutputs, false); @@ -162,6 +178,16 @@ Value listunspent(const Array& params, bool fHelp) 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; + } + int64 nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; Object entry; @@ -222,7 +248,7 @@ Value createrawtransaction(const Array& params, bool fHelp) { CBitcoinAddress address(s.name_); if (!address.IsValid()) - throw JSONRPCError(-5, string("Invalid Bitcoin address:")+s.name_); + throw JSONRPCError(-5, string("Invalid Bitcoin address: ")+s.name_); if (setAddress.count(address)) throw JSONRPCError(-8, string("Invalid parameter, duplicated address: ")+s.name_); |