Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | UniValue blockToJSON(const CBlock &block, const CBlockIndex *blockindex, | ||||
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); | result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); | ||||
UniValue txs(UniValue::VARR); | UniValue txs(UniValue::VARR); | ||||
for (const auto &tx : block.vtx) { | for (const auto &tx : block.vtx) { | ||||
if (txDetails) { | if (txDetails) { | ||||
UniValue objTx(UniValue::VOBJ); | UniValue objTx(UniValue::VOBJ); | ||||
TxToJSON(*tx, uint256(), objTx); | TxToJSON(*tx, uint256(), objTx); | ||||
txs.push_back(objTx); | txs.push_back(objTx); | ||||
} else | } else | ||||
txs.push_back(tx->GetId().GetHex()); | txs.push_back(tx->GetHash().GetHex()); | ||||
} | } | ||||
result.push_back(Pair("tx", txs)); | result.push_back(Pair("tx", txs)); | ||||
result.push_back(Pair("time", block.GetBlockTime())); | result.push_back(Pair("time", block.GetBlockTime())); | ||||
result.push_back( | result.push_back( | ||||
Pair("mediantime", int64_t(blockindex->GetMedianTimePast()))); | Pair("mediantime", int64_t(blockindex->GetMedianTimePast()))); | ||||
result.push_back(Pair("nonce", uint64_t(block.nNonce))); | result.push_back(Pair("nonce", uint64_t(block.nNonce))); | ||||
result.push_back(Pair("bits", strprintf("%08x", block.nBits))); | result.push_back(Pair("bits", strprintf("%08x", block.nBits))); | ||||
result.push_back(Pair("difficulty", GetDifficulty(blockindex))); | result.push_back(Pair("difficulty", GetDifficulty(blockindex))); | ||||
▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | info.push_back( | ||||
Pair("descendantfees", e.GetModFeesWithDescendants().GetSatoshis())); | Pair("descendantfees", e.GetModFeesWithDescendants().GetSatoshis())); | ||||
info.push_back(Pair("ancestorcount", e.GetCountWithAncestors())); | info.push_back(Pair("ancestorcount", e.GetCountWithAncestors())); | ||||
info.push_back(Pair("ancestorsize", e.GetSizeWithAncestors())); | info.push_back(Pair("ancestorsize", e.GetSizeWithAncestors())); | ||||
info.push_back( | info.push_back( | ||||
Pair("ancestorfees", e.GetModFeesWithAncestors().GetSatoshis())); | Pair("ancestorfees", e.GetModFeesWithAncestors().GetSatoshis())); | ||||
const CTransaction &tx = e.GetTx(); | const CTransaction &tx = e.GetTx(); | ||||
std::set<std::string> setDepends; | std::set<std::string> setDepends; | ||||
for (const CTxIn &txin : tx.vin) { | for (const CTxIn &txin : tx.vin) { | ||||
if (mempool.exists(txin.prevout.hash)) { | if (mempool.exists(txin.prevout.unspentid)) { | ||||
setDepends.insert(txin.prevout.hash.ToString()); | setDepends.insert(txin.prevout.unspentid.ToString()); | ||||
} | } | ||||
} | } | ||||
UniValue depends(UniValue::VARR); | UniValue depends(UniValue::VARR); | ||||
for (const std::string &dep : setDepends) { | for (const std::string &dep : setDepends) { | ||||
depends.push_back(dep); | depends.push_back(dep); | ||||
} | } | ||||
info.push_back(Pair("depends", depends)); | info.push_back(Pair("depends", depends)); | ||||
} | } | ||||
UniValue mempoolToJSON(bool fVerbose = false) { | UniValue mempoolToJSON(bool fVerbose = false) { | ||||
if (fVerbose) { | if (fVerbose) { | ||||
LOCK(mempool.cs); | LOCK(mempool.cs); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (const CTxMemPoolEntry &e : mempool.mapTx) { | for (const CTxMemPoolEntry &e : mempool.mapTx) { | ||||
const uint256 &txid = e.GetTx().GetId(); | const uint256 &txhash = e.GetTx().GetHash(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(info, e); | ||||
o.push_back(Pair(txid.ToString(), info)); | o.push_back(Pair(txhash.ToString(), info)); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
std::vector<uint256> vtxids; | std::vector<txhash_t> vtxhashes; | ||||
mempool.queryHashes(vtxids); | mempool.queryHashes(vtxhashes); | ||||
UniValue a(UniValue::VARR); | UniValue a(UniValue::VARR); | ||||
for (const uint256 &txid : vtxids) { | for (const txhash_t &txhash : vtxhashes) { | ||||
a.push_back(txid.ToString()); | a.push_back(txhash.ToString()); | ||||
} | } | ||||
return a; | return a; | ||||
} | } | ||||
} | } | ||||
UniValue getrawmempool(const Config &config, const JSONRPCRequest &request) { | UniValue getrawmempool(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
Show All 27 Lines | UniValue getrawmempool(const Config &config, const JSONRPCRequest &request) { | ||||
return mempoolToJSON(fVerbose); | return mempoolToJSON(fVerbose); | ||||
} | } | ||||
UniValue getmempoolancestors(const Config &config, | UniValue getmempoolancestors(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolancestors txid (verbose)\n" | "getmempoolancestors txhash (verbose)\n" | ||||
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n" | "\nIf txhash is in the mempool, returns all in-mempool ancestors.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id " | "1. \"txhash\" (string, required) The transaction " | ||||
"hash " | |||||
"(must be in mempool)\n" | "(must be in mempool)\n" | ||||
"2. verbose (boolean, optional, default=false) " | "2. verbose (boolean, optional, default=false) " | ||||
"True for a json object, false for array of transaction ids\n" | "True for a json object, false for array of transaction ids\n" | ||||
"\nResult (for verbose=false):\n" | "\nResult (for verbose=false):\n" | ||||
"[ (json array of strings)\n" | "[ (json array of strings)\n" | ||||
" \"transactionid\" (string) The transaction id of an " | " \"txhash\" (string) The transaction hash of an " | ||||
"in-mempool ancestor transaction\n" | "in-mempool ancestor transaction\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nResult (for verbose=true):\n" | "\nResult (for verbose=true):\n" | ||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"transactionid\" : { (json object)\n" + | " \"transactionid\" : { (json object)\n" + | ||||
EntryDescriptionString() + " }, ...\n" | EntryDescriptionString() + " }, ...\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getmempoolancestors", "\"mytxid\"") + | HelpExampleCli("getmempoolancestors", "\"mytxhash\"") + | ||||
HelpExampleRpc("getmempoolancestors", "\"mytxid\"")); | HelpExampleRpc("getmempoolancestors", "\"mytxhash\"")); | ||||
} | } | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (request.params.size() > 1) { | if (request.params.size() > 1) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | txhash_t txhash = (txhash_t)ParseHashV(request.params[0], "parameter 1"); | ||||
LOCK(mempool.cs); | LOCK(mempool.cs); | ||||
CTxMemPool::txiter it = mempool.mapTx.find(hash); | CTxMemPool::txiter it = mempool.mapTx.find(txhash); | ||||
if (it == mempool.mapTx.end()) { | if (it == mempool.mapTx.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not in mempool"); | "Transaction not in mempool"); | ||||
} | } | ||||
CTxMemPool::setEntries setAncestors; | CTxMemPool::setEntries setAncestors; | ||||
uint64_t noLimit = std::numeric_limits<uint64_t>::max(); | uint64_t noLimit = std::numeric_limits<uint64_t>::max(); | ||||
std::string dummy; | std::string dummy; | ||||
mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, | mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, | ||||
noLimit, noLimit, dummy, false); | noLimit, noLimit, dummy, false); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
UniValue o(UniValue::VARR); | UniValue o(UniValue::VARR); | ||||
for (CTxMemPool::txiter ancestorIt : setAncestors) { | for (CTxMemPool::txiter ancestorIt : setAncestors) { | ||||
o.push_back(ancestorIt->GetTx().GetId().ToString()); | o.push_back(ancestorIt->GetTx().GetHash().ToString()); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (CTxMemPool::txiter ancestorIt : setAncestors) { | for (CTxMemPool::txiter ancestorIt : setAncestors) { | ||||
const CTxMemPoolEntry &e = *ancestorIt; | const CTxMemPoolEntry &e = *ancestorIt; | ||||
const uint256 &_hash = e.GetTx().GetId(); | const uint256 &_hash = e.GetTx().GetHash(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(info, e); | ||||
o.push_back(Pair(_hash.ToString(), info)); | o.push_back(Pair(_hash.ToString(), info)); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
UniValue getmempooldescendants(const Config &config, | UniValue getmempooldescendants(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempooldescendants txid (verbose)\n" | "getmempooldescendants txhash (verbose)\n" | ||||
"\nIf txid is in the mempool, returns all in-mempool descendants.\n" | "\nIf txhash is in the mempool, returns all in-mempool " | ||||
"descendants.\n" | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id " | "1. \"txhash\" (string, required) The transaction " | ||||
"hash " | |||||
"(must be in mempool)\n" | "(must be in mempool)\n" | ||||
"2. verbose (boolean, optional, default=false) " | "2. verbose (boolean, optional, default=false) " | ||||
"True for a json object, false for array of transaction ids\n" | "True for a json object, false for array of transaction ids\n" | ||||
"\nResult (for verbose=false):\n" | "\nResult (for verbose=false):\n" | ||||
"[ (json array of strings)\n" | "[ (json array of strings)\n" | ||||
" \"transactionid\" (string) The transaction id of an " | " \"txhash\" (string) The transaction hash of an " | ||||
"in-mempool descendant transaction\n" | "in-mempool descendant transaction\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nResult (for verbose=true):\n" | "\nResult (for verbose=true):\n" | ||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"transactionid\" : { (json object)\n" + | " \"transactionid\" : { (json object)\n" + | ||||
EntryDescriptionString() + " }, ...\n" | EntryDescriptionString() + " }, ...\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getmempooldescendants", "\"mytxid\"") + | HelpExampleCli("getmempooldescendants", "\"mytxhash\"") + | ||||
HelpExampleRpc("getmempooldescendants", "\"mytxid\"")); | HelpExampleRpc("getmempooldescendants", "\"mytxhash\"")); | ||||
} | } | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (request.params.size() > 1) fVerbose = request.params[1].get_bool(); | if (request.params.size() > 1) fVerbose = request.params[1].get_bool(); | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | txhash_t txhash(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(mempool.cs); | LOCK(mempool.cs); | ||||
CTxMemPool::txiter it = mempool.mapTx.find(hash); | CTxMemPool::txiter it = mempool.mapTx.find(txhash); | ||||
if (it == mempool.mapTx.end()) { | if (it == mempool.mapTx.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not in mempool"); | "Transaction not in mempool"); | ||||
} | } | ||||
CTxMemPool::setEntries setDescendants; | CTxMemPool::setEntries setDescendants; | ||||
mempool.CalculateDescendants(it, setDescendants); | mempool.CalculateDescendants(it, setDescendants); | ||||
// CTxMemPool::CalculateDescendants will include the given tx | // CTxMemPool::CalculateDescendants will include the given tx | ||||
setDescendants.erase(it); | setDescendants.erase(it); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
UniValue o(UniValue::VARR); | UniValue o(UniValue::VARR); | ||||
for (CTxMemPool::txiter descendantIt : setDescendants) { | for (CTxMemPool::txiter descendantIt : setDescendants) { | ||||
o.push_back(descendantIt->GetTx().GetId().ToString()); | o.push_back(descendantIt->GetTx().GetHash().ToString()); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (CTxMemPool::txiter descendantIt : setDescendants) { | for (CTxMemPool::txiter descendantIt : setDescendants) { | ||||
const CTxMemPoolEntry &e = *descendantIt; | const CTxMemPoolEntry &e = *descendantIt; | ||||
const uint256 &_hash = e.GetTx().GetId(); | const uint256 &_hash = e.GetTx().GetHash(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(info, e); | ||||
o.push_back(Pair(_hash.ToString(), info)); | o.push_back(Pair(_hash.ToString(), info)); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
UniValue getmempoolentry(const Config &config, const JSONRPCRequest &request) { | UniValue getmempoolentry(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolentry txid\n" | "getmempoolentry txhash\n" | ||||
"\nReturns mempool data for given transaction\n" | "\nReturns mempool data for given transaction\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) " | "1. \"txhash\" (string, required) " | ||||
"The transaction id (must be in mempool)\n" | "The transaction id (must be in mempool)\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{ (json object)\n" + | "{ (json object)\n" + | ||||
EntryDescriptionString() + "}\n" | EntryDescriptionString() + "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getmempoolentry", "\"mytxid\"") + | HelpExampleCli("getmempoolentry", "\"mytxhash\"") + | ||||
HelpExampleRpc("getmempoolentry", "\"mytxid\"")); | HelpExampleRpc("getmempoolentry", "\"mytxhash\"")); | ||||
} | } | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | txhash_t txhash(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(mempool.cs); | LOCK(mempool.cs); | ||||
CTxMemPool::txiter it = mempool.mapTx.find(hash); | CTxMemPool::txiter it = mempool.mapTx.find(txhash); | ||||
if (it == mempool.mapTx.end()) { | if (it == mempool.mapTx.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not in mempool"); | "Transaction not in mempool"); | ||||
} | } | ||||
const CTxMemPoolEntry &e = *it; | const CTxMemPoolEntry &e = *it; | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(info, e); | ||||
▲ Show 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | struct CCoinsStats { | ||||
uint64_t nDiskSize; | uint64_t nDiskSize; | ||||
CAmount nTotalAmount; | CAmount nTotalAmount; | ||||
CCoinsStats() | CCoinsStats() | ||||
: nHeight(0), nTransactions(0), nTransactionOutputs(0), nBogoSize(0), | : nHeight(0), nTransactions(0), nTransactionOutputs(0), nBogoSize(0), | ||||
nDiskSize(0), nTotalAmount(0) {} | nDiskSize(0), nTotalAmount(0) {} | ||||
}; | }; | ||||
static void ApplyStats(CCoinsStats &stats, CHashWriter &ss, const uint256 &hash, | static void ApplyStats(CCoinsStats &stats, CHashWriter &ss, | ||||
const unspentid_t &hash, | |||||
const std::map<uint32_t, Coin> &outputs) { | const std::map<uint32_t, Coin> &outputs) { | ||||
assert(!outputs.empty()); | assert(!outputs.empty()); | ||||
ss << hash; | ss << hash; | ||||
ss << VARINT(outputs.begin()->second.GetHeight() * 2 + | ss << VARINT(outputs.begin()->second.GetHeight() * 2 + | ||||
outputs.begin()->second.IsCoinBase()); | outputs.begin()->second.IsCoinBase()); | ||||
stats.nTransactions++; | stats.nTransactions++; | ||||
for (const auto output : outputs) { | for (const auto output : outputs) { | ||||
ss << VARINT(output.first + 1); | ss << VARINT(output.first + 1); | ||||
ss << *(const CScriptBase *)(&output.second.GetTxOut().scriptPubKey); | ss << *(const CScriptBase *)(&output.second.GetTxOut().scriptPubKey); | ||||
ss << VARINT(output.second.GetTxOut().nValue.GetSatoshis()); | ss << VARINT(output.second.GetTxOut().nValue.GetSatoshis()); | ||||
stats.nTransactionOutputs++; | stats.nTransactionOutputs++; | ||||
stats.nTotalAmount += output.second.GetTxOut().nValue.GetSatoshis(); | stats.nTotalAmount += output.second.GetTxOut().nValue.GetSatoshis(); | ||||
stats.nBogoSize += | stats.nBogoSize += | ||||
32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + | 32 /* txhash */ + 4 /* vout index */ + 4 /* height + coinbase */ + | ||||
8 /* amount */ + 2 /* scriptPubKey len */ + | 8 /* amount */ + 2 /* scriptPubKey len */ + | ||||
output.second.GetTxOut().scriptPubKey.size() /* scriptPubKey */; | output.second.GetTxOut().scriptPubKey.size() /* scriptPubKey */; | ||||
} | } | ||||
ss << VARINT(0); | ss << VARINT(0); | ||||
} | } | ||||
//! Calculate statistics about the unspent transaction output set | //! Calculate statistics about the unspent transaction output set | ||||
static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats) { | static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats) { | ||||
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); | std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); | ||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); | CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); | ||||
stats.hashBlock = pcursor->GetBestBlock(); | stats.hashBlock = pcursor->GetBestBlock(); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight; | stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight; | ||||
} | } | ||||
ss << stats.hashBlock; | ss << stats.hashBlock; | ||||
uint256 prevkey; | unspentid_t prevkey; | ||||
std::map<uint32_t, Coin> outputs; | std::map<uint32_t, Coin> outputs; | ||||
while (pcursor->Valid()) { | while (pcursor->Valid()) { | ||||
boost::this_thread::interruption_point(); | boost::this_thread::interruption_point(); | ||||
COutPoint key; | COutPoint key; | ||||
Coin coin; | Coin coin; | ||||
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) { | if (pcursor->GetKey(key) && pcursor->GetValue(coin)) { | ||||
if (!outputs.empty() && key.hash != prevkey) { | if (!outputs.empty() && key.unspentid != prevkey) { | ||||
ApplyStats(stats, ss, prevkey, outputs); | ApplyStats(stats, ss, prevkey, outputs); | ||||
outputs.clear(); | outputs.clear(); | ||||
} | } | ||||
prevkey = key.hash; | prevkey = key.unspentid; | ||||
outputs[key.n] = std::move(coin); | outputs[key.n] = std::move(coin); | ||||
} else { | } else { | ||||
return error("%s: unable to read value", __func__); | return error("%s: unable to read value", __func__); | ||||
} | } | ||||
pcursor->Next(); | pcursor->Next(); | ||||
} | } | ||||
if (!outputs.empty()) { | if (!outputs.empty()) { | ||||
ApplyStats(stats, ss, prevkey, outputs); | ApplyStats(stats, ss, prevkey, outputs); | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | UniValue gettxoutsetinfo(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"gettxout \"txid\" n ( include_mempool )\n" | "gettxout \"txhash\" n ( include_mempool )\n" | ||||
"\nReturns details about an unspent transaction output.\n" | "\nReturns details about an unspent transaction output.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id\n" | "1. \"unspentid\" (string, required) The Unspent transaction " | ||||
"id\n" | |||||
"2. n (numeric, required) vout number\n" | "2. n (numeric, required) vout number\n" | ||||
"3. include_mempool (boolean, optional) Whether to include the " | "3. include_mempool (boolean, optional) Whether to include the " | ||||
"mempool\n" | "mempool\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{\n" | "{\n" | ||||
" \"bestblock\" : \"hash\", (string) the block hash\n" | " \"bestblock\" : \"hash\", (string) the block hash\n" | ||||
" \"confirmations\" : n, (numeric) The number of " | " \"confirmations\" : n, (numeric) The number of " | ||||
"confirmations\n" | "confirmations\n" | ||||
Show All 14 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
" ]\n" | " ]\n" | ||||
" },\n" | " },\n" | ||||
" \"coinbase\" : true|false (boolean) Coinbase or not\n" | " \"coinbase\" : true|false (boolean) Coinbase or not\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nGet unspent transactions\n" + | "\nGet unspent transactions\n" + | ||||
HelpExampleCli("listunspent", "") + "\nView the details\n" + | HelpExampleCli("listunspent", "") + "\nView the details\n" + | ||||
HelpExampleCli("gettxout", "\"txid\" 1") + | HelpExampleCli("gettxout", "\"txhash\" 1") + | ||||
"\nAs a json rpc call\n" + | "\nAs a json rpc call\n" + | ||||
HelpExampleRpc("gettxout", "\"txid\", 1")); | HelpExampleRpc("gettxout", "\"txhash\", 1")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
std::string strHash = request.params[0].get_str(); | std::string strHash = request.params[0].get_str(); | ||||
uint256 hash(uint256S(strHash)); | unspentid_t hash(uint256S(strHash)); | ||||
int n = request.params[1].get_int(); | int n = request.params[1].get_int(); | ||||
COutPoint out(hash, n); | COutPoint out(hash, n); | ||||
bool fMempool = true; | bool fMempool = true; | ||||
if (request.params.size() > 2) { | if (request.params.size() > 2) { | ||||
fMempool = request.params[2].get_bool(); | fMempool = request.params[2].get_bool(); | ||||
} | } | ||||
Coin coin; | Coin coin; | ||||
▲ Show 20 Lines • Show All 539 Lines • ▼ Show 20 Lines | static const CRPCCommand commands[] = { | ||||
{ "blockchain", "getblockchaininfo", getblockchaininfo, true, {} }, | { "blockchain", "getblockchaininfo", getblockchaininfo, true, {} }, | ||||
{ "blockchain", "getbestblockhash", getbestblockhash, true, {} }, | { "blockchain", "getbestblockhash", getbestblockhash, true, {} }, | ||||
{ "blockchain", "getblockcount", getblockcount, true, {} }, | { "blockchain", "getblockcount", getblockcount, true, {} }, | ||||
{ "blockchain", "getblock", getblock, true, {"blockhash","verbose"} }, | { "blockchain", "getblock", getblock, true, {"blockhash","verbose"} }, | ||||
{ "blockchain", "getblockhash", getblockhash, true, {"height"} }, | { "blockchain", "getblockhash", getblockhash, true, {"height"} }, | ||||
{ "blockchain", "getblockheader", getblockheader, true, {"blockhash","verbose"} }, | { "blockchain", "getblockheader", getblockheader, true, {"blockhash","verbose"} }, | ||||
{ "blockchain", "getchaintips", getchaintips, true, {} }, | { "blockchain", "getchaintips", getchaintips, true, {} }, | ||||
{ "blockchain", "getdifficulty", getdifficulty, true, {} }, | { "blockchain", "getdifficulty", getdifficulty, true, {} }, | ||||
{ "blockchain", "getmempoolancestors", getmempoolancestors, true, {"txid","verbose"} }, | { "blockchain", "getmempoolancestors", getmempoolancestors, true, {"txhash","verbose"} }, | ||||
{ "blockchain", "getmempooldescendants", getmempooldescendants, true, {"txid","verbose"} }, | { "blockchain", "getmempooldescendants", getmempooldescendants, true, {"txhash","verbose"} }, | ||||
{ "blockchain", "getmempoolentry", getmempoolentry, true, {"txid"} }, | { "blockchain", "getmempoolentry", getmempoolentry, true, {"txhash"} }, | ||||
{ "blockchain", "getmempoolinfo", getmempoolinfo, true, {} }, | { "blockchain", "getmempoolinfo", getmempoolinfo, true, {} }, | ||||
{ "blockchain", "getrawmempool", getrawmempool, true, {"verbose"} }, | { "blockchain", "getrawmempool", getrawmempool, true, {"verbose"} }, | ||||
{ "blockchain", "gettxout", gettxout, true, {"txid","n","include_mempool"} }, | { "blockchain", "gettxout", gettxout, true, {"txhash","n","include_mempool"} }, | ||||
{ "blockchain", "gettxoutsetinfo", gettxoutsetinfo, true, {} }, | { "blockchain", "gettxoutsetinfo", gettxoutsetinfo, true, {} }, | ||||
{ "blockchain", "pruneblockchain", pruneblockchain, true, {"height"} }, | { "blockchain", "pruneblockchain", pruneblockchain, true, {"height"} }, | ||||
{ "blockchain", "verifychain", verifychain, true, {"checklevel","nblocks"} }, | { "blockchain", "verifychain", verifychain, true, {"checklevel","nblocks"} }, | ||||
{ "blockchain", "preciousblock", preciousblock, true, {"blockhash"} }, | { "blockchain", "preciousblock", preciousblock, true, {"blockhash"} }, | ||||
/* Not shown in help */ | /* Not shown in help */ | ||||
{ "hidden", "invalidateblock", invalidateblock, true, {"blockhash"} }, | { "hidden", "invalidateblock", invalidateblock, true, {"blockhash"} }, | ||||
{ "hidden", "reconsiderblock", reconsiderblock, true, {"blockhash"} }, | { "hidden", "reconsiderblock", reconsiderblock, true, {"blockhash"} }, | ||||
Show All 11 Lines |