Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 2,623 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"{\n" | "{\n" | ||||
" \"unspents\": [\n" | " \"unspents\": [\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\" : \"transactionid\", (string) The " | " \"txid\" : \"transactionid\", (string) The " | ||||
"transaction id\n" | "transaction id\n" | ||||
" \"vout\": n, (numeric) the vout value\n" | " \"vout\": n, (numeric) the vout value\n" | ||||
" \"scriptPubKey\" : \"script\", (string) the script " | " \"scriptPubKey\" : \"script\", (string) the script " | ||||
"key\n" | "key\n" | ||||
" \"desc\" : \"descriptor\", (string) A specialized " | |||||
"descriptor for the matched scriptPubKey\n" | |||||
" \"amount\" : x.xxx, (numeric) The total " | " \"amount\" : x.xxx, (numeric) The total " | ||||
"amount in " + | "amount in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" of the unspent output\n" | " of the unspent output\n" | ||||
" \"height\" : n, (numeric) Height of the " | " \"height\" : n, (numeric) Height of the " | ||||
"unspent transaction output\n" | "unspent transaction output\n" | ||||
" }\n" | " }\n" | ||||
" ,...], \n" | " ,...], \n" | ||||
Show All 30 Lines | static UniValue scantxoutset(const Config &config, | ||||
} else if (request.params[0].get_str() == "start") { | } else if (request.params[0].get_str() == "start") { | ||||
CoinsViewScanReserver reserver; | CoinsViewScanReserver reserver; | ||||
if (!reserver.reserve()) { | if (!reserver.reserve()) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
"Scan already in progress, use action \"abort\" or \"status\""); | "Scan already in progress, use action \"abort\" or \"status\""); | ||||
} | } | ||||
std::set<CScript> needles; | std::set<CScript> needles; | ||||
std::map<CScript, std::string> descriptors; | |||||
Amount total_in = Amount::zero(); | Amount total_in = Amount::zero(); | ||||
// loop through the scan objects | // loop through the scan objects | ||||
for (const UniValue &scanobject : | for (const UniValue &scanobject : | ||||
request.params[1].get_array().getValues()) { | request.params[1].get_array().getValues()) { | ||||
std::string desc_str; | std::string desc_str; | ||||
int range = 1000; | int range = 1000; | ||||
if (scanobject.isStr()) { | if (scanobject.isStr()) { | ||||
Show All 34 Lines | if (request.params[0].get_str() == "status") { | ||||
std::vector<CScript> scripts; | std::vector<CScript> scripts; | ||||
if (!desc->Expand(i, provider, scripts, provider)) { | if (!desc->Expand(i, provider, scripts, provider)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
strprintf( | strprintf( | ||||
"Cannot derive script without private keys: '%s'", | "Cannot derive script without private keys: '%s'", | ||||
desc_str)); | desc_str)); | ||||
} | } | ||||
needles.insert(scripts.begin(), scripts.end()); | for (const auto &script : scripts) { | ||||
std::string inferred = | |||||
InferDescriptor(script, provider)->ToString(); | |||||
needles.emplace(script); | |||||
descriptors.emplace(std::move(script), std::move(inferred)); | |||||
} | |||||
} | } | ||||
} | } | ||||
// Scan the unspent transaction output set for inputs | // Scan the unspent transaction output set for inputs | ||||
UniValue unspents(UniValue::VARR); | UniValue unspents(UniValue::VARR); | ||||
std::vector<CTxOut> input_txos; | std::vector<CTxOut> input_txos; | ||||
std::map<COutPoint, Coin> coins; | std::map<COutPoint, Coin> coins; | ||||
g_should_abort_scan = false; | g_should_abort_scan = false; | ||||
Show All 18 Lines | if (request.params[0].get_str() == "status") { | ||||
input_txos.push_back(txo); | input_txos.push_back(txo); | ||||
total_in += txo.nValue; | total_in += txo.nValue; | ||||
UniValue unspent(UniValue::VOBJ); | UniValue unspent(UniValue::VOBJ); | ||||
unspent.pushKV("txid", outpoint.GetTxId().GetHex()); | unspent.pushKV("txid", outpoint.GetTxId().GetHex()); | ||||
unspent.pushKV("vout", int32_t(outpoint.GetN())); | unspent.pushKV("vout", int32_t(outpoint.GetN())); | ||||
unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey.begin(), | unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey.begin(), | ||||
txo.scriptPubKey.end())); | txo.scriptPubKey.end())); | ||||
unspent.pushKV("desc", descriptors[txo.scriptPubKey]); | |||||
unspent.pushKV("amount", ValueFromAmount(txo.nValue)); | unspent.pushKV("amount", ValueFromAmount(txo.nValue)); | ||||
unspent.pushKV("height", int32_t(coin.GetHeight())); | unspent.pushKV("height", int32_t(coin.GetHeight())); | ||||
unspents.push_back(unspent); | unspents.push_back(unspent); | ||||
} | } | ||||
result.pushKV("unspents", unspents); | result.pushKV("unspents", unspents); | ||||
result.pushKV("total_amount", ValueFromAmount(total_in)); | result.pushKV("total_amount", ValueFromAmount(total_in)); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |