| 804 | } |
| 805 | |
| 806 | static UniValue getblock(const JSONRPCRequest& request) |
| 807 | { |
| 808 | if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) |
| 809 | throw std::runtime_error( |
| 810 | "getblock \"blockhash\" ( verbosity legacy) \n" |
| 811 | "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n" |
| 812 | "If verbosity is 1, returns an Object with information about block <hash>.\n" |
| 813 | "If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n" |
| 814 | "\nArguments:\n" |
| 815 | "1. \"blockhash\" (string, required) The block hash\n" |
| 816 | "2. \"verbosity\" (numeric, optional, default=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data\n" |
| 817 | "3. \"legacy\" (boolean, optional, default=false) indicates if the block should be in legacy format\n" |
| 818 | "\nResult (for verbosity = 0):\n" |
| 819 | "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" |
| 820 | "\nResult (for verbosity = 1):\n" |
| 821 | "{\n" |
| 822 | " \"hash\" : \"hash\", (string) the block hash (same as provided)\n" |
| 823 | " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" |
| 824 | " \"size\" : n, (numeric) The block size\n" |
| 825 | " \"strippedsize\" : n, (numeric) The block size excluding witness data\n" |
| 826 | " \"weight\" : n (numeric) The block weight as defined in BIP 141\n" |
| 827 | " \"height\" : n, (numeric) The block height or index\n" |
| 828 | " \"version\" : n, (numeric) The block version\n" |
| 829 | " \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n" |
| 830 | " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" |
| 831 | " \"tx\" : [ (array of string) The transaction ids\n" |
| 832 | " \"transactionid\" (string) The transaction id\n" |
| 833 | " ,...\n" |
| 834 | " ],\n" |
| 835 | " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" |
| 836 | " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" |
| 837 | " \"nonce\" : n, (numeric) The nonce\n" |
| 838 | " \"bits\" : \"1d00ffff\", (string) The bits\n" |
| 839 | " \"difficulty\" : x.xxx, (numeric) The difficulty\n" |
| 840 | " \"chainwork\" : \"xxxx\", (string) Expected number of hashes required to produce the chain up to this block (in hex)\n" |
| 841 | " \"nTx\" : n, (numeric) The number of transactions in the block.\n" |
| 842 | " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" |
| 843 | " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n" |
| 844 | "}\n" |
| 845 | "\nResult (for verbosity = 2):\n" |
| 846 | "{\n" |
| 847 | " ..., Same output as verbosity = 1.\n" |
| 848 | " \"tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result.\n" |
| 849 | " ,...\n" |
| 850 | " ],\n" |
| 851 | " ,... Same output as verbosity = 1.\n" |
| 852 | "}\n" |
| 853 | "\nExamples:\n" |
| 854 | + HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") |
| 855 | + HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") |
| 856 | ); |
| 857 | |
| 858 | LOCK(cs_main); |
| 859 | |
| 860 | std::string strHash = request.params[0].get_str(); |
| 861 | uint256 hash(uint256S(strHash)); |
| 862 | |
| 863 | int verbosity = 1; |
nothing calls this directly
no test coverage detected