13 #include "json/json_spirit_value.h"
24 if (blockindex == NULL)
32 int nShift = (blockindex->
nBits >> 24) & 0xff;
35 (double)0x0000ffff / (
double)(blockindex->
nBits & 0x00ffffff);
57 txGen.SetMerkleBranch(&block);
60 result.push_back(Pair(
"height", blockindex->
nHeight));
61 result.push_back(Pair(
"version", block.
nVersion));
66 result.push_back(Pair(
"tx", txs));
68 result.push_back(Pair(
"nonce", (uint64_t)block.
nNonce));
70 result.push_back(Pair(
"difficulty",
GetDifficulty(blockindex)));
73 if (blockindex->
pprev)
84 if (fHelp || params.size() != 0)
87 "\nReturns the number of blocks in the longest block chain.\n"
89 "n (numeric) The current block count\n"
100 if (fHelp || params.size() != 0)
103 "\nReturns the hash of the best (tip) block in the longest block chain.\n"
105 "\"hex\" (string) the block hash hex encoded\n"
116 if (fHelp || params.size() != 0)
119 "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
121 "n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
133 if (fHelp || params.size() > 1)
135 "getrawmempool ( verbose )\n"
136 "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
138 "1. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n"
139 "\nResult: (for verbose = false):\n"
140 "[ (json array of string)\n"
141 " \"transactionid\" (string) The transaction id\n"
144 "\nResult: (for verbose = true):\n"
146 " \"transactionid\" : { (json object)\n"
147 " \"size\" : n, (numeric) transaction size in bytes\n"
148 " \"fee\" : n, (numeric) transaction fee in bitcoins\n"
149 " \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n"
150 " \"height\" : n, (numeric) block height when transaction entered pool\n"
151 " \"startingpriority\" : n, (numeric) priority when transaction entered pool\n"
152 " \"currentpriority\" : n, (numeric) transaction priority now\n"
153 " \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n"
154 " \"transactionid\", (string) parent transaction id\n"
163 bool fVerbose =
false;
164 if (params.size() > 0)
165 fVerbose = params[0].get_bool();
173 const uint256& hash = entry.first;
176 info.push_back(Pair(
"size", (
int)e.
GetTxSize()));
178 info.push_back(Pair(
"time", e.
GetTime()));
179 info.push_back(Pair(
"height", (
int)e.
GetHeight()));
183 set<string> setDepends;
184 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
189 Array depends(setDepends.begin(), setDepends.end());
190 info.push_back(Pair(
"depends", depends));
191 o.push_back(Pair(hash.
ToString(), info));
197 vector<uint256> vtxid;
201 BOOST_FOREACH(
const uint256& hash, vtxid)
210 if (fHelp || params.size() != 1)
212 "getblockhash index\n"
213 "\nReturns hash of block in best-block-chain at index provided.\n"
215 "1. index (numeric, required) The block index\n"
217 "\"hash\" (string) The block hash\n"
223 int nHeight = params[0].get_int();
225 throw runtime_error(
"Block number out of range.");
233 if (fHelp || params.size() < 1 || params.size() > 2)
235 "getblock \"hash\" ( verbose )\n"
236 "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
237 "If verbose is true, returns an Object with information about block <hash>.\n"
239 "1. \"hash\" (string, required) The block hash\n"
240 "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
241 "\nResult (for verbose = true):\n"
243 " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
244 " \"confirmations\" : n, (numeric) The number of confirmations\n"
245 " \"size\" : n, (numeric) The block size\n"
246 " \"height\" : n, (numeric) The block height or index\n"
247 " \"version\" : n, (numeric) The block version\n"
248 " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
249 " \"tx\" : [ (array of string) The transaction ids\n"
250 " \"transactionid\" (string) The transaction id\n"
253 " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
254 " \"nonce\" : n, (numeric) The nonce\n"
255 " \"bits\" : \"1d00ffff\", (string) The bits\n"
256 " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
257 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
258 " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
260 "\nResult (for verbose=false):\n"
261 "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
263 +
HelpExampleCli(
"getblock",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
264 +
HelpExampleRpc(
"getblock",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
267 std::string strHash = params[0].get_str();
270 bool fVerbose =
true;
271 if (params.size() > 1)
272 fVerbose = params[1].get_bool();
296 if (fHelp || params.size() != 0)
299 "\nReturns statistics about the unspent transaction output set.\n"
300 "Note this call may take some time.\n"
303 " \"height\":n, (numeric) The current block height (index)\n"
304 " \"bestblock\": \"hex\", (string) the best block hash hex\n"
305 " \"transactions\": n, (numeric) The number of transactions\n"
306 " \"txouts\": n, (numeric) The number of output transactions\n"
307 " \"bytes_serialized\": n, (numeric) The serialized size\n"
308 " \"hash_serialized\": \"hash\", (string) The serialized hash\n"
309 " \"total_amount\": x.xxx (numeric) The total amount\n"
320 ret.push_back(Pair(
"height", (int64_t)stats.
nHeight));
322 ret.push_back(Pair(
"transactions", (int64_t)stats.
nTransactions));
324 ret.push_back(Pair(
"bytes_serialized", (int64_t)stats.
nSerializedSize));
333 if (fHelp || params.size() < 2 || params.size() > 3)
335 "gettxout \"txid\" n ( includemempool )\n"
336 "\nReturns details about an unspent transaction output.\n"
338 "1. \"txid\" (string, required) The transaction id\n"
339 "2. n (numeric, required) vout value\n"
340 "3. includemempool (boolean, optional) Whether to included the mem pool\n"
343 " \"bestblock\" : \"hash\", (string) the block hash\n"
344 " \"confirmations\" : n, (numeric) The number of confirmations\n"
345 " \"value\" : x.xxx, (numeric) The transaction value in btc\n"
346 " \"scriptPubKey\" : { (json object)\n"
347 " \"asm\" : \"code\", (string) \n"
348 " \"hex\" : \"hex\", (string) \n"
349 " \"reqSigs\" : n, (numeric) Number of required signatures\n"
350 " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n"
351 " \"addresses\" : [ (array of string) array of bitcoin addresses\n"
352 " \"bitcoinaddress\" (string) bitcoin address\n"
356 " \"version\" : n, (numeric) The version\n"
357 " \"coinbase\" : true|false (boolean) Coinbase or not\n"
361 "\nGet unspent transactions\n"
363 "\nView the details\n"
365 "\nAs a json rpc call\n"
371 std::string strHash = params[0].get_str();
373 int n = params[1].get_int();
374 bool fMempool =
true;
375 if (params.size() > 2)
376 fMempool = params[2].get_bool();
389 if (n<0 || (
unsigned int)n>=coins.
vout.size() || coins.
vout[n].IsNull())
396 ret.push_back(Pair(
"confirmations", 0));
398 ret.push_back(Pair(
"confirmations", pindex->
nHeight - coins.
nHeight + 1));
402 ret.push_back(Pair(
"scriptPubKey", o));
403 ret.push_back(Pair(
"version", coins.
nVersion));
404 ret.push_back(Pair(
"coinbase", coins.
fCoinBase));
411 if (fHelp || params.size() > 2)
413 "verifychain ( checklevel numblocks )\n"
414 "\nVerifies blockchain database.\n"
416 "1. checklevel (numeric, optional, 0-4, default=3) How thorough the block verification is.\n"
417 "2. numblocks (numeric, optional, default=288, 0=all) The number of blocks to check.\n"
419 "true|false (boolean) Verified or not\n"
425 int nCheckLevel =
GetArg(
"-checklevel", 3);
426 int nCheckDepth =
GetArg(
"-checkblocks", 288);
427 if (params.size() > 0)
428 nCheckLevel = params[0].get_int();
429 if (params.size() > 1)
430 nCheckDepth = params[1].get_int();
432 return VerifyDB(nCheckLevel, nCheckDepth);
437 if (fHelp || params.size() != 0)
439 "getblockchaininfo\n"
440 "Returns an object containing various state info regarding block chain processing.\n"
443 " \"chain\": \"xxxx\", (string) current chain (main, testnet3, regtest)\n"
444 " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
445 " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
446 " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
447 " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
448 " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
462 obj.push_back(Pair(
"chain", chain));
const string & DataDir() const
uint64_t nTransactionOutputs
unsigned int GetHeight() const
const_iterator begin() const
std::vector< CTxOut > vout
void ScriptPubKeyToJSON(const CScript &scriptPubKey, Object &out, bool fIncludeHex)
Value getblockcount(const Array ¶ms, bool fHelp)
std::string HelpExampleRpc(string methodname, string args)
bool VerifyDB(int nCheckLevel, int nCheckDepth)
Verify consistency of the block and coin databases.
void queryHashes(std::vector< uint256 > &vtxid)
Value gettxoutsetinfo(const Array ¶ms, bool fHelp)
Object blockToJSON(const CBlock &block, const CBlockIndex *blockindex)
Double ended buffer combining vector and stream-like interfaces.
Object JSONRPCError(int code, const string &message)
Value getblockchaininfo(const Array ¶ms, bool fHelp)
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
Value getblock(const Array ¶ms, bool fHelp)
bool GetStats(CCoinsStats &stats)
Value getdifficulty(const Array ¶ms, bool fHelp)
CChain chainActive
The currently-connected chain of blocks.
bool GetCoins(const uint256 &txid, CCoins &coins)
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or NULL if none.
int Height() const
Return the maximal height in the chain.
std::string HexBits(unsigned int nBits)
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or NULL if the given index is not found or is the tip...
Value ValueFromAmount(int64_t amount)
unsigned int GetSerializeSize(char a, int, int=0)
An input of a transaction.
bool GetCoins(const uint256 &txid, CCoins &coins)
double GetPriority(unsigned int currentHeight) const
std::map< uint256, CTxMemPoolEntry > mapTx
Value getrawmempool(const Array ¶ms, bool fHelp)
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
std::string GetHex() const
double GuessVerificationProgress(CBlockIndex *pindex, bool fSigchecks)
void pruneSpent(const uint256 &hash, CCoins &coins)
const CTransaction & GetTx() const
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos)
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
std::string ToString() const
static const int PROTOCOL_VERSION
double GetDifficulty(const CBlockIndex *blockindex)
bool exists(uint256 hash)
int GetDepthInMainChain(CBlockIndex *&pindexRet) const
std::pair< CService, int > proxyType
Value getbestblockhash(const Array ¶ms, bool fHelp)
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
std::string HelpExampleCli(string methodname, string args)
std::vector< CTransaction > vtx
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Value getblockhash(const Array ¶ms, bool fHelp)
static const unsigned int MEMPOOL_HEIGHT
Fake height value used in CCoins to signify they are only in the memory pool (since 0...
The basic transaction that is broadcasted on the network and contained in blocks. ...
Value gettxout(const Array ¶ms, bool fHelp)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Value verifychain(const Array ¶ms, bool fHelp)
CCoinsView that brings transactions from a memorypool into view.
map< uint256, CBlockIndex * > mapBlockIndex
uint256 GetBlockHash() const
A transaction with a merkle branch linking it to the block chain.
const_iterator end() const