Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "rpc/blockchain.h" | #include "rpc/blockchain.h" | ||||
#include "amount.h" | #include "amount.h" | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "checkpoints.h" | #include "checkpoints.h" | ||||
#include "coins.h" | #include "coins.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "core_io.h" | |||||
#include "hash.h" | #include "hash.h" | ||||
#include "policy/policy.h" | #include "policy/policy.h" | ||||
#include "primitives/transaction.h" | #include "primitives/transaction.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "rpc/tojson.h" | #include "rpc/tojson.h" | ||||
#include "streams.h" | #include "streams.h" | ||||
#include "sync.h" | #include "sync.h" | ||||
#include "txdb.h" | #include "txdb.h" | ||||
▲ Show 20 Lines • Show All 460 Lines • ▼ Show 20 Lines | UniValue getrawmempool(const Config &config, const JSONRPCRequest &request) { | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (request.params.size() > 0) { | if (request.params.size() > 0) { | ||||
fVerbose = request.params[0].get_bool(); | fVerbose = request.params[0].get_bool(); | ||||
} | } | ||||
return mempoolToJSON(fVerbose); | return mempoolToJSON(fVerbose); | ||||
} | } | ||||
UniValue getrawmempooltxs(const Config &config, const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() > 1) { | |||||
throw std::runtime_error( | |||||
"getrawmempooltxs ( verbose )\n" | |||||
"\nReturns all transactions in memory pool as a json array of " | |||||
"transaction data.\n" | |||||
"\nArguments:\n" | |||||
"1. verbose (boolean, optional, default=false) True for a json " | |||||
"object, false for array of transaction data\n" | |||||
"\nResult: (for verbose = false):\n" | |||||
"[ (json array of string)\n" | |||||
" \"data\" (string) The serialized hex-encoded " | |||||
" data\n" | |||||
" ,...\n" | |||||
"]\n" | |||||
"\nResult: (for verbose = true):\n" | |||||
"[ (json array of objects)\n" | |||||
" {\n" | |||||
" \"hex\" : \"data\", (string) The serialized, " | |||||
"hex-encoded data for 'txid'\n" | |||||
" \"txid\" : \"id\", (string) The transaction id (same " | |||||
"as provided)\n" | |||||
" \"hash\" : \"id\", (string) The transaction hash " | |||||
"(differs from txid for witness transactions)\n" | |||||
" \"size\" : n, (numeric) The serialized " | |||||
"transaction size\n" | |||||
" \"version\" : n, (numeric) The version\n" | |||||
" \"locktime\" : ttt, (numeric) The lock time\n" | |||||
" \"vin\" : [ (array of json objects)\n" | |||||
" {\n" | |||||
" \"txid\": \"id\", (string) The transaction id\n" | |||||
" \"vout\": n, (numeric) \n" | |||||
" \"scriptSig\": { (json object) The script\n" | |||||
" \"asm\": \"asm\", (string) asm\n" | |||||
" \"hex\": \"hex\" (string) hex\n" | |||||
" },\n" | |||||
" \"sequence\": n (numeric) The script sequence " | |||||
"number\n" | |||||
" }\n" | |||||
" ,...\n" | |||||
" ],\n" | |||||
" \"vout\" : [ (array of json objects)\n" | |||||
" {\n" | |||||
" \"value\" : x.xxx, (numeric) The value in " + | |||||
CURRENCY_UNIT + | |||||
"\n" | |||||
" \"n\" : n, (numeric) index\n" | |||||
" \"scriptPubKey\" : { (json object)\n" | |||||
" \"asm\" : \"asm\", (string) the asm\n" | |||||
" \"hex\" : \"hex\", (string) the hex\n" | |||||
" \"reqSigs\" : n, (numeric) The required " | |||||
"sigs\n" | |||||
" \"type\" : \"pubkeyhash\", (string) The type, eg " | |||||
"'pubkeyhash'\n" | |||||
" \"addresses\" : [ (json array of string)\n" | |||||
" \"address\" (string) bitcoin address\n" | |||||
" ,...\n" | |||||
" ]\n" | |||||
" }\n" | |||||
" }\n" | |||||
" ,...\n" | |||||
" ]\n" | |||||
" }\n" | |||||
"]\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("getrawmempooltxs", "") + | |||||
HelpExampleCli("getrawmempooltxs", "true") + | |||||
HelpExampleRpc("getrawmempooltxs", "true")); | |||||
} | |||||
// Accept either a bool (true) or a num (>=1) to indicate verbose output. | |||||
bool fVerbose = false; | |||||
if (request.params.size() > 0) { | |||||
if (request.params[0].isNum()) { | |||||
if (request.params[0].get_int() != 0) { | |||||
fVerbose = true; | |||||
} | |||||
} else if (request.params[0].isBool()) { | |||||
if (request.params[0].isTrue()) { | |||||
fVerbose = true; | |||||
} | |||||
} else { | |||||
throw JSONRPCError( | |||||
RPC_TYPE_ERROR, | |||||
"Invalid type provided. Verbose parameter must be a boolean."); | |||||
} | |||||
} | |||||
UniValue o(UniValue::VARR); | |||||
if (!fVerbose) { | |||||
for (const CTxMemPoolEntry &e : mempool.mapTx) { | |||||
std::string strHex = | |||||
EncodeHexTx(e.GetTx(), RPCSerializationFlags()); | |||||
o.push_back(strHex); | |||||
} | |||||
return o; | |||||
} | |||||
uint256 hashBlock; | |||||
for (const CTxMemPoolEntry &e : mempool.mapTx) { | |||||
std::string strHex = EncodeHexTx(e.GetTx(), RPCSerializationFlags()); | |||||
UniValue utx(UniValue::VOBJ); | |||||
utx.pushKV("hex", strHex); | |||||
TxToJSON(config, e.GetTx(), hashBlock, utx); | |||||
o.push_back(utx); | |||||
} | |||||
return o; | |||||
} | |||||
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 txid (verbose)\n" | ||||
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n" | "\nIf txid is in the mempool, returns all in-mempool ancestors.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
▲ Show 20 Lines • Show All 1,316 Lines • ▼ Show 20 Lines | static const ContextFreeRPCCommand commands[] = { | ||||
{ "blockchain", "getblockheader", getblockheader, {"blockhash","verbose"} }, | { "blockchain", "getblockheader", getblockheader, {"blockhash","verbose"} }, | ||||
{ "blockchain", "getchaintips", getchaintips, {} }, | { "blockchain", "getchaintips", getchaintips, {} }, | ||||
{ "blockchain", "getdifficulty", getdifficulty, {} }, | { "blockchain", "getdifficulty", getdifficulty, {} }, | ||||
{ "blockchain", "getmempoolancestors", getmempoolancestors, {"txid","verbose"} }, | { "blockchain", "getmempoolancestors", getmempoolancestors, {"txid","verbose"} }, | ||||
{ "blockchain", "getmempooldescendants", getmempooldescendants, {"txid","verbose"} }, | { "blockchain", "getmempooldescendants", getmempooldescendants, {"txid","verbose"} }, | ||||
{ "blockchain", "getmempoolentry", getmempoolentry, {"txid"} }, | { "blockchain", "getmempoolentry", getmempoolentry, {"txid"} }, | ||||
{ "blockchain", "getmempoolinfo", getmempoolinfo, {} }, | { "blockchain", "getmempoolinfo", getmempoolinfo, {} }, | ||||
{ "blockchain", "getrawmempool", getrawmempool, {"verbose"} }, | { "blockchain", "getrawmempool", getrawmempool, {"verbose"} }, | ||||
{ "blockchain", "getrawmempooltxs", getrawmempooltxs, {"verbose"} }, | |||||
{ "blockchain", "gettxout", gettxout, {"txid","n","include_mempool"} }, | { "blockchain", "gettxout", gettxout, {"txid","n","include_mempool"} }, | ||||
{ "blockchain", "gettxoutsetinfo", gettxoutsetinfo, {} }, | { "blockchain", "gettxoutsetinfo", gettxoutsetinfo, {} }, | ||||
{ "blockchain", "pruneblockchain", pruneblockchain, {"height"} }, | { "blockchain", "pruneblockchain", pruneblockchain, {"height"} }, | ||||
{ "blockchain", "verifychain", verifychain, {"checklevel","nblocks"} }, | { "blockchain", "verifychain", verifychain, {"checklevel","nblocks"} }, | ||||
{ "blockchain", "preciousblock", preciousblock, {"blockhash"} }, | { "blockchain", "preciousblock", preciousblock, {"blockhash"} }, | ||||
/* Not shown in help */ | /* Not shown in help */ | ||||
{ "hidden", "finalizeblock", finalizeblock, {"blockhash"} }, | { "hidden", "finalizeblock", finalizeblock, {"blockhash"} }, | ||||
Show All 15 Lines |