Bitcoin Core  25.99.0
P2P Digital Currency
rest.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2022 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <rest.h>
7 
8 #include <blockfilter.h>
9 #include <chain.h>
10 #include <chainparams.h>
11 #include <core_io.h>
12 #include <httpserver.h>
13 #include <index/blockfilterindex.h>
14 #include <index/txindex.h>
15 #include <node/blockstorage.h>
16 #include <node/context.h>
17 #include <primitives/block.h>
18 #include <primitives/transaction.h>
19 #include <rpc/blockchain.h>
20 #include <rpc/mempool.h>
21 #include <rpc/protocol.h>
22 #include <rpc/server.h>
23 #include <rpc/server_util.h>
24 #include <streams.h>
25 #include <sync.h>
26 #include <txmempool.h>
27 #include <util/any.h>
28 #include <util/check.h>
29 #include <validation.h>
30 #include <version.h>
31 
32 #include <any>
33 #include <string>
34 
35 #include <univalue.h>
36 
38 using node::NodeContext;
39 
40 static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
41 static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;
42 
43 static const struct {
45  const char* name;
46 } rf_names[] = {
49  {RESTResponseFormat::HEX, "hex"},
50  {RESTResponseFormat::JSON, "json"},
51 };
52 
53 struct CCoin {
54  uint32_t nHeight;
56 
57  CCoin() : nHeight(0) {}
58  explicit CCoin(Coin&& in) : nHeight(in.nHeight), out(std::move(in.out)) {}
59 
61  {
62  uint32_t nTxVerDummy = 0;
63  READWRITE(nTxVerDummy, obj.nHeight, obj.out);
64  }
65 };
66 
67 static bool RESTERR(HTTPRequest* req, enum HTTPStatusCode status, std::string message)
68 {
69  req->WriteHeader("Content-Type", "text/plain");
70  req->WriteReply(status, message + "\r\n");
71  return false;
72 }
73 
81 static NodeContext* GetNodeContext(const std::any& context, HTTPRequest* req)
82 {
83  auto node_context = util::AnyPtr<NodeContext>(context);
84  if (!node_context) {
86  strprintf("%s:%d (%s)\n"
87  "Internal bug detected: Node context not found!\n"
88  "You may report this issue here: %s\n",
89  __FILE__, __LINE__, __func__, PACKAGE_BUGREPORT));
90  return nullptr;
91  }
92  return node_context;
93 }
94 
102 static CTxMemPool* GetMemPool(const std::any& context, HTTPRequest* req)
103 {
104  auto node_context = util::AnyPtr<NodeContext>(context);
105  if (!node_context || !node_context->mempool) {
106  RESTERR(req, HTTP_NOT_FOUND, "Mempool disabled or instance not found");
107  return nullptr;
108  }
109  return node_context->mempool.get();
110 }
111 
119 static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
120 {
121  auto node_context = util::AnyPtr<NodeContext>(context);
122  if (!node_context || !node_context->chainman) {
124  strprintf("%s:%d (%s)\n"
125  "Internal bug detected: Chainman disabled or instance not found!\n"
126  "You may report this issue here: %s\n",
127  __FILE__, __LINE__, __func__, PACKAGE_BUGREPORT));
128  return nullptr;
129  }
130  return node_context->chainman.get();
131 }
132 
133 RESTResponseFormat ParseDataFormat(std::string& param, const std::string& strReq)
134 {
135  // Remove query string (if any, separated with '?') as it should not interfere with
136  // parsing param and data format
137  param = strReq.substr(0, strReq.rfind('?'));
138  const std::string::size_type pos_format{param.rfind('.')};
139 
140  // No format string is found
141  if (pos_format == std::string::npos) {
142  return rf_names[0].rf;
143  }
144 
145  // Match format string to available formats
146  const std::string suffix(param, pos_format + 1);
147  for (const auto& rf_name : rf_names) {
148  if (suffix == rf_name.name) {
149  param.erase(pos_format);
150  return rf_name.rf;
151  }
152  }
153 
154  // If no suffix is found, return RESTResponseFormat::UNDEF and original string without query string
155  return rf_names[0].rf;
156 }
157 
158 static std::string AvailableDataFormatsString()
159 {
160  std::string formats;
161  for (const auto& rf_name : rf_names) {
162  if (strlen(rf_name.name) > 0) {
163  formats.append(".");
164  formats.append(rf_name.name);
165  formats.append(", ");
166  }
167  }
168 
169  if (formats.length() > 0)
170  return formats.substr(0, formats.length() - 2);
171 
172  return formats;
173 }
174 
175 static bool CheckWarmup(HTTPRequest* req)
176 {
177  std::string statusmessage;
178  if (RPCIsInWarmup(&statusmessage))
179  return RESTERR(req, HTTP_SERVICE_UNAVAILABLE, "Service temporarily unavailable: " + statusmessage);
180  return true;
181 }
182 
183 static bool rest_headers(const std::any& context,
184  HTTPRequest* req,
185  const std::string& strURIPart)
186 {
187  if (!CheckWarmup(req))
188  return false;
189  std::string param;
190  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
191  std::vector<std::string> path = SplitString(param, '/');
192 
193  std::string raw_count;
194  std::string hashStr;
195  if (path.size() == 2) {
196  // deprecated path: /rest/headers/<count>/<hash>
197  hashStr = path[1];
198  raw_count = path[0];
199  } else if (path.size() == 1) {
200  // new path with query parameter: /rest/headers/<hash>?count=<count>
201  hashStr = path[0];
202  try {
203  raw_count = req->GetQueryParameter("count").value_or("5");
204  } catch (const std::runtime_error& e) {
205  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
206  }
207  } else {
208  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/headers/<hash>.<ext>?count=<count>");
209  }
210 
211  const auto parsed_count{ToIntegral<size_t>(raw_count)};
212  if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) {
213  return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, raw_count));
214  }
215 
216  uint256 hash;
217  if (!ParseHashStr(hashStr, hash))
218  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
219 
220  const CBlockIndex* tip = nullptr;
221  std::vector<const CBlockIndex*> headers;
222  headers.reserve(*parsed_count);
223  {
224  ChainstateManager* maybe_chainman = GetChainman(context, req);
225  if (!maybe_chainman) return false;
226  ChainstateManager& chainman = *maybe_chainman;
227  LOCK(cs_main);
228  CChain& active_chain = chainman.ActiveChain();
229  tip = active_chain.Tip();
230  const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
231  while (pindex != nullptr && active_chain.Contains(pindex)) {
232  headers.push_back(pindex);
233  if (headers.size() == *parsed_count) {
234  break;
235  }
236  pindex = active_chain.Next(pindex);
237  }
238  }
239 
240  switch (rf) {
242  DataStream ssHeader{};
243  for (const CBlockIndex *pindex : headers) {
244  ssHeader << pindex->GetBlockHeader();
245  }
246 
247  std::string binaryHeader = ssHeader.str();
248  req->WriteHeader("Content-Type", "application/octet-stream");
249  req->WriteReply(HTTP_OK, binaryHeader);
250  return true;
251  }
252 
254  DataStream ssHeader{};
255  for (const CBlockIndex *pindex : headers) {
256  ssHeader << pindex->GetBlockHeader();
257  }
258 
259  std::string strHex = HexStr(ssHeader) + "\n";
260  req->WriteHeader("Content-Type", "text/plain");
261  req->WriteReply(HTTP_OK, strHex);
262  return true;
263  }
265  UniValue jsonHeaders(UniValue::VARR);
266  for (const CBlockIndex *pindex : headers) {
267  jsonHeaders.push_back(blockheaderToJSON(tip, pindex));
268  }
269  std::string strJSON = jsonHeaders.write() + "\n";
270  req->WriteHeader("Content-Type", "application/json");
271  req->WriteReply(HTTP_OK, strJSON);
272  return true;
273  }
274  default: {
275  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
276  }
277  }
278 }
279 
280 static bool rest_block(const std::any& context,
281  HTTPRequest* req,
282  const std::string& strURIPart,
283  TxVerbosity tx_verbosity)
284 {
285  if (!CheckWarmup(req))
286  return false;
287  std::string hashStr;
288  const RESTResponseFormat rf = ParseDataFormat(hashStr, strURIPart);
289 
290  uint256 hash;
291  if (!ParseHashStr(hashStr, hash))
292  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
293 
294  CBlock block;
295  const CBlockIndex* pblockindex = nullptr;
296  const CBlockIndex* tip = nullptr;
297  ChainstateManager* maybe_chainman = GetChainman(context, req);
298  if (!maybe_chainman) return false;
299  ChainstateManager& chainman = *maybe_chainman;
300  {
301  LOCK(cs_main);
302  tip = chainman.ActiveChain().Tip();
303  pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
304  if (!pblockindex) {
305  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
306  }
307 
308  if (chainman.m_blockman.IsBlockPruned(pblockindex))
309  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
310 
311  }
312 
313  if (!chainman.m_blockman.ReadBlockFromDisk(block, *pblockindex)) {
314  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
315  }
316 
317  switch (rf) {
320  ssBlock << block;
321  std::string binaryBlock = ssBlock.str();
322  req->WriteHeader("Content-Type", "application/octet-stream");
323  req->WriteReply(HTTP_OK, binaryBlock);
324  return true;
325  }
326 
329  ssBlock << block;
330  std::string strHex = HexStr(ssBlock) + "\n";
331  req->WriteHeader("Content-Type", "text/plain");
332  req->WriteReply(HTTP_OK, strHex);
333  return true;
334  }
335 
337  UniValue objBlock = blockToJSON(chainman.m_blockman, block, tip, pblockindex, tx_verbosity);
338  std::string strJSON = objBlock.write() + "\n";
339  req->WriteHeader("Content-Type", "application/json");
340  req->WriteReply(HTTP_OK, strJSON);
341  return true;
342  }
343 
344  default: {
345  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
346  }
347  }
348 }
349 
350 static bool rest_block_extended(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
351 {
352  return rest_block(context, req, strURIPart, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
353 }
354 
355 static bool rest_block_notxdetails(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
356 {
357  return rest_block(context, req, strURIPart, TxVerbosity::SHOW_TXID);
358 }
359 
360 static bool rest_filter_header(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
361 {
362  if (!CheckWarmup(req)) return false;
363 
364  std::string param;
365  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
366 
367  std::vector<std::string> uri_parts = SplitString(param, '/');
368  std::string raw_count;
369  std::string raw_blockhash;
370  if (uri_parts.size() == 3) {
371  // deprecated path: /rest/blockfilterheaders/<filtertype>/<count>/<blockhash>
372  raw_blockhash = uri_parts[2];
373  raw_count = uri_parts[1];
374  } else if (uri_parts.size() == 2) {
375  // new path with query parameter: /rest/blockfilterheaders/<filtertype>/<blockhash>?count=<count>
376  raw_blockhash = uri_parts[1];
377  try {
378  raw_count = req->GetQueryParameter("count").value_or("5");
379  } catch (const std::runtime_error& e) {
380  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
381  }
382  } else {
383  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/blockfilterheaders/<filtertype>/<blockhash>.<ext>?count=<count>");
384  }
385 
386  const auto parsed_count{ToIntegral<size_t>(raw_count)};
387  if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) {
388  return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, raw_count));
389  }
390 
391  uint256 block_hash;
392  if (!ParseHashStr(raw_blockhash, block_hash)) {
393  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + raw_blockhash);
394  }
395 
396  BlockFilterType filtertype;
397  if (!BlockFilterTypeByName(uri_parts[0], filtertype)) {
398  return RESTERR(req, HTTP_BAD_REQUEST, "Unknown filtertype " + uri_parts[0]);
399  }
400 
401  BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
402  if (!index) {
403  return RESTERR(req, HTTP_BAD_REQUEST, "Index is not enabled for filtertype " + uri_parts[0]);
404  }
405 
406  std::vector<const CBlockIndex*> headers;
407  headers.reserve(*parsed_count);
408  {
409  ChainstateManager* maybe_chainman = GetChainman(context, req);
410  if (!maybe_chainman) return false;
411  ChainstateManager& chainman = *maybe_chainman;
412  LOCK(cs_main);
413  CChain& active_chain = chainman.ActiveChain();
414  const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block_hash);
415  while (pindex != nullptr && active_chain.Contains(pindex)) {
416  headers.push_back(pindex);
417  if (headers.size() == *parsed_count)
418  break;
419  pindex = active_chain.Next(pindex);
420  }
421  }
422 
423  bool index_ready = index->BlockUntilSyncedToCurrentChain();
424 
425  std::vector<uint256> filter_headers;
426  filter_headers.reserve(*parsed_count);
427  for (const CBlockIndex* pindex : headers) {
428  uint256 filter_header;
429  if (!index->LookupFilterHeader(pindex, filter_header)) {
430  std::string errmsg = "Filter not found.";
431 
432  if (!index_ready) {
433  errmsg += " Block filters are still in the process of being indexed.";
434  } else {
435  errmsg += " This error is unexpected and indicates index corruption.";
436  }
437 
438  return RESTERR(req, HTTP_NOT_FOUND, errmsg);
439  }
440  filter_headers.push_back(filter_header);
441  }
442 
443  switch (rf) {
445  DataStream ssHeader{};
446  for (const uint256& header : filter_headers) {
447  ssHeader << header;
448  }
449 
450  std::string binaryHeader = ssHeader.str();
451  req->WriteHeader("Content-Type", "application/octet-stream");
452  req->WriteReply(HTTP_OK, binaryHeader);
453  return true;
454  }
456  DataStream ssHeader{};
457  for (const uint256& header : filter_headers) {
458  ssHeader << header;
459  }
460 
461  std::string strHex = HexStr(ssHeader) + "\n";
462  req->WriteHeader("Content-Type", "text/plain");
463  req->WriteReply(HTTP_OK, strHex);
464  return true;
465  }
467  UniValue jsonHeaders(UniValue::VARR);
468  for (const uint256& header : filter_headers) {
469  jsonHeaders.push_back(header.GetHex());
470  }
471 
472  std::string strJSON = jsonHeaders.write() + "\n";
473  req->WriteHeader("Content-Type", "application/json");
474  req->WriteReply(HTTP_OK, strJSON);
475  return true;
476  }
477  default: {
478  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
479  }
480  }
481 }
482 
483 static bool rest_block_filter(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
484 {
485  if (!CheckWarmup(req)) return false;
486 
487  std::string param;
488  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
489 
490  // request is sent over URI scheme /rest/blockfilter/filtertype/blockhash
491  std::vector<std::string> uri_parts = SplitString(param, '/');
492  if (uri_parts.size() != 2) {
493  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/blockfilter/<filtertype>/<blockhash>");
494  }
495 
496  uint256 block_hash;
497  if (!ParseHashStr(uri_parts[1], block_hash)) {
498  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + uri_parts[1]);
499  }
500 
501  BlockFilterType filtertype;
502  if (!BlockFilterTypeByName(uri_parts[0], filtertype)) {
503  return RESTERR(req, HTTP_BAD_REQUEST, "Unknown filtertype " + uri_parts[0]);
504  }
505 
506  BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
507  if (!index) {
508  return RESTERR(req, HTTP_BAD_REQUEST, "Index is not enabled for filtertype " + uri_parts[0]);
509  }
510 
511  const CBlockIndex* block_index;
512  bool block_was_connected;
513  {
514  ChainstateManager* maybe_chainman = GetChainman(context, req);
515  if (!maybe_chainman) return false;
516  ChainstateManager& chainman = *maybe_chainman;
517  LOCK(cs_main);
518  block_index = chainman.m_blockman.LookupBlockIndex(block_hash);
519  if (!block_index) {
520  return RESTERR(req, HTTP_NOT_FOUND, uri_parts[1] + " not found");
521  }
522  block_was_connected = block_index->IsValid(BLOCK_VALID_SCRIPTS);
523  }
524 
525  bool index_ready = index->BlockUntilSyncedToCurrentChain();
526 
527  BlockFilter filter;
528  if (!index->LookupFilter(block_index, filter)) {
529  std::string errmsg = "Filter not found.";
530 
531  if (!block_was_connected) {
532  errmsg += " Block was not connected to active chain.";
533  } else if (!index_ready) {
534  errmsg += " Block filters are still in the process of being indexed.";
535  } else {
536  errmsg += " This error is unexpected and indicates index corruption.";
537  }
538 
539  return RESTERR(req, HTTP_NOT_FOUND, errmsg);
540  }
541 
542  switch (rf) {
544  DataStream ssResp{};
545  ssResp << filter;
546 
547  std::string binaryResp = ssResp.str();
548  req->WriteHeader("Content-Type", "application/octet-stream");
549  req->WriteReply(HTTP_OK, binaryResp);
550  return true;
551  }
553  DataStream ssResp{};
554  ssResp << filter;
555 
556  std::string strHex = HexStr(ssResp) + "\n";
557  req->WriteHeader("Content-Type", "text/plain");
558  req->WriteReply(HTTP_OK, strHex);
559  return true;
560  }
563  ret.pushKV("filter", HexStr(filter.GetEncodedFilter()));
564  std::string strJSON = ret.write() + "\n";
565  req->WriteHeader("Content-Type", "application/json");
566  req->WriteReply(HTTP_OK, strJSON);
567  return true;
568  }
569  default: {
570  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
571  }
572  }
573 }
574 
575 // A bit of a hack - dependency on a function defined in rpc/blockchain.cpp
577 
578 static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
579 {
580  if (!CheckWarmup(req))
581  return false;
582  std::string param;
583  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
584 
585  switch (rf) {
587  JSONRPCRequest jsonRequest;
588  jsonRequest.context = context;
589  jsonRequest.params = UniValue(UniValue::VARR);
590  UniValue chainInfoObject = getblockchaininfo().HandleRequest(jsonRequest);
591  std::string strJSON = chainInfoObject.write() + "\n";
592  req->WriteHeader("Content-Type", "application/json");
593  req->WriteReply(HTTP_OK, strJSON);
594  return true;
595  }
596  default: {
597  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
598  }
599  }
600 }
601 
602 
604 
605 static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
606 {
607  if (!CheckWarmup(req)) return false;
608 
609  std::string hash_str;
610  const RESTResponseFormat rf = ParseDataFormat(hash_str, str_uri_part);
611 
612  switch (rf) {
614  JSONRPCRequest jsonRequest;
615  jsonRequest.context = context;
616  jsonRequest.params = UniValue(UniValue::VARR);
617 
618  if (!hash_str.empty()) {
619  uint256 hash;
620  if (!ParseHashStr(hash_str, hash)) {
621  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hash_str);
622  }
623 
624  const ChainstateManager* chainman = GetChainman(context, req);
625  if (!chainman) return false;
626  if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(ParseHashV(hash_str, "blockhash")))) {
627  return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
628  }
629 
630  jsonRequest.params.pushKV("blockhash", hash_str);
631  }
632 
633  req->WriteHeader("Content-Type", "application/json");
634  req->WriteReply(HTTP_OK, getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n");
635  return true;
636  }
637  default: {
638  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
639  }
640  }
641 
642 }
643 
644 static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
645 {
646  if (!CheckWarmup(req))
647  return false;
648 
649  std::string param;
650  const RESTResponseFormat rf = ParseDataFormat(param, str_uri_part);
651  if (param != "contents" && param != "info") {
652  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/mempool/<info|contents>.json");
653  }
654 
655  const CTxMemPool* mempool = GetMemPool(context, req);
656  if (!mempool) return false;
657 
658  switch (rf) {
660  std::string str_json;
661  if (param == "contents") {
662  std::string raw_verbose;
663  try {
664  raw_verbose = req->GetQueryParameter("verbose").value_or("true");
665  } catch (const std::runtime_error& e) {
666  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
667  }
668  if (raw_verbose != "true" && raw_verbose != "false") {
669  return RESTERR(req, HTTP_BAD_REQUEST, "The \"verbose\" query parameter must be either \"true\" or \"false\".");
670  }
671  std::string raw_mempool_sequence;
672  try {
673  raw_mempool_sequence = req->GetQueryParameter("mempool_sequence").value_or("false");
674  } catch (const std::runtime_error& e) {
675  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
676  }
677  if (raw_mempool_sequence != "true" && raw_mempool_sequence != "false") {
678  return RESTERR(req, HTTP_BAD_REQUEST, "The \"mempool_sequence\" query parameter must be either \"true\" or \"false\".");
679  }
680  const bool verbose{raw_verbose == "true"};
681  const bool mempool_sequence{raw_mempool_sequence == "true"};
682  if (verbose && mempool_sequence) {
683  return RESTERR(req, HTTP_BAD_REQUEST, "Verbose results cannot contain mempool sequence values. (hint: set \"verbose=false\")");
684  }
685  str_json = MempoolToJSON(*mempool, verbose, mempool_sequence).write() + "\n";
686  } else {
687  str_json = MempoolInfoToJSON(*mempool).write() + "\n";
688  }
689 
690  req->WriteHeader("Content-Type", "application/json");
691  req->WriteReply(HTTP_OK, str_json);
692  return true;
693  }
694  default: {
695  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
696  }
697  }
698 }
699 
700 static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
701 {
702  if (!CheckWarmup(req))
703  return false;
704  std::string hashStr;
705  const RESTResponseFormat rf = ParseDataFormat(hashStr, strURIPart);
706 
707  uint256 hash;
708  if (!ParseHashStr(hashStr, hash))
709  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
710 
711  if (g_txindex) {
712  g_txindex->BlockUntilSyncedToCurrentChain();
713  }
714 
715  const NodeContext* const node = GetNodeContext(context, req);
716  if (!node) return false;
717  uint256 hashBlock = uint256();
718  const CTransactionRef tx = GetTransaction(/*block_index=*/nullptr, node->mempool.get(), hash, hashBlock, node->chainman->m_blockman);
719  if (!tx) {
720  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
721  }
722 
723  switch (rf) {
726  ssTx << tx;
727 
728  std::string binaryTx = ssTx.str();
729  req->WriteHeader("Content-Type", "application/octet-stream");
730  req->WriteReply(HTTP_OK, binaryTx);
731  return true;
732  }
733 
736  ssTx << tx;
737 
738  std::string strHex = HexStr(ssTx) + "\n";
739  req->WriteHeader("Content-Type", "text/plain");
740  req->WriteReply(HTTP_OK, strHex);
741  return true;
742  }
743 
745  UniValue objTx(UniValue::VOBJ);
746  TxToUniv(*tx, /*block_hash=*/hashBlock, /*entry=*/ objTx);
747  std::string strJSON = objTx.write() + "\n";
748  req->WriteHeader("Content-Type", "application/json");
749  req->WriteReply(HTTP_OK, strJSON);
750  return true;
751  }
752 
753  default: {
754  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
755  }
756  }
757 }
758 
759 static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
760 {
761  if (!CheckWarmup(req))
762  return false;
763  std::string param;
764  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
765 
766  std::vector<std::string> uriParts;
767  if (param.length() > 1)
768  {
769  std::string strUriParams = param.substr(1);
770  uriParts = SplitString(strUriParams, '/');
771  }
772 
773  // throw exception in case of an empty request
774  std::string strRequestMutable = req->ReadBody();
775  if (strRequestMutable.length() == 0 && uriParts.size() == 0)
776  return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
777 
778  bool fInputParsed = false;
779  bool fCheckMemPool = false;
780  std::vector<COutPoint> vOutPoints;
781 
782  // parse/deserialize input
783  // input-format = output-format, rest/getutxos/bin requires binary input, gives binary output, ...
784 
785  if (uriParts.size() > 0)
786  {
787  //inputs is sent over URI scheme (/rest/getutxos/checkmempool/txid1-n/txid2-n/...)
788  if (uriParts[0] == "checkmempool") fCheckMemPool = true;
789 
790  for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++)
791  {
792  uint256 txid;
793  int32_t nOutput;
794  std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-'));
795  std::string strOutput = uriParts[i].substr(uriParts[i].find('-')+1);
796 
797  if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
798  return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
799 
800  txid.SetHex(strTxid);
801  vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput));
802  }
803 
804  if (vOutPoints.size() > 0)
805  fInputParsed = true;
806  else
807  return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
808  }
809 
810  switch (rf) {
812  // convert hex to bin, continue then with bin part
813  std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
814  strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
815  [[fallthrough]];
816  }
817 
819  try {
820  //deserialize only if user sent a request
821  if (strRequestMutable.size() > 0)
822  {
823  if (fInputParsed) //don't allow sending input over URI and HTTP RAW DATA
824  return RESTERR(req, HTTP_BAD_REQUEST, "Combination of URI scheme inputs and raw post data is not allowed");
825 
826  DataStream oss{};
827  oss << strRequestMutable;
828  oss >> fCheckMemPool;
829  oss >> vOutPoints;
830  }
831  } catch (const std::ios_base::failure&) {
832  // abort in case of unreadable binary data
833  return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
834  }
835  break;
836  }
837 
839  if (!fInputParsed)
840  return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
841  break;
842  }
843  default: {
844  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
845  }
846  }
847 
848  // limit max outpoints
849  if (vOutPoints.size() > MAX_GETUTXOS_OUTPOINTS)
850  return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Error: max outpoints exceeded (max: %d, tried: %d)", MAX_GETUTXOS_OUTPOINTS, vOutPoints.size()));
851 
852  // check spentness and form a bitmap (as well as a JSON capable human-readable string representation)
853  std::vector<unsigned char> bitmap;
854  std::vector<CCoin> outs;
855  std::string bitmapStringRepresentation;
856  std::vector<bool> hits;
857  bitmap.resize((vOutPoints.size() + 7) / 8);
858  ChainstateManager* maybe_chainman = GetChainman(context, req);
859  if (!maybe_chainman) return false;
860  ChainstateManager& chainman = *maybe_chainman;
861  decltype(chainman.ActiveHeight()) active_height;
862  uint256 active_hash;
863  {
864  auto process_utxos = [&vOutPoints, &outs, &hits, &active_height, &active_hash, &chainman](const CCoinsView& view, const CTxMemPool* mempool) EXCLUSIVE_LOCKS_REQUIRED(chainman.GetMutex()) {
865  for (const COutPoint& vOutPoint : vOutPoints) {
866  Coin coin;
867  bool hit = (!mempool || !mempool->isSpent(vOutPoint)) && view.GetCoin(vOutPoint, coin);
868  hits.push_back(hit);
869  if (hit) outs.emplace_back(std::move(coin));
870  }
871  active_height = chainman.ActiveHeight();
872  active_hash = chainman.ActiveTip()->GetBlockHash();
873  };
874 
875  if (fCheckMemPool) {
876  const CTxMemPool* mempool = GetMemPool(context, req);
877  if (!mempool) return false;
878  // use db+mempool as cache backend in case user likes to query mempool
879  LOCK2(cs_main, mempool->cs);
880  CCoinsViewCache& viewChain = chainman.ActiveChainstate().CoinsTip();
881  CCoinsViewMemPool viewMempool(&viewChain, *mempool);
882  process_utxos(viewMempool, mempool);
883  } else {
884  LOCK(cs_main);
885  process_utxos(chainman.ActiveChainstate().CoinsTip(), nullptr);
886  }
887 
888  for (size_t i = 0; i < hits.size(); ++i) {
889  const bool hit = hits[i];
890  bitmapStringRepresentation.append(hit ? "1" : "0"); // form a binary string representation (human-readable for json output)
891  bitmap[i / 8] |= ((uint8_t)hit) << (i % 8);
892  }
893  }
894 
895  switch (rf) {
897  // serialize data
898  // use exact same output as mentioned in Bip64
899  DataStream ssGetUTXOResponse{};
900  ssGetUTXOResponse << active_height << active_hash << bitmap << outs;
901  std::string ssGetUTXOResponseString = ssGetUTXOResponse.str();
902 
903  req->WriteHeader("Content-Type", "application/octet-stream");
904  req->WriteReply(HTTP_OK, ssGetUTXOResponseString);
905  return true;
906  }
907 
909  DataStream ssGetUTXOResponse{};
910  ssGetUTXOResponse << active_height << active_hash << bitmap << outs;
911  std::string strHex = HexStr(ssGetUTXOResponse) + "\n";
912 
913  req->WriteHeader("Content-Type", "text/plain");
914  req->WriteReply(HTTP_OK, strHex);
915  return true;
916  }
917 
919  UniValue objGetUTXOResponse(UniValue::VOBJ);
920 
921  // pack in some essentials
922  // use more or less the same output as mentioned in Bip64
923  objGetUTXOResponse.pushKV("chainHeight", active_height);
924  objGetUTXOResponse.pushKV("chaintipHash", active_hash.GetHex());
925  objGetUTXOResponse.pushKV("bitmap", bitmapStringRepresentation);
926 
927  UniValue utxos(UniValue::VARR);
928  for (const CCoin& coin : outs) {
929  UniValue utxo(UniValue::VOBJ);
930  utxo.pushKV("height", (int32_t)coin.nHeight);
931  utxo.pushKV("value", ValueFromAmount(coin.out.nValue));
932 
933  // include the script in a json output
935  ScriptToUniv(coin.out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
936  utxo.pushKV("scriptPubKey", o);
937  utxos.push_back(utxo);
938  }
939  objGetUTXOResponse.pushKV("utxos", utxos);
940 
941  // return json string
942  std::string strJSON = objGetUTXOResponse.write() + "\n";
943  req->WriteHeader("Content-Type", "application/json");
944  req->WriteReply(HTTP_OK, strJSON);
945  return true;
946  }
947  default: {
948  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
949  }
950  }
951 }
952 
953 static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
954  const std::string& str_uri_part)
955 {
956  if (!CheckWarmup(req)) return false;
957  std::string height_str;
958  const RESTResponseFormat rf = ParseDataFormat(height_str, str_uri_part);
959 
960  int32_t blockheight = -1; // Initialization done only to prevent valgrind false positive, see https://github.com/bitcoin/bitcoin/pull/18785
961  if (!ParseInt32(height_str, &blockheight) || blockheight < 0) {
962  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid height: " + SanitizeString(height_str));
963  }
964 
965  CBlockIndex* pblockindex = nullptr;
966  {
967  ChainstateManager* maybe_chainman = GetChainman(context, req);
968  if (!maybe_chainman) return false;
969  ChainstateManager& chainman = *maybe_chainman;
970  LOCK(cs_main);
971  const CChain& active_chain = chainman.ActiveChain();
972  if (blockheight > active_chain.Height()) {
973  return RESTERR(req, HTTP_NOT_FOUND, "Block height out of range");
974  }
975  pblockindex = active_chain[blockheight];
976  }
977  switch (rf) {
979  DataStream ss_blockhash{};
980  ss_blockhash << pblockindex->GetBlockHash();
981  req->WriteHeader("Content-Type", "application/octet-stream");
982  req->WriteReply(HTTP_OK, ss_blockhash.str());
983  return true;
984  }
986  req->WriteHeader("Content-Type", "text/plain");
987  req->WriteReply(HTTP_OK, pblockindex->GetBlockHash().GetHex() + "\n");
988  return true;
989  }
991  req->WriteHeader("Content-Type", "application/json");
993  resp.pushKV("blockhash", pblockindex->GetBlockHash().GetHex());
994  req->WriteReply(HTTP_OK, resp.write() + "\n");
995  return true;
996  }
997  default: {
998  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
999  }
1000  }
1001 }
1002 
1003 static const struct {
1004  const char* prefix;
1005  bool (*handler)(const std::any& context, HTTPRequest* req, const std::string& strReq);
1006 } uri_prefixes[] = {
1007  {"/rest/tx/", rest_tx},
1008  {"/rest/block/notxdetails/", rest_block_notxdetails},
1009  {"/rest/block/", rest_block_extended},
1010  {"/rest/blockfilter/", rest_block_filter},
1011  {"/rest/blockfilterheaders/", rest_filter_header},
1012  {"/rest/chaininfo", rest_chaininfo},
1013  {"/rest/mempool/", rest_mempool},
1014  {"/rest/headers/", rest_headers},
1015  {"/rest/getutxos", rest_getutxos},
1016  {"/rest/deploymentinfo/", rest_deploymentinfo},
1017  {"/rest/deploymentinfo", rest_deploymentinfo},
1018  {"/rest/blockhashbyheight/", rest_blockhash_by_height},
1019 };
1020 
1021 void StartREST(const std::any& context)
1022 {
1023  for (const auto& up : uri_prefixes) {
1024  auto handler = [context, up](HTTPRequest* req, const std::string& prefix) { return up.handler(context, req, prefix); };
1025  RegisterHTTPHandler(up.prefix, false, handler);
1026  }
1027 }
1028 
1030 {
1031 }
1032 
1033 void StopREST()
1034 {
1035  for (const auto& up : uri_prefixes) {
1036  UnregisterHTTPHandler(up.prefix, false);
1037  }
1038 }
int ret
#define PACKAGE_BUGREPORT
UniValue blockToJSON(BlockManager &blockman, const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, TxVerbosity verbosity)
Block description to JSON.
Definition: blockchain.cpp:164
UniValue blockheaderToJSON(const CBlockIndex *tip, const CBlockIndex *blockindex)
Block header to JSON.
Definition: blockchain.cpp:135
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
BlockFilterType
Definition: blockfilter.h:90
BlockFilterIndex * GetBlockFilterIndex(BlockFilterType filter_type)
Get a block filter index by type.
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
Definition: chain.h:120
Complete block filter struct as defined in BIP 157.
Definition: blockfilter.h:112
const std::vector< unsigned char > & GetEncodedFilter() const LIFETIMEBOUND
Definition: blockfilter.h:135
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
bool LookupFilter(const CBlockIndex *block_index, BlockFilter &filter_out) const
Get a single filter by block.
bool LookupFilterHeader(const CBlockIndex *block_index, uint256 &header_out) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_headers_cache)
Get a single filter header by block.
Definition: block.h:69
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:151
uint256 GetBlockHash() const
Definition: chain.h:259
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
Definition: chain.h:308
An in-memory indexed chain of blocks.
Definition: chain.h:436
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip...
Definition: chain.h:472
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:452
int Height() const
Return the maximal height in the chain.
Definition: chain.h:481
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:466
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:230
Abstract view on the open txout dataset.
Definition: coins.h:174
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:820
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:316
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:405
An output of a transaction.
Definition: transaction.h:158
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:870
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1054
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:975
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1055
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1056
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:981
A UTXO entry.
Definition: coins.h:32
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:186
std::string str() const
Definition: streams.h:207
In-flight HTTP request.
Definition: httpserver.h:57
std::optional< std::string > GetQueryParameter(const std::string &key) const
Get the query parameter value from request uri for a specified key, or std::nullopt if the key is not...
Definition: httpserver.cpp:663
void WriteReply(int nStatus, const std::string &strReply="")
Write HTTP reply.
Definition: httpserver.cpp:592
void WriteHeader(const std::string &hdr, const std::string &value)
Write output header.
Definition: httpserver.cpp:580
std::string ReadBody()
Read request body.
Definition: httpserver.cpp:560
UniValue params
Definition: request.h:33
std::any context
Definition: request.h:38
UniValue HandleRequest(const JSONRPCRequest &request) const
Definition: util.cpp:568
void push_back(UniValue val)
Definition: univalue.cpp:104
@ VOBJ
Definition: univalue.h:21
@ VARR
Definition: univalue.h:21
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:126
void SetHex(const char *psz)
Definition: uint256.cpp:21
std::string GetHex() const
Definition: uint256.cpp:11
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
256-bit opaque blob.
Definition: uint256.h:105
bool ParseHashStr(const std::string &strHex, uint256 &result)
Parse a hex string into 256 bits.
Definition: core_read.cpp:236
TxVerbosity
Verbose level for block's transaction.
Definition: core_io.h:26
@ SHOW_DETAILS_AND_PREVOUT
The same as previous option with information about prevouts if available.
@ SHOW_TXID
Only TXID for each block's transaction.
void ScriptToUniv(const CScript &script, UniValue &out, bool include_hex=true, bool include_address=false, const SigningProvider *provider=nullptr)
Definition: core_write.cpp:150
void TxToUniv(const CTransaction &tx, const uint256 &block_hash, UniValue &entry, bool include_hex=true, int serialize_flags=0, const CTxUndo *txundo=nullptr, TxVerbosity verbosity=TxVerbosity::SHOW_DETAILS)
Definition: core_write.cpp:171
UniValue ValueFromAmount(const CAmount amount)
Definition: core_write.cpp:26
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Unregister handler for prefix.
Definition: httpserver.cpp:704
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Register handler for prefix.
Definition: httpserver.cpp:697
Definition: init.h:25
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const uint256 &hash, uint256 &hashBlock, const BlockManager &blockman)
Return transaction with a given hash.
WalletContext context
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:421
static constexpr unsigned int MAX_REST_HEADERS_RESULTS
Definition: rest.cpp:41
static bool rest_blockhash_by_height(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:953
static ChainstateManager * GetChainman(const std::any &context, HTTPRequest *req)
Get the node context chainstatemanager.
Definition: rest.cpp:119
RESTResponseFormat rf
Definition: rest.cpp:44
static bool rest_block_filter(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:483
static bool rest_getutxos(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:759
static bool rest_headers(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:183
static bool rest_tx(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:700
const char * prefix
Definition: rest.cpp:1004
void StartREST(const std::any &context)
Start HTTP REST subsystem.
Definition: rest.cpp:1021
static bool rest_block_notxdetails(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:355
bool(* handler)(const std::any &context, HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:1005
static const struct @10 uri_prefixes[]
void StopREST()
Stop HTTP REST subsystem.
Definition: rest.cpp:1033
RPCHelpMan getdeploymentinfo()
const char * name
Definition: rest.cpp:45
RPCHelpMan getblockchaininfo()
static CTxMemPool * GetMemPool(const std::any &context, HTTPRequest *req)
Get the node context mempool.
Definition: rest.cpp:102
static bool rest_chaininfo(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:578
void InterruptREST()
Interrupt RPC REST subsystem.
Definition: rest.cpp:1029
static bool rest_deploymentinfo(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:605
static bool RESTERR(HTTPRequest *req, enum HTTPStatusCode status, std::string message)
Definition: rest.cpp:67
static bool rest_mempool(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:644
static const struct @9 rf_names[]
static bool CheckWarmup(HTTPRequest *req)
Definition: rest.cpp:175
static bool rest_block_extended(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:350
static NodeContext * GetNodeContext(const std::any &context, HTTPRequest *req)
Get the node context.
Definition: rest.cpp:81
static bool rest_filter_header(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:360
RESTResponseFormat ParseDataFormat(std::string &param, const std::string &strReq)
Parse a URI to get the data format and URI without data format and query string.
Definition: rest.cpp:133
static bool rest_block(const std::any &context, HTTPRequest *req, const std::string &strURIPart, TxVerbosity tx_verbosity)
Definition: rest.cpp:280
static const size_t MAX_GETUTXOS_OUTPOINTS
Definition: rest.cpp:40
static std::string AvailableDataFormatsString()
Definition: rest.cpp:158
RESTResponseFormat
Definition: rest.h:10
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
Definition: mempool.cpp:672
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
Definition: mempool.cpp:340
HTTPStatusCode
HTTP status codes.
Definition: protocol.h:11
@ HTTP_BAD_REQUEST
Definition: protocol.h:13
@ HTTP_OK
Definition: protocol.h:12
@ HTTP_SERVICE_UNAVAILABLE
Definition: protocol.h:19
@ HTTP_NOT_FOUND
Definition: protocol.h:16
@ HTTP_INTERNAL_SERVER_ERROR
Definition: protocol.h:18
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: util.cpp:73
@ SER_NETWORK
Definition: serialize.h:131
#define READWRITE(...)
Definition: serialize.h:140
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:344
int RPCSerializationFlags()
Definition: server.cpp:598
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
Definition: strencodings.h:65
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:21
Definition: rest.cpp:53
CTxOut out
Definition: rest.cpp:55
CCoin(Coin &&in)
Definition: rest.cpp:58
uint32_t nHeight
Definition: rest.cpp:54
CCoin()
Definition: rest.cpp:57
SERIALIZE_METHODS(CCoin, obj)
Definition: rest.cpp:60
NodeContext struct containing references to chain state and connection state.
Definition: context.h:45
#define LOCK2(cs1, cs2)
Definition: sync.h:259
#define LOCK(cs)
Definition: sync.h:258
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:302
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Definition: txindex.cpp:15
bool ParseInt32(std::string_view str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool IsHex(std::string_view str)
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12