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 297 Lines • ▼ Show 20 Lines | void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) { | ||||
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 &txid = 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(txid.ToString(), info)); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
std::vector<uint256> vtxids; | std::vector<uint256> vtxids; | ||||
mempool.queryHashes(vtxids); | mempool.queryHashes(vtxids); | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | UniValue getmempoolancestors(const Config &config, | ||||
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; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | UniValue getmempooldescendants(const Config &config, | ||||
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; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,037 Lines • Show Last 20 Lines |