246 {
249
250 http.add_async_handler("/v1/trace_api/get_block",
252 {
253 auto that = wthis.lock();
254 if (!that) {
255 return;
256 }
257
258 auto block_number = ([&body]() -> std::optional<uint32_t> {
259 if (body.empty()) {
260 return {};
261 }
262
263 try {
265 auto block_num = input.get_object()["block_num"].as_uint64();
266 if (block_num > std::numeric_limits<uint32_t>::max()) {
267 return {};
268 }
269 return block_num;
270 } catch (...) {
271 return {};
272 }
273 })();
274
275 if (!block_number) {
278 return;
279 }
280
281 try {
282
283 const auto deadline = that->calc_deadline( max_response_time );
284 auto resp = that->req_handler->get_block_trace(*block_number, [deadline]() {
FC_CHECK_DEADLINE(deadline); });
285 if (resp.is_null()) {
288 } else {
289 cb( 200, std::move(resp) );
290 }
291 } catch (...) {
293 }
294 });
295
296
297 http.add_async_handler("/v1/trace_api/get_transaction_trace",
298 [wthis=weak_from_this(), max_response_time,
this](std::string, std::string body,
url_response_callback cb)
299 {
300 auto that = wthis.lock();
301 if (!that) {
302 return;
303 }
304
305 auto trx_id = ([&body]() -> std::optional<transaction_id_type> {
306 if (body.empty()) {
307 return {};
308 }
309 try {
311 auto trxid = input.get_object()["id"].as_string();
312 if (trxid.size() < 8 || trxid.size() > 64) {
313 return {};
314 }
316 } catch (...) {
317 return {};
318 }
319 })();
320
321 if (!trx_id) {
324 return;
325 }
326
327 try {
328 const auto deadline = that->calc_deadline( max_response_time );
329
330 get_block_n blk_num =
common->store->get_trx_block_number(*trx_id,
common->minimum_irreversible_history_blocks, [deadline]() { FC_CHECK_DEADLINE(deadline); });
331 if (!blk_num.has_value()){
332 error_results results{404,
"Trace API: transaction id missing in the transaction id log files"};
334 } else {
335 auto resp = that->req_handler->get_transaction_trace(*trx_id, *blk_num, [deadline]() {
FC_CHECK_DEADLINE(deadline); });
336 if (resp.is_null()) {
339 } else {
340 cb( 200, std::move(resp) );
341 }
342 }
343 } catch (...) {
345 }
346 });
347 }
abstract_plugin & get_plugin(const string &name) const
static variant from_string(const string &utf8_str, const parse_type ptype=parse_type::legacy_parser, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
static void handle_exception(const char *api_name, const char *call_name, const string &body, url_response_callback cb)
#define FC_CHECK_DEADLINE(DEADLINE,...)
checksum_type transaction_id_type
std::optional< uint32_t > get_block_n
std::function< void(int, fc::variant)> url_response_callback
A callback function provided to a URL handler to allow it to specify the HTTP response code and body.
Structure used to create JSON error responses.