Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 817 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec3" | HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec3" | ||||
"7b049d214adbda81d7e2a3dd146f6ed09" | "7b049d214adbda81d7e2a3dd146f6ed09" | ||||
"\"")); | "\"")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
std::string strHash = request.params[0].get_str(); | std::string strHash = request.params[0].get_str(); | ||||
uint256 hash(uint256S(strHash)); | BlockHash hash(uint256S(strHash)); | ||||
bool fVerbose = true; | bool fVerbose = true; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
const CBlockIndex *pblockindex = LookupBlockIndex(hash); | const CBlockIndex *pblockindex = LookupBlockIndex(hash); | ||||
if (!pblockindex) { | if (!pblockindex) { | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"214adbda81d7e2a3dd146f6ed09\"") + | "214adbda81d7e2a3dd146f6ed09\"") + | ||||
HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d" | HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d" | ||||
"214adbda81d7e2a3dd146f6ed09\"")); | "214adbda81d7e2a3dd146f6ed09\"")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
std::string strHash = request.params[0].get_str(); | std::string strHash = request.params[0].get_str(); | ||||
uint256 hash(uint256S(strHash)); | BlockHash hash(uint256S(strHash)); | ||||
int verbosity = 1; | int verbosity = 1; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
if (request.params[1].isNum()) { | if (request.params[1].isNum()) { | ||||
verbosity = request.params[1].get_int(); | verbosity = request.params[1].get_int(); | ||||
} else { | } else { | ||||
verbosity = request.params[1].get_bool() ? 1 : 0; | verbosity = request.params[1].get_bool() ? 1 : 0; | ||||
} | } | ||||
Show All 14 Lines | if (verbosity <= 0) { | ||||
return strHex; | return strHex; | ||||
} | } | ||||
return blockToJSON(block, chainActive.Tip(), pblockindex, verbosity >= 2); | return blockToJSON(block, chainActive.Tip(), pblockindex, verbosity >= 2); | ||||
} | } | ||||
struct CCoinsStats { | struct CCoinsStats { | ||||
int nHeight; | int nHeight; | ||||
uint256 hashBlock; | BlockHash hashBlock; | ||||
uint64_t nTransactions; | uint64_t nTransactions; | ||||
uint64_t nTransactionOutputs; | uint64_t nTransactionOutputs; | ||||
uint64_t nBogoSize; | uint64_t nBogoSize; | ||||
uint256 hashSerialized; | uint256 hashSerialized; | ||||
uint64_t nDiskSize; | uint64_t nDiskSize; | ||||
Amount nTotalAmount; | Amount nTotalAmount; | ||||
CCoinsStats() | CCoinsStats() | ||||
▲ Show 20 Lines • Show All 443 Lines • ▼ Show 20 Lines | static UniValue getchaintips(const Config &config, | ||||
* - Iterate through the orphan blocks. If the block isn't pointed to by | * - Iterate through the orphan blocks. If the block isn't pointed to by | ||||
* another orphan, it is a chain tip. | * another orphan, it is a chain tip. | ||||
* - add chainActive.Tip() | * - add chainActive.Tip() | ||||
*/ | */ | ||||
std::set<const CBlockIndex *, CompareBlocksByHeight> setTips; | std::set<const CBlockIndex *, CompareBlocksByHeight> setTips; | ||||
std::set<const CBlockIndex *> setOrphans; | std::set<const CBlockIndex *> setOrphans; | ||||
std::set<const CBlockIndex *> setPrevs; | std::set<const CBlockIndex *> setPrevs; | ||||
for (const std::pair<const uint256, CBlockIndex *> &item : mapBlockIndex) { | for (const std::pair<const BlockHash, CBlockIndex *> &item : | ||||
mapBlockIndex) { | |||||
if (!chainActive.Contains(item.second)) { | if (!chainActive.Contains(item.second)) { | ||||
setOrphans.insert(item.second); | setOrphans.insert(item.second); | ||||
setPrevs.insert(item.second->pprev); | setPrevs.insert(item.second->pprev); | ||||
} | } | ||||
} | } | ||||
for (std::set<const CBlockIndex *>::iterator it = setOrphans.begin(); | for (std::set<const CBlockIndex *>::iterator it = setOrphans.begin(); | ||||
it != setOrphans.end(); ++it) { | it != setOrphans.end(); ++it) { | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"mark as precious\n" | "mark as precious\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("preciousblock", "\"blockhash\"") + | HelpExampleCli("preciousblock", "\"blockhash\"") + | ||||
HelpExampleRpc("preciousblock", "\"blockhash\"")); | HelpExampleRpc("preciousblock", "\"blockhash\"")); | ||||
} | } | ||||
std::string strHash = request.params[0].get_str(); | std::string strHash = request.params[0].get_str(); | ||||
uint256 hash(uint256S(strHash)); | BlockHash hash(uint256S(strHash)); | ||||
CBlockIndex *pblockindex; | CBlockIndex *pblockindex; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
pblockindex = LookupBlockIndex(hash); | pblockindex = LookupBlockIndex(hash); | ||||
if (!pblockindex) { | if (!pblockindex) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
Show All 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"USE WITH CAUTION!\n" | "USE WITH CAUTION!\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("finalizeblock", "\"blockhash\"") + | HelpExampleCli("finalizeblock", "\"blockhash\"") + | ||||
HelpExampleRpc("finalizeblock", "\"blockhash\"")); | HelpExampleRpc("finalizeblock", "\"blockhash\"")); | ||||
} | } | ||||
std::string strHash = request.params[0].get_str(); | std::string strHash = request.params[0].get_str(); | ||||
uint256 hash(uint256S(strHash)); | BlockHash hash(uint256S(strHash)); | ||||
CValidationState state; | CValidationState state; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *pblockindex = LookupBlockIndex(hash); | CBlockIndex *pblockindex = LookupBlockIndex(hash); | ||||
if (!pblockindex) { | if (!pblockindex) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
Show All 24 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"the block to mark as invalid\n" | "the block to mark as invalid\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("invalidateblock", "\"blockhash\"") + | HelpExampleCli("invalidateblock", "\"blockhash\"") + | ||||
HelpExampleRpc("invalidateblock", "\"blockhash\"")); | HelpExampleRpc("invalidateblock", "\"blockhash\"")); | ||||
} | } | ||||
const std::string strHash = request.params[0].get_str(); | const std::string strHash = request.params[0].get_str(); | ||||
const uint256 hash(uint256S(strHash)); | const BlockHash hash(uint256S(strHash)); | ||||
CValidationState state; | CValidationState state; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *pblockindex = LookupBlockIndex(hash); | CBlockIndex *pblockindex = LookupBlockIndex(hash); | ||||
if (!pblockindex) { | if (!pblockindex) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
Show All 21 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"hash of the block to park\n" | "hash of the block to park\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("parkblock", "\"blockhash\"") + | HelpExampleCli("parkblock", "\"blockhash\"") + | ||||
HelpExampleRpc("parkblock", "\"blockhash\"")); | HelpExampleRpc("parkblock", "\"blockhash\"")); | ||||
} | } | ||||
const std::string strHash = request.params[0].get_str(); | const std::string strHash = request.params[0].get_str(); | ||||
const uint256 hash(uint256S(strHash)); | const BlockHash hash(uint256S(strHash)); | ||||
CValidationState state; | CValidationState state; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (mapBlockIndex.count(hash) == 0) { | if (mapBlockIndex.count(hash) == 0) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
Show All 25 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"reconsider\n" | "reconsider\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("reconsiderblock", "\"blockhash\"") + | HelpExampleCli("reconsiderblock", "\"blockhash\"") + | ||||
HelpExampleRpc("reconsiderblock", "\"blockhash\"")); | HelpExampleRpc("reconsiderblock", "\"blockhash\"")); | ||||
} | } | ||||
const std::string strHash = request.params[0].get_str(); | const std::string strHash = request.params[0].get_str(); | ||||
const uint256 hash(uint256S(strHash)); | const BlockHash hash(uint256S(strHash)); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *pblockindex = LookupBlockIndex(hash); | CBlockIndex *pblockindex = LookupBlockIndex(hash); | ||||
if (!pblockindex) { | if (!pblockindex) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
Show All 22 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"unpark\n" | "unpark\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("unparkblock", "\"blockhash\"") + | HelpExampleCli("unparkblock", "\"blockhash\"") + | ||||
HelpExampleRpc("unparkblock", "\"blockhash\"")); | HelpExampleRpc("unparkblock", "\"blockhash\"")); | ||||
} | } | ||||
const std::string strHash = request.params[0].get_str(); | const std::string strHash = request.params[0].get_str(); | ||||
const uint256 hash(uint256S(strHash)); | const BlockHash hash(uint256S(strHash)); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (mapBlockIndex.count(hash) == 0) { | if (mapBlockIndex.count(hash) == 0) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
CBlockIndex *pblockindex = mapBlockIndex[hash]; | CBlockIndex *pblockindex = mapBlockIndex[hash]; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | static UniValue getchaintxstats(const Config &config, | ||||
// By default: 1 month | // By default: 1 month | ||||
int blockcount = 30 * 24 * 60 * 60 / | int blockcount = 30 * 24 * 60 * 60 / | ||||
config.GetChainParams().GetConsensus().nPowTargetSpacing; | config.GetChainParams().GetConsensus().nPowTargetSpacing; | ||||
if (request.params[1].isNull()) { | if (request.params[1].isNull()) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
pindex = chainActive.Tip(); | pindex = chainActive.Tip(); | ||||
} else { | } else { | ||||
uint256 hash = uint256S(request.params[1].get_str()); | BlockHash hash(uint256S(request.params[1].get_str())); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
pindex = LookupBlockIndex(hash); | pindex = LookupBlockIndex(hash); | ||||
if (!pindex) { | if (!pindex) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
if (!chainActive.Contains(pindex)) { | if (!chainActive.Contains(pindex)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Block is not in main chain"); | "Block is not in main chain"); | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | if (request.params[0].isNum()) { | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
strprintf("Target block height %d after current tip %d", height, | strprintf("Target block height %d after current tip %d", height, | ||||
current_tip)); | current_tip)); | ||||
} | } | ||||
pindex = chainActive[height]; | pindex = chainActive[height]; | ||||
} else { | } else { | ||||
const std::string strHash = request.params[0].get_str(); | const std::string strHash = request.params[0].get_str(); | ||||
const uint256 hash(uint256S(strHash)); | const BlockHash hash(uint256S(strHash)); | ||||
pindex = LookupBlockIndex(hash); | pindex = LookupBlockIndex(hash); | ||||
if (!pindex) { | if (!pindex) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
if (!chainActive.Contains(pindex)) { | if (!chainActive.Contains(pindex)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
strprintf("Block is not in chain %s", | strprintf("Block is not in chain %s", | ||||
Params().NetworkIDString())); | Params().NetworkIDString())); | ||||
▲ Show 20 Lines • Show All 525 Lines • Show Last 20 Lines |