14 #include "json/json_spirit_value.h"
25 if (blockindex == NULL)
33 int nShift = (blockindex->
nBits >> 24) & 0xff;
36 (double)0x0000ffff / (
double)(blockindex->
nBits & 0x00ffffff);
58 txGen.SetMerkleBranch(&block);
61 result.push_back(Pair(
"height", blockindex->
nHeight));
62 result.push_back(Pair(
"version", block.
nVersion));
67 result.push_back(Pair(
"tx", txs));
69 result.push_back(Pair(
"nonce", (uint64_t)block.
nNonce));
71 result.push_back(Pair(
"difficulty",
GetDifficulty(blockindex)));
74 if (blockindex->
pprev)
85 if (fHelp || params.size() != 0)
88 "\nReturns the number of blocks in the longest block chain.\n"
90 "n (numeric) The current block count\n"
101 if (fHelp || params.size() != 0)
104 "\nReturns the hash of the best (tip) block in the longest block chain.\n"
106 "\"hex\" (string) the block hash hex encoded\n"
117 if (fHelp || params.size() != 0)
120 "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
122 "n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
134 if (fHelp || params.size() > 1)
136 "getrawmempool ( verbose )\n"
137 "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
139 "1. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n"
140 "\nResult: (for verbose = false):\n"
141 "[ (json array of string)\n"
142 " \"transactionid\" (string) The transaction id\n"
145 "\nResult: (for verbose = true):\n"
147 " \"transactionid\" : { (json object)\n"
148 " \"size\" : n, (numeric) transaction size in bytes\n"
149 " \"fee\" : n, (numeric) transaction fee in anoncoins\n"
150 " \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n"
151 " \"height\" : n, (numeric) block height when transaction entered pool\n"
152 " \"startingpriority\" : n, (numeric) priority when transaction entered pool\n"
153 " \"currentpriority\" : n, (numeric) transaction priority now\n"
154 " \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n"
155 " \"transactionid\", (string) parent transaction id\n"
164 bool fVerbose =
false;
165 if (params.size() > 0)
166 fVerbose = params[0].get_bool();
174 const uint256& hash = entry.first;
177 info.push_back(Pair(
"size", (
int)e.
GetTxSize()));
179 info.push_back(Pair(
"time", e.
GetTime()));
180 info.push_back(Pair(
"height", (
int)e.
GetHeight()));
184 set<string> setDepends;
185 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
190 Array depends(setDepends.begin(), setDepends.end());
191 info.push_back(Pair(
"depends", depends));
192 o.push_back(Pair(hash.
ToString(), info));
198 vector<uint256> vtxid;
202 BOOST_FOREACH(
const uint256& hash, vtxid)
211 if (fHelp || params.size() != 1)
213 "getblockhash index\n"
214 "\nReturns hash of block in best-block-chain at index provided.\n"
216 "1. index (numeric, required) The block index\n"
218 "\"hash\" (string) The block hash\n"
224 int nHeight = params[0].get_int();
226 throw runtime_error(
"Block number out of range.");
234 if (fHelp || params.size() < 1 || params.size() > 2)
236 "getblock \"hash\" ( verbose )\n"
237 "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
238 "If verbose is true, returns an Object with information about block <hash>.\n"
240 "1. \"hash\" (string, required) The block hash\n"
241 "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
242 "\nResult (for verbose = true):\n"
244 " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
245 " \"confirmations\" : n, (numeric) The number of confirmations\n"
246 " \"size\" : n, (numeric) The block size\n"
247 " \"height\" : n, (numeric) The block height or index\n"
248 " \"version\" : n, (numeric) The block version\n"
249 " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
250 " \"tx\" : [ (array of string) The transaction ids\n"
251 " \"transactionid\" (string) The transaction id\n"
254 " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
255 " \"nonce\" : n, (numeric) The nonce\n"
256 " \"bits\" : \"1d00ffff\", (string) The bits\n"
257 " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
258 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
259 " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
261 "\nResult (for verbose=false):\n"
262 "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
264 +
HelpExampleCli(
"getblock",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
265 +
HelpExampleRpc(
"getblock",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
268 std::string strHash = params[0].get_str();
271 bool fVerbose =
true;
272 if (params.size() > 1)
273 fVerbose = params[1].get_bool();
297 if (fHelp || params.size() != 0)
300 "\nReturns statistics about the unspent transaction output set.\n"
301 "Note this call may take some time.\n"
304 " \"height\":n, (numeric) The current block height (index)\n"
305 " \"bestblock\": \"hex\", (string) the best block hash hex\n"
306 " \"transactions\": n, (numeric) The number of transactions\n"
307 " \"txouts\": n, (numeric) The number of output transactions\n"
308 " \"bytes_serialized\": n, (numeric) The serialized size\n"
309 " \"hash_serialized\": \"hash\", (string) The serialized hash\n"
310 " \"total_amount\": x.xxx (numeric) The total amount\n"
321 ret.push_back(Pair(
"height", (int64_t)stats.
nHeight));
323 ret.push_back(Pair(
"transactions", (int64_t)stats.
nTransactions));
325 ret.push_back(Pair(
"bytes_serialized", (int64_t)stats.
nSerializedSize));
334 if (fHelp || params.size() < 2 || params.size() > 3)
336 "gettxout \"txid\" n ( includemempool )\n"
337 "\nReturns details about an unspent transaction output.\n"
339 "1. \"txid\" (string, required) The transaction id\n"
340 "2. n (numeric, required) vout value\n"
341 "3. includemempool (boolean, optional) Whether to included the mem pool\n"
344 " \"bestblock\" : \"hash\", (string) the block hash\n"
345 " \"confirmations\" : n, (numeric) The number of confirmations\n"
346 " \"value\" : x.xxx, (numeric) The transaction value in btc\n"
347 " \"scriptPubKey\" : { (json object)\n"
348 " \"asm\" : \"code\", (string) \n"
349 " \"hex\" : \"hex\", (string) \n"
350 " \"reqSigs\" : n, (numeric) Number of required signatures\n"
351 " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n"
352 " \"addresses\" : [ (array of string) array of anoncoin addresses\n"
353 " \"anoncoinaddress\" (string) anoncoin address\n"
357 " \"version\" : n, (numeric) The version\n"
358 " \"coinbase\" : true|false (boolean) Coinbase or not\n"
362 "\nGet unspent transactions\n"
364 "\nView the details\n"
366 "\nAs a json rpc call\n"
372 std::string strHash = params[0].get_str();
374 int n = params[1].get_int();
375 bool fMempool =
true;
376 if (params.size() > 2)
377 fMempool = params[2].get_bool();
390 if (n<0 || (
unsigned int)n>=coins.
vout.size() || coins.
vout[n].IsNull())
396 if ((
unsigned int)coins.
nHeight == MEMPOOL_HEIGHT)
397 ret.push_back(Pair(
"confirmations", 0));
399 ret.push_back(Pair(
"confirmations", pindex->
nHeight - coins.
nHeight + 1));
403 ret.push_back(Pair(
"scriptPubKey", o));
404 ret.push_back(Pair(
"version", coins.
nVersion));
405 ret.push_back(Pair(
"coinbase", coins.
fCoinBase));
412 if (fHelp || params.size() > 2)
414 "verifychain ( checklevel numblocks )\n"
415 "\nVerifies blockchain database.\n"
417 "1. checklevel (numeric, optional, 0-4, default=3) How thorough the block verification is.\n"
418 "2. numblocks (numeric, optional, default=288, 0=all) The number of blocks to check.\n"
420 "true|false (boolean) Verified or not\n"
426 int nCheckLevel =
GetArg(
"-checklevel", 3);
427 int nCheckDepth =
GetArg(
"-checkblocks", 288);
428 if (params.size() > 0)
429 nCheckLevel = params[0].get_int();
430 if (params.size() > 1)
431 nCheckDepth = params[1].get_int();
433 return VerifyDB(nCheckLevel, nCheckDepth);
438 if (fHelp || params.size() != 0)
440 "getblockchaininfo\n"
441 "Returns an object containing various state info regarding block chain processing.\n"
444 " \"chain\": \"xxxx\", (string) current chain (main, testnet3, regtest)\n"
445 " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
446 " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
447 " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
448 " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
449 " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
463 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.
A combination of a network address (CNetAddr) and a (TCP) port.
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
double GetDifficulty(const CBlockIndex *blockindex)
bool exists(uint256 hash)
int GetDepthInMainChain(CBlockIndex *&pindexRet) const
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)
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