From f3474c7b44d44c6d2ab24450402011d7abcf59db Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Fri, 29 Jun 2018 23:16:06 +0200 Subject: [PATCH] fixes for some bugs in the recent caching functionality --- app/api/coreApi.js | 4 +++- app/api/rpcApi.js | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/api/coreApi.js b/app/api/coreApi.js index 74942e6..bc60685 100644 --- a/app/api/coreApi.js +++ b/app/api/coreApi.js @@ -38,6 +38,9 @@ function tryCacheThenRpcApi(cache, cacheKey, cacheMaxAge, rpcApiFunction) { cache.set(cacheKey, result, cacheMaxAge); resolve(result); + + } else { + resolve(result); } }); } @@ -181,7 +184,6 @@ function getBlocksByHeight(blockHeights) { var combinedBlocks = []; if (blockHeightsNotInCache.length > 0) { rpcApi.getBlocksByHeight(blockHeightsNotInCache).then(function(queriedBlocks) { - console.log("qbs: " + queriedBlocks); var queriedBlocksCurrentIndex = 0; for (var i = 0; i < blockHeights.length; i++) { if (blocksByIndex.hasOwnProperty(i)) { diff --git a/app/api/rpcApi.js b/app/api/rpcApi.js index 1d012c2..791d358 100644 --- a/app/api/rpcApi.js +++ b/app/api/rpcApi.js @@ -31,10 +31,10 @@ function getBlockByHeight(blockHeight) { return new Promise(function(resolve, reject) { getBlocksByHeight([blockHeight]).then(function(results) { if (results && results.length > 0) { - resolve({ success:true, getblock:results[0] }); + resolve(results[0]); } else { - resolve({ success:false }); + resolve(null); } }).catch(function(err) { reject(err); @@ -85,6 +85,8 @@ function getBlockByHash(blockHash) { } function getBlocksByHash(blockHashes) { + console.log("rpc.getBlocksByHash: " + blockHashes); + return new Promise(function(resolve, reject) { var batch = []; for (var i = 0; i < blockHashes.length; i++) { @@ -121,8 +123,12 @@ function getRawTransaction(txid) { return new Promise(function(resolve, reject) { getRawTransactions([txid]).then(function(results) { if (results && results.length > 0) { - resolve(results[0]); + if (results[0].txid) { + resolve(results[0]); + } else { + resolve(null); + } } else { resolve(null); }