From 97d7c6ecded5a5c4a1c3141b9e37fa8329776cb3 Mon Sep 17 00:00:00 2001 From: Sai Raj <39055732+sairajzero@users.noreply.github.com> Date: Fri, 6 Jan 2023 23:02:07 +0530 Subject: [PATCH] Fixed: crashing when unknown block --- lib/services/block/index.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/services/block/index.js b/lib/services/block/index.js index 72f9ed25..c16678db 100644 --- a/lib/services/block/index.js +++ b/lib/services/block/index.js @@ -181,9 +181,19 @@ BlockService.prototype.getRawBlock = function(hash, callback) { if(err) { return callback(err); } - let block_raw = block.toRaw(); - let block_raw_str_hex = block_raw.toString('hex'); - if (!block || typeof block_raw == "undefined" || typeof block_raw_str_hex == "undefined" || block_raw_str_hex == '') { + try{ + if(!block){ + return callback(); + } + let block_raw = block.toRaw(); + if(typeof block_raw == "undefined" || !block_raw){ + return callback(); + } + let block_raw_str_hex = block_raw.toString('hex'); + if(typeof block_raw_str_hex == "undefined" || block_raw_str_hex == ''){ + return callback(); + } + } catch(e){ return callback(); } log.info("Testing getRawBlock " + block_raw_str_hex);